<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Offload from different threads through a DLL in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Offload-from-different-threads-through-a-DLL/m-p/1140018#M78233</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;My issue is as follows:&lt;/P&gt;

&lt;P&gt;I have developed a .dll that defines a class that manages all the offloading and then executes the process of data&amp;nbsp; in Xeon Phi.&lt;/P&gt;

&lt;P&gt;It works fine when there is only a single&amp;nbsp; thread running in the host, creating the class&amp;nbsp; and then executing it. However, when I create more than one&amp;nbsp; thread, the program crashes.&lt;/P&gt;

&lt;P&gt;At&amp;nbsp; some point, I do an initialization of pointers inside a&amp;nbsp; 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&amp;nbsp; basically is like:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;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
...
}

}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Any help is appreciated&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2018 12:26:32 GMT</pubDate>
    <dc:creator>Plaza_del_Olmo__Juli</dc:creator>
    <dc:date>2018-02-16T12:26:32Z</dc:date>
    <item>
      <title>Offload from different threads through a DLL</title>
      <link>https://community.intel.com/t5/Software-Archive/Offload-from-different-threads-through-a-DLL/m-p/1140018#M78233</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;My issue is as follows:&lt;/P&gt;

&lt;P&gt;I have developed a .dll that defines a class that manages all the offloading and then executes the process of data&amp;nbsp; in Xeon Phi.&lt;/P&gt;

&lt;P&gt;It works fine when there is only a single&amp;nbsp; thread running in the host, creating the class&amp;nbsp; and then executing it. However, when I create more than one&amp;nbsp; thread, the program crashes.&lt;/P&gt;

&lt;P&gt;At&amp;nbsp; some point, I do an initialization of pointers inside a&amp;nbsp; 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&amp;nbsp; basically is like:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;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
...
}

}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Any help is appreciated&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 12:26:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offload-from-different-threads-through-a-DLL/m-p/1140018#M78233</guid>
      <dc:creator>Plaza_del_Olmo__Juli</dc:creator>
      <dc:date>2018-02-16T12:26:32Z</dc:date>
    </item>
    <item>
      <title>The object of class myclass</title>
      <link>https://community.intel.com/t5/Software-Archive/Offload-from-different-threads-through-a-DLL/m-p/1140019#M78234</link>
      <description>&lt;P&gt;The object of class myclass that you've created (not shown) resides in the Host.&amp;nbsp; 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:&lt;/P&gt;

&lt;P&gt;a) SetUp must copy the pointer back to the Host upon return from the offload region&lt;BR /&gt;
	b) Run must copy the pointer from the Host into the MIC on each entry into an offload region&lt;/P&gt;

&lt;P&gt;*** None of the other member variables of this object have been declared to be passed.&lt;BR /&gt;
	*** Nor has the this pointer been passed into the offload.&lt;/P&gt;

&lt;P&gt;There is too little of what you intend to (require to) do listed in your post. The following may be of interest:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;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-&amp;gt;Run();
   }
  else
  {
    ...
    foo(array_in_MIC);
    ...
   }
}&lt;/PRE&gt;

&lt;P&gt;The above is just a sketch (completely untested).&lt;/P&gt;

&lt;P&gt;Remember to delete myclass_in_MIC in an offload region in the dtor of myclass&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 15:45:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offload-from-different-threads-through-a-DLL/m-p/1140019#M78234</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2018-02-16T15:45:03Z</dc:date>
    </item>
  </channel>
</rss>

