Merged PR 4500055: Fix autopilot WinML::Engine::Test::BenchmarkProtobuf#onnxzoo_ssd#1.5#GPU

Model node "Slice-505" specifies a 64-bit INTMAX value (9223372036854775807) to mean essentially unbounded. The proper response in this case is to clamp it to 32-bit INTMAX, not bitwise truncate it, which yields -1.

Related work items: #24672220
This commit is contained in:
Dwayne Robinson 2020-04-01 00:10:45 +00:00
parent e6e4339f0b
commit ae15c36687
2 changed files with 13 additions and 1 deletions

View file

@ -20,6 +20,11 @@
}\
}
template<typename T, typename I> T clamp_cast(I input)
{
return static_cast<T>(std::clamp<I>(input, std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max()));
}
namespace OperatorHelper
{
enum TensorAxis { N, C, H, W, DoNotCoerce = UINT_MAX, LeftAligned = INT_MAX, RightAligned = INT_MIN, NoPlacementAdjustment = 0 };

View file

@ -56,9 +56,16 @@ namespace OperatorHelper
{
const int64_t* data = tensor.GetData<int64_t>();
result.reserve(elementCount);
// Use clamped cast rather than static_cast/narrow_cast,
// because it's not uncommon for a model to specify a
// 64-bit INTMAX constant as a sentinel value to mean
// the largest possible value (even though the actual
// dimension values come nowhere close to that, far
// less than 32-bit INTMAX).
for (auto d : gsl::make_span(data, data + elementCount))
{
result.push_back(gsl::narrow_cast<int32_t>(d));
result.push_back(clamp_cast<int32_t>(d));
}
}
break;