cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Raistmer
Adept II

Incorrect arithmetic?

please, look simple kernel

I expect that results buffer will be filled with 1 << 8 + 1 == 257, but recive 131136 instead.
What is wrong?

Kernel code (it's severely cutted test case):

Look ticket 936 for test case.

__kernel void PC_single_pulse_kernel_128(__global float* gpu_power, __constant float* thresh,__global uint* results, const int num_dchunks) { uint tid=get_global_id(0); uint dchunk=get_global_id(1); uint result=0;//R: will contain info about location of found pulses and best signals uint4 was_pulse=(uint4)(0); was_pulse.x=1; result+=was_pulse.x+was_pulse.y<<1+was_pulse.z<<2+was_pulse.w<<3; result+=was_pulse.x<<8+was_pulse.y<<9; //R: last we do is to write result of pulse finding results[32*dchunk+tid]=result; }

0 Likes
3 Replies
Ceq
Journeyman III

I didn't look the code, but notice that the priority of the '<<' operator is lower than the '+' operator, so "1 << 8 + 1 == 512".

0 Likes

Originally posted by: Ceq

I didn't look the code, but notice that the priority of the '<<' operator is lower than the '+' operator, so "1 << 8 + 1 == 512".



Thanks, my bad, I assumed different priority order. It fixed lot of strange things
0 Likes

There's a lesson in that Never assume a priority order - always bracket everything. Saves all sorts of problems.

0 Likes