diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index 1e6318949a..0a387a92fb 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -196,6 +196,8 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Eye class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, float, IsNaN); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, MLFloat16, IsNaN); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Erf); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Sinh); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Cosh); void RegisterOnnxOperatorKernels(std::function fn) { fn(BuildKernel()); @@ -384,6 +386,8 @@ void RegisterOnnxOperatorKernels(std::function fn) { fn(BuildKernel()); fn(BuildKernel()); fn(BuildKernel()); + fn(BuildKernel()); + fn(BuildKernel()); } // Forward declarations of ml op kernels @@ -485,7 +489,7 @@ static void RegisterCPUKernels(std::function create_fn std::shared_ptr CPUExecutionProvider::GetKernelRegistry() const { static std::shared_ptr - kernel_registry = std::make_shared(RegisterCPUKernels); + kernel_registry = std::make_shared(RegisterCPUKernels); return kernel_registry; } @@ -493,7 +497,7 @@ std::vector> CPUExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph, const std::vector& kernel_registries) const { std::vector> - result = IExecutionProvider::GetCapability(graph, kernel_registries); + result = IExecutionProvider::GetCapability(graph, kernel_registries); for (auto& rule : fuse_rules_) { rule(graph, result); diff --git a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc index f2063f5736..1f8324fbef 100644 --- a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc +++ b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc @@ -400,11 +400,10 @@ Status Pow::Compute(OpKernelContext* context) const { std::function, ConstEigenVectorMap, float)> input1scalar = [](EigenVectorMap output, ConstEigenVectorMap input0, float input1) { output = Eigen::pow(input0.array(), input1); }; if (Y.Shape().Size() == 1) { - float value = * Y.Data(); + float value = *Y.Data(); if (value == 2.0) { input1scalar = [](EigenVectorMap output, ConstEigenVectorMap input0, float) { output = Eigen::square(input0.array()); }; - } - else if (value == 3.0) { + } else if (value == 3.0) { input1scalar = [](EigenVectorMap output, ConstEigenVectorMap input0, float) { output = Eigen::cube(input0.array()); }; } } @@ -789,6 +788,46 @@ ONNX_CPU_OPERATOR_KERNEL( KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()), Atan); +template +class Sinh final : public OpKernel { + public: + explicit Sinh(const OpKernelInfo& info) : OpKernel(info) { + } + + Status Compute(OpKernelContext* context) const override { + auto& X = *context->Input(0); + auto& Y = *context->Output(0, X.Shape()); + MakeEigenArrayMap(Y) = MakeEigenArrayMap(X).sinh(); + return Status::OK(); + } +}; + +ONNX_CPU_OPERATOR_KERNEL( + Sinh, + 9, + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()), + Sinh); + +template +class Cosh final : public OpKernel { + public: + explicit Cosh(const OpKernelInfo& info) : OpKernel(info) { + } + + Status Compute(OpKernelContext* context) const override { + auto& X = *context->Input(0); + auto& Y = *context->Output(0, X.Shape()); + MakeEigenArrayMap(Y) = MakeEigenArrayMap(X).cosh(); + return Status::OK(); + } +}; + +ONNX_CPU_OPERATOR_KERNEL( + Cosh, + 9, + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()), + Cosh); + template <> Status PRelu::Compute(OpKernelContext* context) const { return BroadcastTwo( @@ -887,7 +926,6 @@ Status Erf::Compute(OpKernelContext* context) const { ORT_ENFORCE(X_ptr != nullptr); auto& X = *X_ptr; auto& Y = *context->Output(0, X.Shape()); - EigenMap(Y) = EigenMap(X).array().erf(); return Status::OK(); diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 3da5bfefd5..966f674ed9 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -314,8 +314,6 @@ int real_main(int argc, char* argv[]) { {"upsample_nearest", "opset 9 not supported yet"}, {"onehot_with_axis", "opset 9 not supported yet"}, {"onehot_without_axis", "opset 9 not supported yet"}, // also has bug in current test re: output type. Spandan to fix. - {"sinh", "opset 9 not supported yet"}, - {"cosh", "opset 9 not supported yet"}, {"asinh", "opset 9 not supported yet"}, {"acosh", "opset 9 not supported yet"}, {"atanh", "opset 9 not supported yet"}, diff --git a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc index e884554239..fa1b369b2d 100644 --- a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc +++ b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc @@ -163,11 +163,11 @@ TEST(MathOpTest, Sub_int32) { } TEST(MathOpTest, Sub_int64) { - OpTester test("Sub"); - test.AddInput("A", { 3 }, { 1, 5, 6 }); - test.AddInput("B", { 3 }, { 4, 5, 3 }); - test.AddOutput("C", { 3 }, { -3, 0, 3 }); - test.Run(); + OpTester test("Sub"); + test.AddInput("A", {3}, {1, 5, 6}); + test.AddInput("B", {3}, {4, 5, 3}); + test.AddOutput("C", {3}, {-3, 0, 3}); + test.Run(); } TEST(MathOpTest, Sub) { @@ -212,11 +212,11 @@ TEST(MathOpTest, Mul_int32) { } TEST(MathOpTest, Mul_int64) { - OpTester test("Mul"); - test.AddInput("A", { 3 }, { 3, 6, -3 }); - test.AddInput("B", { 3 }, { 4, -3, -2 }); - test.AddOutput("C", { 3 }, { 12, -18, 6 }); - test.Run(); + OpTester test("Mul"); + test.AddInput("A", {3}, {3, 6, -3}); + test.AddInput("B", {3}, {4, -3, -2}); + test.AddOutput("C", {3}, {12, -18, 6}); + test.Run(); } TEST(MathOpTest, Mul) { @@ -246,11 +246,11 @@ TEST(MathOpTest, Div_int32) { } TEST(MathOpTest, Div_int64) { - OpTester test("Div"); - test.AddInput("A", { 3 }, { 4, 8, 8 }); - test.AddInput("B", { 3 }, { 2, 3, 4 }); - test.AddOutput("C", { 3 }, { 2, 2, 2 }); - test.Run(); + OpTester test("Div"); + test.AddInput("A", {3}, {4, 8, 8}); + test.AddInput("B", {3}, {2, 3, 4}); + test.AddOutput("C", {3}, {2, 2, 2}); + test.Run(); } TEST(MathOpTest, Div) { @@ -819,6 +819,16 @@ TEST(MathOpTest, Atan) { TrigTest(test, {-10.0f, -5.0f, 0.0f, 5.0f, 10.0f}); } +TEST(MathOpTest, Sinh) { + OpTester test("Sinh", 9); + TrigTest(test, {-1.0f, -0.5f, 0.0f, 0.5f, 1.0f}); +} + +TEST(MathOpTest, Cosh) { + OpTester test("Cosh", 9); + TrigTest(test, {-1.0f, -0.5f, 0.0f, 0.5f, 1.0f}); +} + TEST(MathOpTest, Expand_8_3x3) { OpTester test("Expand", 8); test.AddInput("data_0", {1}, {1.0f}); diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index 80f7f6c81f..5410c4dbca 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -24,7 +24,6 @@ backend_test.exclude(r'(test_acosh_cpu.*' '|test_atanh_example_cpu.*' '|test_convtranspose_1d_cpu.*' '|test_convtranspose_3d_cpu.*' -'|test_cosh_cpu.*' '|test_cosh_example_cpu.*' '|test_dynamic_slice_cpu.*' '|test_dynamic_slice_default_axes_cpu.*' @@ -43,7 +42,6 @@ backend_test.exclude(r'(test_acosh_cpu.*' '|test_scatter_with_axis_cpu.*' '|test_scatter_without_axis_cpu.*' '|test_sign_cpu.*' -'|test_sinh_cpu.*' '|test_sinh_example_cpu.*' '|test_AvgPool1d_cpu.*' '|test_AvgPool1d_stride_cpu.*'