From 0d6416c0e9eb9ba537890d0fe3f695693a08a8fe Mon Sep 17 00:00:00 2001 From: Linnea May Date: Wed, 17 May 2023 13:27:49 -0700 Subject: [PATCH] DML EP Bitwise operators opset 18 (#15892) ### Description Add dml registration for bitwise and, or, xor and not added in opset 18. ### Motivation and Context --------- Co-authored-by: Linnea May --- docs/OperatorKernels.md | 4 + .../src/Operators/DmlOperatorElementWise.cpp | 16 +- .../src/Operators/OperatorRegistration.cpp | 9 + .../dml/OperatorAuthorHelper/OperatorHelper.h | 4 + .../OperatorAuthorHelper/OperatorVersions.h | 4 + .../cpu/math/element_wise_ops_test.cc | 288 +++++++++++++++++- .../cpu/object_detection/roialign_test.cc | 4 +- 7 files changed, 308 insertions(+), 21 deletions(-) diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md index 73b12eeb8e..71a6a3afeb 100644 --- a/docs/OperatorKernels.md +++ b/docs/OperatorKernels.md @@ -880,6 +880,10 @@ Do not modify directly.* |||9+|**T** = tensor(float), tensor(float16)| |||7+|**T** = tensor(float), tensor(float16)| |BitShift|*in* X:**T**
*in* Y:**T**
*out* Z:**T**|11+|**T** = tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|BitwiseAnd|*in* A:**T**
*in* B:**T**
*out* C:**T**|18+|**T** = tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|BitwiseNot|*in* X:**T**
*out* Y:**T**|18+|**T** = tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|BitwiseOr|*in* A:**T**
*in* B:**T**
*out* C:**T**|18+|**T** = tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|BitwiseXor|*in* A:**T**
*in* B:**T**
*out* C:**T**|18+|**T** = tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |Cast|*in* input:**T1**
*out* output:**T2**|13+|**T1** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||9+|**T1** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||6+|**T1** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorElementWise.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorElementWise.cpp index c1507cf1dc..43d3465709 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorElementWise.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorElementWise.cpp @@ -89,7 +89,7 @@ void SetFusedActivation(T& opDesc, const DML_OPERATOR_DESC* fusedActivation) template<> void SetFusedActivation(DML_ELEMENT_WISE_ADD1_OPERATOR_DESC& opDesc, const DML_OPERATOR_DESC* fusedActivation) -{ +{ opDesc.FusedActivation = fusedActivation; } @@ -118,7 +118,7 @@ public: DML_OPERATOR_DESC opDescDesc = { ApiTraits::OperatorDescTraits::Type, &opDesc}; if (fusedActivation != std::nullopt) - { + { // Activation is only fused for two-input sum operators ORT_THROW_HR_IF(E_INVALIDARG, opDescDesc.Type != DML_OPERATOR_ELEMENT_WISE_ADD1 || kernelInfo.GetInputCount() > 2); @@ -160,7 +160,7 @@ public: std::optional fusedActivation = FusionHelpers::TryGetFusedActivationDesc(kernelInfo); DML_OPERATOR_DESC fusedActivationDmlDesc = fusedActivation ? fusedActivation->GetDmlDesc() : DML_OPERATOR_DESC(); - + // Activation is only fused for two-input sum operators ORT_THROW_HR_IF(E_INVALIDARG, fusedActivation != std::nullopt && inputCount != 2); @@ -294,7 +294,7 @@ public: meanDesc.ATensor = &inputDescs[0]; meanDesc.BTensor = &inputDescs[1]; meanDesc.OutputTensor = &outputDescs[0]; - + SetDmlOperatorDesc({ DML_OPERATOR_ELEMENT_WISE_MEAN, &meanDesc}, kernelInfo); } else @@ -447,7 +447,7 @@ public: opDesc.OutputTensor = outputDescs.data(); // MinMaxDataType will always be equal to inputDataTensorDataType // Assigning minMaxDataType to inputDataTensorDataType because this field - // has to be assigned even if program does not go through below conditional + // has to be assigned even if program does not go through below conditional // logic for some corner test case // Same applies to min and max value. opDesc.MinMaxDataType = this->m_inputTensorDescs[0].GetDmlDataType(); @@ -458,7 +458,7 @@ public: { ReadScalarTensorData(kernelInfo.GetConstantInputTensor(1), /*out*/ &opDesc.Min.Bytes, sizeof(opDesc.Min.Bytes)); } - if (kernelInfo.IsInputValid(2)) + if (kernelInfo.IsInputValid(2)) { ReadScalarTensorData(kernelInfo.GetConstantInputTensor(2), /*out*/ &opDesc.Max.Bytes, sizeof(opDesc.Max.Bytes)); } @@ -720,6 +720,7 @@ DML_OP_DEFINE_CREATION_FUNCTION(Asinh, DmlOperatorElementwiseUnary); DML_OP_DEFINE_CREATION_FUNCTION(Atanh, DmlOperatorElementwiseUnary); DML_OP_DEFINE_CREATION_FUNCTION(Erf, DmlOperatorElementwiseUnary); +DML_OP_DEFINE_CREATION_FUNCTION(BitwiseNot, DmlOperatorElementwiseUnary); // Binary operators: DML_OP_DEFINE_CREATION_FUNCTION(Greater, DmlOperatorElementwiseBinary); @@ -734,6 +735,9 @@ DML_OP_DEFINE_CREATION_FUNCTION(Add, DmlOperatorElementwiseBinary); DML_OP_DEFINE_CREATION_FUNCTION(Mul, DmlOperatorElementwiseBinary); DML_OP_DEFINE_CREATION_FUNCTION(Div, DmlOperatorElementwiseBinary); +DML_OP_DEFINE_CREATION_FUNCTION(BitwiseAnd, DmlOperatorElementwiseBinary); +DML_OP_DEFINE_CREATION_FUNCTION(BitwiseOr, DmlOperatorElementwiseBinary); +DML_OP_DEFINE_CREATION_FUNCTION(BitwiseXor, DmlOperatorElementwiseBinary); // Binary operators that support >2 inputs: DML_OP_DEFINE_CREATION_FUNCTION(Sum, DmlOperatorElementwiseBinaryLoop); diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp index 83df19b5b6..667298d93c 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp @@ -441,6 +441,10 @@ DML_OP_EXTERN_CREATION_FUNCTION(Size); DML_OP_EXTERN_CREATION_FUNCTION(Attention); DML_OP_EXTERN_CREATION_FUNCTION(NonZero); DML_OP_EXTERN_CREATION_FUNCTION(QuickGelu); +DML_OP_EXTERN_CREATION_FUNCTION(BitwiseAnd); +DML_OP_EXTERN_CREATION_FUNCTION(BitwiseOr); +DML_OP_EXTERN_CREATION_FUNCTION(BitwiseXor); +DML_OP_EXTERN_CREATION_FUNCTION(BitwiseNot); DML_OP_EXTERN_QUERY_FUNCTION(MaxPool); DML_OP_EXTERN_QUERY_FUNCTION(Slice); @@ -487,6 +491,7 @@ constexpr static std::array supportedTypeListFloat1 constexpr static std::array supportedTypeListFloat16to32SignedInts8to32 = {SupportedTensorDataTypes::Float16to32 | SupportedTensorDataTypes::Int8 | SupportedTensorDataTypes::Int16 | SupportedTensorDataTypes::Int32}; constexpr static std::array supportedTypeListFloat16to32Ints32to64 = {SupportedTensorDataTypes::Float16to32 | SupportedTensorDataTypes::Ints32Bit | SupportedTensorDataTypes::Ints64Bit}; constexpr static std::array supportedTypeListUInt8to64 = {SupportedTensorDataTypes::UInt8to64}; +constexpr static std::array supportedTypeListAllIntegers = {SupportedTensorDataTypes::Ints8to64}; constexpr static std::array supportedTypeListNumericDefault = { SupportedTensorDataTypes::NumericDefault }; constexpr static std::array supportedTypeListAllScalars = {SupportedTensorDataTypes::AllScalars}; constexpr static std::array supportedTypeListAllScalarsAndSequences = {SupportedTensorDataTypes::AllScalars | SupportedTensorDataTypes::AllSequences}; @@ -841,6 +846,10 @@ constexpr static OperatorRegistrationInformation operatorRegistrationInformation {REG_INFO( 7, And, typeNameListDefault, supportedTypeListBool, DmlGraphSupport::Supported)}, {REG_INFO( 7, Or, typeNameListDefault, supportedTypeListBool, DmlGraphSupport::Supported)}, {REG_INFO( 7, Xor, typeNameListDefault, supportedTypeListBool, DmlGraphSupport::Supported)}, + {REG_INFO( 18, BitwiseAnd, typeNameListDefault, supportedTypeListAllIntegers, DmlGraphSupport::Supported)}, + {REG_INFO( 18, BitwiseOr, typeNameListDefault, supportedTypeListAllIntegers, DmlGraphSupport::Supported)}, + {REG_INFO( 18, BitwiseXor, typeNameListDefault, supportedTypeListAllIntegers, DmlGraphSupport::Supported)}, + {REG_INFO( 18, BitwiseNot, typeNameListDefault, supportedTypeListAllIntegers, DmlGraphSupport::Supported)}, // Imaging Operators {REG_INFO( 7, Crop, typeNameListDefault, supportedTypeListFloat16to32, DmlGraphSupport::Supported)}, diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h index 2815cec715..6cb88e7749 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h @@ -1571,6 +1571,10 @@ using ShapeInferenceHelper_Mod = GetBroadcastedOutputShapeHelper; using ShapeInferenceHelper_BitShift= GetBroadcastedOutputShapeHelper; using ShapeInferenceHelper_Round = GetBroadcastedOutputShapeHelper; using ShapeInferenceHelper_QuickGelu = GetOutputShapeAsInputShapeHelper; +using ShapeInferenceHelper_BitwiseAnd = GetBroadcastedOutputShapeHelper; +using ShapeInferenceHelper_BitwiseOr = GetBroadcastedOutputShapeHelper; +using ShapeInferenceHelper_BitwiseXor = GetBroadcastedOutputShapeHelper; +using ShapeInferenceHelper_BitwiseNot = GetBroadcastedOutputShapeHelper; using ShapeInferenceHelper_ReduceSum = ReduceHelper; using ShapeInferenceHelper_ReduceMean = ReduceHelper; diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorVersions.h b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorVersions.h index 10ba8bb156..fce8fe8b63 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorVersions.h +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorVersions.h @@ -400,6 +400,10 @@ namespace OperatorHelper static const int sc_sinceVer_ReduceMin = 18; static const int sc_sinceVer_ReduceProd = 18; static const int sc_sinceVer_ReduceSumSquare = 18; + static const int sc_sinceVer_BitwiseAnd = 18; + static const int sc_sinceVer_BitwiseOr = 18; + static const int sc_sinceVer_BitwiseXor = 18; + static const int sc_sinceVer_BitwiseNot = 18; static const int sc_sinceVer_Split = 18; } 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 04fbd05669..333861c201 100644 --- a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc +++ b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc @@ -1973,7 +1973,7 @@ TEST(MathOpTest, Less_broadcastBA) { test.Run(); } -TEST(MathOpTest, Less_multidiretional_broadcastAB) { +TEST(MathOpTest, Less_multidirectional_broadcastAB) { OpTester test("Less", 9); test.AddInput("A", {4, 1}, {10, 11, 12, 13}); test.AddInput("B", {2}, {15, 7}); @@ -1981,7 +1981,7 @@ TEST(MathOpTest, Less_multidiretional_broadcastAB) { test.Run(); } -TEST(MathOpTest, Less_multidiretional_broadcastBA) { +TEST(MathOpTest, Less_multidirectional_broadcastBA) { OpTester test("Less", 9); test.AddInput("A", {2}, {15, 7}); test.AddInput("B", {4, 1}, {10, 11, 12, 13}); @@ -2043,7 +2043,7 @@ TEST(MathOpTest, LessOrEqual_broadcastBA) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}); } -TEST(MathOpTest, LessOrEqual_multidiretional_broadcastAB) { +TEST(MathOpTest, LessOrEqual_multidirectional_broadcastAB) { OpTester test("LessOrEqual", 12); test.AddInput("A", {4, 1}, {10, 11, 12, 13}); test.AddInput("B", {2}, {15, 7}); @@ -2052,7 +2052,7 @@ TEST(MathOpTest, LessOrEqual_multidiretional_broadcastAB) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}); } -TEST(MathOpTest, LessOrEqual_multidiretional_broadcastBA) { +TEST(MathOpTest, LessOrEqual_multidirectional_broadcastBA) { OpTester test("LessOrEqual", 12); test.AddInput("A", {2}, {15, 7}); test.AddInput("B", {4, 1}, {10, 11, 12, 13}); @@ -2182,7 +2182,7 @@ TEST(MathOpTest, LessOrEqual_bfloat16_broadcastBA) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}, nullptr, &execution_providers); } -TEST(MathOpTest, LessOrEqual_multidiretional_bfloat16_broadcastAB) { +TEST(MathOpTest, LessOrEqual_multidirectional_bfloat16_broadcastAB) { #ifdef USE_DNNL #ifdef DNNL_GPU_RUNTIME LOGS_DEFAULT(WARNING) << "Hardware does NOT support BF16"; @@ -2206,7 +2206,7 @@ TEST(MathOpTest, LessOrEqual_multidiretional_bfloat16_broadcastAB) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}, nullptr, &execution_providers); } -TEST(MathOpTest, LessOrEqual_multidiretional_bfloat16_broadcastBA) { +TEST(MathOpTest, LessOrEqual_multidirectional_bfloat16_broadcastBA) { #ifdef USE_DNNL #ifdef DNNL_GPU_RUNTIME LOGS_DEFAULT(WARNING) << "Hardware does NOT support BF16"; @@ -2317,7 +2317,7 @@ TEST(MathOpTest, Greater_broadcastBA) { test.Run(); } -TEST(MathOpTest, Greater_multidiretional_broadcastAB) { +TEST(MathOpTest, Greater_multidirectional_broadcastAB) { OpTester test("Greater", 9); test.AddInput("A", {4, 1}, {10, 11, 12, 13}); test.AddInput("B", {2}, {15, 7}); @@ -2325,7 +2325,7 @@ TEST(MathOpTest, Greater_multidiretional_broadcastAB) { test.Run(); } -TEST(MathOpTest, Greater_multidiretional_broadcastBA) { +TEST(MathOpTest, Greater_multidirectional_broadcastBA) { OpTester test("Greater", 9); test.AddInput("A", {2}, {15, 7}); test.AddInput("B", {4, 1}, {10, 11, 12, 13}); @@ -2418,7 +2418,7 @@ TEST(MathOpTest, GreaterOrEqual_broadcastBA) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}); } -TEST(MathOpTest, GreaterOrEqual_multidiretional_broadcastAB) { +TEST(MathOpTest, GreaterOrEqual_multidirectional_broadcastAB) { OpTester test("GreaterOrEqual", 12); test.AddInput("A", {4, 1}, {10, 11, 12, 13}); test.AddInput("B", {2}, {15, 7}); @@ -2427,7 +2427,7 @@ TEST(MathOpTest, GreaterOrEqual_multidiretional_broadcastAB) { {kTensorrtExecutionProvider, kNnapiExecutionProvider, kOpenVINOExecutionProvider}); } -TEST(MathOpTest, GreaterOrEqual_multidiretional_broadcastBA) { +TEST(MathOpTest, GreaterOrEqual_multidirectional_broadcastBA) { OpTester test("GreaterOrEqual", 12); test.AddInput("A", {2}, {15, 7}); test.AddInput("B", {4, 1}, {10, 11, 12, 13}); @@ -2539,7 +2539,7 @@ TEST(MathOpTest, Equal_broadcastBA) { test.Run(); } -TEST(MathOpTest, Equal_multidiretional_broadcastAB) { +TEST(MathOpTest, Equal_multidirectional_broadcastAB) { OpTester test("Equal"); test.AddInput("A", {4, 1}, {1, 0, -1, -1}); test.AddInput("B", {2}, {1, 1}); @@ -2547,7 +2547,7 @@ TEST(MathOpTest, Equal_multidiretional_broadcastAB) { test.Run(); } -TEST(MathOpTest, Equal_multidiretional_broadcastBA) { +TEST(MathOpTest, Equal_multidirectional_broadcastBA) { OpTester test("Equal"); test.AddInput("A", {2}, {1, 1}); test.AddInput("B", {4, 1}, {1, 0, -1, -1}); @@ -2555,7 +2555,7 @@ TEST(MathOpTest, Equal_multidiretional_broadcastBA) { test.Run(); } -TEST(MathOpTest, Equal_multidiretional_broadcastAB_bool) { +TEST(MathOpTest, Equal_multidirectional_broadcastAB_bool) { OpTester test("Equal"); test.AddInput("A", {4, 1}, {true, false, false, false}); test.AddInput("B", {2}, {true, true}); @@ -3076,5 +3076,267 @@ TEST(BitShiftOpTest, BroadcastXRight_Uint8) { test.Run(); } +TEST(MathOpTest, BitwiseAnd) { + OpTester test("BitwiseAnd", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 3}); + test.AddOutput("C", dims, {1, 0, 3}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_int64) { + OpTester test("BitwiseAnd", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 3}); + test.AddOutput("C", dims, {1, 0, 3}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_int8) { + OpTester test("BitwiseAnd", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 3}); + test.AddOutput("C", dims, {1, 0, 3}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_uint8) { + OpTester test("BitwiseAnd", 18); + std::vector dims{4}; + test.AddInput("A", dims, {1, 4, 5, 3}); + test.AddInput("B", dims, {1, 2, 2, 1}); + test.AddOutput("C", dims, {1, 0, 0, 1}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_uint64) { + OpTester test("BitwiseAnd", 18); + std::vector dims{4}; + test.AddInput("A", dims, {10, 11, 12, 13}); + test.AddInput("B", dims, {15, 7, 12, 9}); + test.AddOutput("C", dims, {10, 3, 12, 9}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_broadcastAB) { + OpTester test("BitwiseAnd", 18); + test.AddInput("A", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {10, 3, 12, 5, 14, 7, 0, 1}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_broadcastBA) { + OpTester test("BitwiseAnd", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddOutput("C", {4, 2}, {10, 3, 12, 5, 14, 7, 0, 1}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_multidirectional_broadcastAB) { + OpTester test("BitwiseAnd", 18); + test.AddInput("A", {4, 1}, {10, 11, 12, 13}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {10, 2, 11, 3, 12, 4, 13, 5}); + test.Run(); +} + +TEST(MathOpTest, BitwiseAnd_multidirectional_broadcastBA) { + OpTester test("BitwiseAnd", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 1}, {10, 11, 12, 13}); + test.AddOutput("C", {4, 2}, {10, 2, 11, 3, 12, 4, 13, 5}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr) { + OpTester test("BitwiseOr", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-1, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_int64) { + OpTester test("BitwiseOr", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-1, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_int8) { + OpTester test("BitwiseOr", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-1, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_uint8) { + OpTester test("BitwiseOr", 18); + std::vector dims{4}; + test.AddInput("A", dims, {1, 4, 5, 3}); + test.AddInput("B", dims, {1, 2, 2, 1}); + test.AddOutput("C", dims, {1, 6, 7, 3}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_uint64) { + OpTester test("BitwiseOr", 18); + std::vector dims{4}; + test.AddInput("A", dims, {10, 11, 12, 13}); + test.AddInput("B", dims, {15, 7, 12, 9}); + test.AddOutput("C", dims, {15, 15, 12, 13}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_broadcastAB) { + OpTester test("BitwiseOr", 18); + test.AddInput("A", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {15, 15, 15, 15, 15, 15, 31, 23}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_broadcastBA) { + OpTester test("BitwiseOr", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddOutput("C", {4, 2}, {15, 15, 15, 15, 15, 15, 31, 23}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_multidirectional_broadcastAB) { + OpTester test("BitwiseOr", 18); + test.AddInput("A", {4, 1}, {10, 11, 12, 13}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {15, 15, 15, 15, 15, 15, 15, 15}); + test.Run(); +} + +TEST(MathOpTest, BitwiseOr_multidirectional_broadcastBA) { + OpTester test("BitwiseOr", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 1}, {10, 11, 12, 13}); + test.AddOutput("C", {4, 2}, {15, 15, 15, 15, 15, 15, 15, 15}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor) { + OpTester test("BitwiseXor", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-2, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_int64) { + OpTester test("BitwiseXor", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-2, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_int8) { + OpTester test("BitwiseXor", 18); + std::vector dims{3}; + test.AddInput("A", dims, {-1, -2, 3}); + test.AddInput("B", dims, {1, 0, 4}); + test.AddOutput("C", dims, {-2, -2, 7}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_uint8) { + OpTester test("BitwiseXor", 18); + std::vector dims{4}; + test.AddInput("A", dims, {1, 4, 5, 3}); + test.AddInput("B", dims, {1, 2, 2, 1}); + test.AddOutput("C", dims, {0, 6, 7, 2}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_uint64) { + OpTester test("BitwiseXor", 18); + std::vector dims{4}; + test.AddInput("A", dims, {10, 11, 12, 13}); + test.AddInput("B", dims, {15, 7, 12, 9}); + test.AddOutput("C", dims, {5, 12, 0, 4}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_broadcastAB) { + OpTester test("BitwiseXor", 18); + test.AddInput("A", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {5, 12, 3, 10, 1, 8, 31, 22}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_broadcastBA) { + OpTester test("BitwiseXor", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 2}, {10, 11, 12, 13, 14, 15, 16, 17}); + test.AddOutput("C", {4, 2}, {5, 12, 3, 10, 1, 8, 31, 22}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_multidirectional_broadcastAB) { + OpTester test("BitwiseXor", 18); + test.AddInput("A", {4, 1}, {10, 11, 12, 13}); + test.AddInput("B", {2}, {15, 7}); + test.AddOutput("C", {4, 2}, {5, 13, 4, 12, 3, 11, 2, 10}); + test.Run(); +} + +TEST(MathOpTest, BitwiseXor_multidirectional_broadcastBA) { + OpTester test("BitwiseXor", 18); + test.AddInput("A", {2}, {15, 7}); + test.AddInput("B", {4, 1}, {10, 11, 12, 13}); + test.AddOutput("C", {4, 2}, {5, 13, 4, 12, 3, 11, 2, 10}); + test.Run(); +} + +TEST(MathOpTest, BitwiseNot) { + OpTester test("BitwiseNot", 18); + std::vector dims{3}; + test.AddInput("X", dims, {-1, -2, 3}); + test.AddOutput("Y", dims, {0, 1, -4}); + test.Run(); +} + +TEST(MathOpTest, BitwiseNot_int64) { + OpTester test("BitwiseNot", 18); + std::vector dims{3}; + test.AddInput("X", dims, {-1, -2, 3}); + test.AddOutput("Y", dims, {0, 1, -4}); + test.Run(); +} + +TEST(MathOpTest, BitwiseNot_int8) { + OpTester test("BitwiseNot", 18); + std::vector dims{3}; + test.AddInput("X", dims, {-1, -2, 3}); + test.AddOutput("Y", dims, {0, 1, -4}); + test.Run(); +} + +TEST(MathOpTest, BitwiseNot_uint8) { + OpTester test("BitwiseNot", 18); + std::vector dims{4}; + test.AddInput("X", dims, {1, 4, 5, 3}); + test.AddOutput("Y", dims, {254, 251, 250, 252}); + test.Run(); +} } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/object_detection/roialign_test.cc b/onnxruntime/test/providers/cpu/object_detection/roialign_test.cc index ad9c561ffb..2f97f6e71e 100644 --- a/onnxruntime/test/providers/cpu/object_detection/roialign_test.cc +++ b/onnxruntime/test/providers/cpu/object_detection/roialign_test.cc @@ -29,8 +29,8 @@ TEST(RoiAlignTest, AvgModePositive) { test.AddInput("rois", {5, 4}, {7., 5., 7., 5., -15., -15., -15., -15., -10., 21., -10., 21., 13., 8., 13., 8., -14., 19., -14., 19.}); test.AddInput("batch_indices", {5}, {0, 0, 0, 0, 0}); test.AddOutput("Y", {5, 3, 3, 4}, {2.95833f, 3.20833f, 3.45833f, 3.70833f, 4.625f, 4.875f, 5.125f, 5.375f, 6.29167f, 6.54167f, 6.79167f, 7.04167f, 27.9583f, 28.2083f, 28.4583f, 28.7083f, 29.625f, 29.875f, 30.125f, 30.375f, 31.2917f, 31.5417f, 31.7917f, 32.0417f, 52.9583f, 53.2083f, 53.4583f, 53.7083f, 54.625f, 54.875f, 55.125f, 55.375f, 56.2917f, 56.5417f, 56.7917f, 57.0417f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 7.39583f, 7.39583f, 7.42708f, 7.64583f, 9.0625f, 9.0625f, 9.09375f, 9.3125f, 10.7292f, 10.7292f, 10.7604f, 10.9792f, 32.3958f, 32.3958f, 32.4271f, 32.6458f, 34.0625f, 34.0625f, 34.0938f, 34.3125f, 35.7292f, 35.7292f, 35.7604f, 35.9792f, 57.3958f, 57.3958f, 57.4271f, 57.6458f, 59.0625f, 59.0625f, 59.0938f, 59.3125f, 60.7292f, 60.7292f, 60.7604f, 60.9792f, 4.27083f, 4.52083f, 4.77083f, 5.02083f, 5.9375f, 6.1875f, 6.4375f, 6.6875f, 7.60417f, 7.85417f, 8.10417f, 8.35417f, 29.2708f, 29.5208f, 29.7708f, 30.0208f, 30.9375f, 31.1875f, 31.4375f, 31.6875f, 32.6042f, 32.8542f, 33.1042f, 33.3542f, 54.2708f, 54.5208f, 54.7708f, 55.0208f, 55.9375f, 56.1875f, 56.4375f, 56.6875f, 57.6042f, 57.8542f, 58.1042f, 58.3542f, 6.77083f, 6.77083f, 6.77083f, 6.80208f, 8.4375f, 8.4375f, 8.4375f, 8.46875f, 10.1042f, 10.1042f, 10.1042f, 10.1354f, 31.7708f, 31.7708f, 31.7708f, 31.8021f, 33.4375f, 33.4375f, 33.4375f, 33.4688f, 35.1042f, 35.1042f, 35.1042f, 35.1354f, 56.7708f, 56.7708f, 56.7708f, 56.8021f, 58.4375f, 58.4375f, 58.4375f, 58.4688f, 60.1042f, 60.1042f, 60.1042f, 60.1354f}); - // As per ORT issue https://github.com/microsoft/onnxruntime/issues/6921, the above output values are INCORRECT. // DML has the correct outputs, which are defined below. + // These will replace the above outputs once https://github.com/microsoft/onnxruntime/issues/6921 is fixed. /*test.AddOutput("Y", {5, 3, 3, 4}, { 2.0000, 2.0000, @@ -499,8 +499,8 @@ TEST(RoiAlignTest, MaxModePositive) { test.AddInput("rois", {5, 4}, {7., 5., 7., 5., -15., -15., -15., -15., -10., 21., -10., 21., 13., 8., 13., 8., -14., 19., -14., 19.}); test.AddInput("batch_indices", {5}, {0, 0, 0, 0, 0}); test.AddOutput("Y", {5, 3, 3, 4}, {2.10938f, 2.95313f, 3.375f, 2.53125f, 3.35938f, 4.70313f, 5.375f, 4.03125f, 3.51563f, 4.92188f, 5.625f, 4.21875f, 10.8984f, 15.2578f, 17.4375f, 13.0781f, 17.3568f, 24.2995f, 27.7708f, 20.8281f, 18.1641f, 25.4297f, 29.0625f, 21.7969f, 19.6875f, 27.5625f, 31.5f, 23.625f, 31.3542f, 43.8958f, 50.1667f, 37.625f, 32.8125f, 45.9375f, 52.5f, 39.375f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 25.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 50.f, 5.625f, 5.625f, 5.625f, 4.57031f, 8.95833f, 8.95833f, 8.95833f, 7.27865f, 9.375f, 9.375f, 9.375f, 7.61719f, 19.6875f, 19.6875f, 19.6875f, 15.9961f, 31.3542f, 31.3542f, 31.3542f, 25.4753f, 32.8125f, 32.8125f, 32.8125f, 26.6602f, 33.75f, 33.75f, 33.75f, 27.4219f, 53.75f, 53.75f, 53.75f, 43.6719f, 56.25f, 56.25f, 56.25f, 45.7031f, 4.5f, 3.9375f, 2.8125f, 3.9375f, 5.5f, 4.8125f, 3.4375f, 4.8125f, 4.58333f, 4.01042f, 2.86458f, 3.9375f, 23.25f, 20.3438f, 14.5313f, 18.f, 28.4167f, 24.86458f, 17.76042f, 22.f, 23.25f, 20.3437f, 14.5312f, 18.f, 42.f, 36.75f, 26.25f, 32.0625f, 51.3333f, 44.9167f, 32.08333f, 39.1875f, 42.f, 36.75f, 26.25f, 32.0625f, 4.375f, 4.375f, 4.375f, 4.375f, 7.70833f, 7.70833f, 7.70833f, 7.70833f, 9.375f, 9.375f, 9.375f, 9.375f, 21.875f, 21.875f, 21.875f, 21.875f, 26.9792f, 26.9792f, 26.9792f, 26.9792f, 32.8125f, 32.8125f, 32.8125f, 32.8125f, 40.1042f, 40.1042f, 40.1042f, 40.1042f, 46.25f, 46.25f, 46.25f, 46.25f, 56.25f, 56.25f, 56.25f, 56.25f}); - // As per ort issue #3428, the above output values are INCORRECT. // DML has the correct outputs, which are defined below. + // These will replace the above outputs once https://github.com/microsoft/onnxruntime/issues/6921 is fixed. /*test.AddOutput("Y",{5, 3, 3, 4}, { 2.0000, 2.0000,