Skip to content

Commit 788ef93

Browse files
xuhdevfacebook-github-bot
authored andcommitted
float2::x and float2::y may not be the same as float on ROCm (#35593)
Summary: This causes ambiguity and can be triggered sometimes (e.g., by #35217). Explicitly convert them to float. error: conditional expression is ambiguous; 'const hip_impl::Scalar_accessor<float, Native_vec_, 0>' can be converted to 'float' and vice versa Pull Request resolved: #35593 Differential Revision: D20735663 Pulled By: ezyang fbshipit-source-id: ae6a38a08e59821bae13eb0b9f9bdf21a008d5c0
1 parent dd98abb commit 788ef93

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

caffe2/operators/relu_op.cu

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ __global__ void ReluCUDAKernel<half2>(const int N, const half2* X, half2* Y) {
5454
Y[i] = __hmul2(__hgt2(__ldg(X + i), kZero), __ldg(X + i));
5555
#else
5656
const float2 xx = __half22float2(X[i]);
57-
Y[i] =
58-
__floats2half2_rn(xx.x > 0.0f ? xx.x : 0.0f, xx.y > 0.0f ? xx.y : 0.0f);
57+
// There are explicit cast to float here, because it may otherwise cause ambiguity on ROCm and can be triggered
58+
// sometimes:
59+
//
60+
// error: conditional expression is ambiguous; 'const hip_impl::Scalar_accessor<float, Native_vec_, 0>' can be
61+
// converted to 'float' and vice versa
62+
Y[i] = __floats2half2_rn(xx.x > 0.0f ? static_cast<float>(xx.x) : 0.0f,
63+
xx.y > 0.0f ? static_cast<float>(xx.y) : 0.0f);
5964
#endif
6065
}
6166
}

0 commit comments

Comments
 (0)