0

ピア ツー ピア通信用に 2 つの GPU を設定するのに問題があります。Cuda 4.0 を使用し、fortran でプログラミングしています。PGI コンパイラ

ノードで 4 つの GPU が利用可能であることを確認するプログラムを作成しました。

そのうちの 2 つを使用することにしましたが、次のエラーが発生しました: 0: DEALLOCATE: invalid device pointer

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

       !!!Here 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 

次の場合、エラーはありません。

istat = cudaSetDevice(0)
allocate(a_d(N))
!istat = cudaSetDevice(1)
!allocate(b_d(N))

これで、エラーもありません:

!istat = cudaSetDevice(0)
!allocate(a_d(N))
istat = cudaSetDevice(1)
allocate(b_d(N))

しかし、このリターンエラー

istat = cudaSetDevice(0)
allocate(a_d(N))
istat = cudaSetDevice(1)
allocate(b_d(N))

そのため、プログラムを開始するために 2GPU を設定できないようです。2GPU を設定できない理由と、これを解決するためのヒントを教えてください。

4

1 に答える 1

1

ありがとうジャックランタン!!

それはトリックでした。次のようにコードを変更しましたが、完全に機能します

!clean up      
deallocate(freeBefore, totalBefore,freeAfter,totalAfter)
istat = cudaSetDevice(0)
deallocate(a_d)
istat = cudaSetDevice(1)
deallocate(b_d)
deallocate(a,b)

これが私の問題の答えでした。それが他の人を助けることを願っています。

于 2014-03-09T08:34:51.320 に答える