CUDA C Programming:Hello World!編

シェアする

その買うを、もっとハッピーに。|ハピタス

PyCUDAにはCUDA Cが欠かせないので、CUDA Cの学習を始めることにする。取り敢えず適当なチュートリアルサイトを探して、それを叩き台にして学習することにする。

スポンサーリンク

tutorial siteのgit clone

!mkdir git
cd git
/home/workspace/git
!git clone https://github.com/deeperlearning/professional-cuda-c-programming.git
Cloning into 'professional-cuda-c-programming'...
remote: Enumerating objects: 180, done.
remote: Counting objects: 100% (180/180), done.
remote: Compressing objects: 100% (135/135), done.
remote: Total 180 (delta 44), reused 180 (delta 44), pack-reused 0
Receiving objects: 100% (180/180), 1.22 MiB | 1.85 MiB/s, done.
Resolving deltas: 100% (44/44), done.
cd professional-cuda-c-programming
/home/workspace/git/professional-cuda-c-programming
ls
README.md  examples/  solutions/
cd examples
/home/workspace/git/professional-cuda-c-programming/examples
ls
chapter01/  chapter03/  chapter05/  chapter07/  chapter09/  common/
chapter02/  chapter04/  chapter06/  chapter08/  chapter10/
cd chapter01
/home/workspace/git/professional-cuda-c-programming/examples/chapter01
ls
Makefile  hello.cu
スポンサーリンク

hello world program

# %load hello.cu
#include "../common/common.h"
#include <stdio.h>

/*
 * A simple introduction to programming in CUDA. This program prints "Hello
 * World from GPU! from 10 CUDA threads running on the GPU.
 */

__global__ void helloFromGPU()
{
    printf("Hello World from GPU!\n");
}

int main(int argc, char **argv)
{
    printf("Hello World from CPU!\n");

    helloFromGPU<<<1, 10>>>();
    CHECK(cudaDeviceReset());
    return 0;
}
!make
nvcc -O2 -arch=sm_20 -o hello hello.cu
nvcc fatal   : Value 'sm_20' is not defined for option 'gpu-architecture'
Makefile:6: recipe for target 'hello' failed
make: *** [hello] Error 1
!nvcc -O2 -arch=sm_61 -o hello hello.cu
!./hello
Hello World from CPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!

hello world programmingは基礎中の基礎なので一応やってみた。

スポンサーリンク