Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCL C++ context properties syntax
    primarykey
    data
    text
    <p>I'm trying to learn OpenCL using the C++ bindings. The only thing I haven't understood so far is the following syntax. Trying to create a context based on a device type:</p> <pre><code>cl::Context context(CL_DEVICE_TYPE_CPU, properties); </code></pre> <p>I'm using nvidia's ICD, which as I understand won't let you create a context without defining the platform, so I need the second argument. From the standard, <code>cl_context_properties</code> should be a list of property names, followed by the corresponding values, ended by 0. There's only one <code>cl_context_properties</code> in the standard (table 4.4), which is the property <code>CL_CONTEXT_PLATFORM</code> and has property value of <code>cl_platform_id</code> type. Based on that I thought therefore that this should be OK:</p> <pre><code>cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, platforms[0], 0}; </code></pre> <p>where <code>platforms</code> is my vector of platforms. But it will fail to compile unless instead of <code>platforms[0]</code> I put:</p> <pre><code>(cl_context_properties)(platforms[0])() </code></pre> <p>This is from the example code in the <code>cl.hpp</code> header file.</p> <p>1) It looks like <code>platforms</code> is being cast to type <code>cl_context_properties</code>. Why is this necessary?</p> <p>2) Why is there an extra set of brackets <code>()</code> at the end? </p> <p>Please assume that I'm not a C++ expert (definitely true). I know it's only a small thing but I don't like writing code that I don't understand fully. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload