Skip to content

Commit

Permalink
Merge branch 'master' into fix-batch-to-space
Browse files Browse the repository at this point in the history
  • Loading branch information
lerenhua authored Aug 17, 2023
2 parents 4b545ff + e5d305d commit de819a6
Show file tree
Hide file tree
Showing 116 changed files with 1,569 additions and 671 deletions.
5 changes: 5 additions & 0 deletions tests/kernels/kernel_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,11 @@ class KernelTest {
return _document[key].GetInt64();
}

float GetFloatNumber(const char *key) {
assert(_document[key].IsDouble());
return _document[key].GetFloat();
}

typecode_t GetDataType(const char *key) {
assert(_document[key].IsString());
return Str2DataType(_document[key].GetString());
Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/macro_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
host_runtime_tensor::pool_cpu_only) \
.expect("create expected tensor failed");

#define MAX_CASE_NUM 100
#define MAX_CASE_NUM 10000
#define ENDFIX ".json"
#define PARENT_DIR_1 "../../../tests/kernels/"
#define PARENT_DIR_2 "../../../../tests/kernels/"
Expand Down
28 changes: 19 additions & 9 deletions tests/kernels/test_batch_normalization.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_batch_normalization"

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

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

auto input_shape = GetShapeArray("lhs_shape");
auto typecode = GetDataType("lhs_type");

input = hrt::create(typecode, input_shape,
host_runtime_tensor::pool_cpu_only)
Expand Down Expand Up @@ -59,7 +64,7 @@ class BatchNormalizationTest
init_tensor_var(var);
}

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

virtual void init_tensor_var(runtime::runtime_tensor &tensor) {
std::random_device rd;
Expand All @@ -80,12 +85,8 @@ class BatchNormalizationTest
runtime_tensor var;
};

INSTANTIATE_TEST_SUITE_P(
batch_normalization, BatchNormalizationTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{1, 8, 24, 24}, dims_t{1, 3, 3, 16},
dims_t{2, 4, 8, 8}, dims_t{8, 8},
dims_t{1, 3, 16, 1}, dims_t{1, 1})));
INSTANTIATE_TEST_SUITE_P(batch_normalization, BatchNormalizationTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(BatchNormalizationTest, batch_normalization) {
auto input_ort = runtime_tensor_2_ort_tensor(input);
Expand Down Expand Up @@ -145,6 +146,15 @@ TEST_P(BatchNormalizationTest, batch_normalization) {
}

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

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
4 changes: 4 additions & 0 deletions tests/kernels/test_batch_normalization.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"lhs_shape":[[1, 8, 24, 24], [1, 3, 3, 16], [2, 4, 8, 8], [8, 8], [1, 3, 16, 1], [1, 1]],
"lhs_type":["dt_float32"]
}
29 changes: 22 additions & 7 deletions tests/kernels/test_batch_to_space.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_batch_to_space"

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

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

auto input_shape = GetShapeArray("lhs_shape");
auto expect_shape = GetShapeArray("rhs_shape");
auto typecode = GetDataType("lhs_type");

input = hrt::create(typecode, input_shape,
host_runtime_tensor::pool_cpu_only)
Expand All @@ -44,17 +49,15 @@ class BatchToSpaceTest : public KernelTest,
init_tensor(expect);
}

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

protected:
runtime_tensor input;
runtime_tensor expect;
};

INSTANTIATE_TEST_SUITE_P(BatchToSpace, BatchToSpaceTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{4, 1, 2, 2}),
testing::Values(dims_t{1, 1, 4, 4})));
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(BatchToSpaceTest, BatchToSpace) {

Expand Down Expand Up @@ -105,6 +108,18 @@ TEST_P(BatchToSpaceTest, BatchToSpace) {
}

int main(int argc, char *argv[]) {
READY_TEST_CASE_GENERATE()
FOR_LOOP(lhs_shape, i)
FOR_LOOP(rhs_shape, j)
FOR_LOOP(lhs_type, k)
SPLIT_ELEMENT(lhs_shape, i)
SPLIT_ELEMENT(rhs_shape, 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_batch_to_space.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lhs_shape":[[4, 1, 2, 2]],
"rhs_shape":[[1, 1, 4, 4]],
"lhs_type":["dt_float32"]
}
5 changes: 5 additions & 0 deletions tests/kernels/test_broad_cast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lhs_shape":[[3], [1, 3], [2, 4, 8, 8], [8, 8], [1, 3, 16, 1], [1, 1]],
"rhs_shape":[[1, 8, 24, 24], [1, 3, 3, 16], [2, 4, 8, 8], [8, 8], [1, 3, 16, 1], [1, 1]],
"lhs_type":["dt_float32", "dt_float64", "dt_int32", "dt_int64", "dt_float16"]
}
35 changes: 23 additions & 12 deletions tests/kernels/test_broadcast.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_broad_cast"

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

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

auto typecode = GetDataType("lhs_type");
auto l_shape = GetShapeArray("lhs_shape");
auto r_shape = GetShapeArray("rhs_shape");

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

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

void init_tensor_one(runtime::runtime_tensor &tensor) {
auto dtype = tensor.datatype();
Expand Down Expand Up @@ -176,14 +181,8 @@ class BroadCastTest : public KernelTest,
runtime_tensor new_shape;
};

INSTANTIATE_TEST_SUITE_P(
BroadCast, BroadCastTest,
testing::Combine(testing::Values(dt_float32, dt_float64, dt_int32, dt_int64,
dt_float16),
testing::Values(dims_t{3}, dims_t{1, 3}, dims_t{3, 3},
dims_t{1}, dims_t{1, 3, 1}),
testing::Values(dims_t{1, 3, 3}, dims_t{1, 3, 3, 3},
dims_t{1, 3, 16, 16})));
INSTANTIATE_TEST_SUITE_P(BroadCast, BroadCastTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(BroadCastTest, BroadCast) {

Expand Down Expand Up @@ -219,6 +218,18 @@ TEST_P(BroadCastTest, BroadCast) {
}

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

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
33 changes: 23 additions & 10 deletions tests/kernels/test_cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
#include <nncase/runtime/stackvm/opcode.h>
#include <ortki/operators.h>

#define TEST_CASE_NAME "test_cast"

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

class CastTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, typecode_t, dims_t>> {
public ::testing::TestWithParam<std::tuple<int>> {
public:
void SetUp() override {
auto &&[typecode_input, typecode_output, l_shape] = GetParam();
READY_SUBCASE()

auto typecode_input = GetDataType("lhs_type");
auto typecode_output = GetDataType("rhs_type");
auto l_shape = GetShapeArray("i_shape");

input = hrt::create(typecode_input, l_shape,
host_runtime_tensor::pool_cpu_only)
Expand All @@ -54,7 +59,7 @@ class CastTest : public KernelTest,
.expect("create tensor failed");
}

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

protected:
runtime_tensor input;
Expand All @@ -63,12 +68,8 @@ class CastTest : public KernelTest,
runtime_tensor expected;
};

INSTANTIATE_TEST_SUITE_P(
cast, CastTest,
testing::Combine(testing::Values(dt_int16, dt_int8, dt_float32, dt_uint8),
testing::Values(dt_int16, dt_int8, dt_float32, dt_uint8),
testing::Values(dims_t{1, 3, 16, 16}, dims_t{1, 3, 8, 8},
dims_t{1, 3, 1})));
INSTANTIATE_TEST_SUITE_P(cast, CastTest,
testing::Combine(testing::Range(0, MAX_CASE_NUM)));

TEST_P(CastTest, cast) {
// actual
Expand Down Expand Up @@ -138,6 +139,18 @@ TEST_P(CastTest, cast) {
}

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()

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 5 additions & 0 deletions tests/kernels/test_cast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lhs_shape":[[1, 8, 24, 24], [1, 3, 3, 16], [2, 4, 8, 8], [8, 8], [1, 3, 16, 1], [1, 1]],
"lhs_type":["dt_int16", "dt_float32", "dt_uint8", "dt_int8"],
"rhs_type":["dt_int16", "dt_float32", "dt_uint8", "dt_int8"]
}
4 changes: 2 additions & 2 deletions tests/kernels/test_celu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace ortki;

class CeluTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, float_t>> {
std::tuple<nncase::typecode_t, dims_t, float>> {
public:
void SetUp() override {
auto &&[typecode, input_shape, alpha_value] = GetParam();
Expand All @@ -45,7 +45,7 @@ class CeluTest : public KernelTest,

protected:
runtime_tensor input;
float_t alpha;
float alpha;
};

INSTANTIATE_TEST_SUITE_P(
Expand Down
11 changes: 5 additions & 6 deletions tests/kernels/test_clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

class ClampTest
: public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, float_t, float_t>> {
class ClampTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, float, float>> {
public:
void SetUp() override {
auto &&[typecode, l_shape, value1, value2] = GetParam();
Expand All @@ -47,8 +46,8 @@ class ClampTest

protected:
runtime_tensor input;
float_t min_value;
float_t max_value;
float min_value;
float max_value;
};

INSTANTIATE_TEST_SUITE_P(
Expand Down
Loading

0 comments on commit de819a6

Please sign in to comment.