the Fiddler's picture

C# OpenCL bindings ready for testing

Update: current efforts are focused on Cloo (object-oriented CL wrapper), which can be found here. It provides a much cleaner OpenCL API compared to raw bindings (which are also available in case you need them).

The generator now supports generating C# OpenCL wrappers from the C headers. The OpenCL wrappers reside under the OpenTK.Compute.CL10 namespace of SVN trunk. An OpenCL sample has also been added to Examples.exe: if you have access to an OpenCL implementation, please run the VectorAdd sample and report your results here.

AMD has released a public beta of its OpenCL implementation that you can download from AMD's developer website (free registration needed). This implementation runs on all SSE3-capable CPUs and is available for Window and Linux platforms.

There is a lot of fine-tuning left to do for OpenTK's OpenCL wrappers and the sooner you test the bindings, the sooner they will become ready for release.


Comments

kvark's picture

I've installed ATI Stream SDK.
Running VectorAdd produces the following error:
Unable to find an entry point named 'clCreateContextFromType' in DLL 'opencl.dll'

As far as I can see, this method is used in ATI demos, so there's probably something wrong with OpenTK bindings.

the Fiddler's picture

Thanks for testing.

I have encountered similar issues here and it's good to know they are not limited to my system. Haven't been able to find the cause yet.

It's a fact that P/Invokes work slightly different than the C linker, so it's possible that one works where the other one fails in some specific cases. We might be hitting such a corner case here.

I've yet to test on Linux.

nythrix's picture

Is it possible to move the bindings into one file? The current files were (originally) to contain the high level OpenCL classes.

the Fiddler's picture

Already done in SVN. The actual bindings are under 4 files in the CL10 directory. Everything else is empty and has remained as a guide for the high level classes.

nythrix's picture

Thanks. The ComputePlatform is ready though untested so far. ComputeDevice to arrive in a couple of days.

I too get an EntryPointNotFoundException on CL.GetPlatformID. Its the first CL call overall. Btw: it should be *CL.GetPlatformIDs*
WinXP 32bit / GF 9600GT / Core 2 Duo

Should I start a new thread for the OpenCL objects discussion? The old one is closed.

the Fiddler's picture

Yes, please create a new thread for this. It's also a good idea to create separate threads for any issues you encounter (e.g. GetPlatformIDs), otherwise they tend to get lost in the woods.

Zingam's picture

With Stream SDK 2.0 beta 3 the sample throws an exception.

The Mandelbrot sample with OpenCL.NET lib works.

the Fiddler's picture

Thanks for testing.

Can you please create an issue report with the exception and some details on your operating system? (OS, version and whether it's 32- or 64-bits)

Edit: Ati Stream 2.0 beta 3 still suffers from issue #1124: [OpenCL] EntryPointNotFoundException on CL calls. This is a bug in Ati's code on Windows - the Linux version is working correcty, as is Nvidia's implementation.

mike vasiljevs's picture

Concerning the OpenCL VectorAdd example, that is in latest repository revision, device to host memory writes seem to be missing, as well as the problem with the queue argument (queue instead of the context), more in http://www.opentk.com/node/1233
:?

Inertia's picture

fyi: AMD released Stream SDK v2.0 beta 4 today.

Zingam's picture

I have made a report. I hope it is OK and informative. I get some memory error.

Will OpenCL get a nice OOP wrapper anytime soon?

the Fiddler's picture

Thanks, I believe this error has been fixed in SVN and 0.9.9-3, but I cannot test right now.

Nythrix is working on an OOP wrapper and there's OpenCL.Net, but I don't know the current status of either project. Right now, we are focusing on core OpenTK and the GL & ES bindings and we'll work OpenTK.Compute.

Of course help is welcome:

  • Bug reports for errors like the one you encountered
  • Suggestions on how to make the OpenCL bindings simpler to use (they are hard right now!)
  • Examples and test code (the VectorAdd sample is not enough!)
  • Checking that the bindings match the specs

Every little bit helps!

the Fiddler's picture

The name mangling issue has been reported as fixed in AMD Stream 2.0 beta 4. Can someone please test and confirm whether VectorAdd works now?

Zingam's picture

Well, I've tested it and it does not throw any exceptions for me. But the result I get is

0+0=0
0+0=0
0+0=0
0+0=0
0+0=0
0+0=0
...

To be honest I haven't checked what this example should do. I was only interested if the bindings work.

the Fiddler's picture

Thanks, the important fact is that it doesn't crash anymore!

The 0 + 0 = 0 issue is a bug, I'll fix that.

Bernd's picture

Hi,

the following line from the "vectorAdd" example returns an error 'OpenTK.Compute.CL10.ErrorCode.InvalidKernelName':

// create kernel
            cl_kernel hKernel = CL.CreateKernel(hProgram, "vectorAdd", out error);

resulting in hKernel staying 0 so nothing gets ever called. That is why the result is still all 0.

I am using the ATi Beta 4 together with a HD 5770 using VS 2008.

Regards,
Bernd Krekeler.

the Fiddler's picture

The 0+0=0 issue was unintended (simply forgot to initialize the arrays). Fixed now.

Still haven't been able to test on Ati Stream, due to #1299: [Compute] Ati Stream SDK 2.0 beta 4 causes DllNotFoundException.

viewon01's picture

Hi,

I have a computer with :
- an Intel CPU
- an Intel Graphic Card

So, my question is... if I write an application based on OpenCL... will it work to on machines that doesn't support OpenCL ?
or I must write another version of my soft ?

Thanks

nythrix's picture

I think, Intel does not provide OpenCL drivers, yet. You cannot run such an application without them.

the Fiddler's picture

You can use Ati's Stream SDK (free registration required). It requires SSE3 (any Core 2 or newer will do), but otherwise runs on Intel CPUs just fine.

nythrix's picture

Ouch, I forgot about the CPU :D

viewon01's picture

Hi,

I have download the AMD Stream SDK at : http://developer.amd.com/gpu/ATIStreamSDKBetaProgram/Pages/default.aspx#...

I have download this one : "ati-opencl-beta-driver-v2.0-beta4-xp.zip (109MB)"

But I can't find any OpenCL dll !!!! Even during installation I can't find any option regarding OpenCL :-(

viewon01's picture

Sorry, I have forgot to download a module !!

Thx

chrisse27's picture

After adding <dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/> to OpenTK.dll.config the VectorAdd Sample seems to work correctly on my Snow Leopard system. It outputs correct sums of random integers.

the Fiddler's picture

Thanks, added to r2564, and I'll backport this to trunk soon.

CodyIrons's picture

Hello,

My system is an AMD Phenom2 X4 940 with 3 * 4870 1GB (they are in crossfireX) on Vista x64, i am running the recently released 9.12 hotfix drivers and i have installed the ati-stream-sdk-v2.0-beta4-vista-win7-64.exe (59.3MB).
I am using VSExpress C# 2008 with the OpenTK-0.9.9-3 and running the VectorAdd from trunk I am seeing the following error (i added additional Error checks after each setting of error):

Launching sample: "Vector Addition"
 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: InvalidKernelName
   at Examples.VectorAdd.Main() in C:\Users\Cody\Documents\Downloads\opentk-0.9.9-3\opentk-0.9.9-3\Source\Examples\OpenCL\VectorAdd.cs:line 77
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Examples.ExampleBrowser.RunSample(Control parent, ExampleInfo e) in C:\Users\Cody\Documents\Downloads\opentk-0.9.9-3\opentk-0.9.9-3\Source\Examples\ExampleBrowser.cs:line 335

Pointing at this :

            CL.BuildProgram(hProgram, 0, (IntPtr[])null, null, IntPtr.Zero, IntPtr.Zero);
 
            // create kernel
            cl_kernel hKernel = CL.CreateKernel(hProgram, "vectorAdd", out error);
            if (error != ErrorCode.Success)
                throw new Exception(error.ToString());
 
            // allocate host  vectors

I see your comment on the Invalid Kernel Name exception above but that was back in late October and i was hoping this was addressed by these latest drivers. Is there anything i should check on my end to see if something is not setup properly?

CodyIrons's picture

Sorry, i should have read more on the site, i see the bug entered for this already and we are waiting on beta 5 from ati. I have run this on my nvidia based laptop and it is working fine.

nythrix's picture

A friend of mine suggested I put a line here, given the amount of people (inluding him) ending up reading this thread and never finding the oo wrapper mentioned above. So here goes:

Cloo, the .NET, object oriented OpenCL API wrapper, is finally available and can be downloaded from its sourceforge pages.

the Fiddler's picture

Updated the OP to reflect this.

nythrix's picture

What is the OP?

Edit: Original Post, got it.