简体   繁体   English

Hello World CUDA编译问题

[英]Hello World CUDA compilation issues

I'm using the CUDA by Example book and attempting to compile the first real example in the book. 我正在使用CUDA by Example书籍并尝试编译本书中的第一个真实示例。 I'm on OSX 10.9.2: 我在OSX 10.9.2上:

My source is: 我的来源是:

@punk ~/Documents/Projects/CUDA$ /Developer/NVIDIA/CUDA-6.0/bin/nvcc hello.c
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
hello.c:6:1: error: unknown type name '__global__'
__global__ void kernel(void) {
^
hello.c:6:12: error: expected identifier or '('
__global__ void kernel(void) {
           ^
hello.c:10:3: error: use of undeclared identifier 'kernel'
  kernel<<<1,1>>>();
  ^
hello.c:10:11: error: expected expression
  kernel<<<1,1>>>();
          ^
hello.c:10:17: error: expected expression
  kernel<<<1,1>>>();
                ^
hello.c:10:19: error: expected expression
  kernel<<<1,1>>>();
                  ^
6 errors generated.

And my source is simply: 我的来源很简单:

punk ~/Documents/Projects/CUDA$ cat hello.c

#include <cuda.h>
#include <stddef.h>
#include <stdio.h>
//#include "common/book.h"

__global__ void kernel(void) {
}

int main(void) {
  kernel<<<1,1>>>();

  printf("oh hai\n");
  return 0;
}

I also tested the /Developer/NVIDIA/CUDA-6.0/samples/1_Utilities/deviceQuery example and that built and ran fine. 我还测试了/Developer/NVIDIA/CUDA-6.0/samples/1_Utilities/deviceQuery示例,并且构建并运行正常。

Any help is greatly appreciated! 任何帮助是极大的赞赏! TIA! TIA!

Rename your file to hello.cu 将文件重命名为hello.cu

nvcc by default sends .c or .cpp files directly to the host compiler without doing any device code inspection or compilation on them. nvcc 默认.c.cpp文件直接发送到主机编译器,而不对它们进行任何设备代码检查或编译。

There are various options to change this behavior. 有多种选项可以更改此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM