|
|
|
@ -17,17 +17,17 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include "common/common_test.h"
|
|
|
|
|
#include "mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.h"
|
|
|
|
|
#include "mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.h"
|
|
|
|
|
#include "mindspore/lite/src/kernel_registry.h"
|
|
|
|
|
#include "mindspore/lite/include/context.h"
|
|
|
|
|
|
|
|
|
|
namespace mindspore {
|
|
|
|
|
class TestReluInt8 : public mindspore::Common {
|
|
|
|
|
class TestReluXInt8 : public mindspore::Common {
|
|
|
|
|
public:
|
|
|
|
|
TestReluInt8() {}
|
|
|
|
|
TestReluXInt8() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(TestReluInt8, Relu) {
|
|
|
|
|
TEST_F(TestReluXInt8, Relu) {
|
|
|
|
|
lite::tensor::Tensor in_tensor(kNumberTypeInt8, {2, 2});
|
|
|
|
|
lite::tensor::Tensor out_tensor(kNumberTypeInt8, {2, 2});
|
|
|
|
|
|
|
|
|
@ -68,4 +68,48 @@ TEST_F(TestReluInt8, Relu) {
|
|
|
|
|
in_tensor.SetData(nullptr);
|
|
|
|
|
out_tensor.SetData(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(TestReluXInt8, Relu6) {
|
|
|
|
|
lite::tensor::Tensor in_tensor(kNumberTypeInt8, {2, 4});
|
|
|
|
|
lite::tensor::Tensor out_tensor(kNumberTypeInt8, {2, 4});
|
|
|
|
|
|
|
|
|
|
// -2.5f, -1.5f, 1.25f, 3.0f, 4.5f, 6.0f, 6.5f, 9.0f
|
|
|
|
|
int8_t input_data[] = {-118, -98, -44, -10, 19, 49, 59, 108};
|
|
|
|
|
int8_t output_data[8] = {0};
|
|
|
|
|
in_tensor.SetData(input_data);
|
|
|
|
|
out_tensor.SetData(output_data);
|
|
|
|
|
|
|
|
|
|
const lite::tensor::QuantArg quant_in = {0.0509804f, -69}; // -3.0 -- 10.0
|
|
|
|
|
const lite::tensor::QuantArg quant_out = {0.0392157f, -128}; // 0.0 -- 10.0
|
|
|
|
|
in_tensor.AddQuantParam(quant_in);
|
|
|
|
|
out_tensor.AddQuantParam(quant_out);
|
|
|
|
|
|
|
|
|
|
std::vector<lite::tensor::Tensor *> inputs = {&in_tensor};
|
|
|
|
|
std::vector<lite::tensor::Tensor *> outputs = {&out_tensor};
|
|
|
|
|
|
|
|
|
|
ActivationParameter parameter = {0};
|
|
|
|
|
parameter.op_parameter_.type_ = schema::PrimitiveType_Activation;
|
|
|
|
|
parameter.type_ = schema::ActivationType_RELU6;
|
|
|
|
|
|
|
|
|
|
kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Activation};
|
|
|
|
|
|
|
|
|
|
auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc);
|
|
|
|
|
ASSERT_NE(creator, nullptr);
|
|
|
|
|
|
|
|
|
|
auto ctx = std::make_shared<lite::Context>();
|
|
|
|
|
auto kernel = creator(inputs, outputs, reinterpret_cast<OpParameter *>(¶meter), ctx.get(), desc);
|
|
|
|
|
ASSERT_NE(kernel, nullptr);
|
|
|
|
|
|
|
|
|
|
auto ret = kernel->Run();
|
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
|
|
|
|
|
|
// 0.0f, 0.0f, 1.25f, 3.0f, 4.5f, 6.0f, 6.0f, 6.0f
|
|
|
|
|
int8_t expect[8] = {-128, -128, -96, -52, -14, 25, 25, 25};
|
|
|
|
|
for (int i = 0; i < sizeof(expect); ++i) {
|
|
|
|
|
EXPECT_EQ(output_data[i], expect[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in_tensor.SetData(nullptr);
|
|
|
|
|
out_tensor.SetData(nullptr);
|
|
|
|
|
}
|
|
|
|
|
} // namespace mindspore
|