Commit 0bb6e25f authored by Rostyslav Geyyer's avatar Rostyslav Geyyer
Browse files

Add scale <-> float conversions

parent 4c47048f
......@@ -8,4 +8,14 @@
namespace ck::utils {
__host__ __device__ inline float cast_to_float(e8m0_scale_t const scale)
{
return std::pow(2, bit_cast<uint8_t>(scale) - NumericUtils<e8m0_scale_t>::bias);
}
__host__ __device__ inline e8m0_scale_t cast_from_float(float const scale)
{
return static_cast<uint8_t>(std::log2(scale) + NumericUtils<e8m0_scale_t>::bias);
}
} // namespace ck::utils
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment