<?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 Hi Vincent,  in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921459#M13409</link>
    <description>&lt;P&gt;Hi Vincent,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was a new feature that was to be added to Intel Composer XE SP1 Update 1. It seems that the BKM was updated before the compiler update was publically available. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the meantime, you can use the following work around:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/P&gt;
&lt;P&gt;#define SIZE 10&lt;/P&gt;
&lt;P&gt;#define ALLOC alloc_if(1) free_if(0)&lt;BR /&gt;#define REUSE alloc_if(0) free_if(0)&lt;BR /&gt;#define FREE alloc_if(0) free_if(1)&lt;/P&gt;
&lt;P&gt;// Example of Non-Bitwise Object Transfer, All Data Elements Needed&lt;BR /&gt;typedef struct {&lt;BR /&gt; int m1;&lt;BR /&gt; int *m2;&lt;BR /&gt;} nbwcs;&lt;/P&gt;
&lt;P&gt;__declspec(target(mic)) nbwcs struct1;&lt;/P&gt;
&lt;P&gt;void send_inputs()&lt;BR /&gt;{&lt;BR /&gt; int m1;&lt;BR /&gt; int *m2;&lt;/P&gt;
&lt;P&gt;// Initialize the struct&lt;BR /&gt; struct1.m1 = 10;&lt;BR /&gt; struct1.m2 = (int *)malloc(SIZE * sizeof(int));&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; = i;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; // In this offload data is transferred&lt;BR /&gt; m1 = struct1.m1;&lt;BR /&gt; m2 = struct1.m2;&lt;BR /&gt; #pragma offload target(mic) in(m1) in(m2[0:SIZE] : ALLOC) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; struct1.m1 = m1;&lt;BR /&gt; struct1.m2 = m2;&lt;BR /&gt; printf("MIC offload1: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;void use_the_data()&lt;BR /&gt;{&lt;BR /&gt; // In this offload data is used and updated&lt;BR /&gt; #pragma offload target(mic) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; += i;&lt;BR /&gt; }&lt;BR /&gt; printf("MIC offload2: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;void receive_results()&lt;BR /&gt;{&lt;BR /&gt; int *m2;&lt;/P&gt;
&lt;P&gt;// In this offload data is used,, updated, freed on MIC and brought back to the CPU&lt;BR /&gt; m2 = struct1.m2;&lt;BR /&gt; #pragma offload target(mic) out(m2[0:SIZE] : FREE) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; += i;&lt;BR /&gt; }&lt;BR /&gt; printf("MIC offload3: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt; printf("CPU: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;int main()&lt;BR /&gt;{&lt;BR /&gt; send_inputs();&lt;BR /&gt; use_the_data();&lt;BR /&gt; receive_results();&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2013 20:47:00 GMT</pubDate>
    <dc:creator>Sumedh_N_Intel</dc:creator>
    <dc:date>2013-09-06T20:47:00Z</dc:date>
    <item>
      <title>Offloading a structure with pointers.</title>
      <link>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921457#M13407</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I tried to offload a structure with pointers on the MIC. So I tried the code for the example presented in:&lt;BR /&gt;&lt;A href="http://software.intel.com/en-us/articles/effective-use-of-the-intel-compilers-offload-features" target="_blank"&gt;http://software.intel.com/en-us/articles/effective-use-of-the-intel-compilers-offload-features&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;However, I get a Segmentation Fault (core dumped) and this occurs when execution hits the &lt;BR /&gt;#pragma offload target(mic) in(struct1.m1) in(struct1.m2[0:SIZE] : ALLOC) nocopy(struct1)&lt;BR /&gt;&lt;BR /&gt;When replacing struct1.m2 with a pointer, it works but then we're not using the structure :&lt;BR /&gt;int *ptr = struct.m;2&lt;BR /&gt;#pragma offload target(mic) in(struct1.m1) in(ptr:length(SIZE) ALLOC) nocopy(struct1)&lt;BR /&gt;&lt;BR /&gt;So does the problem come from the compiler or is there something I'm missing?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2013 14:58:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921457#M13407</guid>
      <dc:creator>vincent_b_</dc:creator>
      <dc:date>2013-09-06T14:58:38Z</dc:date>
    </item>
    <item>
      <title>I am looking into this issue.</title>
      <link>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921458#M13408</link>
      <description>&lt;P&gt;I am looking into this issue. Let me get back to you with what I find.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2013 16:09:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921458#M13408</guid>
      <dc:creator>Sumedh_N_Intel</dc:creator>
      <dc:date>2013-09-06T16:09:37Z</dc:date>
    </item>
    <item>
      <title>Hi Vincent, </title>
      <link>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921459#M13409</link>
      <description>&lt;P&gt;Hi Vincent,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was a new feature that was to be added to Intel Composer XE SP1 Update 1. It seems that the BKM was updated before the compiler update was publically available. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the meantime, you can use the following work around:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/P&gt;
&lt;P&gt;#define SIZE 10&lt;/P&gt;
&lt;P&gt;#define ALLOC alloc_if(1) free_if(0)&lt;BR /&gt;#define REUSE alloc_if(0) free_if(0)&lt;BR /&gt;#define FREE alloc_if(0) free_if(1)&lt;/P&gt;
&lt;P&gt;// Example of Non-Bitwise Object Transfer, All Data Elements Needed&lt;BR /&gt;typedef struct {&lt;BR /&gt; int m1;&lt;BR /&gt; int *m2;&lt;BR /&gt;} nbwcs;&lt;/P&gt;
&lt;P&gt;__declspec(target(mic)) nbwcs struct1;&lt;/P&gt;
&lt;P&gt;void send_inputs()&lt;BR /&gt;{&lt;BR /&gt; int m1;&lt;BR /&gt; int *m2;&lt;/P&gt;
&lt;P&gt;// Initialize the struct&lt;BR /&gt; struct1.m1 = 10;&lt;BR /&gt; struct1.m2 = (int *)malloc(SIZE * sizeof(int));&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; = i;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; // In this offload data is transferred&lt;BR /&gt; m1 = struct1.m1;&lt;BR /&gt; m2 = struct1.m2;&lt;BR /&gt; #pragma offload target(mic) in(m1) in(m2[0:SIZE] : ALLOC) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; struct1.m1 = m1;&lt;BR /&gt; struct1.m2 = m2;&lt;BR /&gt; printf("MIC offload1: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;void use_the_data()&lt;BR /&gt;{&lt;BR /&gt; // In this offload data is used and updated&lt;BR /&gt; #pragma offload target(mic) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; += i;&lt;BR /&gt; }&lt;BR /&gt; printf("MIC offload2: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;void receive_results()&lt;BR /&gt;{&lt;BR /&gt; int *m2;&lt;/P&gt;
&lt;P&gt;// In this offload data is used,, updated, freed on MIC and brought back to the CPU&lt;BR /&gt; m2 = struct1.m2;&lt;BR /&gt; #pragma offload target(mic) out(m2[0:SIZE] : FREE) nocopy(struct1)&lt;BR /&gt; {&lt;BR /&gt; for (int i=0; i&amp;lt;SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; struct1.m2&lt;I&gt; += i;&lt;BR /&gt; }&lt;BR /&gt; printf("MIC offload3: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt; fflush(0);&lt;BR /&gt; }&lt;BR /&gt; printf("CPU: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);&lt;BR /&gt;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;int main()&lt;BR /&gt;{&lt;BR /&gt; send_inputs();&lt;BR /&gt; use_the_data();&lt;BR /&gt; receive_results();&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;[/cpp]&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2013 20:47:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921459#M13409</guid>
      <dc:creator>Sumedh_N_Intel</dc:creator>
      <dc:date>2013-09-06T20:47:00Z</dc:date>
    </item>
    <item>
      <title>Hello Sumedh,</title>
      <link>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921460#M13410</link>
      <description>&lt;P&gt;Hello Sumedh,&lt;/P&gt;
&lt;P&gt;Thank you for your answer.&lt;BR /&gt;That's the work around that we used. We just wanted to be sure that we didn't miss something that made the example not work.&lt;/P&gt;
&lt;P&gt;Vincent&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2013 17:50:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Offloading-a-structure-with-pointers/m-p/921460#M13410</guid>
      <dc:creator>vincent_b_</dc:creator>
      <dc:date>2013-09-08T17:50:11Z</dc:date>
    </item>
  </channel>
</rss>

