Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7681 Discussions

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

Ashwin_D_1
Beginner
130 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
130 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;

Reply