Skip to content

bfloat16 does not flush denormals (subnormal floats) to zero #36514

@N-Dekker

Description

@N-Dekker

BFloat16: The secret to high performance on Cloud TPUs, Shibo Wang, Pankaj Kanwar (@pkanwar23 right?) , August 23, 2019, says:

bfloat16 handles denormals differently from FP32: it flushes them to zero

I assume this implies that for a denormal 32-bit floating point, denorm, the expression float{bfloat16{denorm}} should be equal to zero.

The current implementation of tensorflow::bfloat16 (master branch, revision bc28d49) appears to behave differently. As can be observed by the following test:

for (float denorm = std::numeric_limits<float>::denorm_min();
  denorm < std::numeric_limits<float>::min();
  denorm = std::nextafterf(denorm, 1.0f))
    ASSERT_EQ(float{ tensorflow::bfloat16{denorm} }, 0.0f);

This assertion fails on the current implementation, from tensorflow/core/lib/bfloat16

Is that indeed a bug in tensorflow::bfloat16?

Metadata

Metadata

Labels

comp:coreissues related to core part of tensorflowstat:awaiting responseStatus - Awaiting response from authortype:bugBug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions