Reshape intrinsic for cuda fortan


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:


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

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.


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 
call c_f_pointer(C_DEVLOC(temp1), temp2, SIZE(temp1))

Hope this helps,