19.04.2013 Views

543-pdf

543-pdf

543-pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CUDAを使って“Hello World!!”<br />

Hello World!! を表示するサンプル(main.cu)<br />

__global__ void hello( char *data )<br />

{<br />

char *text = "Hello World!!¥n";<br />

data[ threadIdx.x ] = text[ threadIdx.x ];<br />

}<br />

int main( int argc, char *argv[] )<br />

{<br />

char *dData, hData[ 15 ];<br />

}<br />

cudaMalloc( ( void ** )&dData, sizeof( char ) * 15 );<br />

dim3 nThreads( 15, 1 );<br />

dim3 nBlocks( 1, 1 );<br />

hello>( dData );<br />

cudaMemcpy( hData, dData, sizeof( char ) * 15, cudaMemcpyDeviceToHost );<br />

printf( "%s", hData );<br />

cudaFree( dData );<br />

return( 0 );<br />

34

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!