CUDA fortran manual loop index with function call

Good morning,

I’m having a problem with some CUDA code where I set the starting value of a loop index using a function call. Here’s a condensed example:

attributes( global ) subroutine test_kernel()

  integer    :: i, i_max

#if DOES_NOT_WORK
  i = test_func()
#else
  i = 3
#endif

  i_max = 5

  outer: do while( i .lt. i_max )

     i = i + 1
  end do outer

end subroutine test_kernel


integer attributes( device ) function test_func()

  test_func = 3

end function test_func

Which if compiled with DOES_NOT_WORK set produces

PGF90-S-0000-Internal compiler error. size_of:bad dtype       0 (gpu.f90: 30)
PGF90-S-0000-Internal compiler error. size_of: bad dtype        0 (gpu.f90: 30)
PGF90-S-0000-Internal compiler error. unsupported datatype construct       0 (gpu.f90: 30)
  0 inform,   0 warnings,   3 severes, 0 fatal for test_kernel
/tmp/pgcudaforec0dmJYfd0xe.gpu(7): error: identifier "e15" is undefined

1 error detected in the compilation of "/tmp/pgnvd4d0dOfLN6YgQ.nv0".
PGF90-F-0000-Internal compiler error. pgnvd job exited with nonzero status code       0 (gpu.f90: 37)
PGF90/x86-64 Linux 10.9-0: compilation aborted

Any help with this is much appreciated.

-Martin

I wrapped your routine inside a MODULE

% more cuda_ex.CUF
MODULE foo
CONTAINS
attributes( global ) subroutine test_kernel()
integer :: i, i_max
#if DOES_NOT_WORK
i = test_func()
#else
i = 3
#endif
i_max = 5
outer: do while( i .lt. i_max )
i = i + 1
end do outer
end subroutine test_kernel

integer attributes( device ) function test_func()
test_func = 3
end function test_func
end MODULE foo

and it compiled without indicent with

pgf90 -c cuda_ex.CUF
and

pgf90 -c cuda_ex.CUF -Mcuda=cuda3.1

but not

pgf90 -c cuda_ex.CUF -Mcuda=cuda3.0
this had problems.

If you continue to have problems, look at the
output of your compile line with the added switch

-dryrun

if you find you are reading a ‘sitenvrc’ file, rename this file
to something like sitenvrc_bak so it is not read. We do not use this
anymore except for special diagnosis. You should only be using the
CUDA versions we install with 10.9, and not trying to use your
own installation. If you are using Nvidia CUDA, put their bin directories
after PGIs in you PATH.

regards,
dave