# CUDA Fortran : device variable in module

**URL:** <https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [October 5, 2009, 3:47pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417 "2009-10-05T15:47:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RTLEE1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@RTLEE1](https://forums.developer.nvidia.com/u/RTLEE1)\
**Post date:** [October 5, 2009, 3:47pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417/1 "2009-10-05T15:47:58Z")

</div>

In section 3.2.1 of the CUDA Fortran Programming Guide, it says that device variables and arrays may appear in host and device modules. However, the following simple code always gives the error “copyin Symbol Memcpy FAILED: 13”. I’d appreciate any ideas anyone has.

Thanks!

```nohighlight
module cudamod
	implicit none

	integer, device :: int_d(1)
end module cudamod

program fcuda
	use cudafor
	use cudamod
	implicit none

	integer :: int_h(1)

	int_h = 0

	int_d = int_h
end program fcuda

```

---

<div class="post-metadata">

**Author:** ![brentl](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@brentl](https://forums.developer.nvidia.com/u/brentl)\
**Post date:** [October 5, 2009, 11:06pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417/2 "2009-10-05T23:06:03Z")

</div>

Hi,

This is a known problem. Currently, the registering of the structure containing module device data is triggered by the presence of device code in the module. We will address this in a near-term future release.

For now, the work-around is to add a global routine. It doesn’t have to do anything.

contains  
attributes(global) subroutine foo  
end subroutine  
end module cudamod

---

<div class="post-metadata">

**Author:** ![RTLEE1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@RTLEE1](https://forums.developer.nvidia.com/u/RTLEE1)\
**Post date:** [October 6, 2009, 12:53pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417/3 "2009-10-06T12:53:53Z")

</div>

Thanks for the reply. I just tried that, but I still get the same error. I’ve pasted the complete code below.

Thanks! - Todd

```nohighlight
module cudamod
   implicit none

   integer, device :: int_d(1)

   contains
   attributes(global) subroutine foo
   end subroutine foo
end module cudamod

program fcuda
   use cudafor
   use cudamod
   implicit none

   integer :: int_h(1)

   int_h = 0

   int_d = int_h
end program fcuda

```

---

<div class="post-metadata">

**Author:** ![brentl](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@brentl](https://forums.developer.nvidia.com/u/brentl)\
**Post date:** [October 8, 2009, 6:08pm UTC](https://forums.developer.nvidia.com/t/cuda-fortran-device-variable-in-module/131417/4 "2009-10-08T18:08:13Z")

</div>

Sorry, I was running the wrong version of the compiler.

Setting device data in a module won’t be supported in the beta compilers. It will work in our November release.
