From 0adcc93d043faf21453b8907894d523167d45fe6 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 30 Jul 2024 10:56:17 +0900 Subject: [PATCH 1/2] [onert] Revisit DepthwiseConv2D nnfw_api test This commit renames test cases to be simple and adds test cases related to Bias and Multiplier. ONE-DCO-1.0-Signed-off-by: Jiyoung Yun --- .../one_op_tests/DepthwiseConv2D.test.cc | 71 ++++++++++++++++--- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc b/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc index 92833244876..f479a35aa58 100644 --- a/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc +++ b/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc @@ -19,27 +19,51 @@ TEST_F(GenModelTest, OneOp_DepthwiseConv2D) { CircleGen cgen; - std::vector weight_data{1, 2, 3, 4, -9, 10, -11, 12, 5, 6, 7, 8, 13, -14, 15, -16}; + std::vector 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}; uint32_t weight_buf = cgen.addBuffer(weight_data); - std::vector bias_data{1, 2, 3, 4}; + std::vector 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, + 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(cgen.finish()); - _context->addTestCase(uniformTCD({{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({{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 weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; + uint32_t weight_buf = cgen.addBuffer(weight_data); + std::vector 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(cgen.finish()); + _context->addTestCase( + uniformTCD({{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 weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; @@ -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 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 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(cgen.finish()); + _context->addTestCase( + uniformTCD({{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 weight_data{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; From fe938052006d115329a7bbe8d5e334f4fc3f0e14 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 1 Aug 2024 11:15:29 +0900 Subject: [PATCH 2/2] Update wrong weight data ONE-DCO-1.0-Signed-off-by: Jiyoung Yun --- .../src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc b/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc index f479a35aa58..6fa173903b0 100644 --- a/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc +++ b/tests/nnfw_api/src/GenModelTests/one_op_tests/DepthwiseConv2D.test.cc @@ -19,8 +19,7 @@ TEST_F(GenModelTest, OneOp_DepthwiseConv2D) { CircleGen cgen; - std::vector 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 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 bias_data{0.0f, 0.0f}; uint32_t bias_buf = cgen.addBuffer(bias_data);