Variable does not get stored in CUDA Kernel

Dear all,

I have a problem when I run the following subroutine (reported in a simplified version for easy readability):

  subroutine doMx1(n,dli,c,a,b)
    implicit none
    integer, intent(in), dimension(3) :: n
    real(rp), intent(in), dimension(3) :: dli
    real(rp), intent(in), dimension(0:,0:,0:) :: c
    real(rp), intent(out), dimension(0:,0:,0:,1:) :: a,b
    real(rp), dimension(8),device :: mx
    real(rp) :: dli1,dli2,dli3
    real(rp), dimension(3) :: dl
    integer :: i,j,k,ii
    !
#ifdef USE_CUDA
    attributes(managed) :: nor,cur,vof, mx, my,mz,nx,ny,nz,dl
    integer :: istat
#endif
    dli1 = dli(1)
    dli2 = dli(2)
    dli3 = dli(3)

    !$cuf kernel do(3) <<<*,*>>>     
    do k=1,n(3)
      do j=1,n(2)
        do i=1,n(1)
          mx(1)=((c(i+1,j  ,k  )+c(i+1,j+1,k  )+c(i+1,j  ,k+1)+c(i+1,j+1,k+1))-&
                 (c(i  ,j  ,k  )+c(i  ,j+1,k  )+c(i  ,j  ,k+1)+c(i  ,j+1,k+1)))*dli1*0.25
          if (mx(1).gt.0) then
              print*, "here"
          endif
       enddo
     enddo
  enddo

In fact, the value of mx(1) remains zero even for punctual values of c for which it should be different than zero.

Do you have any idea what the issue could be?

Best,

Marcres

Hi Marcres,

Difficult to tell what’s wrong without a full reproducing example. Can you please provide one?

Does “c” have the managed or device attribute? I assume it does since otherwise I would expect that the code would error with an illegal memory address if it wasn’t.

Is mx an array or a scalar? You have it declared as a scalar but using it as an array.

Also, “mx” can’t have both a device and managed attribute, so I’m assuming that the paired down code is incorrect or you’re not defining USE_CUDA.

Though I assume these are just typos in your simplified version. They may be correct in the full version.

-Mat