I was trying debugging the Cuda Fortran code using cuda-gdb. However, I got wrong values when I printed the global variables inside cude-gdb.
Here is the source code:
module test
contains
attributes(global) subroutine saxpy(x,y,a)
implicit none
real,device :: x(:), y(:)
real,value :: a
integer :: i, n
n = size(x)
i = blockDim%x * (blockIdx%x - 1) + threadIdx%x
if (i <= n) y(i) = y(i) + a*x(i)
end subroutine saxpy
end module test
program testSaxpy
use test
use cudafor
implicit none
integer, parameter :: N = 40000
real :: x(N), y(N), result(N), a
real, device :: x_d(N), y_d(N)
type(dim3) :: grid, tBlock
integer :: i
tBlock = dim3(256,1,1)
grid = dim3(ceiling(real(N)/tBlock%x),1,1)
a = 2.0
do i = 1,N
x(i) = float(i)
y(i) = 3.0*float(i)
enddo
result = a*x + y
x_d = x
y_d = y
call saxpy<<<grid, tBlock>>>(x_d,y_d,a)
y = y_d
write(*,*) 'Max error: ', maxval(abs(y-result))
end program testSaxpy
The file was compiled using the following command:
pgf90 -Mcuda=cc8.0 testSaxpy.cuf -O0 -g -Mcuda=debug -Mcuda=nordc
Then I ran:
cuda-gdb ./a.out
Then I set a break point:
b 10
Then run the code:
r
Then at the break point, I tried to print the value of x(1):
p x(1)
and it displayed:
$1 = -6.75539944e+15
which was not correct.
Did I miss anything?
Please let me know if you know how to print the global variables correctly in cuda-gdb. Thanks a lot!