Greetings, I have encountered a problem which might be more related to “CUDA Programming and Performance” forum, but the only entry (https://devtalk.nvidia.com/default/topic/1031566/cuda-9-1-how-to-properly-pass-preprocessor-definitions-in-visual-studio-/#) I found there unfortunately does not have an answer and over a year and half older. So I figured I’d post the question here and cross-reference it in that relevant topic later on.
As the title suggests, host pre-processor definitions are not recognized by the device code.
The setup: Visual Studio 2017, GeForce RTX 2060, CUDA 10.1.243, OptiX 6.0.0, 436.30.
We have a Visual Studio project created via CUDA 10.1 Runtime template (File -> New -> Project -> NVIDIA -> CUDA 10.1 Runtime). We then specify certain preprocessor definitions (let’s assume ‘TEST_MACRO’) via 'Project properties -> Configuration Properties -> C/C++ -> Preprocessor -> type in ‘TEST_MACRO’). The macro is obviously recognized by the host code. Furthermore, in ‘CUDA C/C++ -> Host’ section of the project properties we make sure that ‘Use Host Preprocessor Definitions’ is set to ‘Yes’.
To test my claim, let’s present the following snippet in the device code, for instance, in a ray-gen program:
#ifdef TEST_MACRO int mytestmacro=19421; #endif
Compiling the OptiX kernel and examining the generated *.ptx file reveals that ‘mytestmacro’ (I simply searched by the assigned value, as the name of the registers is incomprehensible to me) is nowhere to be found. Removing the conditional macros and compiling that again results in the assigned value (19421) appearing in the *.ptx file, even though both versions should have produced the same output.
Another simple test was to simply call the ‘#error’ directive which generated a compile error, which means that TEST_MACRO is really not defined:
#ifndef TEST_MACRO #error #endif
What would be the correct way of passing host pre-processor definitions, specifically defined in the project properties, down to the device code?
I assume we can otherwise come up with a different way of passing the definitions, but it would be great to find out what might have been done wrong here on our side, just so we don’t have a gap in understanding certain fundamentals.