<?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 Trouble to pass structure in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100960#M5125</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I've got some problem. I write an motion estimation algorithm using OpenCL. I've got sophisticated structures, like this:&lt;/P&gt;

&lt;P&gt;HOST SIDE:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;typedef struct ctu_info_t ctu_info_t;
typedef struct cu_info_t cu_info_t;
typedef struct thread_t thread_t;
struct cu_info_t
{
  cl_int array[100];
  /*and so on*/
};

struct ctu_info_t
{
  cu_info_t cu_info;
  cl_int array_1[1000];
  cl_int array_2[2000];
  /*and so on*/
};

struct thread_t
{
  ctu_info_t ctu_rd;
  /*another fields*/
};&lt;/PRE&gt;

&lt;P&gt;DEVICE SIDE:&lt;/P&gt;

&lt;PRE class="brush:cpp;" style="font-size: 13.008px;"&gt;typedef struct ctu_info_t ctu_info_t;
typedef struct cu_info_t cu_info_t;
typedef struct thread_t thread_t;
struct cu_info_t
{
  int array[100];
  /*and so on*/
};

struct ctu_info_t
{
  cu_info_t cu_info;
  int array_1[1000];
  int array_2[2000];
  /*and so on*/
};

struct thread_t
{
  ctu_info_t ctu_rd;
  /*another fields*/
};&lt;/PRE&gt;

&lt;P&gt;I don't have any trouble with setting kernel's arguments (kernel func looks like this "__kernel void my_func(ctu_info_t *ctu_info, thread_t *thread) { /*here is the code...*/ }"), but when I call "clEnqueueNDRangeKernel()" I've got this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1KUez26eo_w.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/9401i96363A921E12C7DB/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="1KUez26eo_w.jpg" alt="1KUez26eo_w.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Can anybody help to solve this trouble? I don't know what's wrong I did.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2017 08:09:55 GMT</pubDate>
    <dc:creator>Alexander_M_4</dc:creator>
    <dc:date>2017-02-22T08:09:55Z</dc:date>
    <item>
      <title>Trouble to pass structure</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100960#M5125</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I've got some problem. I write an motion estimation algorithm using OpenCL. I've got sophisticated structures, like this:&lt;/P&gt;

&lt;P&gt;HOST SIDE:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;typedef struct ctu_info_t ctu_info_t;
typedef struct cu_info_t cu_info_t;
typedef struct thread_t thread_t;
struct cu_info_t
{
  cl_int array[100];
  /*and so on*/
};

struct ctu_info_t
{
  cu_info_t cu_info;
  cl_int array_1[1000];
  cl_int array_2[2000];
  /*and so on*/
};

struct thread_t
{
  ctu_info_t ctu_rd;
  /*another fields*/
};&lt;/PRE&gt;

&lt;P&gt;DEVICE SIDE:&lt;/P&gt;

&lt;PRE class="brush:cpp;" style="font-size: 13.008px;"&gt;typedef struct ctu_info_t ctu_info_t;
typedef struct cu_info_t cu_info_t;
typedef struct thread_t thread_t;
struct cu_info_t
{
  int array[100];
  /*and so on*/
};

struct ctu_info_t
{
  cu_info_t cu_info;
  int array_1[1000];
  int array_2[2000];
  /*and so on*/
};

struct thread_t
{
  ctu_info_t ctu_rd;
  /*another fields*/
};&lt;/PRE&gt;

&lt;P&gt;I don't have any trouble with setting kernel's arguments (kernel func looks like this "__kernel void my_func(ctu_info_t *ctu_info, thread_t *thread) { /*here is the code...*/ }"), but when I call "clEnqueueNDRangeKernel()" I've got this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1KUez26eo_w.jpg"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/9401i96363A921E12C7DB/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="1KUez26eo_w.jpg" alt="1KUez26eo_w.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Can anybody help to solve this trouble? I don't know what's wrong I did.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 08:09:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100960#M5125</guid>
      <dc:creator>Alexander_M_4</dc:creator>
      <dc:date>2017-02-22T08:09:55Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100961#M5126</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;Crash is coming from nvopencl.dll , this looks like Nvidia OpenCL driver.&lt;SPAN style="font-size: 1em;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:57:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100961#M5126</guid>
      <dc:creator>Michal_M_Intel</dc:creator>
      <dc:date>2017-02-22T15:57:52Z</dc:date>
    </item>
    <item>
      <title>Afaik, opencl is best served</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100962#M5127</link>
      <description>&lt;P&gt;Afaik, opencl is best served with arrays and building structs inside devices. When structs need to be sent between host and device, both sides has to have exact same alignment and size for each struct defined.&lt;/P&gt;

&lt;P&gt;Opencl version &amp;lt;= 1.2 does not handle this and leaves it to mercy of drivers and responsibility of developer.&lt;/P&gt;

&lt;P&gt;Some of the rules I remember:&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;struct size = power of 2(adding necessary dummy variables)&lt;/LI&gt;
	&lt;LI&gt;biggest fields(inner structs, arrays, vectors) on top, smallest fields on bottom&lt;/LI&gt;
	&lt;LI&gt;struct array aligned on struct size address&lt;/LI&gt;
	&lt;LI&gt;packing host-side structs equally with what device is doing&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;&amp;nbsp;also using pure arrays gives best performance since you get only the needed fields from arrays instead of whole structs which are sub-optimally using memory banks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 14:46:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/Trouble-to-pass-structure/m-p/1100962#M5127</guid>
      <dc:creator>Huseyin_Tugrul_B_</dc:creator>
      <dc:date>2017-02-26T14:46:00Z</dc:date>
    </item>
  </channel>
</rss>

