Moving device data

Hi all, I am a newbie to the domain of HPC, and recently I met a problem of copying device data within a host subroutine. The simplest code is given as below

program test
    use cudafor
    implicit none
    integer::p1(4,4)=0
    integer,device::a1,b1(4),dp1(4,4)
    dp1=p1
    b1(1:4)=dp1(2,1:4)
    a1=dp1(3,2)
end program

And the nvfortran compiler throws an error as below

user@node:~/$ nvfortran test.cuf 
NVFORTRAN-S-0519-More than one device-resident object in assignment (test.cuf: 8)
  0 inform,   0 warnings,   1 severes, 0 fatal for test

It seems that a value in a device array cannot be assigned to a single number allocated on the device. And I do not think it is efficient to write a kernel subroutine just to copy out a single value from a large array.

I’ve seen some posts talked about the same problem, but unfortunately did not find any useful solutions.

I’d like to know if anyone can tell me how to solve this problem?

Thanks a lot!

While CUDA Fortran does allow some data transfer via array syntax, it is limited. See: CUDA Fortran Programming Guide Version 21.7 for ARM, OpenPower, x86

For move complex data transfers, including device-to-device, you’ll want to look at using the cudaMemCpy routines:
https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#mm-cudamemcpy

Do be mindful with using array slices since the data transfers must be contiguous.

Thanks for your reply!

I’ve fixed the problem using pointers. Like

integer::ierr
integer,pointer,device::ptr1
integer,target,device::dp1(4,4)
ptr1=>dp1(3,2)
ierr=cudaMemcpy(a1,ptr1,1,3)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.