开发者

Problem reinterpreting parameters in OpenCL 1.0

Is it possible to reinterpret parameters that have been passed into an OpenCL Kernel. For example, if I have an array of integers being passes in, but I want to interpret the integer at index 16 as a float (don't ask why!) then I would have thought this would work.

__kernel void开发者_开发知识库 Test(__global float* im, __constant int* constArray)
{
  float x = *( (__constant float*) &constArray[16] );
  im[0] = x;
}

However, I get a CL_INVALID_COMMAND_QUEUE error when I next try to use the command queue, implying that the above code has performed an illegal operation.

Any suggests what is wrong with the above, and/or how to achieve the reinterpretation?

I have now tried:

__kernel void Test(__global float* im, __constant int* constArray)
{
  float x = as_float(0x3f800000);
  im[0] = x;
}

and this does indeed give a 1.0f in im[0]. However,

__kernel void Test(__global float* im, __constant int* constArray)
{
  float x = as_float(constArray[16]);
  im[0] = x;
}

always results in zero in im[0] regardless of what is in constArray[16].

Regards,

Mark.


OpenCL includes the as_typen family of operators for reinterpret casting of values from one type to another. If I am understanding the question, you should be able to do something like

__kernel void Test(__global float* im, __constant int* constArray)
{
  float x = as_float(constArray[16]);
  im[0] = x;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜