Restrictions on Device Subprograms

In section 3.1.2 of the CUDA Fortran Programming Guide, it is stated that “A kernel subroutine many not be contained in another subroutine or function, and may not contain any other subprogram”. In section 3.1.5. it says that “A subroutine or function with the device or global attribute must satisfy the following restrictions:…It may not be contained in another subroutine or function”.

Taken literally, this means that only the host main program can call a kernel subroutine. Is this correct, OR, should “another subroutine or function” be read as “another KERNEL subroutine or function”?

Enlightenment needed!

Malcolm Bibby

Hi Malcom,

This is stating that device routines can not be used as a contained routine within another routine. Calling a kernel from a host routine is fine.

This is not allowed:

subroutine foo ()
... do something ...

   attributes(global) subroutine bar () 
... do something ...
    end subroutine bar

end subroutine foo

Hope this helps,

Thanks Mat for the reply. I think I understand what you said. So, if one wants to keep the code for a subroutine with attributes (global) somewhere other than in the main program, one would keep it in a module - is this correct?


Hi Malcom,

one would keep it in a module - is this correct?

Yes, this is the advised method.

  • Mat

Thanks Mat. Now I know the answer it is obvious!!