Skip to content

Commit

Permalink
[cker] remove unnecessary function
Browse files Browse the repository at this point in the history
ONE-DCO-1.0-Signed-off-by: JuYoung Lee [email protected]
  • Loading branch information
icodo98 committed Sep 26, 2024
1 parent cbc9d5f commit bca4c85
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 61 deletions.
57 changes: 0 additions & 57 deletions compute/cker/include/cker/train/operation/AvgPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,63 +29,6 @@ namespace cker
{
namespace train
{
inline void AvgPool2D(const PoolParams &params, const Shape &input_shape, const float *input_data,
const Shape &output_shape, float *output_data)
{
assert(input_shape.DimensionsCount() == 4);
assert(output_shape.DimensionsCount() == 4);
const int batches = MatchingDim(input_shape, 0, output_shape, 0);
const int input_height = input_shape.Dims(1);
const int input_width = input_shape.Dims(2);
const int output_height = output_shape.Dims(1);
const int output_width = output_shape.Dims(2);
const int stride_height = params.stride_height;
const int stride_width = params.stride_width;

// TODO(benoitjacob) make this a proper reference impl without Eigen!
const auto in_mat = MapAsMatrixWithLastDimAsRows(input_data, input_shape);
auto out_mat = MapAsMatrixWithLastDimAsRows(output_data, output_shape);

// Prefill the output to 0.
out_mat.setZero();

for (int b = 0; b < batches; ++b)
{
for (int h = 0; h < output_height; ++h)
{
for (int w = 0; w < output_width; ++w)
{
// (h_start, h_end) * (w_start, w_end) is input range
// that output is projected from.
int h_start = h * stride_height - params.padding_values.height;
int h_end = std::min(h_start + params.filter_height, input_height);
h_start = h_start < 0 ? 0 : h_start;

int w_start = w * stride_width - params.padding_values.width;
int w_end = std::min(w_start + params.filter_width, input_width);
w_start = w_start < 0 ? 0 : w_start;

int count = (h_end - h_start) * (w_end - w_start);
if (h_end <= 0 || w_end <= 0 || count <= 0 || h_start >= input_height ||
w_start >= input_width)
continue;

int out_offset = NodeOffset(b, h, w, output_height, output_width);
for (int ph = h_start; ph < h_end; ++ph)
{
for (int pw = w_start; pw < w_end; ++pw)
{
int in_offset = NodeOffset(b, ph, pw, input_height, input_width);
out_mat.col(out_offset) += in_mat.col(in_offset);
}
}
out_mat.col(out_offset) /= count;
}
}
}

out_mat.cwiseMin(params.float_activation_min).cwiseMax(params.float_activation_max);
}

inline void AvgPool2DGrad(const PoolParams &params, const Shape &incoming_shape,
const float *incoming_data, const Shape &grad_shape, float *grad_data)
Expand Down
8 changes: 4 additions & 4 deletions compute/cker/src/train/AvgPool.test.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,8 +48,8 @@ template <typename T> class AvgPoolOpVerifier
assert(expected_output.size() == _out_shape.FlatSize());

std::vector<T> cacluated_output(_out_shape.FlatSize());
nnfw::cker::train::AvgPool2D(_op_params, _in_shape, input.data(), _out_shape,
cacluated_output.data());
nnfw::cker::AveragePool(_op_params, _in_shape, input.data(), _out_shape,
cacluated_output.data());

if (expect_eq)
EXPECT_EQ(expected_output, cacluated_output);
Expand Down Expand Up @@ -231,7 +231,7 @@ TEST(CKer_Operation, AvgPool2D)
}
}

TEST(CKer_Operation, neg_AvgPool)
TEST(CKer_Operation, neg_AvgPoolInvalidExpectedValue)
{
// Invalid expected value
{
Expand Down

0 comments on commit bca4c85

Please sign in to comment.