Loading...
Searching...
No Matches
convolution_operator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 Artificial Intelligence Techniques, S.L. and Roberto López González
3
4#pragma once
5
7
8namespace opennn
9{
10
12{
13 Index input_height = 0;
14 Index input_width = 0;
15
16 Index kernels_number = 0;
17 Index kernel_height = 0;
18 Index kernel_width = 0;
19 Index kernel_channels = 0;
20 Index row_stride = 1;
21 Index column_stride = 1;
22
23 Index padding_height = 0;
24 Index padding_width = 0;
25
26 bool use_bias = true;
27
31
34
35 bool fuse_relu = false;
36
37 bool weights_relinked = true;
38
39 struct ConvGraphCache;
40
41 unique_ptr<ConvGraphCache> conv_graph_cache;
42
43#ifdef OPENNN_HAS_CUDA
44
45 void apply_gpu_folded(const TensorView& input,
46 const TensorView& folded_weights,
47 const TensorView& folded_bias,
48 bool relu, TensorView& output,
49 const TensorView* residual = nullptr) const;
50#endif
51
52 vector<TensorSpec> parameter_specs() const override;
53 vector<SlotQuantization> parameter_quantization() const override;
54 vector<ParameterSlot> parameter_slots() override;
55 void link_parameters(span<const TensorView>) override;
56 void link_parameter_scales(span<const TensorView>) override;
57
58 void set_parameters_random() override;
59 void set_parameters_glorot() override;
60
62
66
68 void back_propagate(ForwardPropagation&, BackPropagation&, size_t) const override;
69
70private:
71 void apply_cpu(const TensorView&, TensorView&) const;
72 void apply_gpu(const TensorView&, TensorView&) const;
73
74 // Lower bound on what a convolution has to move: read the input, read the
75 // weights, write the output. cuDNN may move more depending on the algorithm
76 // it picks -- an implicit-GEMM pass over a workspace, say -- but never less,
77 // so a scope reporting a high fraction of peak against this is genuinely
78 // bandwidth-bound while a low one only says the bound is loose.
79 double minimum_traffic_bytes(const TensorView& input, const TensorView& output) const;
80
81 void apply_delta_cpu(const TensorView&, const TensorView&,
82 TensorView&) const;
83 void apply_delta_gpu(const TensorView&, const TensorView&,
84 TensorView&, const TensorView&) const;
85};
86
87}
Definition configuration.h:10
ForwardPropagationMode
Definition forward_propagation.h:33
Definition back_propagation.h:19
ConvolutionOperator & operator=(const ConvolutionOperator &)=delete
void link_parameters(span< const TensorView >) override
ConvolutionOperator(const ConvolutionOperator &)=delete
Index padding_width
Definition convolution_operator.h:24
void back_propagate(ForwardPropagation &, BackPropagation &, size_t) const override
void forward_propagate(ForwardPropagation &, size_t, ForwardPropagationMode) override
Index kernel_height
Definition convolution_operator.h:17
Index input_width
Definition convolution_operator.h:14
Index column_stride
Definition convolution_operator.h:21
Index padding_height
Definition convolution_operator.h:23
bool use_bias
Definition convolution_operator.h:26
TensorView bias_gradient
Definition convolution_operator.h:33
void set_parameters_random() override
Index input_height
Definition convolution_operator.h:13
TensorView bias
Definition convolution_operator.h:29
Index kernels_number
Definition convolution_operator.h:16
TensorView weights
Definition convolution_operator.h:28
bool weights_relinked
Definition convolution_operator.h:37
vector< ParameterSlot > parameter_slots() override
bool fuse_relu
Definition convolution_operator.h:35
unique_ptr< ConvGraphCache > conv_graph_cache
Definition convolution_operator.h:41
void link_parameter_scales(span< const TensorView >) override
TensorView weight_gradient
Definition convolution_operator.h:32
Index kernel_channels
Definition convolution_operator.h:19
Index kernel_width
Definition convolution_operator.h:18
vector< SlotQuantization > parameter_quantization() const override
TensorView weight_scale
Definition convolution_operator.h:30
void apply_gpu_folded(const TensorView &input, const TensorView &folded_weights, const TensorView &folded_bias, bool relu, TensorView &output, const TensorView *residual=nullptr) const
Index row_stride
Definition convolution_operator.h:20
void set_parameters_glorot() override
vector< TensorSpec > parameter_specs() const override
Definition forward_propagation.h:52
Definition operator.h:28
Definition tensor_types.h:540