title: OpenCL struct alignment errors
body: <p>I am having troubles with aligning structs between the host and device in OpenCL. I defined many custom structs on both the host and device, and all of them seem to be working perfectly except for one.</p>
  
  <p>I am sending over two structs in an array. All values in the first struct (sObject[0]) are being read correctly in the device, but the second (sObject[1]) is being read in a seemingly corrupt manner where the values are all mixed up and some are missing. </p>
  
  <p>From what I've read, this is possibly a problem with data alignment where the host and device may have different type allocations or padding, but I have verified that the data types have the same size on both the host and device and I have attempted using alignment such as <code>#pragma pack(8)</code>, <code>__attribute__ ((aligned (128)))</code> and <code>__attribute__ ((packed))</code> although I am unsure if they are working correctly with the compiler (VS2017).</p>
  
  <p>Here is the code for the struct on both the host and device:</p>
  
  <p>Host:</p>
  
  <pre><code>typedef struct _cl_tag_sObject {
      cl_double3 m_vCenter;
      cl_double3 m_vBounds1;
      cl_double3 m_vBounds2;
      cl_double m_dRadius;
      cl_bool m_type;
  } sObject;
  </code></pre>
  
  <p>Device:</p>
  
  <pre><code>typedef struct _cl_tag_sObject {
      double3 m_vCenter;
      double3 m_vBounds1;
      double3 m_vBounds2;
      double m_dRadius;
      bool m_type;
  } sObject;
  </code></pre>
  
  <p>Here are the assigned values on the host and the values read from the device:</p>
  
  <p>Host:</p>
  
  <pre><code>m_vCenter = (0,-100.5,0)
  m_vBounds1 = (2,2,2)
  m_vBounds2 = (3,3,3)
  m_dRadius = 100
  m_type = 0
  </code></pre>
  
  <p>Device:</p>
  
  <pre><code>m_vCenter = (0,0,2)
  m_vBounds1 = (2,0,3)
  m_vBounds2 = (3,0,100)
  m_dRadius = 1
  m_type = 0
  </code></pre>
  
  <p>It seems that the value <code>-100.5</code> is being omitted and the middle values in <code>(2,2,2)</code> and <code>(3,3,3)</code> are taking the place of padding, although I am new to OpenCL and am unsure as to how this process actually works.</p>
  
  <p>What is causing this problem and how can it be solved?</p>
  
  <p>Thanks.</p>