ofxOpenCL

Hi,

I’m trying to learn how to use OpenCL with OpenFrameworks. I managed to compile and run Rui Madeira’s first example but I can’t seem to compile Memo’s examples (v0.3) I downloaded from his google code page.

I’m running OF 0.61

ofxOpenCL seems to be an OF plugin so I just added it to the “addons” folder and placed the examples under addonExamples but I get all kinds of missing references.

Unfortunately I’m still quite dumb at understanding references in C++.

Can someone give me some tips on how to install this so that it works or on how to learn to interpret the multiple errors I get during compilation? I tried both adding references to all the missing files and starting from a blank project and add Memo’s sources, both without success.

I’m asking for the fishing rod, not the fish. I don’t want to waste anyone’s time with the actual errors I’m getting. Anyway here they are:
http://tinypaste.com/07b89

Thanks!!
Nuno

hi

i tried out the openCL examples in OF 0.6. hello world and particals worked fine.

when commenting #define USE_OPENGL_CONTEXT out i get these errors:
error: ‘Vec2’ was not declared in this scope
error: ‘class ofxOpenCL’ has no member named ‘readBuffer’
error: ‘Vec2’ was not declared in this scope

images gave me an error message that ends like this:
-framework IOKit -o “/Applications/of_preRelease_v0.06_xcode_FAT/apps/ofxOpenCL/example - images/bin//OpenCL Demo Debug.app/Contents/MacOS/OpenCL Demo Debug”

i686-apple-darwin10-g+±4.2.1: …/…/…/addons/ofxVideoGrabber/libs/osx/lib/libdc1394.a: No such file or directory

i also tried OF 0.61. i used the empty example and pasted all the code and files.

for all three examples i get the following error:
addons/ofxOpenCL/src/ofxOpenCLImage.cpp:99: error: ‘struct ofTextureData’ has no member named ‘textureName’

any ideas?

thx,
stephan.

[quote author=“stephanschulz”]
addons/ofxOpenCL/src/ofxOpenCLImage.cpp:99: error: ‘struct ofTextureData’ has no member named ‘textureName’
.[/quote]

Hi,

what version are you using?

I’ve just

  
svn checkout [http://ofxmsaof.googlecode.com/svn/trunk/](http://ofxmsaof.googlecode.com/svn/trunk/) ofxmsaof-read-only  

and the project compiles fine.

i confirm this error…

ofTextureData struct:

  
  
typedef struct{  
  
	bool bAllocated;  
	int glType;  
	int glTypeInternal;  
	int textureTarget;  
	int pixelType;  // MEMO: added this (GL_FLOAT, GL_UNSIGNED_BYTE etc.  
	float tex_t;  
	float tex_u;  
	float tex_w;  
	float tex_h;  
	float width;  
	float height;  
	bool bFlipTexture;  
	unsigned int textureID;  
  
		  
}ofTextureData;  
  

BTW im checking this on windows now, didnt give this error on linux though.

OK, big problem. For those using OpenCL in windows are you using the NVIDIA SDK?
I have big problems with compatibility because OF uses GLee and NVIDIA SDK for OpenCL uses GLew.

I think its a no no to change nvidia sdk code, so is there anyway to overide redefenitions?

So after having my elderly 8800GT graphics card rained on (yes the studio be leaky me, maties!) I went out and got myself a whopping GTX 470…and what better to stress it out than openCL particles?

10 million of them at ~60fps!!!

Oh yes: GPU 99%, CPU 0%

Managed to get this working on Windows 7 64-bit. I’m using CUDA 3.1 and latest beta drivers (258.69).

Main thing I had to change was the way the Platform, Device and Context were specified.

In essence on a PC this is specified as:

  
     
   cl_context_properties    properties[] = {  
        CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),  
        CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),  
        CL_CONTEXT_PLATFORM, (cl_context_properties)clPlatform,  
    0};  
  

and requires windows.h…there were also a bunch of minor changes necessary throughtout the ofxOpenCL addon (including, including assert.h, specifying, cl.h instead of opencl.h, adding a reference to the current platform in a var I called clPlatform, etc etc)…

I also had to add a call to clEnqueueAcquireGLObjects just before doing kernalUpdate->run1D and a clEnqueueReleaseGLObjects just after…I got the idea for doing that from these cut down openCL-examples.

I’m sure there’s a neat way to impliment a system for registering cl buffer objects created by gl objects so that this code could be moved into the addon itself, but for now I’ve left it in the Update method…didn’t want to mess too much with your code Memo - although happy to have go if you like?

BTW: according to a post here the OSX method for registering an openCL context has been changed…can’t confirm as I don’t have Snow Leopard running yet…

I’ve put a 0.61 project folder here. I’ve only tested it on Win 7 64-bit. Enjoy PC-heads.

EDIT: realised the project folder doesn’t have the modified Addon - duf - that and the src folder for the particles example (on its own) are below.

Memo & Rui: thanks heaps for sharing!

ofxOpenCL.zip

src.zip

Great work!! I’m working on the same thing but came into a big problem… Its that Nvidia libs for opencl are compiled for VS so if you use MINGW it will cause you big problems… So i deduce you are using visual studio?

Not using VS…Which version of CB did you use? I’m using Codeblocks 10.05 and Cuda 3.1…just linked against the libraries (in the lib folder NOT the lib64 folder) and all was good…

Below is the image processing example src in semi-working order…basically involved changing function names to match the current version of the ofxOpenCL addon, as well as adding the clEnqueueAcquireGLObjects / clEnqueueReleaseGLObjects method used in the particles example.

However I can’t seem to get it to work with the clEnqueueWriteImage method (ie., using openCL to copy the image data)…not sure if this is just a problem on my (NVIDIA) hardware. Other people seem to have had the same problem: http://forums.nvidia.com/index.php?showtopic=168500 and: http://oscarbg.blogspot.com/2009/12/opencl-with-mingw.html

I’m looking into cleaning up the clEnqueueAcquireGLObjects / clEnqueueReleaseGLObjects method…would be nicer for memObjects to know if they are doing interop and force the Acquire/Release methods…will post soon…

[EDIT: added a #define for switching between web cam and video files…also realised it’s best/better to just Acquire/Release once, rather than for every kernel->run, so maybe this will always have to be done ‘manually’, as I’ve done here???..also seems to be a glitch with flipY, not sure why ;-)]

Best,
M

src.zip

Hey, somehow I missed the updates on this thread.

Getting windows & linux support on this addon would be great. The current latest version is at http://github.com/memo/msalibs

It is working on mac with current latest version of OF (0.0061 as per www.github.com/openframeworks/openFrameworks )

I haven’t seen any issues on Mac and I’ve tried on various NVidia hardware. Unfortunately no Mac ATI hardware currently supports Image Buffer Objects (!).

Feel free to fork and send me a pull request…

cheers

memo.

@memo: do you use NVIDIA SDK or Apple’s CL . Im not sure but i think they are different.

PS: i have the the hello world example and the particle example working in linux too, just getting the same error as gameover in image processing example.

Hey, Snow Leopard comes with an OpenCL implementation and I’m using that for testing. I don’t even know if you can install any other implementation. I built the addon as per the vendor independent APi as detailed in the khronos specifications
http://www.khronos.org/registry/cl/
The one exception to this is the bit required for opengl context sharing.

the Khronos OpenCL API Specifications PDf I have on my harddisk is from v1.0.48, so thats what I would have taken as a guide. I see that we are at 1.1, any ideas what’s changed?

@memo: thanks heaps for having put this together! opencl performance is nothing short of amazing. I’ve made the fork request, i’m super happy to be able to make a contribution!

@miguel: other than changing wglGetCurrentContext() to glxGetCurrentContext() was there anything else you needed to do to get things working on linux?

I’m in the process of upgrading my mac to snow leopard and am hoping this won’t break my ubuntu install (which I’m yet to try out) - so should hopefully be able to test on all platforms.

So far my research seams to point to openCL interop having been supported earlier with Apple’s openCL framework than with Nvidia’s or ATI’s SDKs.

The links in my previous two posts allude to both cosmetic changes and differences/not-yet-implemented features in at least the Nvidia SDK and possibly the ATI SDK as well:

* there are some cosmetic changes in how to get a shared context on mac (basically making it not a special case) - though I’ll have to test this;
* It appears that clEnqueueWriteImage is only implemented for clCreateImage2D not for clCreateFromGLTexture2D when using the Nvidia SDK;
* I’m assuming the clEnqueueAcquireGLObjects / clEnqueueReleaseGLObjects method is only necessary with the Nvidia SDK, but again have to wait for my 10.6 install to confirm
* I have some ATI hardware here (PC/Win) - so when I get a chance I can check that too…

M

@gameover: Besides the context properties there are some headers to change… quite straight forward changes actualy.

I would like to have feedback from people using ATi’s SDK, as we know Apple’s is working and gameover and I are using NVIDIA’s SDK, i question if its the version of recent OpenCL or the Nvidia implementation.

Hi, on linux is the current method to use opencl based on ATI or Nvidia drivers? Do they supply the opencl.h file? Is there any way to use opencl on a dual core laptop that only has intel graphics? After a bit of googling it seems like opencl in linux is very immature at the moment.

Hey all

I think I’m missing something here.
XCode is complaining that

  
OpenCL/Opencl.h  

doesn’t exist (as in the Khronos spec)

I’m on OSX 10.6.4
If I do a spotlight search, indeed there is no folder on my HDD that’s called OpenCL
There is 3 copies of ‘opencl.h’ on my computer. If I use the one from /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers , then it still references a folder called OpenCL within that opencl.h file. And also it references ‘OpenGL/CGLDevice.h’ which XCode cant find.

I think the XCode I downloaded originally was the XCode for iPhone. I presumed it’d be pretty much the same. But maybe that version doesn’t come with OpenCL proper?

Anybody else have this experience?
I think I might be able to hack a solution together out of found/renamed files.
but maybe it’s best to see if anyone’s got a clean solution to start with.

Thanks
Elliot

Hey all

I think I’m missing something here.
XCode is complaining that

  
OpenCL/Opencl.h  

doesn’t exist (as in the Khronos spec)

I’m on OSX 10.6.4
If I do a spotlight search, indeed there is no folder on my HDD that’s called OpenCL
There are 3 copies of ‘opencl.h’ on my computer. If I use the one from /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers , then that opencl.h file still references a folder called OpenCL. And also it references ‘OpenGL/CGLDevice.h’ which XCode cant find.

I think the XCode I downloaded originally was the XCode for iPhone. I presumed it’d be pretty much the same. But maybe that version doesn’t come with OpenCL proper?

Anybody else have this experience?
I think I might be able to hack a solution together out of found/renamed files.
but maybe it’s best to see if anyone’s got a clean solution to start with.

I’m running XCode 3.2.3 64-bit

Thanks
Elliot

I got around the missing file issue
by Base SDK was set to 10.5, needs to be 10.6 of course

now i’m hitting an error with

  
 CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE  

being undefined

will see how to get around that…

[edit]

ok, scratch that. was just an issue i made myself whilst trying to get around the other one
is there a word for that? like when struggling to escape a spiders web, you only make matters worse?

linker errors now…let’s see what’s next

(i’m starting with the oF 0.6 empty example)

[edit]

not entirely sure how to get the right libs in
but if i drag across the OpenCL.framework for the Source code at

http://www.macresearch.org/opencl-episode3
then i get hello world running!
also, I always wondered if there was a way to do that std:exit(0).

Yes its possible, after tinkering quite a lot with the code i got it all running besides sharing a texture with opengl. Although with your grafics card i don’t see much of an advantage.

Hi there, I’d very much like to know where you got with it - or what’s the “State of Art” concerning openCL and CV ?

(As far as I can see, dear Memo, yours is the state of art. Thank you very much, really - and greetings from Berlin.)

Bene