Skip to content

Commit

Permalink
fix the act test's case (#1032)
Browse files Browse the repository at this point in the history
Co-authored-by: hejunchao <[email protected]>
  • Loading branch information
HeJunchao100813 and hejunchao authored Aug 2, 2023
1 parent b375636 commit 92d5ccc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
15 changes: 9 additions & 6 deletions tests/kernels/test_celu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

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

input = hrt::create(typecode, input_shape,
host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(input);

alpha = alpha_value;
}

void TearDown() override {}

protected:
runtime_tensor input;
float_t alpha;
};

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -51,11 +54,11 @@ INSTANTIATE_TEST_SUITE_P(
testing::Values(dims_t{1}, dims_t{1, 2},
dims_t{1, 3, 16, 16}, dims_t{16, 16},
dims_t{3, 16}, dims_t{1, 3, 16, 1},
dims_t{})));
dims_t{}),
testing::Values(1.2f, 0.8f)));

TEST_P(CeluTest, celu) {
auto input_ort = runtime_tensor_2_ort_tensor(input);
auto alpha = 1.2f;

// expected
auto output_ort = ortki_Celu(input_ort, alpha);
Expand Down
15 changes: 9 additions & 6 deletions tests/kernels/test_elu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,38 @@ using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

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

input =
hrt::create(typecode, l_shape, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(input);

alpha = alpha_value;
}

void TearDown() override {}

protected:
runtime_tensor input;
float_t alpha;
};

INSTANTIATE_TEST_SUITE_P(
elu, EluTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{1, 3, 16, 16}, dims_t{1},
dims_t{8, 8}, dims_t{1, 4, 16},
dims_t{1, 3, 24, 24}, dims_t{})));
dims_t{1, 3, 24, 24}, dims_t{}),
testing::Values(1.2f, 0.8f)));

TEST_P(EluTest, elu) {
auto l_ort = runtime_tensor_2_ort_tensor(input);
auto alpha = 0.8f;

// expected
auto output_ort = ortki_Elu(l_ort, alpha);
Expand Down
16 changes: 10 additions & 6 deletions tests/kernels/test_gelu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,41 @@ using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

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

input =
hrt::create(typecode, l_shape, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(input);

a = a_value;
}

void TearDown() override {}

protected:
runtime_tensor input;
float_t a;
};

INSTANTIATE_TEST_SUITE_P(
gelu, GeluTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{1, 3, 16, 16}, dims_t{1},
dims_t{8, 8}, dims_t{1, 4, 16},
dims_t{1, 3, 24, 24}, dims_t{})));
dims_t{1, 3, 24, 24}, dims_t{}),
testing::Values(1.2f, 0.8f, 0.5f)));

TEST_P(GeluTest, gelu) {
auto l_ort = runtime_tensor_2_ort_tensor(input);

// expected
float_t a_ptr[] = {0.5f};
float_t a_ptr[] = {a};
auto a = hrt::create(nncase::dt_float32, {1},
{reinterpret_cast<gsl::byte *>(a_ptr), sizeof(a_ptr)},
true, host_runtime_tensor::pool_cpu_only)
Expand Down
21 changes: 14 additions & 7 deletions tests/kernels/test_hard_sigmoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,56 @@ using namespace ortki;

class HardSigmoidTest
: public KernelTest,
public ::testing::TestWithParam<std::tuple<nncase::typecode_t, dims_t>> {
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, float_t, float_t>> {
public:
void SetUp() override {
auto &&[typecode, l_shape] = GetParam();
auto &&[typecode, l_shape, value1, value2] = GetParam();

input =
hrt::create(typecode, l_shape, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(input);

alpha_value = value1;
gamma_value = value2;
}

void TearDown() override {}

protected:
runtime_tensor input;
float_t alpha_value;
float_t gamma_value;
};

INSTANTIATE_TEST_SUITE_P(
hard_sigmoid, HardSigmoidTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{1, 3, 16, 16}, dims_t{1},
dims_t{1, 3}, dims_t{1, 3, 16},
dims_t{})));
dims_t{1, 3}, dims_t{1, 3, 16}, dims_t{}),
testing::Values(1.2f, 0.8f, 0.5f, 0.6f),
testing::Values(1.2f, 0.8f, 0.5f, 0.6f)));

TEST_P(HardSigmoidTest, hard_sigmoid) {
auto l_ort = runtime_tensor_2_ort_tensor(input);

// expected
float_t alpha_ptr[] = {0.5f};
float_t alpha_ptr[] = {alpha_value};
auto alpha = hrt::create(nncase::dt_float32, {1},
{reinterpret_cast<gsl::byte *>(alpha_ptr),
sizeof(alpha_ptr)},
true, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");

float_t gamma_ptr[] = {0.6f};
float_t gamma_ptr[] = {gamma_value};
auto gamma = hrt::create(nncase::dt_float32, {1},
{reinterpret_cast<gsl::byte *>(gamma_ptr),
sizeof(gamma_ptr)},
true, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");

auto output_ort = ortki_HardSigmoid(l_ort, 0.5f, 0.6f);
auto output_ort = ortki_HardSigmoid(l_ort, alpha_value, gamma_value);
size_t size = 0;
void *ptr_ort = tensor_buffer(output_ort, &size);
dims_t shape(tensor_rank(output_ort));
Expand Down
19 changes: 12 additions & 7 deletions tests/kernels/test_selu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,41 @@ using namespace nncase;
using namespace nncase::runtime;
using namespace ortki;

class SeluTest
: public KernelTest,
public ::testing::TestWithParam<std::tuple<nncase::typecode_t, dims_t>> {
class SeluTest : public KernelTest,
public ::testing::TestWithParam<
std::tuple<nncase::typecode_t, dims_t, float_t, float_t>> {
public:
void SetUp() override {
auto &&[typecode, l_shape] = GetParam();
auto &&[typecode, l_shape, value1, value2] = GetParam();

input =
hrt::create(typecode, l_shape, host_runtime_tensor::pool_cpu_only)
.expect("create tensor failed");
init_tensor(input);

alpha_value = value1;
gamma_value = value2;
}

void TearDown() override {}

protected:
runtime_tensor input;
float_t alpha_value;
float_t gamma_value;
};

INSTANTIATE_TEST_SUITE_P(
Selu, SeluTest,
testing::Combine(testing::Values(dt_float32),
testing::Values(dims_t{1, 3, 16, 16}, dims_t{1, 3, 16},
dims_t{1, 3}, dims_t{1}, dims_t{8, 8},
dims_t{})));
dims_t{}),
testing::Values(1.2f, 0.8f, 0.5f, 0.6f, 1.5f),
testing::Values(1.2f, 0.8f, 0.5f, 0.6f, 1.5f)));

TEST_P(SeluTest, Selu) {
auto l_ort = runtime_tensor_2_ort_tensor(input);
auto alpha_value = 1.5f;
auto gamma_value = 1.5f;

// expected
float_t alpha_ptr[] = {alpha_value};
Expand Down

0 comments on commit 92d5ccc

Please sign in to comment.