#[cutile::module]
mod kernels {
use cutile::core::*;
#[cutile::entry()]
pub fn quantize_f16_u8<const B: i32>(
out: &mut Tensor<u8, { [B] }>,
input: &Tensor<f16, { [-1] }>,
scale: f16,
zero_point: f16,
) {
let values: Tile<f16, { [B] }> = load_tile_like(input, out);
let raw = values / broadcast_scalar(scale, out.shape())
+ broadcast_scalar(zero_point, out.shape());
let low = constant(f16::from_f32(0.0), out.shape());
let high = constant(f16::from_f32(255.0), out.shape());
out.store(ftoi(
min_tile(max_tile(raw, low), high),
rounding::NearestEven,
));
}
#[cutile::entry()]
pub fn quantize_f16_i8<const B: i32>(
out: &mut Tensor<i8, { [B] }>,
input: &Tensor<f16, { [-1] }>,
scale: f16,
zero_point: f16,
) {
let values: Tile<f16, { [B] }> = load_tile_like(input, out);
let raw = values / broadcast_scalar(scale, out.shape())
+ broadcast_scalar(zero_point, out.shape());
let low = constant(f16::from_f32(-128.0), out.shape());
let high = constant(f16::from_f32(127.0), out.shape());
out.store(ftoi(
min_tile(max_tile(raw, low), high),
rounding::NearestEven,
));
}
}
pub use crate::cuda::cutile::kernel::f16::utility::dequantize_i8_f16;
pub use crate::cuda::cutile::kernel::f16::utility::dequantize_u8_f16;
pub use kernels::*;