4

I have a struct A with a few int and one int * member. How can I use this in offload?

I probably can't do #pragma offload target(mic: 0) inout(A){}..., but what about

#pragma offload target(mic: 0) in(A->firstInt, A->secondInt) inout(A->intPointer:length(A->firstInt*A->secondInt)){}

but I when I tried this I got error: invalid entity for this variable list in offload clause in response when compiling

jabk
  • 1,388
  • 4
  • 25
  • 43
  • From what I found about `#pragma offload`, [you'd better tell us what you're trying to do as there may be a better solution](http://xyproblem.info/). – ivan_pozdeev Dec 10 '15 at 04:20
  • I'm drawing the Mandelbrot's series and I need to parallelize the drawing loop. From what I gathered, I can't pass the struct because the `A->*member* ` is solved during compile time – jabk Dec 13 '15 at 20:44
  • "can't pass the struct (where?) because the A->*member*..." doesn't tell me much, if anything. http://stackoverflow.com/help/how-to-ask There are no telepaths here, don't assume we know anything about your situation. – ivan_pozdeev Dec 14 '15 at 00:20

1 Answers1

1

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))
user0815
  • 1,376
  • 7
  • 8