作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在主机代码中,__CUDA_ARCH__
宏似乎不会生成不同的代码路径,相反,它会为当前设备的确切代码路径生成代码。
但是,如果 __CUDA_ARCH__
在设备代码中,它将为编译选项 (/arch) 中指定的不同设备生成不同的代码路径。
任何人都可以确认这是正确的吗?
最佳答案
__CUDA_ARCH__
在设备代码中使用时将携带一个定义给它的数字,以反射(reflect)当前正在编译的代码架构。
它不打算在主机代码中使用。来自 nvcc manual :
This macro can be used in the implementation of GPU functions for determining the virtual architecture for which it is currently being compiled. The host code (the non-GPU code) must not depend on it.
__CUDA_ARCH__
是未定义的(至少由 CUDA 定义)。正如@tera 在评论中指出的那样,由于宏在主机代码中未定义,因此它可用于区分主机/设备路径,例如,在
__host__ __device__
函数定义中。
#ifndef __CUDA_ARCH__
//host code here
#else
//device code here
#endif
关于cuda - __CUDA_ARCH__ 宏的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16072740/
在主机代码中,__CUDA_ARCH__ 宏似乎不会生成不同的代码路径,相反,它会为当前设备的确切代码路径生成代码。 但是,如果 __CUDA_ARCH__ 在设备代码中,它将为编译选项 (/arch
我是一名优秀的程序员,十分优秀!