编译 CUDA 与数学函数的叮当
Compiling CUDA with clang on math functions
编译以下 CUDA 代码helloWorld.cu使用 clang-11
,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_"函数。
提前感谢您的任何帮助。
您编写的代码是主机代码,C++语法上无效。该代码不应编译,并且编译器行为是正确的。为了编译,代码应如下所示:
#include <algorithm>
int main() {
return std::max(1.0f, 2.0f);
}
也就是说,您必须实际包含定义max
函数的标准库标头,并且您必须使用正确的命名空间。C++没有内置的max
功能。库达做到了。您所看到的只是 clang CUDA 编译轨迹的工件。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 编译 CUDA 与数学函数的叮当
- 为什么叮当使我的简单阶乘函数过于复杂
- 为什么我收到叮当警告:函数"diff"没有以前的原型
- 在可疑的情况下发出叮当警告:函数'foo'可以用属性"noreturn"声明吗?
- 不能在函数中声明运算符.叮当错误或规范