1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CUDA | 応用編

Last updated at Posted at 2021-04-30

https://www.gsic.titech.ac.jp/supercon/main/attwiki/index.php?plugin=attach&refer=Supercomputing%20Contest%202013%2FGPU%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%B3%87%E6%96%99&openfile=gpu-prog-2.pdf
##多次元配列についてのテクニック
CPU上では、大域変数として多次元配列を使える
– short int h_array[MAX1][MAX2][MAX3][MAX4];
のように定義できる
###利用方法(1): cudaMallocによる方法
###利用方法(2): __device__による方法
(1) 大域変数の定義に__device__をつけると、GPUメモリ上に確保される
__device__ int d_array[MAX1][MAX2][MAX3][MAX4];
(2) ただしこのままだと「CPU側から」コピーできない。
cudaGetSymbolAddressで変換しておく必要あり
例:

cudaGetSymbolAddress(&d_array_ptr, d_array);
cudaMemcpy (d_array_ptr, h_array, sizeof(int)*MAX1*MAX2*MAX3*MAX4, cudaMemcpyHostToDevice);
cudaMemcpy (h_array, d_array_ptr,
 sizeof(int)*MAX1*MAX2*MAX3*MAX4, cudaMemcpuDeviceToHost);```
(3) これなら、GPUカーネル関数内でもd_array[i][j][k][l] のように使えてちょっと便利!

##「コアレスド・アクセス」によるメモリアクセス効率化
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/650544/cb446040-a036-05b7-9003-74be58c13041.png)

##ifを避ける

##Stream


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?