Optix 7.0.0 cmake error

Please help,

I have been trying to build my first non-trivial optix 7.0.0 code using cmake version 3.14.5, CUDA version release 9.0, V9.0.176 and everything is going well until I try and put the following include file (from OptiX 7.0.0 SDK - stored in our server at /software/optix700/):
#include <cuda/LocalGeometry.h>

The following is output I get when trying to build:

/software/optix700/SDK/cuda/LocalGeometry.h(62): error #2822: calling a device function(“optixGetPrimitiveIndex”) from a host device function(“getLocalGeometry”) is not allowed

Anyone have any ideas?


The title of this thread is misleading. You have a host compiler error and it’s very clear about what the problem is.

You mean you included OptiX SDK 7.0.0\SDK\cuda\LocalGeometry.h into what source code part of your program and why?

That header is not supposed to be included inside host code but only inside OptiX device code in *.cu files.
(I’m not sure why the function in LocalGeometry.h are declared with SUTIL_HOSTDEVICE. These cannot work on the host.)

The function in there is calling optixGetPrimitiveIndex() and other OptiX 7 device functions declared in OptiX SDK 7.0.0\include\optix_7_device.h and defined in OptiX SDK 7.0.0\include\internal\optix_7_device_impl.h.

You cannot include the optix_7_device.h header directly but use the top-level optix.h header which does this:

#ifdef __CUDACC__
#include "optix_device.h"
#include "optix_host.h"

As such none of the OptiX 7 device functions exist when compiling host code, but only when compiling with one of the CUDA compilers (NVCC or NVRTC).

Note that LocalGeometry.h contains optix.h as first include.

Thank you for the reply. Sorry about the misleading thread title.

As to why I am doing this, I am just trying to learn OptiX 7.0.0 and wanted to create some example code that goes beyond just initializing Optix (which I have already done) and did not use any kind of graphics output to screen just maybe writing out a ppm file as I am running the code on a headless machine.

Incidentally, I have tried putting the included file in a *.cu file with the same result.

All that said, I am not particularly tied this code. If there exists another OptiX 7.0.0 code that is beyond initialization and does not render a GUI window I would gladly use it. Like I said, I am trying to learn OptiX 7.0.0 at this point.

Thank you again.

Incidentally, I have tried putting the included file in a *.cu file with the same result.

Ok, then you’re not compiling the *.cu file as device code to *.ptx source correctly.
That could actually be a problem inside the your CMake script which might not generate the right custom build rule.

LocalGeometry.h is included in the two examples optixWhitted and optixRaycasting and these should work.
The latter should even work on your headless machine. See below.

The easiest method to change an existing OptiX SDK example would be to copy the whole folder of an example you’re interested in, then rename that folder, then change the top-level CMakeLists.txt to contain add_subdirectory(your_new_example_name).
Then change the copied CMakeLists.txt inside your new folder to have a different project name with
OPTIX_add_sample_executable(your_new_example_name <list_of_src_files>)

Configure and Generate the solution with CMake.
Open the solution, (maybe unload all projects except your new one), rebuild the solution, check if the new example builds without errors.
If that worked, you have effectively duplicated a working OptiX SDK example under a different name.
Start to change it at will.

The optixRaycasting example works offscreen only and just writes a *.ppm image. (But that example is rather untypical for OptiX usage, because it only does ray-triangle intersection testing with OptiX and everything else (ray generation, shading) with native CUDA kernels.)
Anyway, the main() function in there contains no sign of any GUI. You can see there what of the GLFW code needs to be removed to make your newly copied example work offscreen only.

If you want to see how to program OptiX examples without using anything from the SDK but the OptiX API headers, check out my more advanced examples.
I’m also using a different, easier to change script for the custom build rules of the OptiX device code *.cu to *.ptx source translation: nvcuda_compile_ptx.cmake
Find how that is called in each of my examples’ CMakeLists.txt.

Same story to build a new example: Copy an example folder, rename it, add_subdirectory() in the CMakeLists.txt one level higher (in folder “apps”), rename all occurrences of the old example name to your new example name.
Important: Do that replacement in all *.txt and *.cpp files and with partial match. The generated *.ptx files get placed in a relative folder with <app_name>_core name which is defined inside the CMakeLists.txt and used inside the *.cpp files to load the *.ptx files

The more advanced examples rtigo3 and nvlink_shared have their rendering resolution independent of the window client area, which would make it easily possible to convert that mode into an offscreen renderer without any window and GUI.
Both contain a benchmark code path (command line option -m 1 or --mode 1) which is already only rendering offscreen and dumping the resulting rendered image.
That is pure raytracing and much faster than with all the display stuff.
The screenshot functionality is slow though because I do the tonemapping on the CPU, but that could be easily done with CUDA.
(Insider: The shortcut rtigo actually stands for Ray Tracing Image Generator OptiX, so I planned it to be offscreen capable initially.)
You would only need to comment out a lot of stuff which isn’t needed anymore starting here: runApp

1 Like

@droettger Thank you for the detailed reply.

I think I will go the route of changing an existing OptiX SDK example. The only potential issue I may have has to do with the fact that later I have to embedded the OptiX 7 project as part of a larger Cmake file. For example if I modify the OptiX SDK example optixRaycasting I have to use a pre-existing CMakeLists.txt file in the directory above and have it call my modified optixRaycasting sub-directory. Not exactly sure how that will work as I am still fairly new to Cmake (came from Makefile background).