OpenCL not finding devices as dll

Hy

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
#else
#define EXPORT_API 
#endif

.........

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 
 {
 [DllImport("CLTest")]
    private static extern int CLGetDeviceCount();

  public int clDeviceCount()
  {
  return CLGetDeviceCount();
  }
}

I don’t have experience with your problem, but perhaps it would be easier if you used the exisiting .Net wrappers:
Cloo: Cloo download | SourceForge.net
The Open Toolkit library: The Open Toolkit library download | SourceForge.net

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.

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 :slight_smile: