Skip to content

Commit 590293b

Browse files
jeffdailypytorchmergebot
authored andcommitted
[ROCm] std::clamp work-around for hip-clang compiler (pytorch#127812)
Fixes pytorch#127666. Other std math functions are replaced with those in the global namespace during hipify. HIP does not claim to support every function in the C++ standard library. std::clamp is not yet supported and we have been relying on the std implementation. For Fedora 40 + gcc 14, a host-side assert is used which is not supported. Work-around this by replacing std::clamp with min and max for USE_ROCM builds. Patch comes from @lamikr. Modified to use #ifndef USE_ROCM. lamikr/rocm_sdk_builder#37 Pull Request resolved: pytorch#127812 Approved by: https://github.com/hongxiayang, https://github.com/malfet
1 parent 311b3cc commit 590293b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

aten/src/ATen/native/cuda/IndexKernel.cu

+6
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ void index_put_kernel_quantized_cuda(TensorIterator& iter, const IntArrayRef ind
259259

260260
gpu_index_kernel(iter, index_size, index_stride, [inv_scale, zero_point, qmin, qmax]C10_DEVICE(char* const out_data, const char* const in_data, const int64_t offset) {
261261
int64_t qvalue = static_cast<int64_t>(zero_point + nearbyintf(*(float*)in_data * inv_scale));
262+
// See https://github.com/pytorch/pytorch/issues/127666
263+
// hip-clang std::clamp __glibcxx_assert_fail host function when building on Fedora40/gcc14
264+
#ifndef USE_ROCM
262265
qvalue = std::clamp(qvalue, qmin, qmax);
266+
#else
267+
qvalue = (qvalue < qmin) ? qmin : (qmax < qvalue) ? qmax : qvalue;
268+
#endif
263269
*(scalar_t*)(out_data + offset) = static_cast<scalar_t>(qvalue);
264270
});
265271
});

0 commit comments

Comments
 (0)