From 480f98ebacfa07871913c376674bf9553b022417 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Thu, 11 Jul 2024 10:39:33 -0700 Subject: [PATCH 01/14] Update DirectML from 1.14.1 to 1.15.0 --- .pipelines/nuget_config/x64/packages.config | 2 +- .pipelines/nuget_config/x86/packages.config | 2 +- cmake/external/dml.cmake | 2 +- packages.config | 2 +- tools/nuget/generate_nuspec_for_native_nuget.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pipelines/nuget_config/x64/packages.config b/.pipelines/nuget_config/x64/packages.config index 9066e13ee1c8d..7bf8181b1f838 100644 --- a/.pipelines/nuget_config/x64/packages.config +++ b/.pipelines/nuget_config/x64/packages.config @@ -1,6 +1,6 @@  - + diff --git a/.pipelines/nuget_config/x86/packages.config b/.pipelines/nuget_config/x86/packages.config index a8e5b35b28b36..30f7862a11078 100644 --- a/.pipelines/nuget_config/x86/packages.config +++ b/.pipelines/nuget_config/x86/packages.config @@ -1,6 +1,6 @@  - + diff --git a/cmake/external/dml.cmake b/cmake/external/dml.cmake index f74b694471203..54e361ffdb3ae 100644 --- a/cmake/external/dml.cmake +++ b/cmake/external/dml.cmake @@ -41,7 +41,7 @@ if (NOT onnxruntime_USE_CUSTOM_DIRECTML) set(NUGET_CONFIG ${PROJECT_SOURCE_DIR}/../NuGet.config) set(PACKAGES_CONFIG ${PROJECT_SOURCE_DIR}/../packages.config) get_filename_component(PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/../packages ABSOLUTE) - set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.1.14.1) + set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.1.15.0) # Restore nuget packages, which will pull down the DirectML redist package. add_custom_command( diff --git a/packages.config b/packages.config index 3f3e4f5298881..f69e5b4f27956 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index 88d1cebc84f8d..60d1884a9591f 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -219,7 +219,7 @@ def add_common_dependencies(xml_text, package_name, version): def generate_dependencies(xml_text, package_name, version): - dml_dependency = '' + dml_dependency = '' if package_name == "Microsoft.AI.MachineLearning": xml_text.append("") From aeb4b954676e7881afb5600a419eeb548a7ef928 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Thu, 11 Jul 2024 12:33:10 -0700 Subject: [PATCH 02/14] New operators now registered --- docs/OperatorKernels.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md index df5897529baae..ed944b5a6df79 100644 --- a/docs/OperatorKernels.md +++ b/docs/OperatorKernels.md @@ -970,6 +970,7 @@ Do not modify directly.* |||12+|**T** = tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||11+|**T** = tensor(float), tensor(float16)| |||6+|**T** = tensor(float), tensor(float16)| +|Col2Im|*in* input:**T**
*in* image_shape:**tensor(int64)**
*in* block_shape:**tensor(int64)**
*out* output:**T**|18+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |Concat|*in* inputs:**T**
*out* concat_result:**T**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||11+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||4+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| @@ -1131,7 +1132,8 @@ Do not modify directly.* |PRelu|*in* X:**T**
*in* slope:**T**
*out* Y:**T**|16+|**T** = tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int8)| |||9+|**T** = tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int8)| |||7+|**T** = tensor(float), tensor(float16)| -|Pad|*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*in* axes:**Tind**
*out* output:**T**

or

*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|18+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Pad|*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*in* axes:**Tind**
*out* output:**T**

or

*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|19+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||18+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||11+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||2+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| @@ -1199,7 +1201,9 @@ Do not modify directly.* |||14+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||5+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| -|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|19+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|||18+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|||13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||11+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||10+|**T** = tensor(float), tensor(float16)| |ReverseSequence|*in* input:**T**
*in* sequence_lens:**tensor(int64)**
*out* Y:**T**|10+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| From a4324c3ca510bcc541b2fcca9df4fc7c3f555565 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Mon, 15 Jul 2024 08:21:50 -0700 Subject: [PATCH 03/14] Restrict RESAMPLE3 changes to opset18+ --- .../src/Operators/DmlOperatorResize.cpp | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index 5256e01f86fb6..26ea940a0fdec 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -263,11 +263,6 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper std::string mode = kernelCreationContext.GetOptionalAttribute(AttrName::Mode, "NEAREST"); DML_INTERPOLATION_MODE interpolationMode = Dml::MapStringToInteropolationMode(mode); - -#if DML_TARGET_VERSION >= 0x6400 - const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); -#endif - // Map ONNX to DML's mode using offsets and rounding direction. // These offsets are in addition to the coordinate transform offsets. DML_AXIS_DIRECTION roundingDirection = DML_AXIS_DIRECTION_DECREASING; @@ -307,25 +302,35 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper std::vector inputDescs = GetDmlInputDescs(); std::vector outputDescs = GetDmlOutputDescs(); -#if DML_TARGET_VERSION >= 0x6400 - DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; - operatorDesc.Antialiased = static_cast(antialiased); -#else - DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; -#endif - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); -#if DML_TARGET_VERSION >= 0x6400 - DML_OPERATOR_DESC opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; -#else - DML_OPERATOR_DESC opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; -#endif + DML_OPERATOR_DESC opDesc = {}; + if (opsetVersion >= 18) { + // Restrict this change to Resize18 and Resize19 + const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); + DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; + operatorDesc.Antialiased = static_cast(antialiased); + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; + } + else { + DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; + } + SetDmlOperatorDesc(opDesc, kernelCreationContext); } }; From 7d9b4129d9ab0d6e100db3adcc15c54d689c570b Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Mon, 15 Jul 2024 23:38:08 -0700 Subject: [PATCH 04/14] Fix aberrant indentation --- .../src/Operators/DmlOperatorResize.cpp | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index 26ea940a0fdec..bd33be14c2a85 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -303,32 +303,34 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper std::vector outputDescs = GetDmlOutputDescs(); DML_OPERATOR_DESC opDesc = {}; - if (opsetVersion >= 18) { - // Restrict this change to Resize18 and Resize19 - const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); - DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; - operatorDesc.Antialiased = static_cast(antialiased); - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; + if (opsetVersion >= 18) + { + // Restrict this change to Resize18 and Resize19. + const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); + DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; + operatorDesc.Antialiased = static_cast(antialiased); + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; } - else { - DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; + else + { + DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; } SetDmlOperatorDesc(opDesc, kernelCreationContext); From 172bc571e915ed37c702cf97ce70decfb990df97 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 17 Jul 2024 13:03:06 -0700 Subject: [PATCH 05/14] Disable resample3 --- .../src/Operators/DmlOperatorResize.cpp | 8 +++----- .../src/Operators/OperatorRegistration.cpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index 26ea940a0fdec..a650c8fcee187 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -303,8 +303,7 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper std::vector outputDescs = GetDmlOutputDescs(); DML_OPERATOR_DESC opDesc = {}; - if (opsetVersion >= 18) { - // Restrict this change to Resize18 and Resize19 + #if FALSE const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; operatorDesc.Antialiased = static_cast(antialiased); @@ -317,8 +316,7 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; - } - else { + #else DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; operatorDesc.InputTensor = inputDescs.data(); operatorDesc.OutputTensor = outputDescs.data(); @@ -329,7 +327,7 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; - } + #endif SetDmlOperatorDesc(opDesc, kernelCreationContext); } diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp index 27605a6ad8e8c..31106e98e054e 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp @@ -1023,7 +1023,7 @@ constexpr static OperatorRegistrationInformation operatorRegistrationInformation {REG_INFO_VER( 10, Resize, typeNameListDefault, supportedTypeListFloat16to32, DmlGraphSupport::Supported, requiredConstantCpuInputs(1) /*scales*/)}, {REG_INFO_VER( 11, Resize, typeNameListTwo, supportedTypeListResize11, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, {REG_INFO_VER( 13, Resize, typeNameListTwo, supportedTypeListResize13, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, -#if DML_TARGET_VERSION >= 0x6400 +#if FALSE {REG_INFO_VER( 18, Resize, typeNameListTwo, supportedTypeListResize18, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, {REG_INFO_VER( 19, Resize, typeNameListTwo, supportedTypeListResize18, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, #endif From c8c06a24f3c8ac151f7514f9f3ca924d4a8f97e4 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 17 Jul 2024 13:31:42 -0700 Subject: [PATCH 06/14] disable resize18-19 --- .../DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index a650c8fcee187..a80f8d1c8d033 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -371,7 +371,7 @@ void CALLBACK QueryResize(IMLOperatorSupportQueryContextPrivate* context, bool* DML_OP_DEFINE_CREATION_FUNCTION(Resize10, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize11, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize13, VersionedKernel); -#if DML_TARGET_VERSION >= 0x6400 +#if FALSE DML_OP_DEFINE_CREATION_FUNCTION(Resize18, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize19, VersionedKernel); #endif From d02296c8f72b88832deb573d6689e3577e5473a0 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 17 Jul 2024 16:17:11 -0700 Subject: [PATCH 07/14] remove resize registration --- docs/OperatorKernels.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md index ed944b5a6df79..e5a7cb5d1545b 100644 --- a/docs/OperatorKernels.md +++ b/docs/OperatorKernels.md @@ -4,9 +4,11 @@ Do not modify directly.* ## Execution Providers -- [CPUExecutionProvider](#cpuexecutionprovider) -- [CUDAExecutionProvider](#cudaexecutionprovider) -- [DmlExecutionProvider](#dmlexecutionprovider) +- [Supported Operators and Data Types](#supported-operators-and-data-types) +- [Execution Providers](#execution-providers) +- [Operators implemented by CPUExecutionProvider](#operators-implemented-by-cpuexecutionprovider) +- [Operators implemented by CUDAExecutionProvider](#operators-implemented-by-cudaexecutionprovider) +- [Operators implemented by DmlExecutionProvider](#operators-implemented-by-dmlexecutionprovider) --------------- @@ -1201,9 +1203,7 @@ Do not modify directly.* |||14+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||5+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| -|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|19+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| -|||18+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| -|||13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||11+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||10+|**T** = tensor(float), tensor(float16)| |ReverseSequence|*in* input:**T**
*in* sequence_lens:**tensor(int64)**
*out* Y:**T**|10+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| From 7255c842ad0191a99181ae289001da69425b75ca Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 17 Jul 2024 19:13:19 -0700 Subject: [PATCH 08/14] Update operator kernels... again --- docs/OperatorKernels.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md index e5a7cb5d1545b..5e4e8b8179416 100644 --- a/docs/OperatorKernels.md +++ b/docs/OperatorKernels.md @@ -4,11 +4,9 @@ Do not modify directly.* ## Execution Providers -- [Supported Operators and Data Types](#supported-operators-and-data-types) -- [Execution Providers](#execution-providers) -- [Operators implemented by CPUExecutionProvider](#operators-implemented-by-cpuexecutionprovider) -- [Operators implemented by CUDAExecutionProvider](#operators-implemented-by-cudaexecutionprovider) -- [Operators implemented by DmlExecutionProvider](#operators-implemented-by-dmlexecutionprovider) +- [CPUExecutionProvider](#cpuexecutionprovider) +- [CUDAExecutionProvider](#cudaexecutionprovider) +- [DmlExecutionProvider](#dmlexecutionprovider) --------------- From 1ccd38017429063bc6d2806089cc8c961f13ca99 Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Wed, 17 Jul 2024 23:51:51 -0700 Subject: [PATCH 09/14] Fix indentation DmlOperatorResize.cpp again. --- .../src/Operators/DmlOperatorResize.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index a80f8d1c8d033..b93a53fcf8b18 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -304,29 +304,29 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper DML_OPERATOR_DESC opDesc = {}; #if FALSE - const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); - DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; - operatorDesc.Antialiased = static_cast(antialiased); - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; + const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); + DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; + operatorDesc.Antialiased = static_cast(antialiased); + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; #else - DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; + DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; #endif SetDmlOperatorDesc(opDesc, kernelCreationContext); From ebff6b85816cac771e8f65273182525c39b4342e Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Thu, 18 Jul 2024 18:09:29 -0700 Subject: [PATCH 10/14] Update external --- .../DmlExecutionProvider/src/ApiTraits.cpp | 5 +- .../src/External/DirectMLHelpers/ApiHelpers.h | 8 ++- .../src/External/DirectMLHelpers/ApiTraits.h | 54 +++++++++++++-- .../External/DirectMLHelpers/DirectMLSchema.h | 58 ++++++++++++++++ .../DirectMLHelpers/DmlGraphDeserialization.h | 2 +- .../DirectMLHelpers/GeneratedSchemaHelpers.h | 60 ++++++++++++++++- .../DirectMLHelpers/GeneratedSchemaTypes.h | 55 ++++++++-------- .../src/Operators/DmlOperatorResize.cpp | 39 ++++------- .../src/Operators/OperatorRegistration.cpp | 2 +- .../OperatorAuthorHelper/OperatorHelper.cpp | 12 ++-- .../test/api/LearningModelSessionAPITest.cpp | 66 ++++++++++++++++--- 11 files changed, 282 insertions(+), 79 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp index ccc2bfd872231..65fde3a701121 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // This file is automatically generated. Please do not edit it directly. @@ -241,6 +241,7 @@ DML_OPERATOR_TYPE ApiTraits::StringifyHelpers::FromString(std::string_view value {"DML_OPERATOR_ACTIVATION_SWISH", DML_OPERATOR_ACTIVATION_SWISH}, {"DML_OPERATOR_ACTIVATION_HARD_SWISH", DML_OPERATOR_ACTIVATION_HARD_SWISH}, {"DML_OPERATOR_RESAMPLE2", DML_OPERATOR_RESAMPLE2}, + {"DML_OPERATOR_RESAMPLE3", DML_OPERATOR_RESAMPLE3}, {"DML_OPERATOR_RESAMPLE_GRAD1", DML_OPERATOR_RESAMPLE_GRAD1}, {"DML_OPERATOR_DIAGONAL_MATRIX1", DML_OPERATOR_DIAGONAL_MATRIX1}, {"DML_OPERATOR_MULTIHEAD_ATTENTION", DML_OPERATOR_MULTIHEAD_ATTENTION}, @@ -369,6 +370,7 @@ DML_PADDING_MODE ApiTraits::StringifyHelpers::FromString(std::string_view value) {"DML_PADDING_MODE_EDGE", DML_PADDING_MODE_EDGE}, {"DML_PADDING_MODE_REFLECTION", DML_PADDING_MODE_REFLECTION}, {"DML_PADDING_MODE_SYMMETRIC", DML_PADDING_MODE_SYMMETRIC}, + {"DML_PADDING_MODE_WRAP", DML_PADDING_MODE_WRAP}, }; auto index = StringUtil::MapToIndex(value, mapping); if (!index) @@ -454,6 +456,7 @@ DML_FEATURE_LEVEL ApiTraits::StringifyHelpers::FromString(std::string_view value {"DML_FEATURE_LEVEL_6_1", DML_FEATURE_LEVEL_6_1}, {"DML_FEATURE_LEVEL_6_2", DML_FEATURE_LEVEL_6_2}, {"DML_FEATURE_LEVEL_6_3", DML_FEATURE_LEVEL_6_3}, + {"DML_FEATURE_LEVEL_6_4", DML_FEATURE_LEVEL_6_4}, }; auto index = StringUtil::MapToIndex(value, mapping); if (!index) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiHelpers.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiHelpers.h index 9a1c23093f9b9..431a3fdef5a9a 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiHelpers.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiHelpers.h @@ -29,6 +29,9 @@ union ActivationOperatorDescUnion DML_ACTIVATION_THRESHOLDED_RELU_OPERATOR_DESC thresholdedRelu; DML_ACTIVATION_SHRINK_OPERATOR_DESC shrink; DML_ACTIVATION_GELU_OPERATOR_DESC gelu; + DML_ACTIVATION_SWISH_OPERATOR_DESC swish; + DML_ACTIVATION_HARD_SWISH_OPERATOR_DESC hardSwish; + DML_ELEMENT_WISE_CLIP_OPERATOR_DESC clip; }; struct ActivationOperatorDesc @@ -46,7 +49,7 @@ struct ActivationOperatorDesc case DML_OPERATOR_ACTIVATION_CELU: return { activationType, ¶ms.celu }; case DML_OPERATOR_ACTIVATION_HARDMAX: return { activationType, ¶ms.hardmax }; case DML_OPERATOR_ACTIVATION_HARDMAX1: return { activationType, ¶ms.hardmax1 }; - case DML_OPERATOR_ACTIVATION_HARD_SIGMOID: return { activationType, ¶ms.sigmoid }; + case DML_OPERATOR_ACTIVATION_HARD_SIGMOID: return { activationType, ¶ms.hardSigmoid }; case DML_OPERATOR_ACTIVATION_IDENTITY: return { activationType, ¶ms.identity }; case DML_OPERATOR_ACTIVATION_LEAKY_RELU: return { activationType, ¶ms.leakyRelu }; case DML_OPERATOR_ACTIVATION_LINEAR: return { activationType, ¶ms.linear }; @@ -66,6 +69,9 @@ struct ActivationOperatorDesc case DML_OPERATOR_ACTIVATION_THRESHOLDED_RELU: return { activationType, ¶ms.thresholdedRelu }; case DML_OPERATOR_ACTIVATION_SHRINK: return { activationType, ¶ms.shrink }; case DML_OPERATOR_ACTIVATION_GELU: return { activationType, ¶ms.gelu }; + case DML_OPERATOR_ACTIVATION_SWISH: return { activationType, ¶ms.swish }; + case DML_OPERATOR_ACTIVATION_HARD_SWISH: return { activationType, ¶ms.hardSwish }; + case DML_OPERATOR_ELEMENT_WISE_CLIP: return { activationType, ¶ms.clip }; default: ORT_THROW_HR(E_INVALIDARG); return { activationType, ¶ms.relu }; diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h index 6a4354feb2e2e..1b89088eeee56 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -24,7 +24,7 @@ struct EnumTraits template <> struct EnumTraits { - static constexpr auto ValueCount = 174; + static constexpr auto ValueCount = 175; static constexpr size_t ActivationFunctionCount = 26; }; @@ -62,7 +62,7 @@ struct EnumTraits template <> struct EnumTraits { - static constexpr auto ValueCount = 4; + static constexpr auto ValueCount = 5; }; template <> @@ -86,7 +86,7 @@ struct EnumTraits template <> struct EnumTraits { - static constexpr auto ValueCount = 14; + static constexpr auto ValueCount = 15; }; template <> @@ -1023,6 +1023,12 @@ struct OperatorDescTraits static constexpr DML_OPERATOR_TYPE Type = DML_OPERATOR_RESAMPLE2; }; +template <> +struct OperatorDescTraits +{ + static constexpr DML_OPERATOR_TYPE Type = DML_OPERATOR_RESAMPLE3; +}; + template <> struct OperatorDescTraits { @@ -1053,6 +1059,18 @@ struct OperatorDescTraits static constexpr DML_OPERATOR_TYPE Type = DML_OPERATOR_MATRIX_MULTIPLY_INTEGER_TO_FLOAT; }; +template <> +struct OperatorDescTraits +{ + static constexpr DML_OPERATOR_TYPE Type = DML_OPERATOR_FOLD; +}; + +template <> +struct OperatorDescTraits +{ + static constexpr DML_OPERATOR_TYPE Type = DML_OPERATOR_UNFOLD; +}; + template <> struct OperatorDescTraits { @@ -2073,6 +2091,12 @@ struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_RESAMPLE2> using DescType = DML_RESAMPLE2_OPERATOR_DESC; }; +template <> +struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_RESAMPLE3> +{ + using DescType = DML_RESAMPLE3_OPERATOR_DESC; +}; + template <> struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_RESAMPLE_GRAD1> { @@ -2103,6 +2127,18 @@ struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_MATRIX_MULTIPLY_INTEGE using DescType = DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_DESC; }; +template <> +struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_FOLD> +{ + using DescType = DML_FOLD_OPERATOR_DESC; +}; + +template <> +struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_UNFOLD> +{ + using DescType = DML_UNFOLD_OPERATOR_DESC; +}; + template <> struct OperatorTypeTraits<(DML_OPERATOR_TYPE)DML_OPERATOR_MEAN_VARIANCE_NORMALIZATION2> { @@ -2575,6 +2611,8 @@ auto OperatorTypeVisitor(DML_OPERATOR_TYPE type, Visitor&& visitor, Ts&&... args return std::invoke(std::forward(visitor), DML_BATCH_NORMALIZATION_TRAINING_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_RESAMPLE2: return std::invoke(std::forward(visitor), DML_RESAMPLE2_OPERATOR_DESC{}, std::forward(args)...); + case DML_OPERATOR_RESAMPLE3: + return std::invoke(std::forward(visitor), DML_RESAMPLE3_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_RESAMPLE_GRAD1: return std::invoke(std::forward(visitor), DML_RESAMPLE_GRAD1_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_DIAGONAL_MATRIX1: @@ -2585,6 +2623,10 @@ auto OperatorTypeVisitor(DML_OPERATOR_TYPE type, Visitor&& visitor, Ts&&... args return std::invoke(std::forward(visitor), DML_QUANTIZED_LINEAR_AVERAGE_POOLING_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_MATRIX_MULTIPLY_INTEGER_TO_FLOAT: return std::invoke(std::forward(visitor), DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_DESC{}, std::forward(args)...); + case DML_OPERATOR_FOLD: + return std::invoke(std::forward(visitor), DML_FOLD_OPERATOR_DESC{}, std::forward(args)...); + case DML_OPERATOR_UNFOLD: + return std::invoke(std::forward(visitor), DML_UNFOLD_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_MEAN_VARIANCE_NORMALIZATION2: return std::invoke(std::forward(visitor), DML_MEAN_VARIANCE_NORMALIZATION2_OPERATOR_DESC{}, std::forward(args)...); case DML_OPERATOR_MULTIHEAD_ATTENTION1: @@ -2650,7 +2692,6 @@ auto OperatorTypeVisitor(DML_OPERATOR_TYPE type, Visitor&& visitor, Ts&&... args } } - namespace StringifyHelpers { template @@ -2871,6 +2912,7 @@ inline gsl::czstring ToString(DML_OPERATOR_TYPE value) case DML_OPERATOR_ACTIVATION_SWISH: return "DML_OPERATOR_ACTIVATION_SWISH"; case DML_OPERATOR_ACTIVATION_HARD_SWISH: return "DML_OPERATOR_ACTIVATION_HARD_SWISH"; case DML_OPERATOR_RESAMPLE2: return "DML_OPERATOR_RESAMPLE2"; + case DML_OPERATOR_RESAMPLE3: return "DML_OPERATOR_RESAMPLE3"; case DML_OPERATOR_RESAMPLE_GRAD1: return "DML_OPERATOR_RESAMPLE_GRAD1"; case DML_OPERATOR_DIAGONAL_MATRIX1: return "DML_OPERATOR_DIAGONAL_MATRIX1"; case DML_OPERATOR_MULTIHEAD_ATTENTION: return "DML_OPERATOR_MULTIHEAD_ATTENTION"; @@ -2971,6 +3013,7 @@ inline gsl::czstring ToString(DML_PADDING_MODE value) case DML_PADDING_MODE_EDGE: return "DML_PADDING_MODE_EDGE"; case DML_PADDING_MODE_REFLECTION: return "DML_PADDING_MODE_REFLECTION"; case DML_PADDING_MODE_SYMMETRIC: return "DML_PADDING_MODE_SYMMETRIC"; + case DML_PADDING_MODE_WRAP: return "DML_PADDING_MODE_WRAP"; default: assert(false); return ""; @@ -3036,6 +3079,7 @@ inline gsl::czstring ToString(DML_FEATURE_LEVEL value) case DML_FEATURE_LEVEL_6_1: return "DML_FEATURE_LEVEL_6_1"; case DML_FEATURE_LEVEL_6_2: return "DML_FEATURE_LEVEL_6_2"; case DML_FEATURE_LEVEL_6_3: return "DML_FEATURE_LEVEL_6_3"; + case DML_FEATURE_LEVEL_6_4: return "DML_FEATURE_LEVEL_6_4"; default: assert(false); return ""; diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DirectMLSchema.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DirectMLSchema.h index e0ccb2f51f109..14a7383e67897 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DirectMLSchema.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DirectMLSchema.h @@ -2306,6 +2306,26 @@ constexpr DML_OPERATOR_SCHEMA DML_RESAMPLE2_OPERATOR_SCHEMA { DML_RESAMPLE2_OPERATOR_SCHEMA_FIELDS, }; +constexpr DML_SCHEMA_FIELD DML_RESAMPLE3_OPERATOR_SCHEMA_FIELDS[9] { + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "InputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_OUTPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "OutputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "InterpolationMode", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "RoundingDirection", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "DimensionCount", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_FLOAT_ARRAY, "Scales", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_FLOAT_ARRAY, "InputPixelOffsets", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_FLOAT_ARRAY, "OutputPixelOffsets", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "Antialiased", false }, +}; + +constexpr DML_OPERATOR_SCHEMA DML_RESAMPLE3_OPERATOR_SCHEMA { + "DML_OPERATOR_RESAMPLE3", + DML_OPERATOR_RESAMPLE3, + DML_SCHEMA_OPERATOR_SUPPORT_FLAG_NONE, + 9, + DML_RESAMPLE3_OPERATOR_SCHEMA_FIELDS, +}; + constexpr DML_SCHEMA_FIELD DML_RESAMPLE_GRAD1_OPERATOR_SCHEMA_FIELDS[8] { DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "InputGradientTensor", false }, DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_OUTPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "OutputGradientTensor", false }, @@ -2414,6 +2434,44 @@ constexpr DML_OPERATOR_SCHEMA DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_SCHE DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_SCHEMA_FIELDS, }; +constexpr DML_SCHEMA_FIELD DML_FOLD_OPERATOR_SCHEMA_FIELDS[8] { + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "InputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_OUTPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "OutputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "DimensionCount", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "WindowSizes", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "Strides", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "Dilations", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "StartPadding", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "EndPadding", false }, +}; + +constexpr DML_OPERATOR_SCHEMA DML_FOLD_OPERATOR_SCHEMA { + "DML_OPERATOR_FOLD", + DML_OPERATOR_FOLD, + DML_SCHEMA_OPERATOR_SUPPORT_FLAG_NONE, + 8, + DML_FOLD_OPERATOR_SCHEMA_FIELDS, +}; + +constexpr DML_SCHEMA_FIELD DML_UNFOLD_OPERATOR_SCHEMA_FIELDS[8] { + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "InputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_OUTPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "OutputTensor", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT, "DimensionCount", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "WindowSizes", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "Strides", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "Dilations", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "StartPadding", false }, + DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_ATTRIBUTE, DML_SCHEMA_FIELD_TYPE_UINT_ARRAY, "EndPadding", false }, +}; + +constexpr DML_OPERATOR_SCHEMA DML_UNFOLD_OPERATOR_SCHEMA { + "DML_OPERATOR_UNFOLD", + DML_OPERATOR_UNFOLD, + DML_SCHEMA_OPERATOR_SUPPORT_FLAG_NONE, + 8, + DML_UNFOLD_OPERATOR_SCHEMA_FIELDS, +}; + constexpr DML_SCHEMA_FIELD DML_MEAN_VARIANCE_NORMALIZATION2_OPERATOR_SCHEMA_FIELDS[10] { DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "InputTensor", false }, DML_SCHEMA_FIELD { DML_SCHEMA_FIELD_KIND_INPUT_TENSOR, DML_SCHEMA_FIELD_TYPE_TENSOR_DESC, "ScaleTensor", true }, diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DmlGraphDeserialization.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DmlGraphDeserialization.h index 9decf0dce1bb2..203df0b3b8371 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DmlGraphDeserialization.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/DmlGraphDeserialization.h @@ -11,4 +11,4 @@ struct NodeIndex DmlSerializedGraphDesc DeserializeDmlGraph( const uint8_t* flatbufferGraphDescBlob, - /*out*/ std::vector>& rawData); \ No newline at end of file + /*out*/ std::vector>& rawData); diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaHelpers.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaHelpers.h index 298ecd657635e..23b5a491c7d96 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaHelpers.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaHelpers.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -1422,6 +1422,20 @@ inline std::vector GetFields(const DML_RESAMPLE2_OPERATOR_DESC& d OperatorField(&DML_RESAMPLE2_OPERATOR_SCHEMA.Fields[7], ToOperatorFieldType(static_cast(desc.OutputPixelOffsets), desc.DimensionCount)), }; } +inline std::vector GetFields(const DML_RESAMPLE3_OPERATOR_DESC& desc) +{ + return { + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[0], ToOperatorFieldType(static_cast(desc.InputTensor))), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[1], ToOperatorFieldType(static_cast(desc.OutputTensor))), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[2], ToOperatorFieldType(static_cast(desc.InterpolationMode))), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[3], ToOperatorFieldType(static_cast(desc.RoundingDirection))), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[4], ToOperatorFieldType(static_cast(desc.DimensionCount))), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[5], ToOperatorFieldType(static_cast(desc.Scales), desc.DimensionCount)), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[6], ToOperatorFieldType(static_cast(desc.InputPixelOffsets), desc.DimensionCount)), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[7], ToOperatorFieldType(static_cast(desc.OutputPixelOffsets), desc.DimensionCount)), + OperatorField(&DML_RESAMPLE3_OPERATOR_SCHEMA.Fields[8], ToOperatorFieldType(static_cast(desc.Antialiased))), + }; +} inline std::vector GetFields(const DML_RESAMPLE_GRAD1_OPERATOR_DESC& desc) { return { @@ -1500,6 +1514,32 @@ inline std::vector GetFields(const DML_MATRIX_MULTIPLY_INTEGER_TO OperatorField(&DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_SCHEMA.Fields[7], ToOperatorFieldType(static_cast(desc.OutputTensor))), }; } +inline std::vector GetFields(const DML_FOLD_OPERATOR_DESC& desc) +{ + return { + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[0], ToOperatorFieldType(static_cast(desc.InputTensor))), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[1], ToOperatorFieldType(static_cast(desc.OutputTensor))), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[2], ToOperatorFieldType(static_cast(desc.DimensionCount))), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[3], ToOperatorFieldType(static_cast(desc.WindowSizes), desc.DimensionCount)), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[4], ToOperatorFieldType(static_cast(desc.Strides), desc.DimensionCount)), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[5], ToOperatorFieldType(static_cast(desc.Dilations), desc.DimensionCount)), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[6], ToOperatorFieldType(static_cast(desc.StartPadding), desc.DimensionCount)), + OperatorField(&DML_FOLD_OPERATOR_SCHEMA.Fields[7], ToOperatorFieldType(static_cast(desc.EndPadding), desc.DimensionCount)), + }; +} +inline std::vector GetFields(const DML_UNFOLD_OPERATOR_DESC& desc) +{ + return { + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[0], ToOperatorFieldType(static_cast(desc.InputTensor))), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[1], ToOperatorFieldType(static_cast(desc.OutputTensor))), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[2], ToOperatorFieldType(static_cast(desc.DimensionCount))), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[3], ToOperatorFieldType(static_cast(desc.WindowSizes), desc.DimensionCount)), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[4], ToOperatorFieldType(static_cast(desc.Strides), desc.DimensionCount)), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[5], ToOperatorFieldType(static_cast(desc.Dilations), desc.DimensionCount)), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[6], ToOperatorFieldType(static_cast(desc.StartPadding), desc.DimensionCount)), + OperatorField(&DML_UNFOLD_OPERATOR_SCHEMA.Fields[7], ToOperatorFieldType(static_cast(desc.EndPadding), desc.DimensionCount)), + }; +} inline std::vector GetFields(const DML_MEAN_VARIANCE_NORMALIZATION2_OPERATOR_DESC& desc) { return { @@ -1912,11 +1952,14 @@ inline const DML_OPERATOR_SCHEMA& GetSchema(DML_OPERATOR_TYPE operatorType) case DML_OPERATOR_ROI_ALIGN_GRAD: return DML_ROI_ALIGN_GRAD_OPERATOR_SCHEMA; case DML_OPERATOR_BATCH_NORMALIZATION_TRAINING: return DML_BATCH_NORMALIZATION_TRAINING_OPERATOR_SCHEMA; case DML_OPERATOR_RESAMPLE2: return DML_RESAMPLE2_OPERATOR_SCHEMA; + case DML_OPERATOR_RESAMPLE3: return DML_RESAMPLE3_OPERATOR_SCHEMA; case DML_OPERATOR_RESAMPLE_GRAD1: return DML_RESAMPLE_GRAD1_OPERATOR_SCHEMA; case DML_OPERATOR_DIAGONAL_MATRIX1: return DML_DIAGONAL_MATRIX1_OPERATOR_SCHEMA; case DML_OPERATOR_MULTIHEAD_ATTENTION: return DML_MULTIHEAD_ATTENTION_OPERATOR_SCHEMA; case DML_OPERATOR_QUANTIZED_LINEAR_AVERAGE_POOLING: return DML_QUANTIZED_LINEAR_AVERAGE_POOLING_OPERATOR_SCHEMA; case DML_OPERATOR_MATRIX_MULTIPLY_INTEGER_TO_FLOAT: return DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_SCHEMA; + case DML_OPERATOR_FOLD: return DML_FOLD_OPERATOR_SCHEMA; + case DML_OPERATOR_UNFOLD: return DML_UNFOLD_OPERATOR_SCHEMA; case DML_OPERATOR_MEAN_VARIANCE_NORMALIZATION2: return DML_MEAN_VARIANCE_NORMALIZATION2_OPERATOR_SCHEMA; case DML_OPERATOR_MULTIHEAD_ATTENTION1: return DML_MULTIHEAD_ATTENTION1_OPERATOR_SCHEMA; case DML_OPERATOR_QUANTIZE: return DML_QUANTIZE_OPERATOR_SCHEMA; @@ -2095,11 +2138,14 @@ inline const bool IsValidOperator(DML_OPERATOR_TYPE operatorType) case DML_OPERATOR_ROI_ALIGN_GRAD: case DML_OPERATOR_BATCH_NORMALIZATION_TRAINING: case DML_OPERATOR_RESAMPLE2: + case DML_OPERATOR_RESAMPLE3: case DML_OPERATOR_RESAMPLE_GRAD1: case DML_OPERATOR_DIAGONAL_MATRIX1: case DML_OPERATOR_MULTIHEAD_ATTENTION: case DML_OPERATOR_QUANTIZED_LINEAR_AVERAGE_POOLING: case DML_OPERATOR_MATRIX_MULTIPLY_INTEGER_TO_FLOAT: + case DML_OPERATOR_FOLD: + case DML_OPERATOR_UNFOLD: case DML_OPERATOR_MEAN_VARIANCE_NORMALIZATION2: case DML_OPERATOR_MULTIHEAD_ATTENTION1: case DML_OPERATOR_QUANTIZE: @@ -2695,6 +2741,10 @@ inline AbstractOperatorDesc ConvertOperatorDesc(const DML_OPERATOR_DESC& opDesc) return AbstractOperatorDesc( &DML_RESAMPLE2_OPERATOR_SCHEMA, GetFields(*static_cast(opDesc.Desc))); + case DML_OPERATOR_RESAMPLE3: + return AbstractOperatorDesc( + &DML_RESAMPLE3_OPERATOR_SCHEMA, + GetFields(*static_cast(opDesc.Desc))); case DML_OPERATOR_RESAMPLE_GRAD1: return AbstractOperatorDesc( &DML_RESAMPLE_GRAD1_OPERATOR_SCHEMA, @@ -2715,6 +2765,14 @@ inline AbstractOperatorDesc ConvertOperatorDesc(const DML_OPERATOR_DESC& opDesc) return AbstractOperatorDesc( &DML_MATRIX_MULTIPLY_INTEGER_TO_FLOAT_OPERATOR_SCHEMA, GetFields(*static_cast(opDesc.Desc))); + case DML_OPERATOR_FOLD: + return AbstractOperatorDesc( + &DML_FOLD_OPERATOR_SCHEMA, + GetFields(*static_cast(opDesc.Desc))); + case DML_OPERATOR_UNFOLD: + return AbstractOperatorDesc( + &DML_UNFOLD_OPERATOR_SCHEMA, + GetFields(*static_cast(opDesc.Desc))); case DML_OPERATOR_MEAN_VARIANCE_NORMALIZATION2: return AbstractOperatorDesc( &DML_MEAN_VARIANCE_NORMALIZATION2_OPERATOR_SCHEMA, diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaTypes.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaTypes.h index a94bb67b68d36..5ea0d470b20ce 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaTypes.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/GeneratedSchemaTypes.h @@ -1,21 +1,21 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once using ApiAttributeVariant = std::variant< - const DML_TENSOR_DESC*, - const DML_OPERATOR_DESC*, - UINT, - UINT64, - INT, - FLOAT, - const UINT*, - const INT*, - const FLOAT*, - const DML_SCALE_BIAS*, - DML_SIZE_2D, - DML_SCALAR_UNION, + const DML_TENSOR_DESC*, + const DML_OPERATOR_DESC*, + UINT, + UINT64, + INT, + FLOAT, + const UINT*, + const INT*, + const FLOAT*, + const DML_SCALE_BIAS*, + DML_SIZE_2D, + DML_SCALAR_UNION, BOOL >; @@ -39,20 +39,20 @@ namespace OperatorFieldTypes } using OperatorFieldVariant = std::variant< - OperatorFieldTypes::TensorDesc, - OperatorFieldTypes::TensorDescArray, - OperatorFieldTypes::FusedActivationOperatorDesc, - OperatorFieldTypes::FusedActivationOperatorDescArray, - OperatorFieldTypes::UInt, - OperatorFieldTypes::UInt64, - OperatorFieldTypes::Int, - OperatorFieldTypes::Float, - OperatorFieldTypes::UIntArray, - OperatorFieldTypes::IntArray, - OperatorFieldTypes::FloatArray, - OperatorFieldTypes::ScaleBias, - OperatorFieldTypes::Size2D, - OperatorFieldTypes::ScalarUnion, + OperatorFieldTypes::TensorDesc, + OperatorFieldTypes::TensorDescArray, + OperatorFieldTypes::FusedActivationOperatorDesc, + OperatorFieldTypes::FusedActivationOperatorDescArray, + OperatorFieldTypes::UInt, + OperatorFieldTypes::UInt64, + OperatorFieldTypes::Int, + OperatorFieldTypes::Float, + OperatorFieldTypes::UIntArray, + OperatorFieldTypes::IntArray, + OperatorFieldTypes::FloatArray, + OperatorFieldTypes::ScaleBias, + OperatorFieldTypes::Size2D, + OperatorFieldTypes::ScalarUnion, OperatorFieldTypes::Bool >; @@ -126,4 +126,3 @@ class OperatorField const DML_SCHEMA_FIELD* m_schema; OperatorFieldVariant m_data; }; - diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp index a80f8d1c8d033..84e8ffbe61e52 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp @@ -303,31 +303,18 @@ class DmlOperatorResize : public DmlOperator, public ResizeHelper std::vector outputDescs = GetDmlOutputDescs(); DML_OPERATOR_DESC opDesc = {}; - #if FALSE - const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); - DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; - operatorDesc.Antialiased = static_cast(antialiased); - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; - #else - DML_RESAMPLE2_OPERATOR_DESC operatorDesc = {}; - operatorDesc.InputTensor = inputDescs.data(); - operatorDesc.OutputTensor = outputDescs.data(); - operatorDesc.InterpolationMode = interpolationMode; - operatorDesc.RoundingDirection = roundingDirection; - operatorDesc.Scales = paddedScales.data(); - operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); - operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); - operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); - opDesc = { DML_OPERATOR_RESAMPLE2, &operatorDesc }; - #endif + const int antialiased = kernelCreationContext.GetOptionalAttribute(AttrName::Antialiased, 0); + DML_RESAMPLE3_OPERATOR_DESC operatorDesc = {}; + operatorDesc.Antialiased = static_cast(antialiased); + operatorDesc.InputTensor = inputDescs.data(); + operatorDesc.OutputTensor = outputDescs.data(); + operatorDesc.InterpolationMode = interpolationMode; + operatorDesc.RoundingDirection = roundingDirection; + operatorDesc.Scales = paddedScales.data(); + operatorDesc.DimensionCount = gsl::narrow_cast(paddedScales.size()); + operatorDesc.InputPixelOffsets = inputPixelOffsets.data(); + operatorDesc.OutputPixelOffsets = outputPixelOffsets.data(); + opDesc = { DML_OPERATOR_RESAMPLE3, &operatorDesc }; SetDmlOperatorDesc(opDesc, kernelCreationContext); } @@ -371,10 +358,8 @@ void CALLBACK QueryResize(IMLOperatorSupportQueryContextPrivate* context, bool* DML_OP_DEFINE_CREATION_FUNCTION(Resize10, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize11, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize13, VersionedKernel); -#if FALSE DML_OP_DEFINE_CREATION_FUNCTION(Resize18, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Resize19, VersionedKernel); -#endif DML_OP_DEFINE_CREATION_FUNCTION(Upsample7, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Upsample9, VersionedKernel); DML_OP_DEFINE_CREATION_FUNCTION(Upsample10, VersionedKernel); diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp index 31106e98e054e..27605a6ad8e8c 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp @@ -1023,7 +1023,7 @@ constexpr static OperatorRegistrationInformation operatorRegistrationInformation {REG_INFO_VER( 10, Resize, typeNameListDefault, supportedTypeListFloat16to32, DmlGraphSupport::Supported, requiredConstantCpuInputs(1) /*scales*/)}, {REG_INFO_VER( 11, Resize, typeNameListTwo, supportedTypeListResize11, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, {REG_INFO_VER( 13, Resize, typeNameListTwo, supportedTypeListResize13, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, -#if FALSE +#if DML_TARGET_VERSION >= 0x6400 {REG_INFO_VER( 18, Resize, typeNameListTwo, supportedTypeListResize18, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, {REG_INFO_VER( 19, Resize, typeNameListTwo, supportedTypeListResize18, DmlGraphSupport::Supported, requiredConstantCpuInputs(1, 2, 3) /*roi, scales, sizes*/, std::nullopt, QueryResize)}, #endif diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp index 3a7cf28ef903e..8faa4e45bf054 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp @@ -1857,14 +1857,16 @@ namespace OperatorHelper DowncastDimensions(gsl::span(shapeData), /*out*/ m_blockShape); const uint32_t dimCount = gsl::narrow_cast(m_blockShape.size()); - m_dilations = {dimCount, 1}; - m_pads = {dimCount * 2, 0}; - m_strides = {dimCount, 1}; + m_dilations.resize(dimCount); + std::fill(m_dilations.begin(), m_dilations.end(), 1); + m_pads.resize(dimCount, 0); + std::fill(m_pads.begin(), m_pads.end(), 0); + m_strides.resize(dimCount, 1); + std::fill(m_strides.begin(), m_strides.end(), 1); if (kernelInformation.HasAttribute(AttrName::Dilations, MLOperatorAttributeType::IntArray)) { shapeData = kernelInformation.GetAttributes().GetOptionalAttributeVectorInt32(AttrName::Dilations); - m_dilations.resize(shapeData.size()); DowncastDimensions(gsl::span(shapeData), /*out*/ m_dilations); ML_CHECK_VALID_ARGUMENT(m_dilations.size() == dimCount); } @@ -1872,7 +1874,6 @@ namespace OperatorHelper if (kernelInformation.HasAttribute(AttrName::Pads, MLOperatorAttributeType::IntArray)) { shapeData = kernelInformation.GetAttributes().GetOptionalAttributeVectorInt32(AttrName::Pads); - m_pads.resize(shapeData.size()); DowncastDimensions(gsl::span(shapeData), /*out*/ m_pads); ML_CHECK_VALID_ARGUMENT(m_pads.size() == dimCount * 2); } @@ -1880,7 +1881,6 @@ namespace OperatorHelper if (kernelInformation.HasAttribute(AttrName::Strides, MLOperatorAttributeType::IntArray)) { shapeData = kernelInformation.GetAttributes().GetOptionalAttributeVectorInt32(AttrName::Strides); - m_strides.resize(shapeData.size()); DowncastDimensions(gsl::span(shapeData), /*out*/ m_strides); ML_CHECK_VALID_ARGUMENT(m_strides.size() == dimCount); } diff --git a/winml/test/api/LearningModelSessionAPITest.cpp b/winml/test/api/LearningModelSessionAPITest.cpp index d6e70e35e3a6d..5a6ff84069fc4 100644 --- a/winml/test/api/LearningModelSessionAPITest.cpp +++ b/winml/test/api/LearningModelSessionAPITest.cpp @@ -2117,15 +2117,65 @@ static void ModelBuilding_HannWindow() { } static void ModelBuilding_HammingWindow() { -#if !defined(BUILD_INBOX) + auto input = + std::vector{0.0, 0.0, 0.0, 0.0, + 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, + 1.0, 1.0, 1.0, 1.0, + 0.0, 0.0, 0.0, 0.0, + }; auto expected = - std::vector{0.086957f, 0.095728f, 0.121707f, 0.163894f, 0.220669f, 0.289848f, 0.368775f, 0.454415f, - 0.543478f, 0.632541f, 0.718182f, 0.797108f, 0.866288f, 0.923062f, 0.965249f, 0.991228f, - 1.000000f, 0.991228f, 0.965249f, 0.923062f, 0.866288f, 0.797108f, 0.718182f, 0.632541f, - 0.543478f, 0.454415f, 0.368775f, 0.289848f, 0.220669f, 0.163894f, 0.121707f, 0.095728f}; - WindowFunction(L"HammingWindow", TensorKind::Float, expected); - WindowFunction(L"HammingWindow", TensorKind::Double, expected); -#endif + std::vector{0.f, 1.f, 1.f, 1.f, 1.f, + 1.f, 0.f, 1.f, 0.f, 0.f, + 0.f, 2.f, 1.f, 2.f, 1.f, + 1.f, 0.f, 1.f, 0.f, 0.f, + 0.f, 1.f, 0.f, 1.f, 0.f}; + + std::vector input_shape = {1,9,4}; + std::vector output_shape = {1,1,5,5}; + + auto model = LearningModelBuilder::Create(18) + .Inputs().Add(LearningModelBuilder::CreateTensorFeatureDescriptor(L"Input", TensorKind::Float, input_shape)) + .Outputs().Add(LearningModelBuilder::CreateTensorFeatureDescriptor(L"Output", TensorKind::Float, output_shape)) + .Operators() + .Add(Operator(L"Col2Im") + .SetInput(L"input", L"Input") + .SetAttribute( + L"strides", TensorInt64Bit::CreateFromArray({2}, {INT64(2), INT64(2)}) + ) + .SetConstant( + L"image_shape", TensorInt64Bit::CreateFromArray({2}, {INT64(5), INT64(5)}) + ) + .SetConstant( + L"block_shape", TensorInt64Bit::CreateFromArray({2}, {INT64(3), INT64(3)}) + ) + .SetOutput(L"output", L"Output")) + .CreateModel(); + + auto device = LearningModelDevice(LearningModelDeviceKind::DirectX); + LearningModelSession session(model, device); + LearningModelBinding binding(session); + + binding.Bind(L"Input", TensorFloat::CreateFromArray(input_shape, input)); + + // Evaluate + auto result = session.Evaluate(binding, L""); + + // Check results + // constexpr float error_threshold = .001f; + auto y_tensor = result.Outputs().Lookup(L"Output").as(); + auto y_ivv = y_tensor.GetAsVectorView(); + for (uint32_t i = 0; i < y_ivv.Size(); i++) { + if (i % 5 == 0) { + printf("\n"); + } + printf("%f, ", y_ivv.GetAt(i)); + //WINML_EXPECT_TRUE(abs(y_ivv.GetAt(i) - expected[i]) < error_threshold); + } } static void ModelBuilding_BlackmanWindow() { From 0e7d95ca85fc58de39373b1f547c285b313a6295 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Thu, 18 Jul 2024 20:09:19 -0700 Subject: [PATCH 11/14] undo changes here --- .../test/api/LearningModelSessionAPITest.cpp | 66 +++---------------- 1 file changed, 8 insertions(+), 58 deletions(-) diff --git a/winml/test/api/LearningModelSessionAPITest.cpp b/winml/test/api/LearningModelSessionAPITest.cpp index 5a6ff84069fc4..d6e70e35e3a6d 100644 --- a/winml/test/api/LearningModelSessionAPITest.cpp +++ b/winml/test/api/LearningModelSessionAPITest.cpp @@ -2117,65 +2117,15 @@ static void ModelBuilding_HannWindow() { } static void ModelBuilding_HammingWindow() { - auto input = - std::vector{0.0, 0.0, 0.0, 0.0, - 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, - 1.0, 1.0, 1.0, 1.0, - 0.0, 0.0, 0.0, 0.0, - }; +#if !defined(BUILD_INBOX) auto expected = - std::vector{0.f, 1.f, 1.f, 1.f, 1.f, - 1.f, 0.f, 1.f, 0.f, 0.f, - 0.f, 2.f, 1.f, 2.f, 1.f, - 1.f, 0.f, 1.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 1.f, 0.f}; - - std::vector input_shape = {1,9,4}; - std::vector output_shape = {1,1,5,5}; - - auto model = LearningModelBuilder::Create(18) - .Inputs().Add(LearningModelBuilder::CreateTensorFeatureDescriptor(L"Input", TensorKind::Float, input_shape)) - .Outputs().Add(LearningModelBuilder::CreateTensorFeatureDescriptor(L"Output", TensorKind::Float, output_shape)) - .Operators() - .Add(Operator(L"Col2Im") - .SetInput(L"input", L"Input") - .SetAttribute( - L"strides", TensorInt64Bit::CreateFromArray({2}, {INT64(2), INT64(2)}) - ) - .SetConstant( - L"image_shape", TensorInt64Bit::CreateFromArray({2}, {INT64(5), INT64(5)}) - ) - .SetConstant( - L"block_shape", TensorInt64Bit::CreateFromArray({2}, {INT64(3), INT64(3)}) - ) - .SetOutput(L"output", L"Output")) - .CreateModel(); - - auto device = LearningModelDevice(LearningModelDeviceKind::DirectX); - LearningModelSession session(model, device); - LearningModelBinding binding(session); - - binding.Bind(L"Input", TensorFloat::CreateFromArray(input_shape, input)); - - // Evaluate - auto result = session.Evaluate(binding, L""); - - // Check results - // constexpr float error_threshold = .001f; - auto y_tensor = result.Outputs().Lookup(L"Output").as(); - auto y_ivv = y_tensor.GetAsVectorView(); - for (uint32_t i = 0; i < y_ivv.Size(); i++) { - if (i % 5 == 0) { - printf("\n"); - } - printf("%f, ", y_ivv.GetAt(i)); - //WINML_EXPECT_TRUE(abs(y_ivv.GetAt(i) - expected[i]) < error_threshold); - } + std::vector{0.086957f, 0.095728f, 0.121707f, 0.163894f, 0.220669f, 0.289848f, 0.368775f, 0.454415f, + 0.543478f, 0.632541f, 0.718182f, 0.797108f, 0.866288f, 0.923062f, 0.965249f, 0.991228f, + 1.000000f, 0.991228f, 0.965249f, 0.923062f, 0.866288f, 0.797108f, 0.718182f, 0.632541f, + 0.543478f, 0.454415f, 0.368775f, 0.289848f, 0.220669f, 0.163894f, 0.121707f, 0.095728f}; + WindowFunction(L"HammingWindow", TensorKind::Float, expected); + WindowFunction(L"HammingWindow", TensorKind::Double, expected); +#endif } static void ModelBuilding_BlackmanWindow() { From 20a1a65983d06c08fb725041fc753a51fc12050e Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Fri, 19 Jul 2024 07:33:43 -0700 Subject: [PATCH 12/14] opkernels... --- docs/OperatorKernels.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/OperatorKernels.md b/docs/OperatorKernels.md index 5e4e8b8179416..ed944b5a6df79 100644 --- a/docs/OperatorKernels.md +++ b/docs/OperatorKernels.md @@ -1201,7 +1201,9 @@ Do not modify directly.* |||14+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| |||5+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| -|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|19+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|||18+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| +|||13+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||11+|**T1** = tensor(float), tensor(float16), tensor(int8), tensor(uint8)
**T2** = tensor(float), tensor(float16)| |||10+|**T** = tensor(float), tensor(float16)| |ReverseSequence|*in* input:**T**
*in* sequence_lens:**tensor(int64)**
*out* Y:**T**|10+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| From 7e6297bae5f9deb5fed9721ca8298831790f881b Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Fri, 19 Jul 2024 16:57:49 -0700 Subject: [PATCH 13/14] use assign --- .../dml/OperatorAuthorHelper/OperatorHelper.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp index 8faa4e45bf054..deed62901dfb0 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp @@ -852,7 +852,7 @@ namespace OperatorHelper { ML_CHECK_VALID_ARGUMENT(outputShape[C] == gsl::narrow_cast(m_outputShapes[0].GetShape()[C]), "Output channel must be equivalent to filter channel."); - } + } for (size_t i = 0; i < m_kernel.spatialDimensionCount; ++i) { @@ -1857,12 +1857,9 @@ namespace OperatorHelper DowncastDimensions(gsl::span(shapeData), /*out*/ m_blockShape); const uint32_t dimCount = gsl::narrow_cast(m_blockShape.size()); - m_dilations.resize(dimCount); - std::fill(m_dilations.begin(), m_dilations.end(), 1); - m_pads.resize(dimCount, 0); - std::fill(m_pads.begin(), m_pads.end(), 0); - m_strides.resize(dimCount, 1); - std::fill(m_strides.begin(), m_strides.end(), 1); + m_dilations.assign(dimCount, 1); + m_pads.assign(dimCount, 0); + m_strides.assign(dimCount, 1); if (kernelInformation.HasAttribute(AttrName::Dilations, MLOperatorAttributeType::IntArray)) { From 75c3d40b990c591c9b462714e17c61ffa085c81c Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Fri, 19 Jul 2024 17:36:54 -0700 Subject: [PATCH 14/14] Update ApiTraits, as it causes issues with Serialization. --- .../providers/dml/DmlExecutionProvider/src/ApiTraits.cpp | 3 +++ .../src/External/DirectMLHelpers/ApiTraits.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp index 65fde3a701121..a10ba8099f39a 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ApiTraits.cpp @@ -251,6 +251,9 @@ DML_OPERATOR_TYPE ApiTraits::StringifyHelpers::FromString(std::string_view value {"DML_OPERATOR_MULTIHEAD_ATTENTION1", DML_OPERATOR_MULTIHEAD_ATTENTION1}, {"DML_OPERATOR_QUANTIZE", DML_OPERATOR_QUANTIZE}, {"DML_OPERATOR_DEQUANTIZE", DML_OPERATOR_DEQUANTIZE}, + {"DML_OPERATOR_ROI_ALIGN_GRAD", DML_OPERATOR_ROI_ALIGN_GRAD}, + {"DML_OPERATOR_FOLD", DML_OPERATOR_FOLD}, + {"DML_OPERATOR_UNFOLD", DML_OPERATOR_UNFOLD}, }; auto index = StringUtil::MapToIndex(value, mapping); if (!index) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h index 1b89088eeee56..ccd4d4c76e744 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/DirectMLHelpers/ApiTraits.h @@ -24,7 +24,7 @@ struct EnumTraits template <> struct EnumTraits { - static constexpr auto ValueCount = 175; + static constexpr auto ValueCount = 178; static constexpr size_t ActivationFunctionCount = 26; }; @@ -2922,6 +2922,9 @@ inline gsl::czstring ToString(DML_OPERATOR_TYPE value) case DML_OPERATOR_MULTIHEAD_ATTENTION1: return "DML_OPERATOR_MULTIHEAD_ATTENTION1"; case DML_OPERATOR_QUANTIZE: return "DML_OPERATOR_QUANTIZE"; case DML_OPERATOR_DEQUANTIZE: return "DML_OPERATOR_DEQUANTIZE"; + case DML_OPERATOR_ROI_ALIGN_GRAD: return "DML_OPERATOR_ROI_ALIGN_GRAD"; + case DML_OPERATOR_FOLD: return "DML_OPERATOR_FOLD"; + case DML_OPERATOR_UNFOLD: return "DML_OPERATOR_UNFOLD"; default: assert(false); return "";