ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
circle_planner::ScratchpadHelperLinux Class Reference

#include <ScratchpadHelperLinux.h>

Collaboration diagram for circle_planner::ScratchpadHelperLinux:

Public Member Functions

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 27 of file ScratchpadHelperLinux.h.

Member Function Documentation

◆ ComputeScratchpadSizeAveragePool2d()

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

Implements circle_planner::IScratchpadHelper.

Definition at line 30 of file ScratchpadHelperLinux.h.

31 {
32 // for linux AveragePool2d scratchpad tensors size = 0
33 return 0;
34 }

◆ ComputeScratchpadSizeBatchMatMul()

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

Implements circle_planner::IScratchpadHelper.

Definition at line 37 of file ScratchpadHelperLinux.h.

38 {
39 const auto lhs = loco::must_cast<luci::CircleNode *>(batch_mat_mul->x());
40 const auto rhs = loco::must_cast<luci::CircleNode *>(batch_mat_mul->y());
41
42 std::vector<uint32_t> scratchpad_sizes;
43
44 // Scratchpad for lhs
45 uint32_t scratchpad_size = 1;
46 for (int32_t i = 0; i < lhs->rank(); ++i)
47 scratchpad_size *= lhs->dim(i).value();
48
49 scratchpad_sizes.push_back(scratchpad_size * luci::size(lhs->dtype()));
50
51 // Scratchpad for rhs
52 scratchpad_size = 1;
53 for (int32_t i = 0; i < rhs->rank(); ++i)
54 scratchpad_size *= rhs->dim(i).value();
55
56 scratchpad_sizes.push_back(scratchpad_size * luci::size(rhs->dtype()));
57
58 return scratchpad_sizes;
59 }
loco::Node * y(void) const
loco::Node * x(void) const
uint32_t size(loco::DataType data_type)
Returns the size of the data type.

References luci::size().

◆ ComputeScratchpadSizeConv2d()

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

Implements circle_planner::IScratchpadHelper.

Definition at line 61 of file ScratchpadHelperLinux.h.

62 {
63 const auto conv_input = loco::must_cast<luci::CircleNode *>(conv->input());
64 const auto filter = loco::must_cast<luci::CircleNode *>(conv->filter());
65
66 const uint32_t stride_height = conv->stride()->h();
67 const uint32_t stride_width = conv->stride()->w();
68
69 const uint32_t dilation_height_factor = conv->dilation()->h();
70 const uint32_t dilation_width_factor = conv->dilation()->w();
71
72 const uint32_t filter_height = filter->dim(1).value();
73 const uint32_t filter_width = filter->dim(2).value();
74
75 const bool need_dilated_im2col = dilation_height_factor != 1 || dilation_width_factor != 1;
76 const bool need_non_dilated_im2col =
77 stride_height != 1 || stride_width != 1 || filter_height != 1 || filter_width != 1;
78 const bool need_im2col = conv_input->dtype() != loco::DataType::S16 &&
79 (need_dilated_im2col || need_non_dilated_im2col);
80
81 if (!need_im2col)
82 {
83 return 0;
84 }
85
86 const uint32_t input_depth = conv_input->dim(3).value();
87 const uint32_t batches = conv_input->dim(0).value();
88
89 const uint32_t output_height = conv->dim(1).value();
90 const uint32_t output_width = conv->dim(2).value();
91
92 return batches * output_height * output_width * input_depth * filter_height * filter_width *
93 size(conv_input->dtype());
94 }
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
int32_t size[5]
Definition Slice.cpp:35

References size.

◆ ComputeScratchpadSizeDepthwiseConv2d()

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

Implements circle_planner::IScratchpadHelper.

Definition at line 97 of file ScratchpadHelperLinux.h.

98 {
99 // for linux DepthwiseConv2d scratchpad tensors size = 0
100 return 0;
101 }

◆ ComputeScratchpadSizeSVDF()

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

Implements circle_planner::IScratchpadHelper.

Definition at line 103 of file ScratchpadHelperLinux.h.

104 {
105 const auto svdf_input = loco::must_cast<luci::CircleNode *>(svdf->input());
106 const auto weight_feature_input = loco::must_cast<luci::CircleNode *>(svdf->weight_feature());
107
108 if (svdf_input->dtype() == loco::DataType::FLOAT32 and
109 (weight_feature_input->dtype() == loco::DataType::S8 or
110 weight_feature_input->dtype() == loco::DataType::U8))
111 {
112 throw std::runtime_error("Hybrid type is not currently supported for linux platform");
113 }
114
115 std::vector<uint32_t> scratchpad_sizes;
116
117 const auto batch_size = svdf_input->dim(0).value();
118 const auto num_filters = weight_feature_input->dim(0).value();
119 const auto rank = svdf->svdf_rank();
120 const auto num_units = num_filters / rank;
121
122 if (svdf_input->dtype() == loco::DataType::S8)
123 {
124 scratchpad_sizes.push_back(batch_size * num_filters * sizeof(int32_t));
125 scratchpad_sizes.push_back(batch_size * num_units * sizeof(int32_t));
126 }
127 else
128 {
129 scratchpad_sizes.push_back(batch_size * num_filters * sizeof(float));
130 }
131
132 return scratchpad_sizes;
133 }
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: