- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What will happen if I change a pointer value inside the offload region like the code below?
[cpp]#pragma offload inout(p,q: length(10))
{
int* temp = p;
p = q;
q = temp;
}[/cpp]
Will the memory content of p and q on host exchange?
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No. You can't manipulate pointers like that with the hetrogeneous offload model. Your pointers p & q have totally different addresses on host and coprocessor. All your example does is swap pointers on the coprocessor without doing anything on the host.
If you want to manipulate pointers, you would need to use the Cilk_shared offload model, which can maintain common virtual addresses of arbitrarily complex objects (including pointers) between host and coprocessor.
On the other hand, if you just want to swap the data pointed to, you can use the hetrogeneous offload model. The 'temp' pointer is only known to the coprocessor and is created just to swap the data:
#include <iostream>
using namespace std;
int * p=NULL;
int * q=NULL;
int main()
{
p = new(int);
q = new(int);
*p = 1;
*q = 2;
cout << "\n before offload *q = " << *q << endl;
#pragma offload target(mic) inout(p,q: length(8))
{
int * temp = new(int);
*temp = *p;
*p = *q;
*q = *temp;
}
cout << "\n after offload *q = " << *q << endl;
return 0;
}
$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.0.080 Build 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
$ icc U477910-pragma-offload.cpp -offload-attribute-target=mic
$ ./a.out
before offload *q = 2
after offload *q = 1
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then by extension, the following should the following work as well:
[cpp]
#include <iostream>
using namespace std;
int * p=NULL;
int * q=NULL;
int main()
{
p = new(int);
q = new(int);
*p = 1;
*q = 2;
cout << "\n before offload *q = " << *q << endl;
int** pp = &p;
int** pq = &q;
#pragma offload target(mic) inout(pp,qq: length(8))
{
int ** temp = pp;
*pp = *pq;
*pq = temp;
}
cout << "\n after offload *q = " << *q << endl;
return 0;
}
[/cpp]
Though I think you only need intent in
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would think double indirection should work the same, but apparently that confuses the compiler. I'm getting 'offload error: address range partially overlaps with existing allocation' with your example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Patrick and jim. Does this mean offload will only bind the memory address of host and MIC? No matter how I manipulating the pointer inside offload region, compiler will still copy in/out according to the address specified in the directive?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The "useless" case I was illustrating was essentially passing intptr_t integers into and out of the offload region.
Jim Dempsey

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