OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::ConvolutionOp Struct Reference

2D convolution operator (NHWC layout) backed by Eigen on CPU and cuDNN on GPU. More...

#include <operators.h>

Inheritance diagram for opennn::ConvolutionOp:
[legend]

Public Member Functions

void set (Index input_h, Index input_w, Index kernels_n, Index kernel_h, Index kernel_w, Index kernel_c, Index row_stride, Index column_stride, Index padding_h, Index padding_w, Type compute_dtype)
 Configures the convolution geometry and compute precision.
 
vector< TensorSpecparameter_specs () const override
 Returns the tensor specs of trainable parameters owned by this operator.
 
void link_parameters (span< const TensorView > views) override
 Binds parameter views provided by the hosting layer.
 
void link_gradients (span< const TensorView > views) override
 Binds gradient views provided by the hosting layer.
 
void set_parameters_random () override
 Initializes parameters with random values.
 
void set_parameters_glorot () override
 Initializes parameters using Glorot (Xavier) initialization.
 
void destroy_cuda () override
 Releases CUDA resources owned by the operator; called from destructors.
 
 ~ConvolutionOp () override
 
 ConvolutionOp ()=default
 
 ConvolutionOp (const ConvolutionOp &)=delete
 
ConvolutionOpoperator= (const ConvolutionOp &)=delete
 
void forward_propagate (ForwardPropagation &fp, size_t layer, bool is_training) noexcept override
 Runs the operator's forward computation.
 
void back_propagate (ForwardPropagation &fp, BackPropagation &bp, size_t layer) const noexcept override
 Runs the operator's backward computation, accumulating into gradient/delta buffers.
 
void apply_cpu (const TensorView &input, TensorView &output)
 CPU forward path; im2col + GEMM.
 
void apply_gpu (const TensorView &input, TensorView &output, cudnnActivationDescriptor_t fused_activation=nullptr)
 GPU forward path; runs cuDNN convolution with an optional fused activation.
 
void apply_delta (const TensorView &input, const TensorView &output_delta, TensorView &input_delta) const
 Computes input_delta from output_delta and updates weight/bias gradients.
 
- Public Member Functions inherited from opennn::Operator
virtual ~Operator ()=default
 
virtual vector< TensorSpecstate_specs () const
 Returns the tensor specs of persistent state owned by this operator.
 
virtual void link_states (span< const TensorView >)
 Binds state views provided by the hosting layer.
 
virtual void to_JSON (JsonWriter &) const
 Serializes the operator configuration to a JSON writer.
 
virtual void from_JSON (const Json *)
 Restores the operator configuration from a JSON node.
 
virtual void load_state_from_JSON (const Json *)
 Restores persistent state (e.g. running statistics) from a JSON node.
 
TensorViewget_input (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
vector< TensorView > & get_inputs (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_output (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_output_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept
 
TensorViewget_input_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept
 

Public Attributes

Index input_height = 0
 
Index input_width = 0
 
Index kernels_number = 0
 
Index kernel_height = 0
 
Index kernel_width = 0
 
Index kernel_channels = 0
 
Index padding_height = 0
 
Index padding_width = 0
 
Type compute_dtype = Type::FP32
 
TensorView weights
 
TensorView bias
 
TensorView weight_gradient
 
TensorView bias_gradient
 
- Public Attributes inherited from opennn::Operator
vector< size_t > input_slots = {0}
 
vector< size_t > output_slots = {1}
 
vector< size_t > input_delta_slots = {1}
 
vector< size_t > output_delta_slots = {0}
 

Detailed Description

2D convolution operator (NHWC layout) backed by Eigen on CPU and cuDNN on GPU.

Constructor & Destructor Documentation

◆ ~ConvolutionOp()

opennn::ConvolutionOp::~ConvolutionOp ( )
inlineoverride

◆ ConvolutionOp() [1/2]

opennn::ConvolutionOp::ConvolutionOp ( )
default

◆ ConvolutionOp() [2/2]

opennn::ConvolutionOp::ConvolutionOp ( const ConvolutionOp & )
delete

Member Function Documentation

◆ apply_cpu()

void opennn::ConvolutionOp::apply_cpu ( const TensorView & input,
TensorView & output )

CPU forward path; im2col + GEMM.

◆ apply_delta()

void opennn::ConvolutionOp::apply_delta ( const TensorView & input,
const TensorView & output_delta,
TensorView & input_delta ) const

Computes input_delta from output_delta and updates weight/bias gradients.

◆ apply_gpu()

void opennn::ConvolutionOp::apply_gpu ( const TensorView & input,
TensorView & output,
cudnnActivationDescriptor_t fused_activation = nullptr )

GPU forward path; runs cuDNN convolution with an optional fused activation.

◆ back_propagate()

void opennn::ConvolutionOp::back_propagate ( ForwardPropagation & fp,
BackPropagation & bp,
size_t layer ) const
overridevirtualnoexcept

Runs the operator's backward computation, accumulating into gradient/delta buffers.

Parameters
fpForward propagation workspace (read-only).
bpBack propagation workspace receiving gradients and deltas.
layerIndex of the hosting layer in the workspace.

Reimplemented from opennn::Operator.

◆ destroy_cuda()

void opennn::ConvolutionOp::destroy_cuda ( )
overridevirtual

Releases CUDA resources owned by the operator; called from destructors.

Reimplemented from opennn::Operator.

◆ forward_propagate()

void opennn::ConvolutionOp::forward_propagate ( ForwardPropagation & fp,
size_t layer,
bool is_training )
overridevirtualnoexcept

Runs the operator's forward computation.

Parameters
fpForward propagation workspace.
layerIndex of the hosting layer in the workspace.
is_trainingIf true, enables training-only behavior (e.g. dropout sampling).

Reimplemented from opennn::Operator.

◆ link_gradients()

void opennn::ConvolutionOp::link_gradients ( span< const TensorView > )
overridevirtual

Binds gradient views provided by the hosting layer.

Reimplemented from opennn::Operator.

◆ link_parameters()

void opennn::ConvolutionOp::link_parameters ( span< const TensorView > )
overridevirtual

Binds parameter views provided by the hosting layer.

Reimplemented from opennn::Operator.

◆ operator=()

ConvolutionOp & opennn::ConvolutionOp::operator= ( const ConvolutionOp & )
delete

◆ parameter_specs()

vector< TensorSpec > opennn::ConvolutionOp::parameter_specs ( ) const
overridevirtual

Returns the tensor specs of trainable parameters owned by this operator.

Reimplemented from opennn::Operator.

◆ set()

void opennn::ConvolutionOp::set ( Index input_h,
Index input_w,
Index kernels_n,
Index kernel_h,
Index kernel_w,
Index kernel_c,
Index row_stride,
Index column_stride,
Index padding_h,
Index padding_w,
Type compute_dtype )

Configures the convolution geometry and compute precision.

Parameters
input_hInput height in pixels.
input_wInput width in pixels.
kernels_nNumber of output channels (kernels).
kernel_hKernel height.
kernel_wKernel width.
kernel_cKernel channel count (matches input channels).
row_strideVertical stride.
column_strideHorizontal stride.
padding_hVertical zero-padding on each side.
padding_wHorizontal zero-padding on each side.
compute_dtypeDtype used for the matmul computation.

◆ set_parameters_glorot()

void opennn::ConvolutionOp::set_parameters_glorot ( )
overridevirtual

Initializes parameters using Glorot (Xavier) initialization.

Reimplemented from opennn::Operator.

◆ set_parameters_random()

void opennn::ConvolutionOp::set_parameters_random ( )
overridevirtual

Initializes parameters with random values.

Reimplemented from opennn::Operator.

Member Data Documentation

◆ bias

TensorView opennn::ConvolutionOp::bias

◆ bias_gradient

TensorView opennn::ConvolutionOp::bias_gradient

◆ compute_dtype

Type opennn::ConvolutionOp::compute_dtype = Type::FP32

◆ input_height

Index opennn::ConvolutionOp::input_height = 0

◆ input_width

Index opennn::ConvolutionOp::input_width = 0

◆ kernel_channels

Index opennn::ConvolutionOp::kernel_channels = 0

◆ kernel_height

Index opennn::ConvolutionOp::kernel_height = 0

◆ kernel_width

Index opennn::ConvolutionOp::kernel_width = 0

◆ kernels_number

Index opennn::ConvolutionOp::kernels_number = 0

◆ padding_height

Index opennn::ConvolutionOp::padding_height = 0

◆ padding_width

Index opennn::ConvolutionOp::padding_width = 0

◆ weight_gradient

TensorView opennn::ConvolutionOp::weight_gradient

◆ weights

TensorView opennn::ConvolutionOp::weights