RFC: add support for querying whether an array library/device supports subnormal numbers #765
Labels
API extension
Adds new functions or objects to the API.
Needs Discussion
Needs further discussion.
RFC
Request for comments. Feature requests and proposed changes.
topic: Inspection
Array API inspection.
Overview
The handling of subnormal numbers has come up a few times since the beginning of the Consortium:
hypot
specification for computing the square root of the sum of squares #703and is more generally specified as part of IEEE 754, the standard for floating-point numbers.
In short, support for subnormal numbers is likely to vary across conforming array libraries due to hardware constraints and/or configuration. For example, some devices support flushing subnormal numbers to zero for increased performance or for improving security by thwarting timing attacks.
Given this variability, array library consumers don't have a standardized mechanism for determining whether a library and/or device supports subnormal numbers. Knowing whether a library has subnormal support can be beneficial for those libraries concerned about accuracy in the computation of transcendental functions and other domains.
Proposal
This RFC proposes to add support to the inspection API for querying whether an array library/device supports subnormal numbers. Specifically, this RFC proposes updating
info.capabilities
to support an optionaldevice
argument (similar toinfo.default_dtypes
):Currently, the
info.capabilities
API is a nullary function returning a fixed object. This RFC proposes allowing that to remain the default behavior, while extending it to support device-specific capabilities.This RFC proposes adding the following field to the dictionary returned by
info.capabilities()
:{ ... "max rank": Optional[int], + "subnormals": bool }
When
device
isNone
, the value assigned tosubnormals
should correspond to the default device. When adevice
is specified, the value should indicate whether subnormals are supported on that particular device.With this API in place, downstream libraries could query whether a conforming array library and a particular device support subnormal numbers.
Questions
In Improve subnormal expectations #339 (comment), another proposal was adding a field to
finfo
along the lines ofis_subnormal_zero
to handle the case wheresmallest_normal
andsmallest_subnormal
are equal. Are the changes in this RFC a better alternative?Another way for array consuming libraries to check for subnormal support is to perform a calculation which should return a subnormal number (e.g.,
2.25e-308/100.0 > 0.0
). If the result is greater than zero, you have your answer. While not elegant, certainly doable, and array consuming libraries can always write a small helper function to query whenever creating arrays assigned to particular devices. Would the ability to use a dedicated inspection API as proposed in this RFC be more desirable?The text was updated successfully, but these errors were encountered: