How to use the attributes(device) subroutine sub(…)

module ddrealmod

type dd_real
real*8 ddr(2)
end type

interface assignment (=)
module procedure gg
end interface


attributes(device) subroutine gg(qa, db)
implicit real*8 (d),type (dd_real) (q)
intent (out):: qa
intent (in):: db
qa%ddr(1) = db
qa%ddr(2) = 0.d0
end subroutine
end module

I can’t call the subroutine,what’s wrong? Is there any wrong in my code?
Please hele me thank you!


“device” routines can only be called from “global” routines or other “device” routines. You’re trying call it from host code.

  • Mat

Hi Mat,

Thank you I understand it.
But I want to know why “device” routines can’t be called from “global” routines or other “device” routines when they are in different modules.


Hi swl,

There’s no linker for the GPU code, hence no way to associate symbols from different objects. Also, there are no calls so all device routines are inlined by the compiler, hence need to be within the same module.

Hope this helps,

Thank you Mat!