bennC32

Novice needs help creating an Image2D of type CL_HALF_FLOAT

Discussion created by bennC32 on Mar 3, 2011
Latest reply on Mar 7, 2011 by himanshu.gautam
I don't understand how to set up the buffer needed by clCreateImage2D()

I'm trying to use an Image2D with the channel format of type CL_HALF_FLOAT.

I have no trouble using CL_FLOAT images but I would like to use the  CL_HALF_FLOAT type since my application will not fit in the available memory using floats.  The part I can't seem to figure out is how to prepare the buffer that gets passed to clCreateImage2D().  I'm assuming that the buffer needs to be (cl_halt *), but it's not clear to me how to create such a thing.  I have tried something like

   cl_half *halfData = (cl_half *)malloc(numRows*numCols*sizeof(cl_half));
   for (int i=0; i<numRows*numCols; i++) {
      halfData = (cl_half)(floatData);      // where floatData is an array of floats
   }

That does not appear to work, which is not supprising given how cl_half is defined in CL/cl_platform.h (typedef uint16_t  cl_half for Linux).

I have poured over the OpenCL spec looking for some way to convert a float to a cl_half but I didn't find anything.  Any suggestions would be appreciated.  I'm obviously missing something here.  Can anyone point me to an example of using clCreateImage2D() with type CL_HALF_FLOAT?

Thanks,

bennC32

Outcomes