从矢量类型到布尔值的OpenCL类型转换

Adi*_*cin 4 opencl

对于我的OpenCL内核中的语句

uint4 checkCoord; // assign some value
if(checkCoord==(uint4)(0,0,0,0)){
  ; // do something
}
Run Code Online (Sandbox Code Playgroud)

我在OpenCL编译器中收到以下错误

statement requires expression of scalar type ('int  __attribute__((ext_vector_type(4,4)))' invalid)
Run Code Online (Sandbox Code Playgroud)

将uint4类型的变量转换为bool(或标量)值的最简单方法是什么?

Eri*_*lle 5

您应该使用all测试条件在向量的所有组件上进行验证.checkCoord == (uint4)(0,0,0,0)是一个int4,其组件为0(false)或(uint)-1(true).

if ( all( checkCoord == (uint4)(0,0,0,0) ) ) { ... }
Run Code Online (Sandbox Code Playgroud)

根据OpenCL规范(6.3.e),你也可以写

if ( all( checkCoord == 0 ) ) { ... }
Run Code Online (Sandbox Code Playgroud)