【问题标题】:NVCC warning levelNVCC 警告级别
【发布时间】:2013-01-16 00:31:43
【问题描述】:

我希望 NVCC 将以下警告视为错误:

warning : calling a __host__ function("foo") from a __host__ __device__ function("bar")

NVCC 文档“NVIDIA CUDA Compiler Driver NVCC”甚至不包含“警告”一词。

【问题讨论】:

  • 为什么这不是设计上的错误?我刚刚经历了 nvcc 编译成功(只有你提到的警告):__host__ int c() { return 0; } __host__ __device__ void b(){int a = c();} __global__ void a() {b();} /*...*/ a <<<1, 1 >>>(); 和行 a = c(); 变成从 0 读取:mov.u32 %r1, 0; ld.volatile.u32 %r2, [%r1]; 这可以永远工作并且肯定是不是我想要的。为什么编译器要继续这样做?

标签: c++ cuda nvcc


【解决方案1】:

引用 CUDA COMPILER DRIVER NVCC 参考指南,Section 3.2.8. "Generic Tool Options"

--Werror kind 将指定种类的警告变成错误。以下是该选项接受的警告种类列表:

cross-execution-space-call 对不受支持的跨执行空间调用更加严格。对于从__host__ __device____host__ 函数的调用,编译器将生成错误而不是警告。

因此,请执行以下操作:

项目->属性->配置属性->CUDA C/C++->命令行->附加光学->添加--Werror cross-execution-space-call

这个测试程序

#include <cuda.h>
#include <cuda_runtime.h>

void foo() { int a = 2;}

__host__ __device__ void test() {
    int tId = 1;
    foo();
}

int main(int argc, char **argv) { }

返回以下警告

warning : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed

没有上面提到的附加编译选项并返回以下错误

Error   3   error : calling a __host__ function("foo") from a __host__ __device__ function("test") is not allowed

使用上面提到的附加编译选项。

【讨论】:

  • 我刚刚寻找由于 nvcc 将调用 __host__ 函数的 __host__ __device__ 函数编译为无意义的设备代码(即从 0:mov.u32 %r31, 0; ld.u32 %r32, [%r31]; 显式读取)导致的崩溃。有什么理由不使用--Werror cross-execution-space-call
  • 是否存在“从主机 设备主机函数的调用”不是错误的情况?似乎任何这样的调用都会崩溃。
猜你喜欢
  • 1970-01-01
  • 2013-06-23
  • 2011-02-14
  • 2011-04-15
  • 2011-03-23
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
相关资源
最近更新 更多