Hit rate is not as expected for a simple kernel

mossaied2
Tue, 07 Oct 2025 21:02:01 +0000
CUDA-GDB

Hello all;

I have a simple kernel (I am sharing below) which consists of 1 warp and 1 block and also 1 thread. I coded that kernel just to study l1 cache hit rate that is why I wanted it to be very simple.
I have a vector of 16 integer elements that I pass to the gpu kernel where the kernel will multiply the value of each element by 2. Initially any element at index i is equal to i (A[i]=i), e.g. A[0]=0, A[1]=1, … A[15]=15, therefore the return of the kernel would be: A[0]=0, A[1]=2, … A[15]=30.
When I profile the kernel with ncu I was expecting the hit rate to be 96.875% this is because the cache line is 128B and the vector size needs only 16*4B=64B so it is will contained in the cache line. Based on that there will be one miss to read A[0] but then writing to A[0] will be hit and also the rest of reads and writes should be hits since we brought all elements in the cache line when the first miss took place. So in total based on that the hit rate should be 31/32=96.875%. However when I profile the kernel with ncu the hit rate was only 93.75%
Can someone explains this behavior, why the hit rate is 93.75% and not 96.875%? Does the associativity plays any role here?

Kernel

__global__ void vectorScaling(int* A, size_t n)
{
// Total number of blocks
size_t numBlocks = gridDim.x; // it is 1
// Elements per block (handle cases where n isn’t divisible by numBlocks)
size_t elementsPerBlock = (n + numBlocks - 1) / numBlocks; // it is 16

// Compute this block's start and end indices
size_t start = blockIdx.x * elementsPerBlock; // it is 0
size_t end   = min(start + elementsPerBlock, n); // it is 16


// Each thread processes part of its block's segment
for (size_t i = start + threadIdx.x; i < end; i += blockDim.x) { //i=0; i<16; i++
    A[i] = 2 * A[i];
}
}

Here is the command line output:
ncu --metrics l1tex__t_sector_hit_rate.pct ./vectorScaling_THREADS_SIZE_cmd_INTEGERS.exe 1 16
Vector length =, 16
Number of threads =, 1
Number of blocks =, 1
Block * threads =, 1
==PROF== Connected to process 18921 (/mnt/d/Dropbox/GPUcourse/projects/vectorScaling_THREADS_SIZE_cmd_INTEGERS.exe)
sizeof(int) =, 4
A[0] = 0, A[15] = 15
==PROF== Profiling “vectorScaling” - 0: 0%…50%…100% - 1 pass
Execution time:, 1460.263428, milliseconds
A[0] = 0
A[8] = 16
A[15] = 30
==PROF== Disconnected from process 18921
[18921] vectorScaling_THREADS_SIZE_cmd_INTEGERS.exe@127.0.0.1
vectorScaling(int *, unsigned long) (1, 1, 1)x(1, 1, 1), Context 1, Stream 7, Device 0, CC 7.5
Section: Command line profiler metrics

Metric Name Metric Unit Metric Value

l1tex__t_sector_hit_rate.pct % 93.75

4 posts - 3 participants