Commit 924b2848 authored by Andreas Marek's avatar Andreas Marek
Browse files

Check that user does not specify GPU outside of range

parent 1ab373e1
......@@ -84,6 +84,36 @@ module mod_check_for_gpu
stop
endif
success = .true.
numberOfDevices = -1
#ifdef WITH_NVIDIA_GPU_VERSION
! call getenv("CUDA_PROXY_PIPE_DIRECTORY", envname)
success = cuda_getdevicecount(numberOfDevices)
#endif
#ifdef WITH_AMD_GPU_VERSION
! call getenv("CUDA_PROXY_PIPE_DIRECTORY", envname)
success = hip_getdevicecount(numberOfDevices)
#endif
if (.not.(success)) then
#ifdef WITH_NVIDIA_GPU_VERSION
print *,"error in cuda_getdevicecount"
#endif
#ifdef WITH_AMD_GPU_VERSION
print *,"error in hip_getdevicecount"
#endif
stop 1
endif
#ifdef WITH_INTEL_GPU_VERSION
gpuAvailable = .false.
numberOfDevices = -1
numberOfDevices = 1
print *,"Manually setting",numberOfDevices," of GPUs"
if (numberOfDevices .ge. 1) then
gpuAvailable = .true.
endif
#endif
if (obj%is_set("use_gpu_id") == 1) then
call obj%get("use_gpu_id", use_gpu_id, error)
if (use_gpu_id == -99) then
......@@ -110,6 +140,12 @@ module mod_check_for_gpu
endif
endif
if (use_gpu_id+1 .gt. numberOfDevices) then
print *,"Task=",myid," wants to use GPU id=",use_gpu_id," allowed (0:#GPUs-1)"
print *,"However, there are only ",numberOfDevices," on the node"
stop 1
endif
success = .true.
#ifdef WITH_NVIDIA_GPU_VERSION
success = cuda_setdevice(use_gpu_id)
......
......@@ -689,7 +689,8 @@ program test
#if (TEST_GPU_SET_ID == 1) && (TEST_INTEL_GPU == 0)
! simple test
! Can (and should) fail often
gpuID = mod(myid,2)
!gpuID = mod(myid,2)
gpuID = mod(myid,1)
print *,"Task",myid,"wants to use GPU",gpuID
call e%set("use_gpu_id", int(gpuID,kind=c_int), error_elpa)
assert_elpa_ok(error_elpa)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment