I´m pretty sure this is (again) a very simple question for the advanced coders here, but it´s driving me nuts.
I want to compare to vectors and do sth. if they are equal.
Thanks for your help,
Dia
__kernel void test(__constant uint *passedInt4Arr, __global uint *out) { constant uint4* passedInt4Arr_vec4 = (__constant uint4*) passedInt4Arr; uint4 Vec4 = (uint4)(1, 2, 3, 4); // any way to do a direct vector comparison? compiler throws me errors if passedInt4Arr_vec4 == Vec4 is used if(passedInt4Arr_vec4[0].x == Vec4.x && passedInt4Arr_vec4[0].y == Vec4.y && passedInt4Arr_vec4[0].z == Vec4.z && passedInt4Arr_vec4[0].w == Vec4) { do_sth(); } }
extern void do_sth(); __kernel void test(__constant uint *passedInt4Arr, __global uint *out) { constant uint4* passedInt4Arr_vec4 = (__constant uint4*) passedInt4Arr; uint4 Vec4 = (uint4)(1, 2, 3, 4); // any way to do a direct vector comparison? compiler throws me errors if passedInt4Arr_vec4 == Vec4 is used if(passedInt4Arr_vec4[0] == Vec4) { do_sth(); } }
Micah this doesn´t work for me, see the error, which I get from clBuildProgram (I only changed the var names to the example ones).
Any ideas? Using the latest Stream SDK with Cat 9.12 Hotfix (Catalyst_9.12_Hotfix_Win7_Vista_8.682.2RC1_Dec15.exe) on Win7 x64.
Dia
C:\Users\xyz\AppData\Local\Temp\OCLBF0E.tmp.cl(166): error: expression must have arithmetic, enum, or pointer type if(passedInt4Arr_vec4[0] == Vec4) ^
As the error message says, if condition requires the arguments to be arithmetic, enum, or pointer type.
You can use any() or all() function, if the resultant conditional expression is a vector.
Originally posted by: omkaranathan As the error message says, if condition requires the arguments to be arithmetic, enum, or pointer type.
You can use any() or all() function, if the resultant conditional expression is a vector.
I´m unsure if I got your point. I want to compare 2 Vectors, if they are equal (all components are equal) I want to proceed in the if-statement.
OpenCL doc sais, that any() or all() test for sign bit, so could you give me a hint with some code?
Thanks,
Dia
Edit: And why works the direct comparison for Micah, but not for me?
if(any(passedInt4Arr_vec4[0] == Vec4)) should work fine.
Thanks omkaranathan,
Your code works and it´s even a bit faster than a AND linked component-comparison, nice . I read somewhere, that one should avoid control flow (if-Statements), is there any way to achieve that check I do, but faster?
Dia
Originally posted by: diapolo Thanks omkaranathan,
Your code works and it´s even a bit faster than a AND linked component-comparison, nice . I read somewhere, that one should avoid control flow (if-Statements), is there any way to achieve that check I do, but faster?
Dia
diapolo,
It is not possible to check condition without control instructions(if, switch, do, while and for). Any flow control instruction can significantly affect the instruction throughput by casuing threads of the same wavefront to diverge i.e to follow different execution paths.