# Allocate derived type array on device

**URL:** <https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [August 13, 2012, 3:47am UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161 "2012-08-13T03:47:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyfengMIT](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cyfengMIT](https://forums.developer.nvidia.com/u/cyfengMIT)\
**Post date:** [August 13, 2012, 3:47am UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161/1 "2012-08-13T03:47:17Z")

</div>

Hi, all

I try to allocate derived type array on gpu device. However, I will get the compiling message “error S0155 : more than one device-resident object in assignment” while the statement is “allocate( g\_cf(i)%a(0:j), g\_cf(i)%b(0:j) )”.  
And I got the runtime message “Process 0: Signalled ACCESS\_VIOLATION at 0x40001c8e” while using the statement instead “allocate( g\_cf(i)%a(j+1), g\_cf(i)%b(j+1) )”.

I’ve tried it using PVF 10.9 on WIN 7 and 12.3 on Linux.  
Did I do anything wrong?  
Thank you.

```nohighlight
      program prog
      use cudafor
      implicit none   
      ! Variables
      Type g_ch
        integer :: cst
        real*8,allocatable :: a(:)
        integer,allocatable :: b(:)
      End type
      Type(g_ch),allocatable,device :: g_cf(:)
      Type(g_ch),allocatable ::cf(:)
      Integer::num, i, j
      
      num=10
      allocate( cf(num) )
      do i=1,num
        cf(i)%cst=i+num
	    allocate( cf(i)%a(0:cf(i)%cst), cf(i)%b(0:cf(i)%cst) )	    
      end do
      
      allocate( g_cf(num) )
      do i=1,num
        g_cf(i)%cst=cf(i)%cst
        j=g_cf(i)%cst
	    allocate( g_cf(i)%a(0:j), g_cf(i)%b(0:j) )
	    !allocate( g_cf(i)%a(j+1), g_cf(i)%b(j+1) )
      end do

      end program prog

```

cyfeng

---

<div class="post-metadata">

**Author:** ![cyfengMIT](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cyfengMIT](https://forums.developer.nvidia.com/u/cyfengMIT)\
**Post date:** [August 13, 2012, 10:56am UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161/2 "2012-08-13T10:56:13Z")

</div>

Hi, all:

Is my case same as this previous post?

> [@Allocate memory in structure of arrays (CUDA Fortran)](https://forums.developer.nvidia.com/t/allocate-memory-in-structure-of-arrays-cuda-fortran/132691/1):
>
> Hello. I’m trying to compile and execute next code: 1.cuf : module fluid type omg real, allocatable :: sad(:) real, allocatable :: saf end type end module program broken\_derivative\_types use cudafor use cudadevice use fluid implicit none integer :: istat type (omg) :: h type (omg), device :: d real, allocatable, device :: d\_z(:) real, allocatable :: h\_z(:) print \*, "dbg" istat = cudaMalloc(d\_z, 10) allocate(h\_z(10)) d\_z = 10.0 h\_z = d\_z print \*, h\_z…

> …user defined types used as device types can only be composed of basic types, or fixed size arrays.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [August 13, 2012, 4:27pm UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161/3 "2012-08-13T16:27:06Z")

</div>

> Is my case same as this previous post?

Yes. Once NVIDIA supports dynamic allocation on the device (coming in CUDA 5 and Kepler2) this restriction may change, but for now, only fixed size types can have the device attribute.

- Mat

---

<div class="post-metadata">

**Author:** ![cyfengMIT](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cyfengMIT](https://forums.developer.nvidia.com/u/cyfengMIT)\
**Post date:** [August 14, 2012, 3:48am UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161/4 "2012-08-14T03:48:39Z")

</div>

Hi, Mat,

OK…Thank you very much.  
And is there any schedule about PGI Fotran supporting CUDA 5 ?  
Thank you in advance.

Feng

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [August 14, 2012, 4:59pm UTC](https://forums.developer.nvidia.com/t/allocate-derived-type-array-on-device/133161/5 "2012-08-14T16:59:13Z")

</div>

Hi Feng,

We usually include the next CUDA version about a month after NVIDIA officially releases it. Though, it may take us a bit to get all the new CUDA 5 features integrated into CUDA Fortran.

- Mat
