The half-float [1] type would interoperate with standard 32-bit and 64-bit
floats. Also, to avoid redundant conversions the arithmetic operators should
yield a float32_t result. This behavior is consistent with the use of
half-floats as a compressed storage format.
This enhancement would likely depend on issue #216.
class float16_t
{
unsigned short s;
public:
// constructors
__host__ __device__
float16_t()
: s(float32_t()) {}
__host__ __device__
float16_t(const float32_t& f)
: s(__float2half_rn(f)) {}
// arithmetic
__host__ __device__
float32_t operator+(const float16_t& f) const
{
// note: return a float
return static_cast<float32_t>(*this) + static_cast<float32_t>(f);
}
// cast to float
__host__ __device__
operator float32_t(void) const
{
return __half2float(s);
}
};
[1] http://en.wikipedia.org/wiki/Half_precision_floating-point_format
Original issue reported on code.google.com by wnbell on 27 Oct 2010 at 3:03
Original issue reported on code.google.com by
wnbell
on 27 Oct 2010 at 3:03