cuda 编程 helloworld 打印 blockIdx和threadIdx

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cuda 编程 helloworld 打印 blockIdx和threadIdx相关的知识,希望对你有一定的参考价值。


#include <stdio.h>

__global__ void hello_from_gpu()

const int bid = blockIdx.x;
const int tid = threadIdx.x;
printf("Hello World from block %d and thread %d!\\n", bid, tid);


int main(void)

hello_from_gpu<<<2, 4>>>();
cudaDeviceSynchronize();
return 0;
nvcc hello4.cu -o hello4
./hello4
Hello World from block 1 and thread 0!
Hello World from block 1 and thread 1!
Hello World from block 1 and thread 2!
Hello World from block 1 and thread 3!
Hello World from block 0 and thread 0!
Hello World from block 0 and thread 1!
Hello World from block 0 and thread 2!
Hello World from block 0 and thread 3!


以上是关于cuda 编程 helloworld 打印 blockIdx和threadIdx的主要内容,如果未能解决你的问题,请参考以下文章

cuda 编 程 helloworld 打印 blockIdx和threadIdx.x threadIdx.y

cuda 编程 helloworld

cuda 线程索引

Hello World的条件输出

无法打印从 CUDA 内核返回的值 [关闭]

Lua的基本使用