I’m new to CUDA Fortran. Can someone please explain what is wrong with the following code? Why am I getting segmentation fault? What should I do to pass variables from different modules to a kernel called a subroutine as the code below?
case 1:
attributes(global) subroutine increment(a)
implicit none
real(kind=8),device::a(:)
integer :: i
i = threadIdx%x
a(i)=a(i)+1
if(a(i)/=2)then
write(*,*)' Program Passed in Device'
endif
end subroutine increment
module common
implicit none
real(kind=8):: a(2)
real(kind=8),device:: a_d(2)
end module common
program incrementTestGPU
use cudafor
use common
implicit none
a=1
a_d=a
call prac
end program incrementTestGPU
subroutine prac
use common
use cudafor
call increment<<<1,2>>>(a_d)
a=a_d
if(any(a/=2))then
write(*,*)' **** Program Failed **** '
else
write(*,*)' **** Program Passed **** '
endif
end subroutine prac
Earlier I got segmentation fault, now the code is not printing the write statement in the device.
case 2:
module simpleOps_m
contains
attributes(global) subroutine increment(a)
implicit none
real(kind=8),device::a(2)
integer :: i
i = threadIdx%x
a(i)=a(i)+1
if(a(i)/=2)then
print*,' Program Passed in Device',a(i)
endif
end subroutine increment
end module simpleOps_m
module common
implicit none
real(kind=8):: a(2)
real(kind=8),device:: a_d(2)
end module common
program incrementTestGPU
use cudafor
use common
use practice
implicit none
a=1
a_d=a
call prac
end program incrementTestGPU
module practice
contains
subroutine prac
use simpleOps_m
call increment<<<1,2>>>(a_d)
a=a_d
if(any(a/=2))then
write(*,*)' **** Program Failed **** '
else
write(*,*)' **** Program Passed **** '
endif
end subroutine prac
end module practice```