Skip to content

Commit 7054b7b

Browse files
committed
Modify PREFER_GPU macro
1 parent 693c7f4 commit 7054b7b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/common/include/macros.fpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@
3434
if (prefer_gpu_mode .eq. 1) then
3535
#:for arg in args
3636
!print*, "Moving ${arg}$ to GPU => ", SHAPE(${arg}$)
37-
! unset
38-
istat = cudaMemAdvise( c_devloc(${arg}$), SIZEOF(${arg}$), cudaMemAdviseUnSetPreferredLocation, cudaCpuDeviceId )
37+
! set preferred location GPU
38+
istat = cudaMemAdvise( c_devloc(${arg}$), SIZEOF(${arg}$), cudaMemAdviseSetPreferredLocation, 0 )
3939
if (istat /= cudaSuccess) then
4040
write(*,"('Error code: ',I0, ': ')") istat
4141
write(*,*) cudaGetErrorString(istat)
4242
endif
43-
! set
44-
istat = cudaMemAdvise( c_devloc(${arg}$), SIZEOF(${arg}$), cudaMemAdviseSetPreferredLocation, 0 )
43+
! set accessed by CPU
44+
istat = cudaMemAdvise( c_devloc(${arg}$), SIZEOF(${arg}$), cudaMemAdviseSetAccessedBy, cudaCpuDeviceId )
45+
if (istat /= cudaSuccess) then
46+
write(*,"('Error code: ',I0, ': ')") istat
47+
write(*,*) cudaGetErrorString(istat)
48+
endif
49+
! prefetch to GPU - physically populate memory pages
50+
istat = cudaMemPrefetchAsync( c_devloc(${arg}$), SIZEOF(${arg}$), 0, 0 )
4551
if (istat /= cudaSuccess) then
4652
write(*,"('Error code: ',I0, ': ')") istat
4753
write(*,*) cudaGetErrorString(istat)

0 commit comments

Comments
 (0)