Community
cancel
Showing results for 
Search instead for 
Did you mean: 
49 Views

Offload from different threads through a DLL

Hi all, 

 My issue is as follows:

I have developed a .dll that defines a class that manages all the offloading and then executes the process of data  in Xeon Phi.

It works fine when there is only a single  thread running in the host, creating the class  and then executing it. However, when I create more than one  thread, the program crashes.

At  some point, I do an initialization of pointers inside a  offload region, as it is data I only need in Xeon Phi memory. But, when I reach the point when I need that pointer, seems like it is not allocated. Code  basically is like:

class __declspec(target) myclass
{
  double *array_in_MIC;
...
 void SetUp();
 void Run();
...
};

myclass::SetUp()
{

...
#pragma offload target(mic) nocopy(array_in_MIC: REUSE RETAIN)
{
...
array_in_MIC=(double*) calloc(Ndata, sizeof(double)); 
// Correctly allocates memory in Xeon Phi, and array_in_MIC has an address value
...
}
}

myclass::Run()
{

#pragma offload target(mic) nocopy(array_in_MIC: REUSE RETAIN)
{
...
foo(array_in_MIC); // When I reach this point, array_in_MIC is 0
...
}

}

 

 

 

Any help is appreciated

0 Kudos
1 Reply
jimdempseyatthecove
Black Belt
49 Views

The object of class myclass that you've created (not shown) resides in the Host.  This object contains a pointer, which (is intended to) point to a block of memory allocated on MIC. IOW the allocate is to be performed inside the MIC, but the pointer is to be preserved inside the Host. To accomplish this:

a) SetUp must copy the pointer back to the Host upon return from the offload region
b) Run must copy the pointer from the Host into the MIC on each entry into an offload region

*** None of the other member variables of this object have been declared to be passed.
*** Nor has the this pointer been passed into the offload.

There is too little of what you intend to (require to) do listed in your post. The following may be of interest:

class __declspec(target) myclass
{
  myclass* myclass_in_MIC;
  double *array_in_MIC;
...
 void SetUp();
 void Run();
...
};

myclass()
{
  myclass_in_MIC=NULL;
  array_in_MIC=NULL;
}

myclass::SetUp()
{
  assert(myclass_in_MIC == NULL);
...
#pragma offload target(mic) out(myclass_in_MIC) // additional in/out here
{
...
myclass_in_MIC = new myclass;
array_in_MIC=(double*) calloc(Ndata, sizeof(double)); 
// Correctly allocates memory in Xeon Phi, and array_in_MIC has an address value
...
}
}

myclass::Run()
{
  if(myclass_in_MIC)
  {
    myclass*This = this;
   #pragma offload target(mic) in(This) // additional in/out here
   {
      This->Run();
   }
  else
  {
    ...
    foo(array_in_MIC);
    ...
   }
}

The above is just a sketch (completely untested).

Remember to delete myclass_in_MIC in an offload region in the dtor of myclass

Jim Dempsey

Reply