0

I was wondering what is the best way to get started to code a middleware that will capture all OpenCL apicalls. I could then write a program to replay the trace on a different system.

I'm assuming this will not need any special hooks in the driver. If this is the case, then I suppose we will not be able to do it.

I could not find examples on the internet. If you are aware of any resources- website or books, can you please let me know?

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • Have you tried anything of your own, or do you have a specific idea you want to ask about? This kind of question as it is is a bit too broad for stckoverflow. – mfa May 20 '16 at 13:13
  • Your best bet is to download sources for OpenCL ICD (opencl.dll) from khronos.org, modify them, and make your own opencl.dll with all the capturing code. That should actually be pretty straightforward based on my recollection of seeing this code. https://github.com/KhronosGroup/OpenCL-ICD-Loader – void_ptr May 20 '16 at 23:02

1 Answers1

0

Develop wrapper library (say, myopencl.so), link it against system OpenCL library (say, libopencl.so).

In myopencl.so, implement entry points for all OpenCL API calls as follows:

typdef cl_int (*clEnqueueNDRangeKernel_fptr)(/*arguments here*/);

cl_int clEnqueueNDRangeKernel(/*arguments here*/)
{
    // Do whatever you want to do;

    // Get function pointer from system OpenCL library;
    clEnqueueNDRangeKernel_fptr enqueue_fptr = dlsym("clEnqueueNDRangeKernel");

    // Call actual OpenCL function;
    return enqueue_fptr(/*arguments here*/);
}

Link your application against myopencl.so instead of libopencl.so. You'll have to write a lot of boilerplate code, though.

Roman Arzumanyan
  • 1,784
  • 10
  • 10