From e62b62015d4a05c3b232dbbffb0399b3d43fd912 Mon Sep 17 00:00:00 2001 From: Chen Xin Date: Mon, 8 Aug 2022 11:26:12 +0800 Subject: [PATCH] Added conv3d unit test Signed-off-by: Chen Xin --- src/tim/vx/ops/conv3d_test.cc | 57 ++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/tim/vx/ops/conv3d_test.cc b/src/tim/vx/ops/conv3d_test.cc index 53ff47e..c9530cb 100644 --- a/src/tim/vx/ops/conv3d_test.cc +++ b/src/tim/vx/ops/conv3d_test.cc @@ -119,7 +119,7 @@ TEST(Conv3d, shape_1_1_2_3_3_float32_simple_cwhdn) { auto final_graph = tim::transform::LayoutInference(graph, ctx); EXPECT_TRUE(final_graph.first->Compile()); - + final_graph.second[input_tensor]->CopyDataToTensor(input_data.data()); EXPECT_TRUE(final_graph.first->Run()); @@ -133,4 +133,59 @@ TEST(Conv3d, shape_1_1_2_3_3_float32_simple_cwhdn) { for (uint32_t idx = 0; idx < golden.size(); idx++) { EXPECT_TRUE(std::abs(golden[idx] - output[idx]) < 0.01); } +} + +TEST(Conv3d, shape_4_2_2_2_1_float32_simple_whdcn) { + auto ctx = tim::vx::Context::Create(); + auto graph = ctx->CreateGraph(); + + tim::vx::ShapeType input_shape({4, 2, 2, 2, 1}); //whdcn + tim::vx::ShapeType weight_shape({2, 2, 2, 2, 2}); //whdIcOc + tim::vx::ShapeType output_shape( + {3, 1, 1, weight_shape[4], input_shape[4]}); //whdcn + + tim::vx::TensorSpec input_spec(tim::vx::DataType::FLOAT32, input_shape, + tim::vx::TensorAttribute::INPUT); + tim::vx::TensorSpec weight_spec(tim::vx::DataType::FLOAT32, weight_shape, + tim::vx::TensorAttribute::CONSTANT); + tim::vx::TensorSpec output_spec(tim::vx::DataType::FLOAT32, output_shape, + tim::vx::TensorAttribute::OUTPUT); + + std::vector input_data = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; + + std::vector weight_data = {-1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, + 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1}; + + // whdcn + std::vector golden = {26, 24, 22, -8, -6, -4}; + + auto input_tensor = graph->CreateTensor(input_spec); + auto weight_tensor = graph->CreateTensor(weight_spec, weight_data.data()); + + auto output_tensor = graph->CreateTensor(output_spec); + + std::array stride({1, 1, 1}); + std::array dilation({1, 1, 1}); + + auto conv3d = graph->CreateOperation( + tim::vx::PadType::VALID, stride, dilation); + (*conv3d) + .BindInput(input_tensor) + .BindInput(weight_tensor) + .BindOutput(output_tensor); + + EXPECT_TRUE(graph->Compile()); + + input_tensor->CopyDataToTensor(input_data.data()); + + EXPECT_TRUE(graph->Run()); + + uint32_t output_size = 1; + for (auto i : output_tensor->GetShape()) { + output_size *= i; + } + std::vector output(output_size); + EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data())); + EXPECT_EQ(output,golden); } \ No newline at end of file