【发布时间】:2020-06-29 03:13:28
【问题描述】:
用clang-11编译以下CUDA代码helloWorld.cu,
int main() {
return max(1.0f, 2.0f);
}
,使用命令clang++-11 -o helloWorld helloWorld.cu --cuda-gpu-arch=sm_75 -ldl -lrt -lcudart_static -pthread -L/usr/local/cuda/lib64,遇到错误:
helloWorld.cu:2:12: error: no matching function for call to 'max'
return max(1.0f, 2.0f);
^~~
/usr/lib/llvm-11/lib/clang/11.0.0/include/__clang_cuda_math.h:194:16: note: candidate function not viable: call to __device__ function from __host__ function
__DEVICE__ int max(int __a, int __b) { return __nv_max(__a, __b); }
...
/usr/local/cuda-10.2/include/crt/math_functions.hpp:1079:31: note: candidate function not viable: call to __device__ function from __host__ function
__MATH_FUNCTIONS_DECL__ float max(float a, float b)
...
请注意,匹配函数实际上被编译器正确定位(即“math_functions.hpp:1079:31”),但被错误地推断为“_device_”函数。
提前感谢您的帮助。
【问题讨论】: