<cuda/std/complex>#
2026-10-07
1 min read time
This page documents the cuda::std::complex support in libhipcxx, including the omission of complex literals and extensions for infinity handling and half and bfloat16 types.
Omissions#
When a translation unit is compiled with hipcc, complex does not provide the complex literals i, if, and
il. Their suffixes do not start with an underscore, a form that is reserved for the standard library. The literals
are available when a translation unit is compiled directly with the host compiler.
complex<long double> is available, but long double is demoted to double in device code. The type therefore
has a different size in host and device code and must not be shared between them.
Extensions#
Handling of infinities
Our implementation by default recovers infinite values during multiplication and division. The recovery only runs when the unrecovered result is
NaNin both components, but it enlarges the generated code considerably, so we allow disabling that canonicalization if it is not desired.Definition of
LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONSdisables canonicalization for both multiplication and division.Definition of
LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_MULTIPLICATIONorLIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_DIVISIONdisables canonicalization for multiplication or division individually.Support for half and bfloat16
Our implementation includes support for the
__halftype from<hip/hip_fp16.h>and the__hip_bfloat16type from<hip/hip_bf16.h>. Both are available when the translation unit is compiled with hipcc, including host-only translation units. They are not available when a translation unit is compiled directly with the host compiler.C++20 constexpr
<complex>is available in C++17.