ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_planner::ScratchpadHelperCMSISNN Class Reference

#include <ScratchpadHelperCMSISNN.h>

Collaboration diagram for circle_planner::ScratchpadHelperCMSISNN:

Public Member Functions

 ScratchpadHelperCMSISNN (bool use_dsp)
 
uint32_t ComputeScratchpadSizeAveragePool2d (const luci::CircleAveragePool2D *avg_pool) final
 
std::vector< uint32_t > ComputeScratchpadSizeBatchMatMul (const luci::CircleBatchMatMul *batch_mat_mul) final
 
uint32_t ComputeScratchpadSizeConv2d (const luci::CircleConv2D *conv) final
 
uint32_t ComputeScratchpadSizeDepthwiseConv2d (const luci::CircleDepthwiseConv2D *depthwise_conv) final
 
std::vector< uint32_t > ComputeScratchpadSizeSVDF (const luci::CircleSVDF *svdf) final
 
- Public Member Functions inherited from circle_planner::IScratchpadHelper
virtual ~IScratchpadHelper ()=default
 

Detailed Description

Definition at line 39 of file ScratchpadHelperCMSISNN.h.

Constructor & Destructor Documentation

◆ ScratchpadHelperCMSISNN()

circle_planner::ScratchpadHelperCMSISNN::ScratchpadHelperCMSISNN ( bool  use_dsp)
inlineexplicit

Definition at line 42 of file ScratchpadHelperCMSISNN.h.

42 : _use_dsp(use_dsp)
43 {
44 // Do nothing
45 }

Member Function Documentation

◆ ComputeScratchpadSizeAveragePool2d()

uint32_t circle_planner::ScratchpadHelperCMSISNN::ComputeScratchpadSizeAveragePool2d ( const luci::CircleAveragePool2D avg_pool)
inlinefinalvirtual

Implements circle_planner::IScratchpadHelper.

Definition at line 47 of file ScratchpadHelperCMSISNN.h.

48 {
49 // Main logic of arm_avgpool_s8_get_buffer_size
50
51 const auto avg_pool_input = loco::must_cast<luci::CircleNode *>(avg_pool->value());
52
53 if (avg_pool_input->dtype() != loco::DataType::S8 or !_use_dsp)
54 return 0;
55
56 const auto depth = static_cast<int32_t>(avg_pool_input->dim(3).value());
57
58 return depth * sizeof(int32_t);
59 }
loco::Node * value(void) const

◆ ComputeScratchpadSizeBatchMatMul()

std::vector< uint32_t > circle_planner::ScratchpadHelperCMSISNN::ComputeScratchpadSizeBatchMatMul ( const luci::CircleBatchMatMul batch_mat_mul)
inlinefinalvirtual

Implements circle_planner::IScratchpadHelper.

Definition at line 62 of file ScratchpadHelperCMSISNN.h.

63 {
64 throw std::runtime_error("BatchMatMul is not currently supported for cmsisnn platform");
65 }

◆ ComputeScratchpadSizeConv2d()

uint32_t circle_planner::ScratchpadHelperCMSISNN::ComputeScratchpadSizeConv2d ( const luci::CircleConv2D conv)
inlinefinalvirtual

Implements circle_planner::IScratchpadHelper.

Definition at line 67 of file ScratchpadHelperCMSISNN.h.

68 {
69 // Main logic of arm_convolve_wrapper_s8_get_buffer_size
70
71 const auto dilation_height_factor = static_cast<int32_t>(conv->dilation()->h());
72 const auto dilation_width_factor = static_cast<int32_t>(conv->dilation()->w());
73
74 const auto conv_input = loco::must_cast<luci::CircleNode *>(conv->input());
75 const auto filter = loco::must_cast<luci::CircleNode *>(conv->filter());
76
77 if (dilation_width_factor != 1 or dilation_height_factor != 1 or
78 conv_input->dtype() != loco::DataType::S8)
79 {
80 return 0;
81 }
82
83 const auto input_depth = static_cast<int32_t>(conv_input->dim(3).value());
84
85 const auto input_height = static_cast<int32_t>(conv_input->dim(1).value());
86 const auto input_width = static_cast<int32_t>(conv_input->dim(2).value());
87
88 const auto filter_height = static_cast<int32_t>(filter->dim(1).value());
89 const auto filter_width = static_cast<int32_t>(filter->dim(2).value());
90
91 const auto stride_height = static_cast<int32_t>(conv->stride()->h());
92 const auto stride_width = static_cast<int32_t>(conv->stride()->w());
93
94 const auto output_height = static_cast<int32_t>(conv->dim(1).value());
95 const auto output_width = static_cast<int32_t>(conv->dim(2).value());
96
97 assert(conv_input->quantparam()->zerop.size() == 1);
98 assert(conv->quantparam()->zerop.size() == 1);
99
100 const auto padding_height = computePadding(stride_height, dilation_height_factor, input_height,
101 filter_height, output_height);
102 const auto padding_width =
103 computePadding(stride_width, dilation_width_factor, input_width, filter_width, output_width);
104
105 if ((padding_width == 0) && (padding_height == 0) && (input_depth % 4 == 0) &&
106 (stride_width == 1) && (stride_height == 1) && (filter_width == 1) && (filter_height == 1))
107 {
108 return 0;
109 }
110
111 if (_use_dsp)
112 {
113 return (2 * input_depth * filter_width * filter_height) * sizeof(int16_t);
114 }
115
116 return 0;
117 }
int32_t computePadding(int32_t stride, int32_t dilation_rate, int32_t in_size, int32_t filter_size, int32_t out_size)
Definition Utils.h:41
void conv(const nncc::core::ADT::feature::Shape &out_shape, nncc::core::ADT::feature::Accessor< OutputDType > &out_data, const nncc::core::ADT::feature::Shape &in_shape, const nncc::core::ADT::feature::Reader< InputDType > &in_data, const nncc::core::ADT::kernel::Shape &ker_shape, const nncc::core::ADT::kernel::Reader< KernelDType > &ker_data, const PadInfo &pad_info, const StrideInfo &stride_info)
Definition Conv2D.h:34

◆ ComputeScratchpadSizeDepthwiseConv2d()

uint32_t circle_planner::ScratchpadHelperCMSISNN::ComputeScratchpadSizeDepthwiseConv2d ( const luci::CircleDepthwiseConv2D depthwise_conv)
inlinefinalvirtual

Implements circle_planner::IScratchpadHelper.

Definition at line 120 of file ScratchpadHelperCMSISNN.h.

121 {
122 // Main logic of arm_depthwise_conv_wrapper_s8_get_buffer_size
123
124 const auto dilation_height_factor = static_cast<int32_t>(depthwise_conv->dilation()->h());
125 const auto dilation_width_factor = static_cast<int32_t>(depthwise_conv->dilation()->w());
126
127 const auto depthwise_conv_input = loco::must_cast<luci::CircleNode *>(depthwise_conv->input());
128 const auto filter = loco::must_cast<luci::CircleNode *>(depthwise_conv->filter());
129
130 if (dilation_width_factor != 1 or dilation_height_factor != 1 or
131 depthwise_conv_input->dtype() != loco::DataType::S8)
132 {
133 return 0;
134 }
135
136 const auto input_depth = static_cast<int32_t>(depthwise_conv_input->dim(3).value());
137 const auto output_depth = static_cast<int32_t>(depthwise_conv->dim(3).value());
138 const auto batch_size = static_cast<int32_t>(depthwise_conv_input->dim(0).value());
139
140 if (input_depth != output_depth or batch_size != 1 or !_use_dsp)
141 return 0;
142
143 const auto filter_height = static_cast<int32_t>(filter->dim(1).value());
144 const auto filter_width = static_cast<int32_t>(filter->dim(2).value());
145
146 return input_depth * filter_height * filter_width * sizeof(int16_t);
147 }
loco::Node * filter(void) const
const Dilation * dilation(void) const
loco::Node * input(void) const
uint32_t h() const
uint32_t w() const

◆ ComputeScratchpadSizeSVDF()

std::vector< uint32_t > circle_planner::ScratchpadHelperCMSISNN::ComputeScratchpadSizeSVDF ( const luci::CircleSVDF svdf)
inlinefinalvirtual

Implements circle_planner::IScratchpadHelper.

Definition at line 149 of file ScratchpadHelperCMSISNN.h.

150 {
151 const auto svdf_input = loco::must_cast<luci::CircleNode *>(svdf->input());
152 const auto weight_feature_input = loco::must_cast<luci::CircleNode *>(svdf->weight_feature());
153
154 if (svdf_input->dtype() == loco::DataType::FLOAT32 and
155 (weight_feature_input->dtype() == loco::DataType::S8 or
156 weight_feature_input->dtype() == loco::DataType::U8))
157 {
158 throw std::runtime_error("Hybrid type is not currently supported for linux platform");
159 }
160
161 std::vector<uint32_t> scratchpad_sizes;
162
163 const auto batch_size = svdf_input->dim(0).value();
164 const auto num_filters = weight_feature_input->dim(0).value();
165 const auto rank = svdf->svdf_rank();
166 const auto num_units = num_filters / rank;
167
168 if (svdf_input->dtype() == loco::DataType::S8)
169 {
170 scratchpad_sizes.push_back(batch_size * num_filters * sizeof(int32_t));
171 scratchpad_sizes.push_back(batch_size * num_units * sizeof(int32_t));
172 }
173 else
174 {
175 scratchpad_sizes.push_back(batch_size * num_filters * sizeof(float));
176 }
177
178 return scratchpad_sizes;
179 }
loco::Node * input(void) const
Definition CircleSVDF.h:38
loco::Node * weight_feature(void) const
Definition CircleSVDF.h:41
int32_t svdf_rank() const
Definition CircleSVDF.h:60

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