{"id":6128,"date":"2014-04-13T04:33:11","date_gmt":"2014-04-13T04:33:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/c11-thread_local-or-array-of-opencl-1-2-cl_kernel-objects-collection-of-common-programming-errors\/"},"modified":"2014-04-13T04:33:11","modified_gmt":"2014-04-13T04:33:11","slug":"c11-thread_local-or-array-of-opencl-1-2-cl_kernel-objects-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/c11-thread_local-or-array-of-opencl-1-2-cl_kernel-objects-collection-of-common-programming-errors\/","title":{"rendered":"C++11: thread_local or array of OpenCL 1.2 cl_kernel objects?-Collection of common programming errors"},"content":{"rendered":"<p>I need to run several C++11 threads (GCC 4.7.1) parallely in host. Each of them needs to use a device, say a GPU. As per OpenCL 1.2 spec (p. 357):<\/p>\n<pre><code>All OpenCL API calls are thread-safe75 except clSetKernelArg. \nclSetKernelArg is safe to call from any host thread, and is safe\nto call re-entrantly so long as concurrent calls operate on different\ncl_kernel objects. However, the behavior of the cl_kernel object is\nundefined if clSetKernelArg is called from multiple host threads on\nthe same cl_kernel object at the same time.\n<\/code><\/pre>\n<p>An elegant way would be to use thread_local cl_kernel objects and the other way I can think of is to use an array of these objects such that i&#8217;th thread uses i&#8217;th object. As I have not implemented these earlier I was wondering if any of the two are good or are there better ways of getting things done.<\/p>\n<p>A third way perhaps would be to use a mutex for a single cl_object and associate it with an event handler. Then the thread can wait till the event is finished. Not sure if this works though in multi-threaded situation&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I need to run several C++11 threads (GCC 4.7.1) parallely in host. Each of them needs to use a device, say a GPU. As per OpenCL 1.2 spec (p. 357): All OpenCL API calls are thread-safe75 except clSetKernelArg. clSetKernelArg is safe to call from any host thread, and is safe to call re-entrantly so long [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6128","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6128"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6128\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}