global constant floats shared in device code with Visual Studio

I have this exact issue posed on Stack Overflow http://stackoverflow.com/questions/11564081/why-i-cant-use-global-float-constants-in-device-code but this was never answered. I figured it would be more appropriate to ask here.

Essentially I have a header with global float constants I want to share between host and device code. Seems pretty straight forward thing to want to do. However, on Windows (VC11) only, I get ‘identifier “X” is undefined in device code’.

There is a similar question posed here https://devtalk.nvidia.com/default/topic/413405 which I sort of understand that says the issue is that I’m declaring memory in the host and the gpu which isn’t allowed.

So does this just happen to work on gcc (linux) and clang (OS X) because somehow the host compiler is doing things differently there?

  • James

It’s a documented limitation of attempting to use this with the visual studio host compiler:

http://stackoverflow.com/questions/33218522/cuda-host-device-variables

http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#const-variables

You’ll need to find another approach to using a global float (or double) constant this way (on windows)

Yes, somehow the host compiler matters.