Skip to content

Commit

Permalink
Feature/json (#1074)
Browse files Browse the repository at this point in the history
* fix topK

---------

Co-authored-by: hejunchao <[email protected]>
Co-authored-by: HeJunchao100813 <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 6544a5c commit e5f39af
Show file tree
Hide file tree
Showing 36 changed files with 284 additions and 176 deletions.
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
52 changes: 31 additions & 21 deletions tests/kernels/test_gather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,47 @@
#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");
init_tensor(input);

int64_t indices_array[] = {0, 0, 1, 1};
indices = hrt::create(dt_int64, {2, 2},
int64_t indices_array[] = {0, 0, -1, -1};
indices = hrt::create(dt_int64, {4},
{reinterpret_cast<gsl::byte *>(indices_array),
sizeof(indices_array)},
true, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");

batchDims_value = value;
int64_t batchDims_array[1] = {value};
batchDims_value = value >= 0
? (size_t)value >= shape.size() ? -1 : value
: -(size_t)value > shape.size() ? -1
: value;

int64_t batchDims_array[1] = {batchDims_value};
batchDims = hrt::create(dt_int64, dims_t{1},
{reinterpret_cast<gsl::byte *>(batchDims_array),
sizeof(batchDims_array)},
true, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
}

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

protected:
runtime_tensor input;
Expand All @@ -62,19 +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,
2} /*, dims_t{3, 5},
dims_t{2, 3, 1}, dims_t{5, 7, 5},
dims_t{5, 4, 3, 2}, dims_t{5, 5, 7, 7},
dims_t{2, 3, 3, 5}*/),
testing::Values(-1, 0, 1)));
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 @@ -112,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();
}
Loading

0 comments on commit e5f39af

Please sign in to comment.