e8m0_utils.hpp 571 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
// SPDX-License-Identifier: MIT
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.

#pragma once

#include "ck/utility/data_type.hpp"
#include "ck/utility/mxfp_utils.hpp"

namespace ck::utils {

11
12
13
14
15
16
17
18
19
20
__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);
}

21
} // namespace ck::utils