call to 'max' is ambiguous

Hi,

I get this error in the WebCL application “Animated M-set explorer” at
http://www.ibiblio.org/e-notes/webcl/webcl.htm
with kernel
[html]
#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#else
#pragma OPENCL EXTENSION cl_amd_fp64 : enable
#endif
__kernel void ckMandelbrot(__global uchar4* col, float scale){
ushort x = get_global_id(0), y = get_global_id(1);

double Cr = (x - 256) / scale + .37014983130958534;
double Ci = (y - 256) / scale + .10511722270082503;
double I=0, R=0,  I2=0, R2=0;
ushort n=0;
while ( (R2+I2 < 4.) && (n < 1024) ){
  I=(R+R)*I+Ci;  R=R2-I2+Cr;  R2=R*R;  I2=I*I;  n++;
}
if (n == 1024) col[y*512 + x] = (uchar4)(0, 0, 0, 255);
else{
  short c = (short)((n % 64)*24.);
  col[y*512 + x] = (uchar4)(
   min( max( 0, abs(c - 768) - 384), 255 ),
   min( max( 0, 512 - abs(c - 512)), 255 ),
   min( max( 0, 512 - abs(c - 1024)), 255 ),
   255);
}

}
[/html]
really it is just clamp(…, 0, 255). How can I correct my script?

Evgeny

Hello,

c is short but 0 and 255 are int, you need to pass the same variable type to all three parameters of the function to clear up wich overload you want to use.

Let me comment some issues I noticed:

Division is very costly and should be avoided if possible. As scale is a kernel parameter, you should pass 1.0 / scale as parameter, computed on host side, and in the kernel just use a multiply instead.

%64 is equal to & 63 but modulus is several number of times more costly. This applies to any power of two.

Hope this helps.

Regards,

Nils

if 0, 255 … are int then as I think
512 - abs(c - 512))
should be converted to int too. So what is “255” type (uchar, short, ushort…)?
(I could try e.g. “(short)255” but I have not recent NVidia GPU near :)

Evgeny