Skip to content

Commit

Permalink
[DML EP] Fix Clip clamping (#22251)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
  • Loading branch information
PatriceVignola authored Sep 27, 2024
1 parent 1e3cd86 commit ebda23b
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,19 @@ class DmlOperatorElementwiseClip11 : public DmlOperator
// logic for some corner test case
// Same applies to min and max value.
opDesc.MinMaxDataType = this->m_inputTensorDescs[0].GetDmlDataType();
CastToClampedScalarUnion<double>(opDesc.MinMaxDataType, -DBL_MAX, /*out*/&opDesc.Min);
CastToClampedScalarUnion<double>(opDesc.MinMaxDataType, DBL_MAX, /*out*/&opDesc.Max);

if (opDesc.MinMaxDataType == DML_TENSOR_DATA_TYPE_FLOAT16 || opDesc.MinMaxDataType == DML_TENSOR_DATA_TYPE_FLOAT32 || opDesc.MinMaxDataType == DML_TENSOR_DATA_TYPE_FLOAT64)
{
CastToClampedScalarUnion<double>(opDesc.MinMaxDataType, -DBL_MAX, /*out*/&opDesc.Min);
CastToClampedScalarUnion<double>(opDesc.MinMaxDataType, DBL_MAX, /*out*/&opDesc.Max);
}
else
{
// It's not safe to use DBL_MAX for non-float datatypes because not all integer can be represented in the range.
// For example, static_cast<int64_t>(static_cast<double>(INT64_MAX)) will yield a negative number.
CastToClampedScalarUnion<int64_t>(opDesc.MinMaxDataType, -INT64_MAX, /*out*/&opDesc.Min);
CastToClampedScalarUnion<uint64_t>(opDesc.MinMaxDataType, UINT64_MAX, /*out*/&opDesc.Max);
}

if (kernelInfo.IsInputValid(1))
{
Expand Down

0 comments on commit ebda23b

Please sign in to comment.