54. GPUの選択
計算機がGPUを複数搭載している場合
CUDAで利用するGPUを選択
CUDA APIを利用したGPUの選択
cudaSetDevice()命令
GPGPU講習会
program main
use cudafor
変数宣言 !ここでは標準でGPU0が使われる
GPUやCPUを使った処理 !
stat = cudaSetDevice(3) !ここからGPU3が使われる
...
end program main
54 2016/01/13
68. Hello World
何を確認するか
最小構成のプログラムの作り方
ファイル命名規則(拡張子は.f90)
コンパイルの方法(gfortran, pgf90等を使用)
program main
implicit none
print *,"hello world"
end program main
GPGPU講習会68 2016/01/13
helloworld.f90
69. CUDA FortranでHello World
何を確認するか
最小構成のプログラムの作り方
ファイル命名規則(拡張子は.cuf)
コンパイルの方法(pgf90を使用)
program main
implicit none
print *,"hello world"
end program main
GPGPU講習会69
program main
implicit none
print *,"hello world"
end program main
違いは拡張子だけ?
2016/01/13
helloworld.cuf helloworld.f90
71. CUDA FortranでHello World
CUDA Fortran専用の処理を追加
2016/01/13GPGPU講習会71
module cuf_kernel
implicit none
contains
attributes(global) subroutine kernel()
end subroutine kernel
end module cuf_kernel
program main
use cudafor
use cuf_kernel
implicit none
call kernel<<<1,1>>>()
print *,"hello world"
end program main
GPUで実行されるサブルーチン
(カーネル)
attributes(global)が追加
・・・
通常のサブルーチン呼出と
は異なり,<<<>>>が追加
・・・
helloworld_kernel.cuf
113. CUDAでカーネルを作成するときの制限
GPGPU講習会113
x,yはCPU側のメモリに存在
値渡し
CPU→GPUへ値がコピーされる
Fortranはポインタ渡し
値渡しにする場合はvalue
属性を付ける
attributes(global) &
subroutine add(a, x, b, y, c)
implicit none
real :: a(N)
real :: b(N)
real :: c(N)
real,value :: x,y !値渡し
integer :: i
do i=1,N
c(i) = x*a(i) + y*b(i)
end do
end subroutine add
:
program main
:
call add<<<1,1>>>(a,1.0,b,2.0,c)
:
end program main
2016/01/13