{"id":22,"date":"2009-12-08T12:18:39","date_gmt":"2009-12-08T12:18:39","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/gpgpu\/?p=22"},"modified":"2009-12-08T12:18:39","modified_gmt":"2009-12-08T12:18:39","slug":"streaming-input","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/gpgpu\/2009\/12\/08\/streaming-input\/","title":{"rendered":"Streaming input"},"content":{"rendered":"<p>In most of the NVidia and AMD examples, the kernel code is kept in a separate .cl file and streamed in. In Apple&#8217;s HelloCL example, the kernel code is stored as a string in the file.<\/p>\n<p>The NVidia examples use a function &#8211; oclLoadProgStream. The AMD examples use a non-portable stream. Here&#8217;s how to do it without using any vendor-specific functions.<\/p>\n<p>#include &lt;fstream&gt;<\/p>\n<p>&#8230;<\/p>\n<p>std::ifstream in;<br \/>\nstd::string KernelSource, line;<\/p>\n<p>&#8230;<\/p>\n<p>in.open(&#8220;hello.cl&#8221;);<br \/>\nif (in.is_open())<br \/>\nwhile (getline(in, line))<br \/>\nKernelSource += line + &#8220;\\n&#8221;;<br \/>\nelse<br \/>\n{<br \/>\nprintf(&#8220;Error: hello.cl does not exist!\\n&#8221;);<br \/>\nreturn EXIT_FAILURE;<br \/>\n}<br \/>\nin.close();<\/p>\n<p>Note that the end of line markers must be included, otherwise the number of characters in the string must be supplied.<\/p>\n<p>Download the source: <a href=\"http:\/\/users.ecs.soton.ac.uk\/mz\/opencl\/hello.cpp\" target=\"_blank\">hello.cpp<\/a>, <a href=\"http:\/\/users.ecs.soton.ac.uk\/mz\/opencl\/hello.cl\">hello.cl<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In most of the NVidia and AMD examples, the kernel code is kept in a separate .cl file and streamed in. In Apple&#8217;s HelloCL example, the kernel code is stored as a string in the file. The NVidia examples use a function &#8211; oclLoadProgStream. The AMD examples use a non-portable stream. Here&#8217;s how to do [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":3,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":25,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/22\/revisions\/25"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}