Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

Using float16 and bfloat16

ddavobsc
Beginner
847 Views

Is it possible to use the float16 or bfloat16 data types with icx compiler?

I am getting the error:

<source>:7:6: error: no type named 'float16_t' in namespace 'std'
    7 | std::float16_t check_float16_conversion(std::float16_t a, std::float16_t b) {
      | ~~~~~^
<source>:7:46: error: no type named 'float16_t' in namespace 'std'
    7 | std::float16_t check_float16_conversion(std::float16_t a, std::float16_t b) {
      |                                         ~~~~~^
<source>:7:64: error: no type named 'float16_t' in namespace 'std'
    7 | std::float16_t check_float16_conversion(std::float16_t a, std::float16_t b) {
      |                                                           ~~~~~^
3 errors generated.

While trying to compile with icx 2025.2.1 -std=c++23

 

I guess it is not supported yet, but then, how can I use float16 or bfloat16?

0 Kudos
3 Replies
hpkfft
Beginner
426 Views

You can use

_Float16

 for IEEE binary16 (half precision).

0 Kudos
yzh_intel
Moderator
402 Views

Hi, bfloat16 type is supported in SYCL extension, https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/supported/sycl_ext_oneapi_bfloat16.asciidoc

There's a simple example you can play with. The data type requires hardware support, otherwise it'll be emulated as float operations. 

 

0 Kudos
hpkfft
Beginner
5 Views

You can use

__bf16

for bfloat16.  As noted in the post above, the data type requires hardware support, otherwise it'll be emulated as single-precision float operations.  The following generates code which does the addition in single-precision then converts the result to bfloat16:

$ cat test.cpp 
__bf16 add(__bf16 x, __bf16 y) {
return x + y;
}

$ icpx -c -mavxneconvert test.cpp

$ nm -C test.o
0000000000000000 T add(std::bfloat16_t, std::bfloat16_t)

 

Future Intel CPUs will support AVX10.2, which includes bfloat16 arithmetic instructions (add, sub, mul, FMA, div, sqrt, ...).

0 Kudos
Reply