access constant memory

Hi,

I understand that access constant memory(as a cache) is faster than access global memory.

But the kernel code I programmed is the same speed when I placed the array in constant or global memory , and two cases as shown :

constant memory
kernel test(constant int * a){

int n = rand (); // rand() function is used to generate a integer number and n is not the same for each workitem
int tmp = a[n];

}


global memory
kernel test(global int * a){

int n = rand (); // rand() function is used to generate a integer number and n is not the same for each workitem
int tmp = a[n];

}


Therefore , each workitem might not access the same address of array a.
These cases result in same speed (kernel time)
In nvidia guide , if access constant memory address is not the same address , it will be access sequentially.

In this code pattern , is it not different between these two cases ?

Thanks

The two code patterns are identical. In both cases a is a pointer passed by value. Global parameters are passed via constant bank. In the first case ‘a’ is a pointer to constant data that is stored in global virtual address range. In the second case ‘a’ is a pointer to mutable data.

Constant cache has lower latency than texture cache. Texture cache has higher throughput than constant cache.