Skip to content

Commit

Permalink
json
Browse files Browse the repository at this point in the history
  • Loading branch information
hejunchao committed Aug 29, 2023
1 parent 6544a5c commit 0022635
Show file tree
Hide file tree
Showing 29 changed files with 160 additions and 93 deletions.
2 changes: 1 addition & 1 deletion tests/kernels/generated/generated_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.expect("create tensor failed"); \
INIT_TENSOR(a1, init_f1); \
} \
void TearDown() override {} \
void TearDown() override { CLEAR_SUBCASE() } \
\
protected: \
runtime_tensor a0; \
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_bucket_pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BucketPadTest : public KernelTest,
.expect("create tensor failed");
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_celu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CeluTest : public KernelTest,
init_tensor_alpha(alpha);
}

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

virtual void init_tensor_alpha(runtime::runtime_tensor &tensor) {
auto dtype = tensor.datatype();
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClampTest : public KernelTest,
max_value = value2;
}

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

protected:
runtime_tensor input;
Expand Down
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]]
}
2 changes: 1 addition & 1 deletion tests/kernels/test_elu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EluTest : public KernelTest,
init_tensor(alpha);
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_erf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ErfTest : public KernelTest,
init_tensor(input);
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_gelu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GeluTest : public KernelTest,
init_tensor_alpha(alpha);
}

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

virtual void init_tensor_alpha(runtime::runtime_tensor &tensor) {
auto dtype = tensor.datatype();
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_get_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GetItemTest
init_tensor(input);
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_hard_sigmoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HardSigmoidTest : public KernelTest,
gamma_value = value2;
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_hard_swish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HardSwishTest : public KernelTest,
.expect("create tensor failed");
}

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

protected:
runtime_tensor input;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/test_hardmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HardmaxTest : public KernelTest,
: 0;
}

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

protected:
runtime_tensor input;
Expand Down
Loading

0 comments on commit 0022635

Please sign in to comment.