Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7873 Discussions

Using global pointers to allocate memory on the MIC and reusing it


Hi all,

I am using the offload programming model for my project. What I have is a global pointer that I use to allocate memory on the MIC. After doing some more computation on the host I then try to copy the results from host memory to the memory in the MIC using in() for host structure and nocopy() for the global pointer. The documentation and a few of the forum posts say that it should work however in my case it results in a segfault.

What I read:

The code is something like this:

//This is global

__attribute__((target(mic:0))) wildstruct* foo;

#pragma offload target(mic:0) nocopy(foo) {

foo = malloc(sizeof(foo));   //foo is then initialized later on in this offload region.


In another file:

#pragma offload target(mic:0) in(anotherFoo[0:LENGTH]) nocopy(foo) {

memset(foo,anotherFoo,sizeof(foo));    //segfaults here. foo is NULL which I believe should not be the case according to the documentation.



0 Kudos
1 Reply

Difficult to say what is problem without the complete code.
Is the pointer foo also declared with target attribute in the second file

__attribute__((target(mic:0))) wildstruct* foo;

0 Kudos