From 6b94872a003eee8ae440e67a8b98a4ac4c694699 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 15 Sep 2025 10:44:57 -0300 Subject: [PATCH] fix(gpu): add an assert to be sure the carry part has correct size in expand --- .../tfhe-cuda-backend/cuda/include/zk/zk_utilities.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backends/tfhe-cuda-backend/cuda/include/zk/zk_utilities.h b/backends/tfhe-cuda-backend/cuda/include/zk/zk_utilities.h index 4541eb02d..4346e4da2 100644 --- a/backends/tfhe-cuda-backend/cuda/include/zk/zk_utilities.h +++ b/backends/tfhe-cuda-backend/cuda/include/zk/zk_utilities.h @@ -209,9 +209,12 @@ template struct zk_expand_mem { params.carry_modulus, carry_extract_and_sanitize_bool_lut_f, gpu_memory_allocated); - // Hint for future readers: if message_modulus == 4 then - // packed_messages_per_lwe becomes 2 - auto num_packed_msgs = log2_int(params.message_modulus); + // We are always packing two LWEs. We just need to be sure we have enough + // space in the carry part to store a message of the same size as is in the + // message part. + if (params.carry_modulus < params.message_modulus) + PANIC("Carry modulus must be at least as large as message modulus"); + auto num_packed_msgs = 2; // Adjust indexes to permute the output and access the correct LUT auto h_indexes_in = static_cast(