Skip to content

Commit

Permalink
[luci-interpreter] Let PALDepthwiseConv2d cast temporary tensors (Sam…
Browse files Browse the repository at this point in the history
…sung#8072)

This commit lets set data type for temporary tensors in PAL interface for DepthwiseConv2D kernel.

ONE-DCO-1.0-Signed-off-by: Artem Balyshev [email protected]
  • Loading branch information
BalyshevArtem authored Dec 6, 2021
1 parent 04e28bc commit ed89080
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion compiler/luci-interpreter/pal/cmsisnn/PALDepthwiseConv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ inline void DepthwiseConvPerChannel<int8_t>(

static inline void SetupScratchpadTensor(luci_interpreter::Tensor *scratchpad,
const tflite::DepthwiseParams &params,
const luci_interpreter::DataType &input_data_type,
const tflite::RuntimeShape &input_shape,
const tflite::RuntimeShape &filter_shape,
const tflite::RuntimeShape &output_shape)
Expand All @@ -150,6 +151,7 @@ static inline void SetupScratchpadTensor(luci_interpreter::Tensor *scratchpad,

if (dw_conv_params.dilation.h == 1 && dw_conv_params.dilation.w == 1)
{
assert(input_data_type == loco::DataType::S8);
const int batch_size = tflite::MatchingDim(input_shape, 0, output_shape, 0);
const int output_depth = tflite::MatchingDim(filter_shape, 3, output_shape, 3);

Expand All @@ -174,7 +176,9 @@ static inline void SetupScratchpadTensor(luci_interpreter::Tensor *scratchpad,
const int32_t buf_size = arm_depthwise_conv_wrapper_s8_get_buffer_size(
&dw_conv_params, &input_dims, &filter_dims, &output_dims);

luci_interpreter::Shape scratchpad_shape{buf_size};
auto data_type_size = static_cast<int32_t>(luci_interpreter::getDataTypeSize(input_data_type));

luci_interpreter::Shape scratchpad_shape{buf_size * data_type_size};
scratchpad->resize(scratchpad_shape);
}
else
Expand Down
2 changes: 2 additions & 0 deletions compiler/luci-interpreter/pal/linux/PALDepthwiseConv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ inline void DepthwiseConvPerChannel<int8_t>(

static inline void SetupScratchpadTensor(luci_interpreter::Tensor *scratchpad,
const tflite::DepthwiseParams &params,
const luci_interpreter::DataType &input_data_type,
const tflite::RuntimeShape &input_shape,
const tflite::RuntimeShape &filter_shape,
const tflite::RuntimeShape &output_shape)

{
(void)params;
(void)input_data_type;
(void)input_shape;
(void)filter_shape;
(void)output_shape;
Expand Down
2 changes: 2 additions & 0 deletions compiler/luci-interpreter/pal/mcu/PALDepthwiseConv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ inline void DepthwiseConvPerChannel<int8_t>(

static inline void SetupScratchpadTensor(luci_interpreter::Tensor *scratchpad,
const tflite::DepthwiseParams &params,
const luci_interpreter::DataType &input_data_type,
const tflite::RuntimeShape &input_shape,
const tflite::RuntimeShape &filter_shape,
const tflite::RuntimeShape &output_shape)

{
(void)params;
(void)input_data_type;
(void)input_shape;
(void)filter_shape;
(void)output_shape;
Expand Down
5 changes: 3 additions & 2 deletions compiler/luci-interpreter/src/kernels/DepthwiseConv2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ void DepthwiseConv2D::configure()
params.dilation_width_factor = _params.dilation_width_factor;

auto scratchpad = getOutputTensors()[1];
luci_interpreter_pal::SetupScratchpadTensor(scratchpad, params, getTensorShape(input()),
getTensorShape(filter()), getTensorShape(output()));
luci_interpreter_pal::SetupScratchpadTensor(scratchpad, params, input()->element_type(),
getTensorShape(input()), getTensorShape(filter()),
getTensorShape(output()));
}

void DepthwiseConv2D::execute() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ std::unique_ptr<Kernel> build_kernel_CircleDepthwiseConv2D(const luci::CircleNod
params.dilation_width_factor = node->dilation()->w();
params.activation = node->fusedActivationFunction();

auto scratchpad =
std::make_unique<Tensor>(input->element_type(), Shape({}), AffineQuantization{}, "");
// It is unknown what data will be stored in scratchpad tensor,
// using UINT8 as a most general option
auto scratchpad = std::make_unique<Tensor>(DataType::U8, Shape({}), AffineQuantization{}, "");
scratchpad->set_observable(false);
scratchpad->set_data_buffer(nullptr);
// If node has execution plan then read memory offsets for scratchpad temporary tensor
Expand Down

0 comments on commit ed89080

Please sign in to comment.