diff --git a/candle-core/src/ggml.rs b/candle-core/src/ggml.rs index f6418942..3a0aa5a1 100644 --- a/candle-core/src/ggml.rs +++ b/candle-core/src/ggml.rs @@ -20,8 +20,7 @@ struct BlockQ4_0 { d: f16, qs: [u8; QK4_0 / 2], } -// Hacky static_assert -const _: [u8; 18] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 18); #[repr(C)] struct BlockQ4_1 { @@ -29,7 +28,7 @@ struct BlockQ4_1 { m: f16, qs: [u8; QK4_1 / 2], } -const _: [u8; 20] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 20); #[repr(C)] struct BlockQ5_0 { @@ -37,7 +36,7 @@ struct BlockQ5_0 { qh: [u8; 4], qs: [u8; QK5_0 / 2], } -const _: [u8; 22] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 22); #[repr(C)] struct BlockQ5_1 { @@ -46,14 +45,14 @@ struct BlockQ5_1 { qh: [u8; 4], qs: [u8; QK5_1 / 2], } -const _: [u8; 24] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 24); #[repr(C)] struct BlockQ8_0 { d: f16, qs: [u8; QK8_0], } -const _: [u8; 34] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 34); #[repr(C)] struct BlockQ8_1 { @@ -61,7 +60,7 @@ struct BlockQ8_1 { s: f16, qs: [u8; QK8_1], } -const _: [u8; 36] = [0; std::mem::size_of::()]; +const _: () = assert!(std::mem::size_of::() == 36); #[repr(C)] struct BlockQ2K { @@ -70,7 +69,7 @@ struct BlockQ2K { d: f16, dmin: f16, } -const _: [u8; QK_K / 16 + QK_K / 4 + 2 * 2] = [0; std::mem::size_of::()]; +const _: () = assert!(QK_K / 16 + QK_K / 4 + 2 * 2 == std::mem::size_of::()); #[repr(C)] struct BlockQ3K { @@ -79,7 +78,7 @@ struct BlockQ3K { scales: [u8; 12], d: f16, } -const _: [u8; QK_K / 8 + QK_K / 4 + 12 + 2] = [0; std::mem::size_of::()]; +const _: () = assert!(QK_K / 8 + QK_K / 4 + 12 + 2 == std::mem::size_of::()); // https://github.com/ggerganov/llama.cpp/blob/468ea24fb4633a0d681f7ac84089566c1c6190cb/k_quants.h#L82 #[repr(C)] @@ -89,7 +88,7 @@ struct BlockQ4K { scales: [u8; K_SCALE_SIZE], qs: [u8; QK_K / 2], } -const _: [u8; QK_K / 2 + K_SCALE_SIZE + 2 * 2] = [0; std::mem::size_of::()]; +const _: () = assert!(QK_K / 2 + K_SCALE_SIZE + 2 * 2 == std::mem::size_of::()); #[repr(C)] struct BlockQ5K { @@ -99,7 +98,8 @@ struct BlockQ5K { qh: [u8; QK_K / 8], qs: [u8; QK_K / 2], } -const _: [u8; QK_K / 8 + QK_K / 2 + 2 * 2 + K_SCALE_SIZE] = [0; std::mem::size_of::()]; +const _: () = + assert!(QK_K / 8 + QK_K / 2 + 2 * 2 + K_SCALE_SIZE == std::mem::size_of::()); #[repr(C)] struct BlockQ6K { @@ -108,7 +108,7 @@ struct BlockQ6K { scales: [i8; QK_K / 16], d: f16, } -const _: [u8; 3 * QK_K / 4 + QK_K / 16 + 2] = [0; std::mem::size_of::()]; +const _: () = assert!(3 * QK_K / 4 + QK_K / 16 + 2 == std::mem::size_of::()); // https://github.com/ggerganov/llama.cpp/blob/8183159cf3def112f6d1fe94815fce70e1bffa12/k_quants.c#L354 fn dequantize_row_q2k(xs: &[BlockQ2K], ys: &mut [f32]) -> Result<()> {