开发者

OpenCL type conversion from vector types to boolean

For the statement in my OpenCL kernel

uint4 checkCoord; // assign some value
if(checkCoord==(uint4)(0,0,0,0)){
  ; // do something
}

I am getting the following error in OpenCL compiler

statement requires expression of scalar type ('int  __attribute__((ext_vector_type(4,4)))' invalid)
开发者_开发技巧

What is the easiest way to convert a variable of uint4 type to a bool (or scalar) value?


You should use all to test the condition is verified on all components of the vector. checkCoord == (uint4)(0,0,0,0) is an int4 with components either 0 (false) or (uint)-1 (true).

if ( all( checkCoord == (uint4)(0,0,0,0) ) ) { ... }

According to the OpenCL specs (6.3.e), you could also write

if ( all( checkCoord == 0 ) ) { ... }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜