Your first attempt fails because the structure is not bitwise copyable. In fact, it is not allowed to transfer a structure that contains pointers. With the second approach, the compiler cannot match the member variables since A
is not available on the accelerator. You can solve the problem by extracting the members beforehand and use individual variables instead.
struct S {
int firstInt;
int secondInt;
int *intPointer;
};
Assuming you have an instance A
of the structure above, you can do the following.
int first = A.firstInt;
int second = A.secondInt;
int *pointer = A.intPointer;
Afterwards, you can use the individual variables inside of the offload region.
#pragma offload target(mic: 0) in(first, second)
inout(pointer:length(first*second))
{
/* Use individual variables here. */
}
Make sure to allocate memory on the device before copying the data referred by pointer
.
Alternatively, you can exclude the pointer from your structure and pass it as a separate variable. This way you can copy the entire structure (which is now bitwise copyable) and the pointer individually.
#pragma offload target(mic: 0) in(A) inout(pointer:length(A.first*A.second))