Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onert] Revisit DepthwiseConv2D nnfw_api test #13559

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,51 @@
TEST_F(GenModelTest, OneOp_DepthwiseConv2D)
{
CircleGen cgen;
std::vector<float> weight_data{1, 2, 3, 4, -9, 10, -11, 12, 5, 6, 7, 8, 13, -14, 15, -16};
std::vector<float> weight_data{1.0f, 2.0f, 3.0f, 4.0f, -9.0f, 10.0f, -11.0f, 12.0f,
5.0f, 6.0f, 7.0f, 8.0f, 13.0f, -14.0f, 15.0f, -16};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why weight shape is {1, 2, 2, 2} and data size is 16?

Suggested change
std::vector<float> weight_data{1.0f, 2.0f, 3.0f, 4.0f, -9.0f, 10.0f, -11.0f, 12.0f,
5.0f, 6.0f, 7.0f, 8.0f, 13.0f, -14.0f, 15.0f, -16};
std::vector<float> weight_data{1.0f, 2.0f, 3.0f, 4.0f, -9.0f, 10.0f, -11.0f, 12.0f};

uint32_t weight_buf = cgen.addBuffer(weight_data);
std::vector<float> bias_data{1, 2, 3, 4};
std::vector<float> bias_data{0.0f, 0.0f};
uint32_t bias_buf = cgen.addBuffer(bias_data);
int in = cgen.addTensor({{1, 3, 2, 2}, circle::TensorType::TensorType_FLOAT32});
int weight = cgen.addTensor({{1, 2, 2, 4}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{4}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int out = cgen.addTensor({{1, 2, 1, 4}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1, 2,
jyoungyun marked this conversation as resolved.
Show resolved Hide resolved
int weight = cgen.addTensor({{1, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{2}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int out = cgen.addTensor({{1, 2, 1, 2}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1, 1,
circle::ActivationFunctionType_NONE);
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12}},
{{71, -34, 99, -20, 91, -26, 127, -4}}));
_context->setBackends({"acl_cl", "acl_neon", "cpu", "xnnpack"});
_context->addTestCase(
uniformTCD<float>({{1.0f, 2.0f, 7.0f, 8.0f, 3.0f, 4.0f, 9.0f, 10.0f, 5.0f, 6.0f, 11.0f, 12.0f}},
{{-104.f, 196.0f, -136.0f, 252.0f}}));
_context->setBackends({"acl_cl", "acl_neon", "cpu", "gpu_cl"});
SUCCEED();
}

TEST_F(GenModelTest, OneOp_DepthwiseConv2D_Padding_SAME)
{
CircleGen cgen;
std::vector<float> weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
uint32_t weight_buf = cgen.addBuffer(weight_data);
std::vector<float> bias_data{0.0f, 0.0f};
uint32_t bias_buf = cgen.addBuffer(bias_data);
int in = cgen.addTensor({{1, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32});
int weight = cgen.addTensor({{1, 3, 1, 2}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{2}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int out = cgen.addTensor({{1, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_SAME, 1, 1, 1,
circle::ActivationFunctionType_NONE);
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(
uniformTCD<float>({{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f}},
{{16.0f, 28.0f, 28.0f, 44.0f, 8.0f, 16.0f, 12.0f, 24.0f}}));
_context->setBackends({"acl_cl", "acl_neon", "cpu", "gpu_cl"});
SUCCEED();
}

TEST_F(GenModelTest, OneOp_DepthwiseConv2D_No_Multiplier)
TEST_F(GenModelTest, OneOp_DepthwiseConv2D_Bias)
{
CircleGen cgen;
std::vector<float> weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
Expand All @@ -62,7 +86,32 @@ TEST_F(GenModelTest, OneOp_DepthwiseConv2D_No_Multiplier)
SUCCEED();
}

TEST_F(GenModelTest, OneOp_DepthwiseConv2D_No_Multiplier_RELU6)
TEST_F(GenModelTest, OneOp_DepthwiseConv2D_Muliplier)
{
CircleGen cgen;
std::vector<float> weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
-5.0f, -4.0f, -3.0f, -2.0f, -1.0f, 0.0};
uint32_t weight_buf = cgen.addBuffer(weight_data);
std::vector<float> bias_data{0.5f, -0.5f, 0.3f, -0.3f};
uint32_t bias_buf = cgen.addBuffer(bias_data);
int in = cgen.addTensor({{1, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32});
int weight = cgen.addTensor({{1, 3, 1, 4}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{4}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int out = cgen.addTensor({{1, 2, 2, 4}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_SAME, 1, 1, 2,
circle::ActivationFunctionType_NONE);
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(
uniformTCD<float>({{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f}},
{{-11.5f, -8.5f, -9.7f, -4.3f, -9.5f, -2.5f, -21.7f, -12.3f, 16.5f, 19.5f,
-22.7f, -17.3f, 24.5f, 31.5f, -28.7f, -19.3f}}));
_context->setBackends({"acl_cl", "acl_neon", "cpu", "gpu_cl"});
SUCCEED();
}

TEST_F(GenModelTest, OneOp_DepthwiseConv2D_RELU6)
{
CircleGen cgen;
std::vector<float> weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
Expand Down