global constant floats shared in device code with Visual Studio

I have this exact issue posed on Stack Overflow [url]Host float constant usage in a kernel in CUDA - Stack Overflow 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 [url]https://devtalk.nvidia.com/default/topic/413405[/url] 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:

[url]c++ - CUDA __host__ __device__ variables - Stack Overflow

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

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.