From f487f6be2577d8b69a1378ff79f71b87c270f3eb Mon Sep 17 00:00:00 2001 From: Pranav Prakash Date: Mon, 24 May 2021 13:19:14 -0700 Subject: [PATCH] Add int8/int32 Relu for Opset 14 (#7536) * Add int8 Relu for Opset 14 * update kernel def hashes and exclude TensorRT for int8 relu Co-authored-by: Hari Vallabhaneni --- .../core/providers/cpu/activation/activations.cc | 2 ++ .../core/providers/cpu/cpu_execution_provider.cc | 6 ++++++ .../providers/cpu/activation/activation_op_test.cc | 6 ++++++ .../test/providers/cpu/activation/activation_op_test.h | 2 ++ .../test/testdata/kernel_def_hashes/onnx.cpu.json | 10 +++++++++- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/activation/activations.cc b/onnxruntime/core/providers/cpu/activation/activations.cc index db14b7c677..2aef903066 100644 --- a/onnxruntime/core/providers/cpu/activation/activations.cc +++ b/onnxruntime/core/providers/cpu/activation/activations.cc @@ -49,6 +49,8 @@ REGISTER_VERSIONED_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 13, 13, float); REGISTER_VERSIONED_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 13, 13, double); REGISTER_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 14, float); REGISTER_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 14, double); +REGISTER_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 14, int8_t); +REGISTER_UNARY_ELEMENTWISE_TYPED_KERNEL(Relu, 14, int32_t); REGISTER_UNARY_ELEMENTWISE_KERNEL(Selu, 6); REGISTER_VERSIONED_UNARY_ELEMENTWISE_TYPED_KERNEL(Sigmoid, 6, 12, float); REGISTER_VERSIONED_UNARY_ELEMENTWISE_TYPED_KERNEL(Sigmoid, 6, 12, double); diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index 11ec495b17..2186d7c2f2 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -665,6 +665,8 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, int64_t, CumSum); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, float, Relu); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, double, Relu); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, int8_t, Relu); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, int32_t, Relu); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, Trilu); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, float, Add); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 14, double, Add); @@ -1777,6 +1779,10 @@ Status RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { Relu)>, BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, diff --git a/onnxruntime/test/providers/cpu/activation/activation_op_test.cc b/onnxruntime/test/providers/cpu/activation/activation_op_test.cc index d49726619b..6167905916 100644 --- a/onnxruntime/test/providers/cpu/activation/activation_op_test.cc +++ b/onnxruntime/test/providers/cpu/activation/activation_op_test.cc @@ -100,6 +100,12 @@ TEST_F(ActivationOpTest, Relu) { TestActivationOp("Relu", input_values_double, [](double x) { return std::max(x, 0.0); }); + TestActivationOp("Relu", + input_values_int8, + [](int8_t x) { return std::max(x, static_cast(0)); }, + {}, + /*is_tensorrt_supported=*/ false, + /*opset_version= */ 14); } TEST_F(ActivationOpTest, Elu) { diff --git a/onnxruntime/test/providers/cpu/activation/activation_op_test.h b/onnxruntime/test/providers/cpu/activation/activation_op_test.h index 5cedc61708..e1078a3946 100644 --- a/onnxruntime/test/providers/cpu/activation/activation_op_test.h +++ b/onnxruntime/test/providers/cpu/activation/activation_op_test.h @@ -82,6 +82,8 @@ class ActivationOpTest : public ::testing::Test { 100.0, -100.0, 1000.0, -1000.0, // input values that leads to exp() overflow DBL_MIN, DBL_MIN / 10, -DBL_MIN / 10, // min, denorm, -denorm DBL_MAX, -DBL_MAX, std::numeric_limits::infinity()}}; // max, -max, inf + std::vector> input_values_int8{{-1, -5, 0, 1, 5, 100, -100, // normal input values for activation + std::numeric_limits::min(), std::numeric_limits::max()}}; // min, max void SetUp() override { float low = -1.0f, high = 1.0f; diff --git a/onnxruntime/test/testdata/kernel_def_hashes/onnx.cpu.json b/onnxruntime/test/testdata/kernel_def_hashes/onnx.cpu.json index 2aa13288f8..7a42831764 100644 --- a/onnxruntime/test/testdata/kernel_def_hashes/onnx.cpu.json +++ b/onnxruntime/test/testdata/kernel_def_hashes/onnx.cpu.json @@ -1999,6 +1999,14 @@ "Relu ai.onnx CPUExecutionProvider", 17992752176767437224 ], + [ + "Relu ai.onnx CPUExecutionProvider", + 800813007613791272 + ], + [ + "Relu ai.onnx CPUExecutionProvider", + 8895401642537447048 + ], [ "Reshape ai.onnx CPUExecutionProvider", 15585679549439997664 @@ -2523,4 +2531,4 @@ "Xor ai.onnx CPUExecutionProvider", 14631049987911195736 ] -] \ No newline at end of file +]