これは、例によるcudaの最初の並列コードです。
カーネル呼び出しについて誰か説明してもらえますか:<<< N、1 >>>
これは重要なポイントを持つコードです:
#define N 10
__global__ void add( int *a, int *b, int *c ) {
int tid = blockIdx.x; // this thread handles the data at its thread id
if (tid < N)
c[tid] = a[tid] + b[tid];
}
int main( void ) {
int a[N], b[N], c[N];
int *dev_a, *dev_b, *dev_c;
// allocate the memory on the GPU
// fill the arrays 'a' and 'b' on the CPU
// copy the arrays 'a' and 'b' to the GPU
add<<<N,1>>>( dev_a, dev_b, dev_c );
// copy the array 'c' back from the GPU to the CPU
// display the results
// free the memory allocated on the GPU
return 0;
}
なぜそれを使用したの<<< N , 1 >>>
かというと、各ブロックにN個のブロックと1個のスレッドを使用したということですか?これを記述して<<< 1 , N >>>
、さらに最適化するためにこのブロックで1ブロックとNスレッドを使用できるためです。