View Full Version : OpenCL not finding devices as dll

02-04-2013, 06:13 AM

So I am fairly new to OpenCL and GPGPU in general , all has been great until I wanted to integrate it with one of my C# applications issue being that if I call the functioning from C# OpenCL does not find any valid devices but if I switch from .dll to .exe and execute it as a console application it works just fine

C++ code sample

#if _MSC_VER
#define EXPORT_API __declspec(dllexport) functions with this
#define EXPORT_API


extern "C"
int EXPORT_API CLGetDeviceCount()
cl::Platform::get( &platforms);
cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[i])(), 0 };
context = cl::Context (CL_DEVICE_TYPE_ALL , cps);

devices = context.getInfo<CL_CONTEXT_DEVICES>();

return devices.size() ;

C# code sample

using System.Runtime.InteropServices;


public class SimpleCLCall
private static extern int CLGetDeviceCount();

public int clDeviceCount()
return CLGetDeviceCount();

02-04-2013, 07:28 AM
I don't have experience with your problem, but perhaps it would be easier if you used the exisiting .Net wrappers:
Cloo: http://sourceforge.net/projects/cloo/
The Open Toolkit library: http://sourceforge.net/projects/opentk/

I have no experience with either, so I can't help you much further. Looking at the source code might also help you if you still want to write your own version.

02-04-2013, 11:26 AM
Thank you for the reply , I looked over cloo and is great implementation and it works with my application , but I will still write my own one helps on the learning the API and how everything works easier :)