Device attribute mismatch

Hi all,
I tried with a simple code to compute parallel. My code is
module simple
contains
attributes(global) subroutine increment(a,b)
implicit none
integer, intent(inout)::a(:)
integer,intent(in)::b
integer::i
i=threadIdx%x
a(i)=a(i)+b
return
end subroutine increment
end module simple
program incrementtest
use cudafor
use simple
implicit none
integer,parameter::n=256
integer::a(n),b
integer,device::a_d(n)
a=1
b=3
a_d=a
call increment<<<1,n>>>(a_d,b)
a=a_d
if (any(a.ne.4)) then
write(,) ‘program failed’
else
write(,) ‘program passed’
endif
end program incrementtest

I got an error
PGF90-S-0528-Argument number 2 to increment: device attribute mistach, line28… I got the same error for another program.
Thank for avance

Hi camaptrang,

Since Fortran passes variables by reference, you’re trying to pass b’s host side address to the kernel. Instead, you need to pass “b” by value (i.e. the value of the variable is passed to the device not it’s host address), by simply added the “value” attribute to “b” declaration.

attributes(global) subroutine increment(a,b) 
implicit none 
integer, intent(inout)::a(:) 
integer,value, intent(in)::b 
integer::i 
i=threadIdx%x 
a(i)=a(i)+b 
return 
end subroutine increment

Hope this helps,
Mat

thank you very much mkcolg,
It work now