Skip to content

Commit

Permalink
Merge branch 'master' into feature/add_new_dt
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/kernels/test_gather.cpp
  • Loading branch information
hejunchao committed Aug 30, 2023
2 parents 8bae082 + e5f39af commit 3b15330
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 147 deletions.
64 changes: 43 additions & 21 deletions tests/kernels/test_conv2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
#include <nncase/runtime/stackvm/opcode.h>
#include <ortki/operators.h>

#define TEST_CASE_NAME "test_conv2d"

using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

class Conv2DTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, dims_t, dims_t,
dims_t, dims_t, dims_t, int64_t>> {
public ::testing::TestWithParam<std::tuple<int>> {
public:
void SetUp() override {
auto &&[typecode, input_shape, weight_shape, bias_shape, value1, value2,
value3, value4] = GetParam();
READY_SUBCASE()

auto typecode = GetDataType("lhs_type");
auto input_shape = GetShapeArray("lhs_shape");
auto weight_shape = GetShapeArray("weight_shape");
auto bias_shape = GetShapeArray("bias_shape");
dilations_value = GetShapeArray("dilations_value");
pad_value = GetShapeArray("pad_value");
strides_value = GetShapeArray("strides_value");
group_value = GetNumber("group_value");

input = hrt::create(typecode, input_shape,
host_runtime_tensor::pool_cpu_only)
Expand All @@ -49,14 +57,9 @@ class Conv2DTest : public KernelTest,
host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(bais);

dilations_value = value1;
pad_value = value2;
strides_value = value3;
group_value = value4;
}

void TearDown() override {}
void TearDown() override { CLEAR_SUBCASE() }

protected:
runtime_tensor input;
Expand All @@ -68,16 +71,8 @@ class Conv2DTest : public KernelTest,
int64_t group_value;
};

INSTANTIATE_TEST_SUITE_P(
conv2d, Conv2DTest,
testing::Combine(
testing::Values(dt_float32),
testing::Values(dims_t{1, 4, 5, 5}, dims_t{1, 4, 16, 16}),
testing::Values(dims_t{8, 4, 3, 3}, dims_t{8, 4, 1, 1}),
testing::Values(dims_t{8}), testing::Values(dims_t{2, 2}, dims_t{1, 1}),
testing::Values(dims_t{1, 1, 1, 1} /*, dims_t{0, 0, 1, 0}*/),
testing::Values(dims_t{1, 1}, dims_t{2, 2}),
testing::Values(1 /*, 2*/))); // todo result error
INSTANTIATE_TEST_SUITE_P(conv2d, Conv2DTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(Conv2DTest, conv2d) {
auto input_ort = runtime_tensor_2_ort_tensor(input);
Expand Down Expand Up @@ -181,6 +176,33 @@ TEST_P(Conv2DTest, conv2d) {
}

int main(int argc, char *argv[]) {
READY_TEST_CASE_GENERATE()
FOR_LOOP(lhs_type, i)
FOR_LOOP(lhs_shape, j)
FOR_LOOP(weight_shape, k)
FOR_LOOP(bias_shape, l)
FOR_LOOP(dilations_value, m)
FOR_LOOP(pad_value, n)
FOR_LOOP(strides_value, o)
FOR_LOOP(group_value, p)
SPLIT_ELEMENT(lhs_type, i)
SPLIT_ELEMENT(lhs_shape, j)
SPLIT_ELEMENT(weight_shape, k)
SPLIT_ELEMENT(bias_shape, l)
SPLIT_ELEMENT(dilations_value, m)
SPLIT_ELEMENT(pad_value, n)
SPLIT_ELEMENT(strides_value, o)
SPLIT_ELEMENT(group_value, p)
WRITE_SUB_CASE()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
10 changes: 10 additions & 0 deletions tests/kernels/test_conv2d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"lhs_type":["dt_float32"],
"lhs_shape":[[1, 4, 5, 5], [1, 4, 16, 16]],
"weight_shape":[[8, 4, 3, 3], [8, 4, 1, 1]],
"bias_shape":[[8]],
"dilations_value":[[2, 2], [1, 1]],
"pad_value":[[1, 1, 1, 1]],
"strides_value":[[1, 1], [2, 2]],
"group_value":[1]
}
87 changes: 51 additions & 36 deletions tests/kernels/test_conv2d_transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@
#include <nncase/runtime/stackvm/opcode.h>
#include <ortki/operators.h>

#define TEST_CASE_NAME "test_conv2d_transpose"

using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

class Conv2DTransposeTest
: public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, dims_t, dims_t, dims_t, dims_t,
dims_t, int64_t, dims_t, dims_t>> {
class Conv2DTransposeTest : public KernelTest,
public ::testing::TestWithParam<std::tuple<int>> {
public:
void SetUp() override {
auto &&[typecode, input_shape, weight_shape, bias_shape, value1, value2,
value3, value4, value5, value6] = GetParam();
READY_SUBCASE()

auto typecode = GetDataType("lhs_type");
auto input_shape = GetShapeArray("lhs_shape");
auto weight_shape = GetShapeArray("weight_shape");
auto bias_shape = GetShapeArray("bias_shape");
dilations_value = GetShapeArray("dilations_value");
pad_value = GetShapeArray("pad_value");
strides_value = GetShapeArray("strides_value");
group_value = GetNumber("group_value");
output_padding_value = GetShapeArray("output_padding_value");
output_shape_value = GetShapeArray("output_shape_value");

input = hrt::create(typecode, input_shape,
host_runtime_tensor::pool_cpu_only)
Expand All @@ -50,16 +59,9 @@ class Conv2DTransposeTest
host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(bais);

dilations_value = value1;
pad_value = value2;
strides_value = value3;
group_value = value4;
output_padding_value = value5;
output_shape_value = value6;
}

void TearDown() override {}
void TearDown() override { CLEAR_SUBCASE() }

protected:
runtime_tensor input;
Expand All @@ -73,16 +75,8 @@ class Conv2DTransposeTest
int64_t group_value;
};

INSTANTIATE_TEST_SUITE_P(
conv2d_transpose, Conv2DTransposeTest,
testing::Combine(
testing::Values(dt_float32), testing::Values(dims_t{1, 1, 5, 5}),
testing::Values(dims_t{1, 2, 3, 3}), testing::Values(dims_t{2}),
testing::Values(/*dims_t{2, 2} ,*/ dims_t{1, 1}),
testing::Values(dims_t{1, 1, 1, 1} /*, dims_t{0, 0, 1, 0}*/),
testing::Values(dims_t{1, 1} /*, dims_t{2, 2}*/),
testing::Values(1 /*, 2*/), testing::Values(dims_t{0, 0}),
testing::Values(dims_t{1, 2, 5, 5})));
INSTANTIATE_TEST_SUITE_P(conv2d_transpose, Conv2DTransposeTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(Conv2DTransposeTest, conv2d_transpose) {
auto input_ort = runtime_tensor_2_ort_tensor(input);
Expand Down Expand Up @@ -210,17 +204,38 @@ TEST_P(Conv2DTransposeTest, conv2d_transpose) {
}

int main(int argc, char *argv[]) {
// READY_TEST_CASE_GENERATE()
// FOR_LOOP(lhs_shape, i)
// FOR_LOOP(lhs_type, j)
// FOR_LOOP(rhs_type, k)
// SPLIT_ELEMENT(lhs_shape, i)
// SPLIT_ELEMENT(lhs_type, j)
// SPLIT_ELEMENT(rhs_type, k)
// WRITE_SUB_CASE()
// FOR_LOOP_END()
// FOR_LOOP_END()
// FOR_LOOP_END()
READY_TEST_CASE_GENERATE()
FOR_LOOP(lhs_type, i)
FOR_LOOP(lhs_shape, j)
FOR_LOOP(weight_shape, k)
FOR_LOOP(bias_shape, l)
FOR_LOOP(dilations_value, m)
FOR_LOOP(pad_value, n)
FOR_LOOP(strides_value, o)
FOR_LOOP(group_value, p)
FOR_LOOP(output_padding_value, r)
FOR_LOOP(output_shape_value, s)
SPLIT_ELEMENT(lhs_type, i)
SPLIT_ELEMENT(lhs_shape, j)
SPLIT_ELEMENT(weight_shape, k)
SPLIT_ELEMENT(bias_shape, l)
SPLIT_ELEMENT(dilations_value, m)
SPLIT_ELEMENT(pad_value, n)
SPLIT_ELEMENT(strides_value, o)
SPLIT_ELEMENT(group_value, p)
SPLIT_ELEMENT(output_padding_value, r)
SPLIT_ELEMENT(output_shape_value, s)
WRITE_SUB_CASE()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
12 changes: 10 additions & 2 deletions tests/kernels/test_conv2d_transpose.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"lhs_shape":[[1, 8, 24, 24], [1, 3, 3, 16], [2, 4, 8, 8], [8, 8], [1, 3, 16, 1], [1, 1], [16]],
"lhs_type":["dt_int32"]
"lhs_type":["dt_float32"],
"lhs_shape":[[1, 1, 5, 5]],
"weight_shape":[[1, 2, 3, 3]],
"bias_shape":[[2]],
"dilations_value":[[1, 1]],
"pad_value":[[1, 1, 1, 1]],
"strides_value":[[1, 1]],
"group_value":[1],
"output_padding_value":[[0, 0]],
"output_shape_value":[[1, 2, 5, 5]]
}
37 changes: 23 additions & 14 deletions tests/kernels/test_gather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@
#include <nncase/runtime/stackvm/opcode.h>
#include <ortki/operators.h>

#define TEST_CASE_NAME "test_gather"

using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

class GatherTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, int64_t>> {
public ::testing::TestWithParam<std::tuple<int>> {
public:
void SetUp() override {
auto &&[typecode, shape, value] = GetParam();
READY_SUBCASE()

auto shape = GetShapeArray("lhs_shape");
auto value = GetNumber("axis");
auto typecode = GetDataType("lhs_type");

input = hrt::create(typecode, shape, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
Expand All @@ -57,7 +62,7 @@ class GatherTest : public KernelTest,
.expect("create tensor failed");
}

void TearDown() override {}
void TearDown() override { CLEAR_SUBCASE() }

protected:
runtime_tensor input;
Expand All @@ -66,16 +71,8 @@ class GatherTest : public KernelTest,
int64_t batchDims_value;
};

INSTANTIATE_TEST_SUITE_P(
gather, GatherTest,
testing::Combine(testing::Values(dt_int32, dt_int64, dt_float32, dt_uint64,
dt_int8, dt_int16, dt_uint8, dt_uint16,
dt_uint32, dt_float16, dt_float64,
dt_bfloat16, dt_boolean),
testing::Values(dims_t{2, 3, 5, 7}, dims_t{2, 2},
dims_t{2, 3, 1}, dims_t{5, 5, 7, 7},
dims_t{11}),
testing::Values(-1, 0, 1, -2, -3, 2, 3, -4)));
INSTANTIATE_TEST_SUITE_P(gather, GatherTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(GatherTest, gather) {
auto input_ort = runtime_tensor_2_ort_tensor(input);
Expand Down Expand Up @@ -113,6 +110,18 @@ TEST_P(GatherTest, gather) {
}

int main(int argc, char *argv[]) {
READY_TEST_CASE_GENERATE()
FOR_LOOP(lhs_shape, i)
FOR_LOOP(axis, j)
FOR_LOOP(lhs_type, k)
SPLIT_ELEMENT(lhs_shape, i)
SPLIT_ELEMENT(axis, j)
SPLIT_ELEMENT(lhs_type, k)
WRITE_SUB_CASE()
FOR_LOOP_END()
FOR_LOOP_END()
FOR_LOOP_END()

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 5 additions & 0 deletions tests/kernels/test_gather.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lhs_shape":[[2, 3, 5, 7], [2, 2], [2, 3, 1], [5, 5, 7, 7], [11]],
"axis":[0, 1, -1, 2, 3, -2, -3, -4],
"lhs_type":["dt_float32", "dt_int8", "dt_int32", "dt_uint8", "dt_int16", "dt_uint16", "dt_uint32", "dt_uint64", "dt_int64", "dt_float16", "dt_float64", "dt_bfloat16", "dt_boolean"]
}
Loading

0 comments on commit 3b15330

Please sign in to comment.