{"id":17,"date":"2009-12-08T11:59:03","date_gmt":"2009-12-08T11:59:03","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/gpgpu\/?p=17"},"modified":"2009-12-08T12:03:53","modified_gmt":"2009-12-08T12:03:53","slug":"hellocl","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/gpgpu\/2009\/12\/08\/hellocl\/","title":{"rendered":"HelloCL!"},"content":{"rendered":"<p>(Imagine the post&#8217;s title spoken in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Leslie_Phillips\" target=\"_blank\">Leslie Phillips<\/a>&#8216; drawl. This will probably either amuse you or mean absolutely nothing!)<\/p>\n<p>OK. It&#8217;s party time! I have two Linux boxes, both apparently with OpenCL SDKs, each with a different GPGPU:<\/p>\n<p>euler &#8211; NVidia Tesla 870<\/p>\n<p>crout &#8211; AMD\/ATI FireStream 9270<\/p>\n<p>The supplied examples work, but they have vendor-specific bits. Can I get a &#8220;pure&#8221; OpenCL program to compile and run (without modification) on both machines?<\/p>\n<p>Apple provide an <a href=\"http:\/\/developer.apple.com\/mac\/library\/samplecode\/OpenCL_Hello_World_Example\/index.html#\/\/apple_ref\/doc\/uid\/DTS40008187\" target=\"_blank\">example<\/a> that sets up the environment and runs a small kernel. I had two make two fixes:<\/p>\n<p>#ifdef __APPLE__<br \/>\n#include &lt;OpenCL\/opencl.h&gt;<br \/>\n#else<br \/>\n#include &lt;CL\/cl.h&gt;<br \/>\n#endif<\/p>\n<p>instead of simply<\/p>\n<p>#include &lt;OpenCL\/opencl.h&gt;<\/p>\n<p>Second there was a bug in the call to clGetKernelWorkGroupInfo, that Apple fixed yesterday! (I did this a week ago.) (I also changed the extension from .c to .cpp &#8211; this is not critical.)<\/p>\n<p>We also need a Makefile. Both NVidia and AMD provide very complex Makefiles for their examples. Here&#8217;s my stripped down version. (Change the commented out paths as needed.)<\/p>\n<p># NVIDIA directories<br \/>\n# OCLROOTDIR = \/usr\/local\/NVIDIA_GPU_Computing_SDK\/OpenCL<br \/>\n# INCLUDEDIR = $(OCLROOTDIR)\/inc<br \/>\n# LIBDIR = $(OCLROOTDIR)\/lib<\/p>\n<p># ATI directories<br \/>\nOCLROOTDIR = \/usr\/local\/ati-stream-sdk-v2.0-beta4-lnx64<br \/>\nINCLUDEDIR = $(OCLROOTDIR)\/include<br \/>\nLIBDIR = $(OCLROOTDIR)\/lib\/x86_64<\/p>\n<p>CC = g++<br \/>\nCFLAGS = -c -Wall -I$(INCLUDEDIR)<br \/>\nLDFLAGS = -L$(LIBDIR) -lOpenCL<\/p>\n<p>SOURCES = hello.cpp<br \/>\nOBJECTS = $(SOURCES:.cpp=.o)<br \/>\nEXECUTABLE = hello<\/p>\n<p>all: $(SOURCES) $(EXECUTABLE)<\/p>\n<p>$(EXECUTABLE): $(OBJECTS)<br \/>\n$(CC) $(LDFLAGS) $(OBJECTS) -o $@<\/p>\n<p>.cpp.o:<br \/>\n$(CC) $(CFLAGS) $&lt; -o $@<\/p>\n<p>And it works on both machines!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Imagine the post&#8217;s title spoken in Leslie Phillips&#8216; drawl. This will probably either amuse you or mean absolutely nothing!) OK. It&#8217;s party time! I have two Linux boxes, both apparently with OpenCL SDKs, each with a different GPGPU: euler &#8211; NVidia Tesla 870 crout &#8211; AMD\/ATI FireStream 9270 The supplied examples work, but they have [&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-17","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/17","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=17"}],"version-history":[{"count":4,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/posts\/17\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/gpgpu\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}