Find available graphics card memory using Fortran -
i using globalmemorystatusex in order find out amount of memory in system. there similar way find amount of memory on graphics card? here piece of code :
use kernel32 use ifwinty implicit none type(t_memorystatusex) :: status integer(8) :: retval status%dwlength = sizeof(status) retval = globalmemorystatusex(status) write(*,*) 'memory available =',status%ullavailphys
i using intel visual fortran 2010 on windows 7 x64. thank you!
since tagged question cuda tag, i'll offer cuda answer. not sure if makes sense given environment.
i haven't tested on ivf, works on gfortran , pgi fortran (linux). can use fortran iso_c_binding
module available in many implementations directly call routines cuda runtime api library in fortran code. 1 of routines cudamemgetinfo.
here's worked example of calling gfortran (on linux):
$ cat cuda_mem.f90 !======================================================================================================================= !interface cuda c subroutines !======================================================================================================================= module cuda_rt use iso_c_binding interface ! integer (c_int) function cudamemgetinfo(fre, tot) bind(c, name="cudamemgetinfo") use iso_c_binding implicit none type(c_ptr),value :: fre type(c_ptr),value :: tot end function cudamemgetinfo ! end interface end module cuda_rt !======================================================================================================================= program main !======================================================================================================================= use iso_c_binding use cuda_rt type(c_ptr) :: cpfre, cptot integer*8, target :: freemem, totmem integer*4 :: stat freemem = 0 totmem = 0 cpfre = c_loc(freemem) cptot = c_loc(totmem) stat = cudamemgetinfo(cpfre, cptot) if (stat .ne. 0 ) write (*,*) write (*, '(a, i2)') " cuda error: ", stat write (*,*) stop end if write (*, '(a, i10)') " free: ", freemem write (*, '(a, i10)') " total: ", totmem write (*,*) end program main $ gfortran -o3 cuda_mem.f90 -l/usr/local/cuda/lib64 -lcudart -o cuda_mem $ ./cuda_mem free: 2755256320 total: 2817982464 $
in windows, need have installed cuda environment, (which presumes visual studio). need locate cudart.lib
in install, , link against that. i'm not 100% sure link in ivf, since don't know if link way vs libraries link.
Comments
Post a Comment