summaryrefslogtreecommitdiff
path: root/tests/nnfw_api
diff options
context:
space:
mode:
Diffstat (limited to 'tests/nnfw_api')
-rw-r--r--tests/nnfw_api/src/CircleGen.cc2
-rw-r--r--tests/nnfw_api/src/one_op_tests/Conv2D.test.cc51
-rw-r--r--tests/nnfw_api/src/one_op_tests/DepthwiseConv2D.test.cc65
3 files changed, 117 insertions, 1 deletions
diff --git a/tests/nnfw_api/src/CircleGen.cc b/tests/nnfw_api/src/CircleGen.cc
index 4f1c7f9f5..e4601843c 100644
--- a/tests/nnfw_api/src/CircleGen.cc
+++ b/tests/nnfw_api/src/CircleGen.cc
@@ -624,7 +624,7 @@ uint32_t CircleGen::addCustomOperatorCode(std::string custom_code)
flatbuffers::Offset<circle::Buffer> CircleGen::buildBuffer(const uint8_t *buf, size_t size)
{
- if (buf == nullptr && size == 0)
+ if (buf == nullptr || size == 0)
return circle::CreateBuffer(_fbb);
auto buffer = _fbb.CreateVector(buf, size);
return circle::CreateBuffer(_fbb, buffer);
diff --git a/tests/nnfw_api/src/one_op_tests/Conv2D.test.cc b/tests/nnfw_api/src/one_op_tests/Conv2D.test.cc
index dccf2e5b8..46632f18d 100644
--- a/tests/nnfw_api/src/one_op_tests/Conv2D.test.cc
+++ b/tests/nnfw_api/src/one_op_tests/Conv2D.test.cc
@@ -166,6 +166,31 @@ TEST_F(GenModelTest, OneOp_Conv2D_U8_PerChannel)
SUCCEED();
}
+TEST_F(GenModelTest, OneOp_Conv2D_I8_Hybrid_PerChannel)
+{
+ CircleGen cgen;
+ std::vector<int8_t> weight_data{1, 2, 3, 1, 2, 3, 7, 8, 9};
+ uint32_t weight_buf = cgen.addBuffer(weight_data);
+ std::vector<float> bias_data{0, 0, 0};
+ uint32_t bias_buf = cgen.addBuffer(bias_data);
+ int in = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ std::vector<float> weight_scales = {0.5, 1, 0.5};
+ std::vector<int64_t> weight_zeropoints = {0, 0, 0};
+ int weight = cgen.addTensor({{3, 1, 1, 3}, circle::TensorType::TensorType_INT8, weight_buf},
+ weight_scales, weight_zeropoints);
+ int bias = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32, bias_buf});
+ int out = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ cgen.addOperatorConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1,
+ circle::ActivationFunctionType_NONE);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ _context->addTestCase(uniformTCD<float>({{5, 5, 5}}, {{15, 30, 60}}));
+ _context->setBackends({"cpu"});
+
+ SUCCEED();
+}
+
TEST_F(GenModelTest, neg_OneOp_Conv2D_Type)
{
CircleGen cgen;
@@ -276,3 +301,29 @@ TEST_F(GenModelTest, neg_OneOp_Conv2D_I8_NonZero_ZeroPoints)
SUCCEED();
}
+
+TEST_F(GenModelTest, neg_OneOp_Conv2D_I8_Hybrid_PerTensor)
+{
+ CircleGen cgen;
+ std::vector<int8_t> weight_data{1, 2, 3, 4, 5, 6, 7, 8, 9};
+ uint32_t weight_buf = cgen.addBuffer(weight_data);
+ std::vector<float> bias_data{0, 2, 4};
+ uint32_t bias_buf = cgen.addBuffer(bias_data);
+ int in = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ // Hybrid does not support per-tensor.
+ std::vector<float> weight_scales = {0.5};
+ std::vector<int64_t> weight_zeropoints = {0};
+ int weight = cgen.addTensor({{3, 1, 1, 3}, circle::TensorType::TensorType_INT8, weight_buf},
+ weight_scales, weight_zeropoints);
+ int bias = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32, bias_buf});
+ int out = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ cgen.addOperatorConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1,
+ circle::ActivationFunctionType_NONE);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ _context->setBackends({"cpu"});
+ _context->expectFailCompile();
+
+ SUCCEED();
+}
diff --git a/tests/nnfw_api/src/one_op_tests/DepthwiseConv2D.test.cc b/tests/nnfw_api/src/one_op_tests/DepthwiseConv2D.test.cc
index f82d988d5..55f43dcaf 100644
--- a/tests/nnfw_api/src/one_op_tests/DepthwiseConv2D.test.cc
+++ b/tests/nnfw_api/src/one_op_tests/DepthwiseConv2D.test.cc
@@ -203,6 +203,45 @@ TEST_F(GenModelTest, OneOp_DepthwiseConv2D_U8_PerChannel)
SUCCEED();
}
+TEST_F(GenModelTest, OneOp_DepthwiseConv2D_I8_Hybrid_PerChannel)
+{
+ CircleGen cgen;
+ // weight
+ // clang-format off
+ std::vector<int8_t> weight_data{1, 2, 1, 2, -9, 10, -9, 10,
+ 5, 6, 5, 6, 13, -14, 13, -14};
+ // clang-format on
+ uint32_t weight_buf = cgen.addBuffer(weight_data);
+ std::vector<float> weight_scales = {1, 1, 1, 1};
+ std::vector<int64_t> weight_zeropoints = {0, 0, 0, 0};
+ int weight = cgen.addTensor({{1, 2, 2, 4}, circle::TensorType::TensorType_INT8, weight_buf},
+ weight_scales, weight_zeropoints);
+ // bias
+ std::vector<float> bias_data{0, 1, 2, 3};
+ uint32_t bias_buf = cgen.addBuffer(bias_data);
+ int bias = cgen.addTensor({{1, 1, 1, 4}, circle::TensorType::TensorType_FLOAT32, bias_buf});
+
+ // in and out
+ int in = cgen.addTensor({{1, 3, 2, 2}, circle::TensorType::TensorType_FLOAT32});
+ int out = cgen.addTensor({{1, 2, 1, 4}, circle::TensorType::TensorType_FLOAT32});
+
+ cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1, 2,
+ circle::ActivationFunctionType_NONE);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ // clang-format off
+ _context->addTestCase(uniformTCD<float>({{0, 1, 2, 3,
+ 0, 1, 2, 3,
+ 0, 1, 2, 3}},
+ {{8, -7, 20, -1,
+ 8, -7, 20, -1}}));
+ // clang-format on
+ _context->setBackends({"cpu"});
+
+ SUCCEED();
+}
+
TEST_F(GenModelTest, neg_OneOp_DepthwiseConv2D_Stride)
{
CircleGen cgen;
@@ -500,3 +539,29 @@ TEST_F(GenModelTest, neg_OneOp_DepthwiseConv2D_I8_NonZero_ZeroPoints)
SUCCEED();
}
+
+TEST_F(GenModelTest, neg_OneOp_DepthwiseConv2D_I8_Hybrid_PerTensor)
+{
+ // PerTensor Quantized Weight is not supported
+ CircleGen cgen;
+ std::vector<int8_t> weight_data{1, 2, 3};
+ uint32_t weight_buf = cgen.addBuffer(weight_data);
+ std::vector<float> bias_data{0, 2, 4};
+ uint32_t bias_buf = cgen.addBuffer(bias_data);
+ int in = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ // Hybrid does not support per-tensor.
+ std::vector<float> weight_scales = {0.5};
+ std::vector<int64_t> weight_zeropoints = {0};
+ int weight = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_INT8, weight_buf},
+ weight_scales, weight_zeropoints);
+ int bias = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32, bias_buf});
+ int out = cgen.addTensor({{1, 1, 1, 3}, circle::TensorType::TensorType_FLOAT32});
+ cgen.addOperatorDepthwiseConv2D({{in, weight, bias}, {out}}, circle::Padding_VALID, 1, 1,
+ /* depth_multiplier */ 1, circle::ActivationFunctionType_NONE);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ _context->expectFailCompile();
+ _context->setBackends({"cpu"});
+ SUCCEED();
+}