bruteforce: Fix retry logic for cases with subnormals (#2091)

Replace the occurrences of 0.0f == test' with 0.0f == HTF(test)'. The
types of 0.0f and test are not the same, so the equality comparison will
get undesired result when the test represents a -0.0h (i.e., test is
32768=0x8000). In this situation, 0.0f == test will be false, but 0.0f
== HTF(test) will be true.

Revise each if-statement to match the OpenCL s7.5.3 Item 4, specifically
modify to check that the result is subnormal instead of checking that it
is zero. "If the result of 3. is a sub-normal before rounding, the
result may be flushed to zero"

Co-authored-by: tnimburk <tnimburk@qti.qualcomm.com>
This commit is contained in:
Sreelakshmi Haridas Maruthur
2024-10-08 10:53:55 -06:00
committed by GitHub
parent d339fd4356
commit 7d86714c10

View File

@@ -300,10 +300,10 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fail && ftz) if (fail && ftz)
{ {
// retry per section 6.5.3.2 with flushing on // retry per section 6.5.3.2 with flushing on
if (0.0f == test float r = f->func.f_fma(HTF(hp0[j]), HTF(hp1[j]),
&& 0.0f HTF(hp2[j]), FLUSHED);
== f->func.f_fma(HTF(hp0[j]), HTF(hp1[j]), cl_half c = HFF(r);
HTF(hp2[j]), FLUSHED)) if (0.0f == HTF(test) && IsHalfSubnormal(c))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
@@ -349,13 +349,15 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err3) < fabsf(err)) err = err3; if (fabsf(err3) < fabsf(err)) err = err3;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r3 = f->func.f_fma(0.0f, HTF(hp1[j]),
&& (0.0f HTF(hp2[j]), FLUSHED);
== f->func.f_fma(0.0f, HTF(hp1[j]), float r4 = f->func.f_fma(-0.0f, HTF(hp1[j]),
HTF(hp2[j]), FLUSHED) HTF(hp2[j]), FLUSHED);
|| 0.0f cl_half c3 = HFF(r3);
== f->func.f_fma(-0.0f, HTF(hp1[j]), cl_half c4 = HFF(r4);
HTF(hp2[j]), FLUSHED)))
if (0.0f == HTF(test)
&& (IsHalfSubnormal(c3) || IsHalfSubnormal(c4)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
@@ -424,28 +426,28 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err5) < fabsf(err)) err = err5; if (fabsf(err5) < fabsf(err)) err = err5;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r5 = f->func.f_fma(0.0f, 0.0f,
&& (0.0f HTF(hp2[j]), FLUSHED);
== f->func.f_fma(0.0f, 0.0f, float r6 = f->func.f_fma(-0.0f, 0.0f,
HTF(hp2[j]), HTF(hp2[j]), FLUSHED);
FLUSHED) float r7 = f->func.f_fma(0.0f, -0.0f,
|| 0.0f HTF(hp2[j]), FLUSHED);
== f->func.f_fma(-0.0f, 0.0f, float r8 = f->func.f_fma(-0.0f, -0.0f,
HTF(hp2[j]), HTF(hp2[j]), FLUSHED);
FLUSHED)
|| 0.0f cl_half c5 = HFF(r5);
== f->func.f_fma(0.0f, -0.0f, cl_half c6 = HFF(r6);
HTF(hp2[j]), cl_half c7 = HFF(r7);
FLUSHED) cl_half c8 = HFF(r8);
|| 0.0f if (0.0f == HTF(test)
== f->func.f_fma(-0.0f, -0.0f, && (IsHalfSubnormal(c5)
HTF(hp2[j]), || IsHalfSubnormal(c6)
FLUSHED))) || IsHalfSubnormal(c7)
|| IsHalfSubnormal(c8)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
} }
if (IsHalfSubnormal(hp2[j])) if (IsHalfSubnormal(hp2[j]))
{ {
if (test == 0.0f) // 0*0+0 is 0 if (test == 0.0f) // 0*0+0 is 0
@@ -517,19 +519,24 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err5) < fabsf(err)) err = err5; if (fabsf(err5) < fabsf(err)) err = err5;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r9 = f->func.f_fma(0.0f, HTF(hp1[j]),
&& (0.0f 0.0f, FLUSHED);
== f->func.f_fma(0.0f, HTF(hp1[j]), float r10 = f->func.f_fma(-0.0f, HTF(hp1[j]),
0.0f, FLUSHED) 0.0f, FLUSHED);
|| 0.0f float r11 = f->func.f_fma(0.0f, HTF(hp1[j]),
== f->func.f_fma(-0.0f, HTF(hp1[j]), -0.0f, FLUSHED);
0.0f, FLUSHED) float r12 = f->func.f_fma(-0.0f, HTF(hp1[j]),
|| 0.0f -0.0f, FLUSHED);
== f->func.f_fma(0.0f, HTF(hp1[j]),
-0.0f, FLUSHED) cl_half c9 = HFF(r9);
|| 0.0f cl_half c10 = HFF(r10);
== f->func.f_fma(-0.0f, HTF(hp1[j]), cl_half c11 = HFF(r11);
-0.0f, FLUSHED))) cl_half c12 = HFF(r12);
if (0.0f == HTF(test)
&& (IsHalfSubnormal(c9)
|| IsHalfSubnormal(c10)
|| IsHalfSubnormal(c11)
|| IsHalfSubnormal(c12)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
@@ -575,13 +582,14 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err3) < fabsf(err)) err = err3; if (fabsf(err3) < fabsf(err)) err = err3;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r7 = f->func.f_fma(HTF(hp0[j]), 0.0f,
&& (0.0f HTF(hp2[j]), FLUSHED);
== f->func.f_fma(HTF(hp0[j]), 0.0f, float r8 = f->func.f_fma(HTF(hp0[j]), -0.0f,
HTF(hp2[j]), FLUSHED) HTF(hp2[j]), FLUSHED);
|| 0.0f cl_half c7 = HFF(r7);
== f->func.f_fma(HTF(hp0[j]), -0.0f, cl_half c8 = HFF(r8);
HTF(hp2[j]), FLUSHED))) if (0.0f == HTF(test)
&& (IsHalfSubnormal(c7) || IsHalfSubnormal(c8)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
@@ -650,19 +658,24 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err5) < fabsf(err)) err = err5; if (fabsf(err5) < fabsf(err)) err = err5;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r13 = f->func.f_fma(HTF(hp0[j]), 0.0f,
&& (0.0f 0.0f, FLUSHED);
== f->func.f_fma(HTF(hp0[j]), 0.0f, float r14 = f->func.f_fma(HTF(hp0[j]), -0.0f,
0.0f, FLUSHED) 0.0f, FLUSHED);
|| 0.0f float r15 = f->func.f_fma(HTF(hp0[j]), 0.0f,
== f->func.f_fma(HTF(hp0[j]), -0.0f, -0.0f, FLUSHED);
0.0f, FLUSHED) float r16 = f->func.f_fma(HTF(hp0[j]), -0.0f,
|| 0.0f -0.0f, FLUSHED);
== f->func.f_fma(HTF(hp0[j]), 0.0f,
-0.0f, FLUSHED) cl_half c9 = HFF(r13);
|| 0.0f cl_half c10 = HFF(r14);
== f->func.f_fma(HTF(hp0[j]), -0.0f, cl_half c11 = HFF(r15);
-0.0f, FLUSHED))) cl_half c12 = HFF(r16);
if (0.0f == HTF(test)
&& (IsHalfSubnormal(c9)
|| IsHalfSubnormal(c10)
|| IsHalfSubnormal(c11)
|| IsHalfSubnormal(c12)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;
@@ -707,15 +720,15 @@ int TestFunc_Half_Half_Half_Half(const Func *f, MTdata d, bool relaxedMode)
if (fabsf(err3) < fabsf(err)) err = err3; if (fabsf(err3) < fabsf(err)) err = err3;
// retry per section 6.5.3.4 // retry per section 6.5.3.4
if (0.0f == test float r17 = f->func.f_fma(HTF(hp0[j]), HTF(hp1[j]),
&& (0.0f 0.0f, FLUSHED);
== f->func.f_fma(HTF(hp0[j]), float r18 = f->func.f_fma(HTF(hp0[j]), HTF(hp1[j]),
HTF(hp1[j]), 0.0f, -0.0f, FLUSHED);
FLUSHED) cl_half c13 = HFF(r17);
|| 0.0f cl_half c14 = HFF(r18);
== f->func.f_fma(HTF(hp0[j]), if (0.0f == HTF(test)
HTF(hp1[j]), -0.0f, && (IsHalfSubnormal(c13)
FLUSHED))) || IsHalfSubnormal(c14)))
{ {
fail = 0; fail = 0;
err = 0.0f; err = 0.0f;