<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 14, 2015 at 4:19 PM, Jan Vesely <span dir="ltr"><<a href="mailto:jan.vesely@rutgers.edu" target="_blank">jan.vesely@rutgers.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, 2015-06-13 at 21:22 -0500, Aaron Watry wrote:<br>
> Meh, this still feels broken.  Give me a bit longer.<br>
<br>
</span>and it is :). I don't think this can work based on abs(expected - real),<br>
since ULP depends on the magnitude of the numbers. This information is<br>
lost after subtraction.<br></blockquote><div><br></div><div>Yeah, that's essentially the conclusion that I came to last night as well.  Currently, we're saying that 3 ULP is 3x the smallest representable floating point number, not 3x the interval between adjacent float values for the given magnitude.<br><br></div><div>I was thinking that we might need to take the expected value, cast to unsigned, add the ulp value, then convert back to float.  From there, find the difference between expected and the expected+ulp, and use that as a tolerance.  We could alternatively call nextafterf/nextafter the required number of times from the expected value in either direction and get a min/max allowed value and then check that the result value is in that range.<br><br></div>Yes, we still run into cases where the tests themselves are expected an incorrectly rounded value, but at least the ULP checking code might be functioning correctly then.<br></div><div class="gmail_quote"><div> <br></div><div>Thoughts?<br></div><div><br></div><div>--Aaron<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I had an idea some time back to implement this using nextafterf in both<br>
directions and checking whether the result falls in that interval.<br>
However, there is still a problem. Some of the expected values are<br>
already rounded (I'm not sure what rounding mode is used by python by<br>
default), but unless it always rounds in one direction, we'll still get<br>
slight differences based on whether the actual value was rounded up or<br>
down.<br>
<br>
I have attached a small test program that shows the deficiencies of<br>
fabsf based approaches.<br>
<br>
regards,<br>
Jan<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> --Aaron<br>
><br>
> On Sat, Jun 13, 2015 at 2:28 PM, Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>> wrote:<br>
><br>
> > We need to actually check against the float value from the union,<br>
> > instead of just doing (diff > ulp), which seems to cast the diff to<br>
> > an int before checking against ulp.<br>
> ><br>
> > Signed-off-by: Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>><br>
> > CC: Tom Stellard <<a href="mailto:thomas.stellard@amd.com">thomas.stellard@amd.com</a>><br>
> > CC: Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
> > ---<br>
> >  tests/util/piglit-util-cl.c | 28 ++++++++++++++--------------<br>
> >  1 file changed, 14 insertions(+), 14 deletions(-)<br>
> ><br>
> > diff --git a/tests/util/piglit-util-cl.c b/tests/util/piglit-util-cl.c<br>
> > index 47e0c7a..6cdd718 100644<br>
> > --- a/tests/util/piglit-util-cl.c<br>
> > +++ b/tests/util/piglit-util-cl.c<br>
> > @@ -80,7 +80,7 @@ piglit_cl_probe_floating(float value, float expect,<br>
> > uint32_t ulp)<br>
> ><br>
> >         diff = fabsf(value - expect);<br>
> ><br>
> > -       if(diff > ulp || isnan(value)) {<br>
> > +       if (diff > t.f || isnan(value)) {<br>
> >                 printf("Expecting %f (0x%x) with tolerance %f (%u ulps),<br>
> > but got %f (0x%x)\n",<br>
> >                        e.f, e.u, t.f, t.u, v.f, v.u);<br>
> >                 return false;<br>
> > @@ -108,7 +108,7 @@ piglit_cl_probe_double(double value, double expect,<br>
> > uint64_t ulp)<br>
> ><br>
> >         diff = fabsl(value - expect);<br>
> ><br>
> > -       if(diff > ulp || isnan(value)) {<br>
> > +       if (diff > t.f || isnan(value)) {<br>
> >                 printf("Expecting %f (0x%lx) with tolerance %f (%lu ulps),<br>
> > but got %f (0x%lx)\n",<br>
> >                        e.f, e.u, t.f, t.u, v.f, v.u);<br>
> >                 return false;<br>
> > @@ -162,7 +162,7 @@ piglit_cl_get_platform_version(cl_platform_id platform)<br>
> >         int scanf_count;<br>
> >         int major;<br>
> >         int minor;<br>
> > -<br>
> > +<br>
> >         /*<br>
> >          * Returned format:<br>
> >          *<br>
> >  OpenCL<space><major_version.minor_version><space><platform-specific<br>
> > information><br>
> > @@ -353,7 +353,7 @@ piglit_cl_get_info(void* fn_ptr, void* obj, cl_uint<br>
> > param)<br>
> ><br>
> >         if(errNo == CL_SUCCESS) {<br>
> >                 param_ptr = calloc(param_size, sizeof(char));<br>
> > -<br>
> > +<br>
> >                 /* retrieve param */<br>
> >                 if(fn_ptr == clGetPlatformInfo) {<br>
> >                         errNo = clGetPlatformInfo(*(cl_platform_id*)obj,<br>
> > param,<br>
> > @@ -463,7 +463,7 @@ piglit_cl_get_program_build_info(cl_program program,<br>
> > cl_device_id device,<br>
> >                 .program = program,<br>
> >                 .device = device<br>
> >         };<br>
> > -<br>
> > +<br>
> >         return piglit_cl_get_info(clGetProgramBuildInfo, &args, param);<br>
> >  }<br>
> ><br>
> > @@ -479,7 +479,7 @@ piglit_cl_get_kernel_work_group_info(cl_kernel kernel,<br>
> > cl_device_id device,<br>
> >                 .kernel = kernel,<br>
> >                 .device = device<br>
> >         };<br>
> > -<br>
> > +<br>
> >         return piglit_cl_get_info(clGetKernelWorkGroupInfo, &args, param);<br>
> >  }<br>
> ><br>
> > @@ -620,7 +620,7 @@ piglit_cl_get_device_ids(cl_platform_id platform_id,<br>
> > cl_device_type device_type,<br>
> >                                         piglit_cl_get_error_name(errNo));<br>
> >                                 return 0;<br>
> >                         }<br>
> > -<br>
> > +<br>
> >                         /* get device list */<br>
> >                         if(device_ids != NULL && num_device_ids > 0) {<br>
> >                                 *device_ids = malloc(num_device_ids *<br>
> > sizeof(cl_device_id));<br>
> > @@ -761,7 +761,7 @@<br>
> > piglit_cl_build_program_with_source_extended(piglit_cl_context context,<br>
> >                         piglit_cl_get_error_name(errNo));<br>
> >                 return NULL;<br>
> >         }<br>
> > -<br>
> > +<br>
> >         errNo = clBuildProgram(program,<br>
> >                                context->num_devices,<br>
> >                                context->device_ids,<br>
> > @@ -788,7 +788,7 @@<br>
> > piglit_cl_build_program_with_source_extended(piglit_cl_context context,<br>
> >                         char* log =<br>
> > piglit_cl_get_program_build_info(program,<br>
> ><br>
> >  context->device_ids[i],<br>
> ><br>
> >  CL_PROGRAM_BUILD_LOG);<br>
> > -<br>
> > +<br>
> >                         printf("Build log for device %s:\n -------- \n%s\n<br>
> > -------- \n",<br>
> >                                device_name,<br>
> >                                log);<br>
> > @@ -848,11 +848,11 @@<br>
> > piglit_cl_build_program_with_binary_extended(piglit_cl_context context,<br>
> >                 for(i = 0; i < context->num_devices; i++) {<br>
> >                         char* device_name =<br>
> > piglit_cl_get_device_info(context->device_ids[i],<br>
> ><br>
> > CL_DEVICE_NAME);<br>
> > -<br>
> > +<br>
> >                         printf("Error for %s: %s\n",<br>
> >                                device_name,<br>
> >                                piglit_cl_get_error_name(binary_status[i]));<br>
> > -<br>
> > +<br>
> >                         free(device_name);<br>
> >                 }<br>
> ><br>
> > @@ -860,7 +860,7 @@<br>
> > piglit_cl_build_program_with_binary_extended(piglit_cl_context context,<br>
> >                 return NULL;<br>
> >         }<br>
> >         free(binary_status);<br>
> > -<br>
> > +<br>
> >         errNo = clBuildProgram(program,<br>
> >                                context->num_devices,<br>
> >                                context->device_ids,<br>
> > @@ -884,11 +884,11 @@<br>
> > piglit_cl_build_program_with_binary_extended(piglit_cl_context context,<br>
> >                         char* log =<br>
> > piglit_cl_get_program_build_info(program,<br>
> ><br>
> >  context->device_ids[i],<br>
> ><br>
> >  CL_PROGRAM_BUILD_LOG);<br>
> > -<br>
> > +<br>
> >                         printf("Build log for device %s:\n -------- \n%s\n<br>
> > -------- \n",<br>
> >                                device_name,<br>
> >                                log);<br>
> > -<br>
> > +<br>
> >                         free(device_name);<br>
> >                         free(log);<br>
> >                 }<br>
> > --<br>
> > 2.1.4<br>
> ><br>
> ><br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
</font></span></blockquote></div><br></div></div>