Reshape intrinsic for cuda fortan

Hi,

I have a 3D array on device and want to reshape it to 1D. What is the best possible option. Don’t want do a data copy from location to another.

here is a example code:

HOST CODE:

integer, dimension(10,20,30),device:: temp1
integer,dimension(6000),device:temp2

temp2 = reshape(source=temp1,shape=shape(temp2))

The above code doesn’t seem to work.

I was wondering whether reshape is supported in cuda fortan or not.
I tried googling but was unable to get any useful information.

Sriram

Hi Sriram,

RESHAPE isn’t supported with device arrays since it would require the data to be copied back to the host, put in a temp array, perform the reshape, and then copy the data back to the device. However, even if supported, RESHAPE would copy the data.

What I think you want is that “temp1” and “temp2” both point to the same data on the device. In this case what you need to do is change temp2 to be allocatable, and then use the “c_f_pointer” to have both arrays point to the same data.

For example, something like:

...
integer, dimension(10,20,30), device:: temp1 
integer,dimension(:),allocatable,device:temp2 
call c_f_pointer(C_DEVLOC(temp1), temp2, SIZE(temp1))
...

Hope this helps,
Mat