<?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 A macro for neatly error-checking OpenCL API functions. in OpenCL* for CPU</title>
    <link>https://community.intel.com/t5/OpenCL-for-CPU/A-macro-for-neatly-error-checking-OpenCL-API-functions/m-p/1072382#M4482</link>
    <description>&lt;P&gt;Here are some macros that I use to error check my OpenCL API functions:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;A href="https://gist.github.com/allanmac/9328bb2d6a99b86883195f8f78fd1b93"&gt;https://gist.github.com/allanmac/9328bb2d6a99b86883195f8f78fd1b93&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The two macros of interest are:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;  #define cl(...)    cl_assert((cl##__VA_ARGS__), __FILE__, __LINE__, true);
  #define cl_ok(err) cl_assert(err, __FILE__, __LINE__, true);
&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;And they're used like this:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;cl_program program = clCreateProgramWithBinary(context,
                                                 1,
                                                 &amp;amp;device_id,
                                                 bins_sizeof,
                                                 bins,
                                                 &amp;amp;status,
                                                 &amp;amp;err);
  cl_ok(err);

  cl(BuildProgram(program,
                  1,
                  &amp;amp;device_id,
                  NULL,
                  NULL,
                  NULL));
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Simply adding two ellipses will give you OpenCL API error checking to those OpenCL functions that return a cl_int error code.&lt;/P&gt;

&lt;P&gt;The second "cl_ok(err)" form handles API functions that initialize an error as an argument.&lt;/P&gt;

&lt;P&gt;Note there is also a useful function for converting OpenCL errors to strings:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;char const * clGetErrorString(cl_int const err);&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jul 2016 17:02:29 GMT</pubDate>
    <dc:creator>allanmac1</dc:creator>
    <dc:date>2016-07-26T17:02:29Z</dc:date>
    <item>
      <title>A macro for neatly error-checking OpenCL API functions.</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/A-macro-for-neatly-error-checking-OpenCL-API-functions/m-p/1072382#M4482</link>
      <description>&lt;P&gt;Here are some macros that I use to error check my OpenCL API functions:&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;A href="https://gist.github.com/allanmac/9328bb2d6a99b86883195f8f78fd1b93"&gt;https://gist.github.com/allanmac/9328bb2d6a99b86883195f8f78fd1b93&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The two macros of interest are:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;  #define cl(...)    cl_assert((cl##__VA_ARGS__), __FILE__, __LINE__, true);
  #define cl_ok(err) cl_assert(err, __FILE__, __LINE__, true);
&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;And they're used like this:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;cl_program program = clCreateProgramWithBinary(context,
                                                 1,
                                                 &amp;amp;device_id,
                                                 bins_sizeof,
                                                 bins,
                                                 &amp;amp;status,
                                                 &amp;amp;err);
  cl_ok(err);

  cl(BuildProgram(program,
                  1,
                  &amp;amp;device_id,
                  NULL,
                  NULL,
                  NULL));
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Simply adding two ellipses will give you OpenCL API error checking to those OpenCL functions that return a cl_int error code.&lt;/P&gt;

&lt;P&gt;The second "cl_ok(err)" form handles API functions that initialize an error as an argument.&lt;/P&gt;

&lt;P&gt;Note there is also a useful function for converting OpenCL errors to strings:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;char const * clGetErrorString(cl_int const err);&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2016 17:02:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/A-macro-for-neatly-error-checking-OpenCL-API-functions/m-p/1072382#M4482</guid>
      <dc:creator>allanmac1</dc:creator>
      <dc:date>2016-07-26T17:02:29Z</dc:date>
    </item>
    <item>
      <title>There appears to be no way to</title>
      <link>https://community.intel.com/t5/OpenCL-for-CPU/A-macro-for-neatly-error-checking-OpenCL-API-functions/m-p/1072383#M4483</link>
      <description>&lt;P&gt;There appears to be no way to edit a "first post".&lt;/P&gt;

&lt;P&gt;Typo:&amp;nbsp;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Simply adding two &lt;S&gt;ellipses&lt;/S&gt;&amp;nbsp;&lt;EM&gt;parentheses&lt;/EM&gt; will give you OpenCL API error checking for those functions that return a cl_int error code.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I was thinking too much about vararg ellipses!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2016 17:26:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/OpenCL-for-CPU/A-macro-for-neatly-error-checking-OpenCL-API-functions/m-p/1072383#M4483</guid>
      <dc:creator>allanmac1</dc:creator>
      <dc:date>2016-07-26T17:26:00Z</dc:date>
    </item>
  </channel>
</rss>

