Switch default f8 conversion to stochastic rounding (#1048)

* Switch default f8 conversion to stochastic rounding

* Refactor f8-related type_converts

* Add an element-wise op
This commit is contained in:
Rostyslav Geyyer
2023-11-27 20:06:17 -06:00
committed by GitHub
parent 60ecfd73f9
commit 6ef034f6ca
3 changed files with 307 additions and 238 deletions

View File

@@ -281,6 +281,24 @@ struct ConvertF8SR
}
};
struct ConvertF8RNE
{
// convert to fp8 using rounding to nearest even
template <typename Y, typename X>
__host__ __device__ void operator()(Y& y, const X& x) const
{
// check Y datatype
static_assert(is_same<Y, f8_t>::value || is_same<Y, bf8_t>::value,
"Data type is not supported by this operation!");
// check X datatype
static_assert(is_same<X, float>::value || is_same<X, half_t>::value,
"Data type is not supported by this operation!");
y = f8_convert_rne<Y>(x);
}
};
struct Scale
{
__host__ __device__ Scale(float scale) : scale_(scale) {}