Failure of NVCC to recognize memory type

It seems that I’m facing a problem where NVCC fails to recognize which type of memory to bind to the variable: either constant or global.

The code below:

int* memPtr;
if (X==0){


works fine in EMU mode and crashes on a real hardware. When I comment either of the “if” statements it works OK.
I realize that it’s impossible to perform this binding in compile time, but what I vote for is to add error message if such problem is detected.

Well, if it only crashes if (X==0) then the emu actually is wrong as you are not allowed to write to const mem.


Sorry, my mistake. I intended the last expression to be:

int k=memPtr[0];

Well, I bumped into the same problem again, and now it’s b/w global and shared memory. Really painful… Maybe someone from NVIDIA can comment:

Here’s the code snippet :

shared int* ptr;

shared int sh_data[2];

global int g_data[2];

if (condition){





int x=ptr[0];

This kernel fails to launch ( unspecified launch failure), while when I comment one of the “if” branches out - it works fine.

Any hope for this to be solved some day?

My own guess is that accesses to different memory types require two different HW ops to be issued, and thus must be resolved at compile time. So unless there’ll be HW support for runtime pointer resolution - no hope for this to work…

Just look in the ptx and you will see different instructions: ld.local,, ld.shared, etc… This is indeed the case.

Anyways, didn’t you see section in the programming guide?

"Pointers in code that is executed on the device are supported as long as the compiler

is able to resolve whether they point to either the shared memory space or the

global memory space, otherwise they are restricted to only point to memory

allocated or declared in the global memory space. "