I am trying to use GNU decimal floats with NVCC and I get the following error:
/usr/include/c++/4.8/decimal/decimal(230): error: invalid argument to attribute "mode"
The affected line is the following:
typedef float __decfloat32 __attribute__((mode(SD)));
I assume that NVCC does not support SD as an argument for mode. Is there any workaround or it is just not possible with NVCC? The code works well when compiling for CPU.
How/where is this SD defined?
Thanks!
Update: I could find where SD is defined for GCC. Two great answers here:
What does GCC __attribute__((mode(XX)) actually do?
For GCC: gcc/gcc/machmode.def
/* Decimal floating point modes. */
DECIMAL_FLOAT_MODE (SD, 4, decimal_single_format);
DECIMAL_FLOAT_MODE (DD, 8, decimal_double_format);
DECIMAL_FLOAT_MODE (TD, 16, decimal_quad_format);
Isolating the host code in a *.cpp file works ok. Once the code goes into a *.cu, NVCC is used and it doesn't compile anymore. I can keep device/host code apart but I was investigating how the GCC decimal library works internally in combination with NVCC.
Where can I find more information about NVCC connected to this?
The problem is that this line defines __decfloat32
as float __attribute__ mode((SD))
. All these underscores indicate that you're using compiler-specific names. This is indeed the case: __decfloat32
is a GCC extension. This is useful primarily when GCC runs on an AIX system with decimal floating point hardware.
NVCC obviously doesn't target AIX. Even if they would implement the same __attribute__((mode))
as GCC did, they'd still restrict it to SF
and DF
. Even TF
(128 bits) will be missing as that's not supported by NVidia. They're definitely not going to spent a few months implementing decimal floats, so mode(SD)
won't be implemented either.
Still, I'm 99% sure that this is an XY problem. Decimal and binary floating point are both finite-precision approximations, and a 64 bit binary FP number is much more precise and much faster than a 32 bits decimal FP.