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
This commit is contained in:
Dwayne Robinson 2021-11-13 00:45:45 +00:00
parent 363cb2300b
commit 3e5d636f6c
3 changed files with 47 additions and 4 deletions

View file

@ -301,7 +301,7 @@ constexpr static std::array<SupportedTensorDataTypes, 2> supportedTypeListLogica
constexpr static std::array<SupportedTensorDataTypes, 2> supportedTypeListLogicalComparison9 = /* A&B,C */ { SupportedTensorDataTypes::Float16to32|SupportedTensorDataTypes::Ints8to64, SupportedTensorDataTypes::Bool };
constexpr static std::array<SupportedTensorDataTypes, 1> supportedTypeListSigned = { SupportedTensorDataTypes::Float16to32 | SupportedTensorDataTypes::Int64 | SupportedTensorDataTypes::Int32 | SupportedTensorDataTypes::Int16 | SupportedTensorDataTypes::Int8 };
constexpr static std::array<SupportedTensorDataTypes, 1> supportedTypeListRange = {SupportedTensorDataTypes::Int16|SupportedTensorDataTypes::Int32|SupportedTensorDataTypes::Int64|SupportedTensorDataTypes::Float32};
constexpr static std::array<SupportedTensorDataTypes, 2> supportedTypeListResize11 = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Float32 /* float32 ROI read by CPU */};
constexpr static std::array<SupportedTensorDataTypes, 2> supportedTypeListResize11 = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Float16to32 /* float32 ROI read by CPU */};
constexpr static std::array<SupportedTensorDataTypes, 3> supportedTypeListInteger = {SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8, SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8, SupportedTensorDataTypes::Int32 };
constexpr static std::array<SupportedTensorDataTypes, 1> supportedTypeListInteger8 = {SupportedTensorDataTypes::Int8|SupportedTensorDataTypes::UInt8 };
constexpr static std::array<SupportedTensorDataTypes, 2> supportedTypeListRoiAlign = {SupportedTensorDataTypes::Float16to32, SupportedTensorDataTypes::Int32|SupportedTensorDataTypes::Int64 };

View file

@ -86,16 +86,59 @@ namespace OperatorHelper
const std::vector<uint32_t>& 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<onnxruntime::MLFloat16>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(v); });
}
break;
case MLOperatorTensorDataType::/*Float32*/Float:
{
const float* data = tensor.GetData<float>();
result.assign(data, data + elementCount);
}
break;
case MLOperatorTensorDataType::/*Float64*/Double:
{
const double* data = tensor.GetData<double>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(v); });
}
break;
case MLOperatorTensorDataType::Int32:
{
const int32_t* data = tensor.GetData<int32_t>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(v); });
}
break;
case MLOperatorTensorDataType::UInt32:
{
const uint32_t* data = tensor.GetData<uint32_t>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(v); });
}
break;
case MLOperatorTensorDataType::Int64:
{
const int64_t* data = tensor.GetData<int64_t>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(v); });
}
break;
case MLOperatorTensorDataType::UInt64:
{
const uint64_t* data = tensor.GetData<uint64_t>();
std::transform(result.begin(), result.end(), result.begin(), [](auto v) {return static_cast<float>(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<uint32_t>(INT_MIN))
{
labelSizes[labelIndex] = dimensionSize;
}

View file

@ -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 {