ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::compute::DepthwiseConv2D Class Reference

#include <DepthwiseConv2D.h>

Public Member Functions

 DepthwiseConv2D ()=default
 
DepthwiseParamsparams (void)
 
void input (const loco::TensorShape &shape, const float *data)
 
void filter (const loco::TensorShape &shape, const float *data)
 
void bias (const loco::TensorShape &shape, const float *data)
 
void fused_act_func (FusedActFunc func)
 
void output (float *data)
 
bool prepare (void)
 
const loco::TensorShapeoutput_shape (void) const
 
void compute (void)
 

Detailed Description

Definition at line 29 of file DepthwiseConv2D.h.

Constructor & Destructor Documentation

◆ DepthwiseConv2D()

luci::compute::DepthwiseConv2D::DepthwiseConv2D ( )
default

Member Function Documentation

◆ bias()

void luci::compute::DepthwiseConv2D::bias ( const loco::TensorShape shape,
const float *  data 
)
inline

Definition at line 49 of file DepthwiseConv2D.h.

50 {
51 _bias_shape = shape;
52 _bias_data = data;
53 }
const T * data(const std::vector< T, Alloc > &v)

References flatbuffers::data().

◆ compute()

void luci::compute::DepthwiseConv2D::compute ( void  )

Definition at line 129 of file DepthwiseConv2D.cpp.

130{
131 assert(_input_data != nullptr);
132 assert(_filter_data != nullptr);
133 // NOTE _bias_shape can be nullptr
134 assert(_output_data != nullptr);
135
136 // NOTE if this fails, structure may have changed
137 static_assert(sizeof(compute::DepthwiseParams) == sizeof(tflite::DepthwiseParams));
138
139 tflite::DepthwiseParams params;
140
141 // clang-format off
163 // clang-format on
164
165 tflite::reference_ops::DepthwiseConv(
166 params, tflite_shape(_input_shape), _input_data, tflite_shape(_filter_shape), _filter_data,
167 tflite_shape(_bias_shape), _bias_data, tflite_shape(_output_shape), _output_data);
168}
DepthwiseParams & params(void)
tflite::PaddingType tflite_padding(const PaddingType type)
tflite::RuntimeShape tflite_shape(const loco::TensorShape &shape)
PaddingValues padding_values
Definition Types.h:56
const int32_t * output_multiplier_per_channel
Definition Types.h:75
const int32_t * output_shift_per_channel
Definition Types.h:76

References luci::compute::DepthwiseParams::depth_multiplier, luci::compute::DepthwiseParams::dilation_height_factor, luci::compute::DepthwiseParams::dilation_width_factor, luci::compute::DepthwiseParams::float_activation_max, luci::compute::DepthwiseParams::float_activation_min, luci::compute::PaddingValues::height, luci::compute::PaddingValues::height_offset, luci::compute::DepthwiseParams::input_offset, luci::compute::DepthwiseParams::output_multiplier, luci::compute::DepthwiseParams::output_multiplier_per_channel, luci::compute::DepthwiseParams::output_offset, luci::compute::DepthwiseParams::output_shift, luci::compute::DepthwiseParams::output_shift_per_channel, luci::compute::DepthwiseParams::padding_type, luci::compute::DepthwiseParams::padding_values, params(), luci::compute::DepthwiseParams::quantized_activation_max, luci::compute::DepthwiseParams::quantized_activation_min, luci::compute::DepthwiseParams::stride_height, luci::compute::DepthwiseParams::stride_width, luci::compute::tflite_padding(), luci::compute::tflite_shape(), luci::compute::DepthwiseParams::weights_offset, luci::compute::PaddingValues::width, and luci::compute::PaddingValues::width_offset.

◆ filter()

void luci::compute::DepthwiseConv2D::filter ( const loco::TensorShape shape,
const float *  data 
)
inline

Definition at line 43 of file DepthwiseConv2D.h.

44 {
45 _filter_shape = shape;
46 _filter_data = data;
47 }

References flatbuffers::data().

◆ fused_act_func()

void luci::compute::DepthwiseConv2D::fused_act_func ( FusedActFunc  func)
inline

Definition at line 55 of file DepthwiseConv2D.h.

55{ _fused_act_func = func; };

◆ input()

void luci::compute::DepthwiseConv2D::input ( const loco::TensorShape shape,
const float *  data 
)
inline

Definition at line 37 of file DepthwiseConv2D.h.

38 {
39 _input_shape = shape;
40 _input_data = data;
41 }

References flatbuffers::data().

◆ output()

void luci::compute::DepthwiseConv2D::output ( float *  data)
inline

Definition at line 57 of file DepthwiseConv2D.h.

57{ _output_data = data; }

References flatbuffers::data().

◆ output_shape()

const loco::TensorShape & luci::compute::DepthwiseConv2D::output_shape ( void  ) const
inline

Definition at line 61 of file DepthwiseConv2D.h.

61{ return _output_shape; }

◆ params()

DepthwiseParams & luci::compute::DepthwiseConv2D::params ( void  )
inline

Definition at line 35 of file DepthwiseConv2D.h.

35{ return _params; }

Referenced by compute().

◆ prepare()

bool luci::compute::DepthwiseConv2D::prepare ( void  )

Definition at line 75 of file DepthwiseConv2D.cpp.

76{
77 // TODO support other ranks if necessary
78 if (_input_shape.rank() != 4 || _filter_shape.rank() != 4)
79 return false;
80 // if bias exist, check if rank is 1
81 if (_bias_data && _bias_shape.rank() != 1)
82 return false;
83
84 auto const input_batches = _input_shape.dim(0).value();
85 auto const input_height = _input_shape.dim(1).value();
86 auto const input_width = _input_shape.dim(2).value();
87 auto const input_depth = _input_shape.dim(3).value();
88
89 auto const filter_height = _filter_shape.dim(1).value();
90 auto const filter_width = _filter_shape.dim(2).value();
91 auto const filter_channels_out = _filter_shape.dim(3).value();
92
93 if (filter_channels_out % input_depth != 0)
94 return false; // wrong input/output depth ratio
95
96 if (_params.depth_multiplier != static_cast<int32_t>(filter_channels_out / input_depth))
97 return false; // wrong depth multiplier value
98
99 if (_bias_shape.dim(0).value() != filter_channels_out)
100 return false; // unsupported bias value
101
102 auto output_height = compute_output(_params.padding_type, input_height, filter_height,
103 _params.stride_height, _params.dilation_height_factor);
104 if (output_height < 0)
105 return false;
106
107 auto output_width = compute_output(_params.padding_type, input_width, filter_width,
108 _params.stride_width, _params.dilation_width_factor);
109 if (output_width < 0)
110 return false;
111
112 get_act_minmax(_fused_act_func, _params.float_activation_min, _params.float_activation_max);
113
114 _output_shape.rank(4);
115 _output_shape.dim(0) = input_batches;
116 _output_shape.dim(1) = output_height;
117 _output_shape.dim(2) = output_width;
118 _output_shape.dim(3) = filter_channels_out;
119
120 _params.padding_values.height =
121 compute_padding(output_height, input_height, filter_height, _params.stride_height,
122 _params.dilation_height_factor);
123 _params.padding_values.width = compute_padding(
124 output_width, input_width, filter_width, _params.stride_width, _params.dilation_width_factor);
125
126 return true;
127}
uint32_t value(void) const
Return the value.
Definition Dimension.h:51
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38
uint32_t rank(void) const
Definition TensorShape.h:35
void get_act_minmax(const FusedActFunc act, float &act_min, float &act_max)

References luci::compute::DepthwiseParams::depth_multiplier, luci::compute::DepthwiseParams::dilation_height_factor, luci::compute::DepthwiseParams::dilation_width_factor, loco::TensorShape::dim(), luci::compute::DepthwiseParams::float_activation_max, luci::compute::DepthwiseParams::float_activation_min, luci::compute::get_act_minmax(), luci::compute::PaddingValues::height, luci::compute::DepthwiseParams::padding_type, luci::compute::DepthwiseParams::padding_values, loco::TensorShape::rank(), luci::compute::DepthwiseParams::stride_height, luci::compute::DepthwiseParams::stride_width, loco::Dimension::value(), and luci::compute::PaddingValues::width.


The documentation for this class was generated from the following files: