From 3e5d636f6ce355e6afd7946ee0634dfe382d8866 Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Sat, 13 Nov 2021 00:45:45 +0000 Subject: [PATCH] Merged PR 6668481: Fix Resize float16 ROI tensor Fix Resize float16 ROI tensor. The ROI tensor is (and always has been) handled by the CPU, but we didn't register that type, nor have a switch case for it. "NVIDIA shared a model with Resize that falling back to CPU due to Float16 resize with Float16 ROI." ``` te.exe OnnxConformanceTests.dll /unicodeOutput:false /name:*Resize* /p:"match=Resize*" Summary: Total=79, Passed=76, Failed=0, Blocked=0, Not Run=0, Skipped=3 ``` Related work items: #33939079 --- .../src/Operators/OperatorRegistration.cpp | 2 +- .../OperatorAuthorHelper/OperatorHelper.cpp | 47 ++++++++++++++++++- .../dml/OperatorAuthorHelper/OperatorHelper.h | 2 +- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp index e6c9f2fea1..10ab559560 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.cpp @@ -301,7 +301,7 @@ constexpr static std::array supportedTypeListLogica constexpr static std::array supportedTypeListLogicalComparison9 = /* A&B,C */ { SupportedTensorDataTypes::Float16to32|SupportedTensorDataTypes::Ints8to64, SupportedTensorDataTypes::Bool }; constexpr static std::array supportedTypeListSigned = { SupportedTensorDataTypes::Float16to32 | SupportedTensorDataTypes::Int64 | SupportedTensorDataTypes::Int32 | SupportedTensorDataTypes::Int16 | SupportedTensorDataTypes::Int8 }; constexpr static std::array supportedTypeListRange = {SupportedTensorDataTypes::Int16|SupportedTensorDataTypes::Int32|SupportedTensorDataTypes::Int64|SupportedTensorDataTypes::Float32}; -constexpr static std::array supportedTypeListResize11 = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Float32 /* float32 ROI read by CPU */}; +constexpr static std::array supportedTypeListResize11 = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Float16to32 /* float32 ROI read by CPU */}; constexpr static std::array supportedTypeListInteger = {SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8, SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8, SupportedTensorDataTypes::Int32 }; constexpr static std::array supportedTypeListInteger8 = {SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8 }; constexpr static std::array supportedTypeListRoiAlign = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Int32|SupportedTensorDataTypes::Int64 }; diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp index 72c956356a..bb501f4cd9 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp @@ -86,16 +86,59 @@ namespace OperatorHelper const std::vector& tensorDimensions = tensor.GetShape(); const uint32_t elementCount = ComputeElementCountFromDimensions(tensorDimensions); + result.resize(elementCount); switch (tensor.GetTensorDataType()) { - case MLOperatorTensorDataType::Float: + case MLOperatorTensorDataType::Float16: + { + const onnxruntime::MLFloat16* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + + case MLOperatorTensorDataType::/*Float32*/Float: { const float* data = tensor.GetData(); result.assign(data, data + elementCount); } break; + case MLOperatorTensorDataType::/*Float64*/Double: + { + const double* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + + case MLOperatorTensorDataType::Int32: + { + const int32_t* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + + case MLOperatorTensorDataType::UInt32: + { + const uint32_t* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + + case MLOperatorTensorDataType::Int64: + { + const int64_t* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + + case MLOperatorTensorDataType::UInt64: + { + const uint64_t* data = tensor.GetData(); + std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast(v); }); + } + break; + default: ML_INVALID_ARGUMENT("Expecting CPU local tensor of type float32."); break; @@ -1110,7 +1153,7 @@ namespace OperatorHelper uint32_t labelIndex = labelIndices[j]; assert(labelIndex < labelSizes.size()); - if (labelSizes[labelIndex] == INT_MIN) + if (labelSizes[labelIndex] == static_cast(INT_MIN)) { labelSizes[labelIndex] = dimensionSize; } diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h index f6cb59a324..66c72ecaca 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.h @@ -6,7 +6,7 @@ #include "Common.h" #include "Attributes.h" #include "core/common/common.h" -#include "..\DmlExecutionProvider\src\ErrorHandling.h" +#include "../DmlExecutionProvider/src/ErrorHandling.h" #include "MLOperatorAuthorHelper.h" namespace OperatorHelper {