mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
printf: Fix floating-point rounding consistency for RTZ devices (#2202)
1. In vector test, prepare RTZ answer for RTZ rounding.
2. In mixed_format_random test, for a given float 'arg', the test
previously used 'arg' directly to generate ref_str:
```
ref_str << str_sprintf(format, arg);
```
This approach incorrectly assumes:
```
(float) arg == to_fp(to_str(arg));
```
However, this assumption fails under RTZ rounding. For example:
```
arg = 0xC642549C
to_str(arg) = -12437.152343f
to_fp_rtz(-12437.152343f) = 0xC642549B (-0X1.84A936P+13)
to_fp_rte(-12437.152343f) = 0xC642549C (-0X1.84A938P+13)
```
To address this, the reference result is now computed based on the
literal float string rather than the original 'arg' value.
This commit is contained in:
@@ -317,8 +317,10 @@ cl_program makeMixedFormatPrintfProgram(cl_kernel* kernel_ptr,
|
||||
{
|
||||
const float max_range = 100000.f;
|
||||
float arg = get_random_float(-max_range, max_range, gMTdata);
|
||||
args_str << str_sprintf("%f", arg) << "f, ";
|
||||
ref_str << str_sprintf(format, arg) << ", ";
|
||||
std::string arg_str = str_sprintf("%f", arg);
|
||||
args_str << arg_str << "f, ";
|
||||
float arg_deviceRound = std::stof(arg_str);
|
||||
ref_str << str_sprintf(format, arg_deviceRound) << ", ";
|
||||
}
|
||||
}
|
||||
// Restore the original CPU rounding mode
|
||||
|
||||
Reference in New Issue
Block a user