`FP8 numbers <https://arxiv.org/pdf/2209.05433>`_ were introduced to accelerate deep learning inferencing. They provide higher throughput of matrix operations because the smaller size allows more of them in the available fixed memory.
HIP has two FP8 number representations called *FP8-OCP* and *FP8-FNUZ*.
Open Compute Project(OCP) number definition can be found `here <https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-12-01-pdf-1>`_.
Definition of FNUZ: fnuz suffix means only finite and NaN values are supported. Unlike other types, Inf are not supported.
NaN is when sign bit is set and all other exponent and mantissa bits are 0. All other values are finite.
This provides one extra value of exponent and adds to the range of supported FP8 numbers.
FP8 Definition
==============
FP8 numbers are composed of a sign, an exponent and a mantissa. Their sizes are dependent on the format.
There are two formats of FP8 numbers, E4M3 and E5M2.
- E4M3: 1 bit sign, 4 bit exponent, 3 bit mantissa
- E5M2: 1 bit sign, 5 bit exponent, 2 bit mantissa
HIP Header
==========
HIP header defined the FP8 ocp/fnuz numbers `here <https://github.com/ROCm/clr/blob/develop/hipamd/include/hip/amd_detail/amd_hip_fp8.h>`_.
Supported Devices
=================
..list-table:: Supported devices for fp8 numbers
:header-rows:1
* - Device Type
- FNUZ FP8
- OCP FP8
* - Host
- Yes
- Yes
* - gfx940/gfx941/gfx942
- Yes
- No
* - gfx1200/gfx1201
- No
- Yes
Usage
=====
To use the FP8 numbers inside HIP programs.
..code-block::c
#include<hip/hip_fp8.h>
FP8 numbers can be used on CPU side:
..code-block::c
__hip_fp8_storage_tconvert_float_to_fp8(
floatin,/* Input val */
__hip_fp8_interpretation_tinterpret,/* interpretation of number E4M3/E5M2 */