2015年9月5日 星期六

CUDA: Hello World!

since: 2015/09/05
update: 2015/09/05

reference:
1. Professional CUDA C Programming
2. I touchs: Get Started On NVIDIA Jetson TK1
3. I touchs: How to re-flash your Jetson TK1 Development Kit 
4. I touchs: Using the Jetson TK1 as a remote development environment for CUDA


A. 在 Nsight Eclipse Edition 撰寫程式如下:
     // 檔名: hello.cu
#include <stdio.h>

// __global__:
// function will be called on the CPU and executed on the GPU

__global__ void helloFromGPU()
{
    // blockIdx.x for block index
    // threadIdx.x for thread index

    printf("Hello World from GPU! block %d thread %d \n", blockIdx.x, threadIdx.x);
}

int main(void)
{
    // hello from cpu
    printf("\nHello World from CPU!\n\n");

    // kernel(GPU code) configuration: total threads = blockNum x threadNum
    int blockNum = 2;
    int threadNum = 3;

    // hello from gpu: call from the host thread to the code on the device side
    helloFromGPU <<<blockNum, threadNum >>>();
    cudaDeviceReset(); //destroy and clean up all resources
    //cudaDeviceSynchronize();

    return 0;
}


-----------------------------------------------------------------------------------------------

B. 執行結果:


沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。