use crate::dtype::DType;
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct BinaryParams {
pub(crate) numel: u32,
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct BroadcastBinaryParams {
pub(crate) numel: u32,
pub(crate) ndim: u32,
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct UnaryParams {
pub(crate) numel: u32,
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct ScalarParams {
pub(crate) numel: u32,
pub(crate) scalar_bits: u32,
}
impl ScalarParams {
pub(crate) fn new(numel: u32, scalar: f64, dtype: DType) -> Self {
let scalar_bits = match dtype {
DType::I32 => (scalar as i32).to_ne_bytes(),
DType::U32 => (scalar as u32).to_ne_bytes(),
_ => (scalar as f32).to_ne_bytes(),
};
Self {
numel,
scalar_bits: u32::from_ne_bytes(scalar_bits),
}
}
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct ClampParams {
pub(crate) numel: u32,
pub(crate) min_bits: u32,
pub(crate) max_bits: u32,
pub(crate) _pad0: u32,
}
impl ClampParams {
pub(crate) fn new(numel: u32, min_val: f64, max_val: f64, dtype: DType) -> Self {
let encode = |v: f64| -> u32 {
match dtype {
DType::I32 => u32::from_ne_bytes((v as i32).to_ne_bytes()),
DType::U32 => v as u32,
_ => u32::from_ne_bytes((v as f32).to_ne_bytes()),
}
};
Self {
numel,
min_bits: encode(min_val),
max_bits: encode(max_val),
_pad0: 0,
}
}
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct WhereParams {
pub(crate) numel: u32,
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct WhereBroadcastParams {
pub(crate) numel: u32,
pub(crate) ndim: u32,
pub(crate) _pad0: u32,
pub(crate) _pad1: u32,
}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct CastParams {
pub(crate) numel: u32,
}