From 1c1d3865615a46ab45c1563e720e6a7ca7bb4760 Mon Sep 17 00:00:00 2001
From: Aditya Goel <48102515+adityagoel4512@users.noreply.github.com>
Date: Tue, 4 Apr 2023 21:44:50 +0100
Subject: [PATCH] Adds int32_t and uint32_t clip kernels (#15306)
---
docs/OperatorKernels.md | 4 +-
onnxruntime/core/providers/cpu/math/clip.cc | 2 +-
.../test/providers/cpu/math/clip_test.cc | 38 +++++++++++++++++++
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md
index 336ef560a9..21c5e0c483 100644
--- a/docs/OperatorKernels.md
+++ b/docs/OperatorKernels.md
@@ -54,8 +54,8 @@ Do not modify directly.*
|Ceil|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float)|
|||[6, 12]|**T** = tensor(double), tensor(float)|
|Celu|*in* X:**T**
*out* Y:**T**|12+|**T** = tensor(float)|
-|Clip|*in* input:**T**
*in* min:**T**
*in* max:**T**
*out* output:**T**
or
*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)|
-|||12|**T** = tensor(double), tensor(float), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)|
+|Clip|*in* input:**T**
*in* min:**T**
*in* max:**T**
*out* output:**T**
or
*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint32), tensor(uint64), tensor(uint8)|
+|||12|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint32), tensor(uint64), tensor(uint8)|
|||11|**T** = tensor(float)|
|||[6, 10]|**T** = tensor(float)|
|Col2Im|*in* input:**T**
*in* image_shape:**tensor(int64)**
*in* block_shape:**tensor(int64)**
*out* output:**T**|18+|**T** = tensor(float)|
diff --git a/onnxruntime/core/providers/cpu/math/clip.cc b/onnxruntime/core/providers/cpu/math/clip.cc
index bd7bc5e7c4..2d9c09dd45 100644
--- a/onnxruntime/core/providers/cpu/math/clip.cc
+++ b/onnxruntime/core/providers/cpu/math/clip.cc
@@ -23,7 +23,7 @@ ORT_SPECIFY_OP_KERNEL_ARG_DEFAULT_TYPES(
float);
ORT_SPECIFY_OP_KERNEL_ARG_DEFAULT_TYPES(
kCpuExecutionProvider, kOnnxDomain, Clip, 12, Input, 0,
- float, double, int8_t, uint8_t, int64_t, uint64_t);
+ float, double, int8_t, uint8_t, int32_t, uint32_t, int64_t, uint64_t);
} // namespace op_kernel_type_control
using EnabledClip11Types = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST(
diff --git a/onnxruntime/test/providers/cpu/math/clip_test.cc b/onnxruntime/test/providers/cpu/math/clip_test.cc
index 5b06e2a175..9582c2face 100644
--- a/onnxruntime/test/providers/cpu/math/clip_test.cc
+++ b/onnxruntime/test/providers/cpu/math/clip_test.cc
@@ -123,6 +123,44 @@ TEST(MathOpTest, Clip_Default_uint64) {
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
+TEST(MathOpTest, Clip_int32) {
+ OpTester test("Clip", 12);
+
+ std::vector dims{3, 3};
+ test.AddInput("X", dims,
+ {-1, 0, 1,
+ -16, 12, -6,
+ -5, 2, 16});
+ test.AddInput("min", {}, {-10});
+ test.AddInput("max", {}, {10});
+ test.AddOutput("Y", dims,
+ {-1, 0, 1,
+ -10, 10, -6,
+ -5, 2, 10});
+
+ // TensorRT does not support Clip opset 12 yet.
+ test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
+}
+
+TEST(MathOpTest, Clip_uint32) {
+ OpTester test("Clip", 12);
+
+ std::vector dims{3, 3};
+ test.AddInput("X", dims,
+ {0, 0, 1,
+ 5, 12, 3,
+ 2, 7, 16});
+ test.AddInput("min", {}, {3});
+ test.AddInput("max", {}, {10});
+ test.AddOutput("Y", dims,
+ {3, 3, 3,
+ 5, 10, 3,
+ 3, 7, 10});
+
+ // TensorRT does not support Clip opset 12 yet.
+ test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
+}
+
TEST(MathOpTest, Clip) {
// To test NNAPI EP, we need the min/max to be in initializers
auto run_test = [](bool min_max_are_initializer) {