How to use 16 bit floating point (half) data in both .C and .CU files?

Hi. I am working on the project including both .C and .CU files. I want to use “half” data in the calculation and the data is operated in both .C and .CU file. But I found that “half” is only avaiable in .CU file and “__fp16” is in .C file on aarch64. I knew there is some library that defines half data type alone. However is there any better solution to solve this issue to make “half” visiable in both .C and .CU? Or any method to make “__fp16” visiable in .CU file that is also fine?
Thanks so much for help!!

I suppose what you mean is to use half floats in both CPU code (.c files) and CUDA kernels (.cu files). Note that the bit layout of ‘half’ operands on the GPU is identical to the 16-bit floating-point format specified by IEEE-754:2008. We use on the CPU side the half_float library (http://half.sourceforge.net/). It is conformant to the same IEEE 754 specification, so one can (if desired) create a half float buffer on the CPU(GPU) and copy it to GPU(CPU). Alternatively the OpenEXR library provides also a class ‘half’.

See also https://devtalk.nvidia.com/default/topic/883897/error-when-trying-to-use-half-fp16-/ and https://devtalk.nvidia.com/default/topic/547080/-half-datatype-ieee-754-conformance/

HannesF99, Thanks for your quick and useful response! I’ll try “half_float library” in my project.