Add the `const` qualifier to variables that are not modified after initialization. This improves code clarity, prevents accidental modifications, and makes the code's intent more explicit to both compilers and other developers.
Add the const
qualifier to variables that are not modified after initialization. This improves code clarity, prevents accidental modifications, and makes the code’s intent more explicit to both compilers and other developers.
Apply const
to:
Example transformations:
// Before
float2 dsB;
dsB = __half22float2(y_dm[j*MMQ_TILE_Y_K + k01/QI8_1]);
int global_idx = blockIdx.x * blockDim.x + threadIdx.x;
int total_elements = batches * channels * out_h * out_w;
// After
const float2 dsB = __half22float2(y_dm[j*MMQ_TILE_Y_K + k01/QI8_1]);
const int global_idx = blockIdx.x * blockDim.x + threadIdx.x;
const int total_elements = batches * channels * out_h * out_w;
This practice is especially important in CUDA kernels and performance-critical code where clarity about data mutability helps with optimization and debugging.
Enter the URL of a public GitHub repository