首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于点对点的多GPU

用于点对点的多GPU
EN

Stack Overflow用户
提问于 2014-03-09 00:34:57
回答 1查看 235关注 0票数 0

我有一些困难,为对等通信设置2个GPU。我正在使用Cuda 4.0,并使用fortran进行编程。PGI编译器

我编写了一个程序,确认我在我的节点上有4个GPU可用。

我决定使用其中的两个,但是有以下错误:0: DEALLOCATE:无效设备指针

代码语言:javascript
复制
subroutine  directTransfer()

        use cudafor
        implicit none

        integer, parameter :: N = 4*1024*1024
        real, pinned, allocatable :: a(:), b(:)
        real, device, allocatable :: a_d(:), b_d(:)


        !these hold free and total memory before and after
        !allocation, used to verify  allocation happening on proper devices

        integer (int_ptr_kind()),allocatable ::
     &   freeBefore(:), totalBefore(:),
     &   freeAfter(:), totalAfter(:)

        integer :: istat, nDevices, i, accessPeer, timingDev
        type(cudaDeviceProp)::prop
        type(cudaEvent)::startEvent,stopEvent
        real :: time

        !allocate host arrays
        allocate(a(N), b(N))
        allocate(freeBefore(0:nDevices -1),
     &      totalBefore(0:nDevices -1))
        allocate(freeAfter(0:nDevices -1),
     &      totalAfter(0:nDevices -1))
        write(*,*) 'Start!'
        !get devices ionfo (including total and free memory)
        !before allocation
        istat = cudaGetDeviceCount(nDevices)
        if(nDevices < 2) then
            write(*,*) 'Need at least two CUDA capable devices'
            stop
        end if

          write(*,"('Number of CUDA-capable devices: ',
     &       i0, /)"),nDevices

        do i = 0, nDevices - 1
            istat = cudaGetDeviceProperties(prop, i)
            istat = cudaSetDevice(i)
            istat = cudaMemGetInfo(freeBefore(i), totalBefore(i))
        end do

       !is the trouble zone!!
        istat = cudaSetDevice(0)
        allocate(a_d(N))
        istat = cudaSetDevice(1)
        allocate(b_d(N))


       deallocate(freeBefore, totalBefore,freeAfter,totalAfter)
       deallocate(a,b,a_d,b_d)
       end subroutine  directTransfer 

以下是我没有错误的地方:

代码语言:javascript
复制
istat = cudaSetDevice(0)
allocate(a_d(N))
!istat = cudaSetDevice(1)
!allocate(b_d(N))

在此情况下,也没有错误:

代码语言:javascript
复制
!istat = cudaSetDevice(0)
!allocate(a_d(N))
istat = cudaSetDevice(1)
allocate(b_d(N))

但是这个返回错误

代码语言:javascript
复制
istat = cudaSetDevice(0)
allocate(a_d(N))
istat = cudaSetDevice(1)
allocate(b_d(N))

因此,我似乎不能设置2GPU来启动我的程序。你能帮我理解为什么不能设置2GPU和解决这个问题的提示吗?

EN

回答 1

Stack Overflow用户

发布于 2014-03-09 08:34:51

谢谢JackOLantern!

这就是诀窍。我修改了代码,如下所示,它运行得非常完美

代码语言:javascript
复制
!clean up      
deallocate(freeBefore, totalBefore,freeAfter,totalAfter)
istat = cudaSetDevice(0)
deallocate(a_d)
istat = cudaSetDevice(1)
deallocate(b_d)
deallocate(a,b)

这是我的问题答案。希望它能帮助别人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22276968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档