AnsweredAssumed Answered

Passing Classes between Host and Device

Question asked by settle on Mar 5, 2012
Latest reply on Apr 11, 2012 by brg

In the OpenCL Static C++ Kernel Language Extension, Rev. 04, Sec. 4.1 (page 10) the example class code on the host and kernel are exactly the same.  However, shouldn't the host side use cl_int to ensure matching data types with the kernel side?  If so, every class needs two code versions: host code (using OpenCL API) and kernel code (using OpenCL Langauge).  Is this correct?

 

Kernel code:

Class Test {

   setX (int value); private: int x; 

}

__kernel foo (__global Test* InClass, ...) {

If (get_global_id(0) == 0) InClass->setX(5);

}

Host Code:

Class Test {

   setX (int value); private: int x; 

}

MyFunc () {

tempClass = new(Test);
... // Some OpenCL startup code
create context, queue, etc. cl_mem classObj = clCreateBuffer(context, CL_USE_HOST_PTR,

sizeof(Test),&tempClass, event); clEnqueueMapBuffer(...,classObj,...);

tempClass.setX(10);
clEnqueueUnmapBuffer(...,classObj,...); //class is passed to the Device clEnqueueNDRange(..., fooKernel, ...); clEnqueueMapBuffer(...,classObj,...); //class is passed back to the Host

}

Outcomes