Skip to content

Commit

Permalink
Add checkDeath function to check assert case
Browse files Browse the repository at this point in the history
ONE-DCO-1.0-Signed-off-by: Jiyoung Yun <[email protected]>
  • Loading branch information
jyoungyun committed Aug 6, 2024
1 parent f1e822d commit 1e52d11
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
7 changes: 2 additions & 5 deletions compute/cker/include/cker/operation/DepthwiseConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,8 @@ void DepthwiseConvOp(const DepthwiseConvParams &params, const Shape &input_shape
stride, pad_height, pad_width, output_height, output_width, output_depth, input_data,
filter_data, padded_filter_data, pad_filter, filter_buffers_data, output_data);

if (bias_data != nullptr)
{
bias_op::biasHelper<float>(bias_shape, bias_data, output_shape, output_data, activation_min,
activation_max);
}
bias_op::biasHelper<float>(bias_shape, bias_data, output_shape, output_data, activation_min,
activation_max);
}

} // namespace cker
Expand Down
45 changes: 45 additions & 0 deletions compute/cker/src/DepthwiseConv.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cker/operation/DepthwiseConv.h>

#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include <vector>

namespace
Expand Down Expand Up @@ -84,6 +85,20 @@ template <typename T> class DepthwiseConvVerifier
_filter_buffers.data(), output_shape, output.data()));
}

void checkDeath(const nnfw::cker::DepthwiseConvParams &params,
const nnfw::cker::Shape &input_shape, const T *input_data,
const nnfw::cker::Shape &filter_shape, const T *filter_data,
const nnfw::cker::Shape &bias_shape, const T *bias_data,
const nnfw::cker::Shape &output_shape, const T *expected)
{
std::vector<T> output(output_shape.FlatSize());
EXPECT_DEATH(nnfw::cker::DepthwiseConvOp(params, input_shape, input_data, filter_shape,
filter_data, bias_shape, bias_data,
_padded_filter.data(), _use_padded_filter,
_filter_buffers.data(), output_shape, output.data()),
"");
}

private:
bool _use_padded_filter;
std::vector<T> _padded_filter;
Expand Down Expand Up @@ -272,4 +287,34 @@ TEST(CKer_Operation, neg_DepthwiseConv)
verifier.checkException(params, input_shape, input.data(), filter_shape, filter.data(),
bias_shape, bias.data(), output_shape, expected.data());
}

// No bias data
{
nnfw::cker::DepthwiseConvParams params{};
params.padding_type = nnfw::cker::PaddingType::kSame;
params.padding_values.width = 0;
params.padding_values.height = 1;
params.stride_width = 1;
params.stride_height = 1;
params.dilation_width_factor = 1;
params.dilation_height_factor = 1;
params.depth_multiplier = 1;
params.float_activation_min = std::numeric_limits<float>::lowest();
params.float_activation_max = std::numeric_limits<float>::max();

nnfw::cker::Shape input_shape{1, 6, 6, 1}; // n, h, w, c
std::vector<float> input = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
nnfw::cker::Shape filter_shape{1, 2, 2, 1}; // 1, h, w, c
std::vector<float> filter = {1.0, 2.0, 3.0, 4.0};
nnfw::cker::Shape bias_shape{1};
nnfw::cker::Shape output_shape{1, 3, 3, 1}; // n, h, w, c
std::vector<float> expected = {4.0, 0.0, 3.0, 0.0, 0.0, 0.0, 2.0, 0.0, 1.0};

DepthwiseConvVerifier<float> verifier;
verifier.prepare(output_shape, filter_shape);
verifier.checkDeath(params, input_shape, input.data(), filter_shape, filter.data(), bias_shape,
nullptr, output_shape, expected.data());
}
}

0 comments on commit 1e52d11

Please sign in to comment.