2011-09-04 10 views
5

उबंटू 10.10मुसीबत संकलन helloworld.cu

यह CUDA by Example से है में इस हैलो दुनिया नमूना संकलन है, अध्याय 3 (कोई संकलन निर्देश प्रदान>: @)

#include <iostream> 

__global__ void kernel (void){ 


} 

int main(void){ 

    kernel <<<1,1>>>(); 
     printf("Hellow World!\n"); 
    return 0; 

} 

मैं यह मिल गया:

$ nvcc -lcudart hello.cu hello.cu(11): error: identifier "printf" is undefined

1 error detected in the compilation of "/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii".

क्यों? इस कोड को कैसे संकलित किया जाना चाहिए?

+0

@awoodland है: Hmmmm, दूसरा जवाब यह होता है, और वास्तव में खंड B14 "printf (" हैलो धागा% d, च =% च है कहते हैं \ n ", threadIdx.x, f);" – Kheldar

+0

तब इसे कैसे संकलित किया जाना चाहिए? – andandandand

+0

उस पुस्तक से कोड सामान केवल स्निपेट हैं यदि मुझे सही याद है, और हमेशा पूर्ण उदाहरण नहीं हैं। उल्लेख नहीं है कि वे उन उदाहरणों में बुरे अभ्यास के अल्टो का उपयोग करते हैं .... –

उत्तर

10

आप शामिल करने के लिए stdio.h नहीं iostreamprintf के लिए (man 3 printf देखें) (जो std::cout सामान के लिए है) की जरूरत है। मुझे here पुस्तक के लिए स्रोत कोड मिला।

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.hstdio.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 
+1

मैंने अध्याय वर्बैटिम, सेक्शन 3.2.2 से दूसरा नमूना पोस्ट किया है, और इसमें andandandand

+0

@omgzor शामिल है: यह एक गलती है। पुस्तक के लिए [इरेटा] (http://developer.nvidia.com/cuda-example-errata-page-0) देखें (पृष्ठ से जो मैंने अपने उत्तर में लिंक किया है)। '' p.23,25 - # इस उदाहरण के लिए शामिल हैं गलत तरीके से दिखाए गए हैं: # शामिल करें और # शामिल "book.h." इसे डाउनलोड करने योग्य कोड पैकेज में सही किया गया है, लेकिन इसे पढ़ना चाहिए: # शामिल करें और # शामिल "../common/book.h" ''। (इसके अलावा आप शायद 'Chapter03/hello_world.cu' की बजाय' Chapter03/simple_kernel.cu' के लिए कोड देख रहे हैं) – user786653

+0

धन्यवाद, मैंने पुस्तक के लिए कोड नहीं देखा है, क्योंकि मेरे पास पीडीएफ नहीं है इसे उपलब्ध के रूप में उल्लेख करें। – andandandand

संबंधित मुद्दे