在Ubuntu 10.10中编译这个hello world示例
这是来自CUDA的示例,第3章(没有提供编译指令>:@)
#include <iostream>
__global__ void kernel (void){
}
int main(void){
kernel <<<1,1>>>();
printf("Hellow World!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我懂了:
$ nvcc -lcudart hello.cu hello.cu(11):错误:标识符"printf"未定义
在编译"/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii"时检测到1错误.
为什么?该代码应如何编译?
use*_*653 12
你需要包括stdio.h
not iostream
(用于std::cout
东西)printf
(参见参考资料man 3 printf
).我在这里找到了这本书的源代码.
chapter03/hello_world.cu
实际上是:
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation.
* Any use, reproduction, disclosure, or distribution of this software
* and related documentation without an express license agreement from
* NVIDIA Corporation is strictly prohibited.
*
* Please refer to the applicable NVIDIA end user license agreement (EULA)
* associated with this source code for terms and conditions that govern
* your use of this NVIDIA software.
*
*/
#include "../common/book.h"
int main( void ) {
printf( "Hello, World!\n" );
return 0;
}
../common/book.h
包括哪里stdio.h
.
该README.txt
文件详细说明了如何编译示例:
The vast majority of these code examples can be compiled quite easily by using NVIDIA's CUDA compiler driver, nvcc. To compile a typical example, say "example.cu," you will simply need to execute: > nvcc example.cu