Software Archive
Read-only legacy content
17060 Discussions

Reuse on-device data within a function call

Paul_S_
Beginner
346 Views

Hi,

is it possible to reuse data that is already on the device eventhough there is a function call inbetween.
Here is an example:

void foo(){
   float* A;
   ... initialize A ...

   #pragma offload_transfer target(mic:0) in(A:length(sizeA) alloc_if(1) free_if(0)) signal(1)
   ...some CPU function... //overlap this function with data transfer
   
   bar(A, sizeA);
}

void bar(float* A, int sizeA){
   #pragma offload_transfer target(mic:0) wait(1)

   #pragma offload target(mic) nocopy(A:length(sizeA) alloc_if(0) free_if(0))
   deviceFunction(A,sizeA);
}

A similar program like this segfaults, because A is not known to the device within bar(). The solution that I've found so far would be to make *A a global variable, but this isn't really practical. I also tried to use pointers to pointers but that didn't work somehow.

Does someone know a solution to this problem?

Thanks

0 Kudos
4 Replies
Ravi_N_Intel
Employee
346 Views

Change

    #pragma offload target(mic) nocopy(A:length(sizeA) alloc_if(0) free_if(0))

to

#pragma offload target(mic) in(A:length(0) alloc_if(0) free_if(0))

0 Kudos
Kevin_D_Intel
Employee
347 Views

Ravi just beat me to it. The keys are IN and length(0) in the scope of bar(). IN creates a new instance of the local pointer A within the new scope of bar() and the length(0) ensures no data transfer. NOCOPY causes the segV because it assumes an instance of the pointer exists when it does not within the new scope.

Your offload in bar() also does not specify the target-id were as in foo() you created/transferred A to target-id 0 (i.e. target(mic:0) ) so be sure bar() also uses the same target-id.

The offload_transfer in bar() appears to only wait on the signal. You could perhaps use offload_wait if there is no associated transfer expected in waiting on that signal.

0 Kudos
Paul_S_
Beginner
346 Views

perfect! Thanks, that helped.

0 Kudos
Kevin_D_Intel
Employee
346 Views

Your welcome. Glad to hear that.

0 Kudos
Reply