From fa72b2a5fa15c1081b7498f193579483f80c8548 Mon Sep 17 00:00:00 2001 From: hariharans29 Date: Wed, 14 Aug 2019 19:36:25 -0700 Subject: [PATCH] Support int64 for ReduceMax --- .../providers/cpu/cpu_execution_provider.cc | 2 ++ .../providers/cpu/reduction/reduction_ops.cc | 9 +++++++++ .../cpu/reduction/reduction_ops_test.cc | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index bb95212533216..e1cc287775d50 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -132,6 +132,7 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, int32_t, ReduceLogSumExp); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, ReduceMax); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, int32_t, ReduceMax); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, int64_t, ReduceMax); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, ReduceMean); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, int32_t, ReduceMean); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, float, ReduceMin); @@ -412,6 +413,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, diff --git a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc index 8c9143a238868..f0a4de9358dcd 100644 --- a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc +++ b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc @@ -30,11 +30,20 @@ namespace onnxruntime { KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()), \ x); +#define REGISTER_UNARY_ELEMENTWISE_KERNEL_INT64_ONLY(x, sinceVersion) \ + ONNX_CPU_OPERATOR_TYPED_KERNEL( \ + x, \ + sinceVersion, \ + int64_t, \ + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()), \ + x); + REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceL1, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceL2, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceLogSum, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceLogSumExp, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceMax, 1); +REGISTER_UNARY_ELEMENTWISE_KERNEL_INT64_ONLY(ReduceMax, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceMean, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceMin, 1); REGISTER_UNARY_ELEMENTWISE_KERNEL(ReduceProd, 1); diff --git a/onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc b/onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc index 3a7e0ad762067..826993af21873 100644 --- a/onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc +++ b/onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc @@ -471,6 +471,23 @@ TEST(ReductionOpTest, ReduceMax_int32) { test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); //TensorRT: axis must be 0 } +TEST(ReductionOpTest, ReduceMax_int64) { + OpTester test("ReduceMax"); + test.AddAttribute("axes", std::vector{1, 2}); + test.AddAttribute("keepdims", (int64_t)1); + test.AddInput("data", {3, 2, 2}, + {1, 2, + 3, 4, + + 5, 6, + 7, 8, + + 9, 10, + 11, 12}); + test.AddOutput("reduced", {3, 1, 1}, {4, 8, 12}); + test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); //TensorRT: axis must be 0 +} + TEST(ReductionOpTest, ReduceMean_default_axes_keepdims) { OpTester test("ReduceMean"); test.AddAttribute("keepdims", (int64_t)1);