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

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

Ashwin_D_1
Beginner
242 Views

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:

https://software.intel.com/en-us/articles/effective-use-of-the-intel-com...

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.

}

Thanks!

0 Kudos
1 Reply
Ravi_N_Intel
Employee
242 Views

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
Reply