简体   繁体   中英

Hello World CUDA compilation issues

I'm using the CUDA by Example book and attempting to compile the first real example in the book. I'm on 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.

Any help is greatly appreciated! TIA!

Rename your file to 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.

There are various options to change this behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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