Memory 使用Fortran查找可用的图形卡内存

Memory 使用Fortran查找可用的图形卡内存,memory,graphics,cuda,fortran,intel,Memory,Graphics,Cuda,Fortran,Intel,我正在使用GlobalMemoryStatusEX查找系统中的内存量。 有没有类似的方法来查找图形卡上的内存量? 下面是我的一段代码: use kernel32 use ifwinty implicit none type(T_MEMORYSTATUSEX) :: status integer(8) :: RetVal status%dwLength = sizeof(status) RetVal = GlobalMemoryStatusEX(status) write(*,*) 'Memo

我正在使用GlobalMemoryStatusEX查找系统中的内存量。 有没有类似的方法来查找图形卡上的内存量? 下面是我的一段代码:

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
我正在Windows 7 x64上使用英特尔Visual Fortran 2010。
谢谢大家!

既然你用CUDA标签标记了这个问题,我就提供一个CUDA的答案。考虑到您的环境,不确定这是否真的有意义

我还没有在IVF上测试过,但它可以在gfortran和PGI fortran(linux)上运行。您可以使用许多实现中提供的fortran
iso_c_binding
模块直接从fortran代码中的CUDA运行时API库调用例程。其中一个例行程序是

下面是一个从gfortran(在linux上)调用它的完整示例:


在windows中,您需要有一个正确安装的CUDA环境(假定为visual studio)。然后,您需要在该安装中找到
cudart.lib
,并链接到它。我不能100%肯定这会在体外受精中成功链接,因为我不知道它是否会与VS图书馆链接的方式类似。

非常感谢您的回答!它在我的体外受精环境中非常有效!
$ cat cuda_mem.f90
!=======================================================================================================================
!Interface to 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 ) then
      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

$