Skip to content

Commit

Permalink
Remove train pad function
Browse files Browse the repository at this point in the history
  • Loading branch information
YongseopKim committed Jan 24, 2024
1 parent e8985be commit b04c37a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
25 changes: 6 additions & 19 deletions compute/cker/include/cker/train/operation/Pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,9 @@ namespace train
* -> [C,2,3,C]
* -> [C,C,C,C]
*/
template <typename T>
inline void Pad(const int32_t *padding_data, int32_t pad_rank, const Shape &input_shape,
const T *input_data, const Shape &output_shape, T *output_data,
const T *constant_value_data)
{
// Use nnfw::cker::Pad directly
nnfw::cker::Pad<T>(padding_data, pad_rank, input_shape, input_data, output_shape, output_data,
constant_value_data);
}

/*
* input_data(backward_output_data) will be transformed by backward of PAD operation with padding
* options to output_data(backward_input_data)
* input_data(backward_output_data) will be transformed by backward of PAD operation (Depad) with
* padding options to output_data(backward_input_data)
*
* input_data(backward_output_data) -> output_data(backward_input_data)
* [C,C,C,C] -> [0,1]
Expand Down Expand Up @@ -119,10 +109,9 @@ inline void Depad(const int32_t *padding_data, int32_t pad_rank, const Shape &in
{
for (auto h = 0; h < out_height; ++h)
{
// TODO: Remove unnecessary literal value 0
const auto in_offset =
(d + padding_depth) * in_plain_size + (h + padding_top) * in_width + (0 + padding_left);
const auto out_offset = (d * out_plain_size) + (h * out_width) + (0);
(d + padding_depth) * in_plain_size + (h + padding_top) * in_width + (padding_left);
const auto out_offset = (d * out_plain_size) + (h * out_width);
// copy a row of input data to output data
std::memcpy(output_data + out_offset, input_data + in_offset, out_width * sizeof(T));
}
Expand Down Expand Up @@ -152,12 +141,10 @@ inline void Depad(const int32_t *padding_data, int32_t pad_rank, const Shape &in
{
for (auto h = 0; h < out_height; ++h)
{
// TODO: Remove unnecessary literal value 0
const auto in_offset = (c + padding_cube) * in_cube_size +
(d + padding_depth) * in_plain_size +
(h + padding_top) * in_width + (0 + padding_left);
const auto out_offset =
(c * out_cube_size) + (d * out_plain_size) + (h * out_width) + (0);
(h + padding_top) * in_width + (padding_left);
const auto out_offset = (c * out_cube_size) + (d * out_plain_size) + (h * out_width);
// copy a row of input data to output data
std::memcpy(output_data + out_offset, input_data + in_offset, out_width * sizeof(T));
}
Expand Down
4 changes: 2 additions & 2 deletions compute/cker/src/train/Pad.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ template <typename T> class PadOpVerifier
assert(expected_output.size() == _out_shape.FlatSize());

std::vector<T> cacluated_output(_out_shape.FlatSize());
nnfw::cker::train::Pad(_op_params.data, _op_params.rank, _in_shape, input.data(), _out_shape,
cacluated_output.data(), &_constant_value);
nnfw::cker::Pad(_op_params.data, _op_params.rank, _in_shape, input.data(), _out_shape,
cacluated_output.data(), &_constant_value);

if (expect_eq)
EXPECT_EQ(expected_output, cacluated_output);
Expand Down

0 comments on commit b04c37a

Please sign in to comment.