Host pre-processor definitions are not passed to OptiX/CUDA kernels

Greetings, I have encountered a problem which might be more related to “CUDA Programming and Performance” forum, but the only entry ( 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:

int mytestmacro=19421;

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

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.

This is very weird. I have a little testing program I use for various things and I added this line to the CUDA module :

#ifdef _MBCS
#pragma message( "MBCS is defined in " __FILE__ )

The “Use Host Preprocessor Definitions” option was set to yes. The macro _MBCS is defined in the host code properties but not in the Host section of the properties. The weird thing is this message appears when compiling the CUDA code so it appears that option is at least partially working.

try to enter

--define-macro TEST_MACRO

in the “Additional options” field of the CommandLine property of the CUDA/C++ properties
this at least works for me for PTX files (on VS 2019 Community v16.2.3; OptiX 6.5.0 SDK CUDA 10.1.243 driver 436.48 Win10PRO 64bit v1809)



in that section also works on my system