- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I print the array A again, it has different data. Why does this happen and how can I fix this?
#define ALLOC alloc_if(1) free_if(0)
#define FREE alloc_if(0) free_if(1)
#define REUSE alloc_if(0) free_if(0)
#ifdef __INTEL_OFFLOAD
#pragma offload_attribute(push,target(mic))
#endif#include <iostream>
void alloc_set(double* A){
#pragma offload target(mic:0) nocopy(A: length(10) ALLOC)
{
for(size_t i=0;i<10;i++) A=i;
}#pragma offload target(mic:0) nocopy(A: REUSE)
{
for(size_t i=0;i<10;i++) std::cout<<A<<' ';
std::cout<<'\n';
}
}
void device_print(double* A){
#pragma offload target(mic:0) nocopy(A: REUSE)
{
for(size_t i=0;i<10;i++) std::cout<<A<<' ';
std::cout<<'\n';
}
}#ifdef __INTEL_OFFLOAD
#pragma offload_attribute(pop)
#endif
int main(){
double* A=new double[10];
alloc_set(A);
device_print(A);
return 0;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found my solution in this thread: http://software.intel.com/en-us/forums/topic/359447
The solution is to use: in(A: length(0) REUSE)
Instead of: nocopy(A: REUSE)
This is counter intuitive but it works.
Intel please fix this messed up notation!! Its been over a year and there are still many such issues!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I’m sorry to hear this continues to be confusing. I’m sure you are well aware of these and offer as aid to others. Two additional related resources are:
Behind the Scenes: Offload Memory Management on the Intel® Xeon Phi™ coprocessor (Blog post)
Effective Use of the Intel Compiler's Offload Features (see Local Pointers Versus Pointers Used Across Offloads)
I don’t know whether this may help also. It is a paraphrase from a past discussion with a Developer about why as in your case and other’s cases, one uses IN with length(0) instead of NOCOPY for updating the pointer value within a new function scope.
When talking about pointers, keep in mind that a pointer besides holding an address of some data is itself a variable that has to be initialized by the offload runtime on the target. Therefore, a pointer transfer is really comprised of two parts – (1) transfer of the data to which the pointer is pointing to the target memory (target memory address is fetched from the memory association table which has host data address as a key) and (2) assigning the address of target memory to the pointer variable on the target. The (1) is controlled by the clause type (IN/OUT/INOUT/NOCOPY) and is intuitively clear, but it is not always obvious when runtime does the second part (2). The pointer variable is updated when (a) target memory is either allocated or deallocated (i.e. clause has alloc_if(1) or free_if(1)) or (b) when a pointer variable is specified in either the IN, OUT or INOUT clause. For (b) the amount of pointed data to transfer is controlled by the length() modifier and it is Ok to specify 0 for length unless the clause has the alloc_if(1) modifier. With zero length the offload updates the pointer variable without transferring pointed data.
If you have some specific suggestions on improving the notation then please let me know and I will forward those to Develop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Kevin, in your second link:
1) Under the heading: Persistence: Statically allocated data, nocopy(y) is used.
2) Under the heading: Persistence: Stack allocated data, nocopy(x) is used.
3) Under the heading: Free-ing memory used by Offload without knowing the length, nocopy(c_ptr:length(0) FREE) is used.
4) Under the heading: Overlapping Data Transfer and Offloaded Computation, nocopy(f2[0:N]) is used.
From your paraphrase, if in/out/nocopy determines the transfer of the pointer value to and from the MIC, then shouldn't we use "in" always for arrays (since we will always need to copy the CPU pointer address to MIC to lookup the corresponding address on MIC). In that case how do we control transfer of array data.
And when we want to free memory, should we use in(A:length(0) FREE)? In several places in your link:
1) Under the heading: Example of Persistent MIC Pointer and Selective Data Transfer, out(a : length(SIZE) FREE) is used.
2) Under the heading: Free-ing memory used by Offload without knowing the length, nocopy(c_ptr:length(0) FREE) is used.
3) Under the heading: Minimize Coprocessor Memory Allocation Overhead, nocopy(p[0:count] : FREE) is used.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page