Is allocate(..., source=...) supported in CUDA Fortran?

I’m using allocate(..., source = ...) to allocate and initialize device memory. Is this supported in CUDA Fortran? Asking because compute-sanitizer is complaining about uninitialized memory access, although the data on the device seems correct. No error from the sanitizer if I first allocate then memcpy.

Test code:

program test

  type dummy
    integer, device, allocatable :: a_d(:)
    integer, allocatable :: a(:)
  end type

  type(dummy) :: b


  b%a = 1.d0

  allocate(b%a_d, source=b%a)


end program
$ nvfortran -gpu=cc70 -cuda -o test.x test.f90
$ compute-sanitizer --tool initcheck ./test.x

========= Host API memory access error at host access to 0x2aab0f800000 of size 40 bytes
=========     Uninitialized access at 0x2aab0f800000 on access by cudaMemcpy source

I’m using NVIDIA HPC SDK 21.3, CUDA 11.2.


It looks like it works, but it may not be the most efficient, so not likely what you want to use if performance matters. It appears we allocate the space on the device, allocate a temp on the host, move the “uninitialized” data from device back to the host temp, copy the src data to the host temp, then copy it back to the device, and delete the host temp That explains the warning from memcpy about accessing uninitialized data. I will look into why we had to do it that way, maybe there is a reason. I know we fallback to a similar mechanism when the compiler can’t tell at compile time how to do a cudaMemcpy or cudaMemcpy2D for something like “A_dev(1:n1:i,1:n2:j,1:n3:k) = A”

Thank you for looking into this! I’ll just remove allocate source from our code. The original author probably chose to use it for convenience.