Software Archive
Read-only legacy content
17060 Discussions

strange behavior of the code using pragma offload

King_Crimson
Beginner
368 Views

I observed a strange behavior of the code below:

//allocate and transfer 

#pragma offload_transfer target(mic:deviceIdx)\

in(arraySize)\

in(input:length(arraySize) ALLOC RETAIN)

 

//reuse. this works fine

#pragma offload target(mic:deviceIdx)

nocopy(input:length(arraySize) REUSE RETAIN)

{

      #pragma omp parallel shared(arraySize, input)

      {

            ......

       }

}

However, if the above "reuse" block is wrapped into a function, say void ReuseDevice(double* data, int dataSize, int deviceIdx);

 an error message pops up:

-->offload error: process on the device 0 was terminated by signal 11

What's the catch? Thanks for help!

 

0 Kudos
1 Solution
Sumedh_N_Intel
Employee
368 Views

When you wrap the 'reuse' block within your function, you are in effect creating a new pointer variable 'data' on the stack which will point to the same location as 'input'. However, during an offload the compiler creates a new pointer variable 'data' for the coprocessor but since you used the modifier 'nocopy' its value is not set and hence the error. If you use in(data:length(0) reuse ) inside the function, the compiler will create the new pointer varianle and set the pointer value to point to the coprocessor side array but will not transfer any data  as the length was set as 0. 

I hope this helps. 

View solution in original post

0 Kudos
3 Replies
Andrey_Vladimirov
New Contributor III
368 Views

Try using "in (input: length(0) ..." instead of "nocopy (input: length(arraySize) ...". It was previously discussed here: http://software.intel.com/en-us/forums/topic/359447 (see the post by Kevin Davis from Fri, 01/25/2013).

0 Kudos
Sumedh_N_Intel
Employee
369 Views

When you wrap the 'reuse' block within your function, you are in effect creating a new pointer variable 'data' on the stack which will point to the same location as 'input'. However, during an offload the compiler creates a new pointer variable 'data' for the coprocessor but since you used the modifier 'nocopy' its value is not set and hence the error. If you use in(data:length(0) reuse ) inside the function, the compiler will create the new pointer varianle and set the pointer value to point to the coprocessor side array but will not transfer any data  as the length was set as 0. 

I hope this helps. 

0 Kudos
King_Crimson
Beginner
368 Views

Sumedh Naik (Intel) wrote:

When you wrap the 'reuse' block within your function, you are in effect creating a new pointer variable 'data' on the stack which will point to the same location as 'input'. However, during an offload the compiler creates a new pointer variable 'data' for the coprocessor but since you used the modifier 'nocopy' its value is not set and hence the error. If you use in(data:length(0) reuse ) inside the function, the compiler will create the new pointer varianle and set the pointer value to point to the coprocessor side array but will not transfer any data  as the length was set as 0. 

I hope this helps. 

Thanks Sumedh, that is definitely an elegant solution.

0 Kudos
Reply