SDK Samples: sutil :: getPtxString? file path?

Hi, I’m still beginner of OptiX.
I still have a lot of questions about the sdk sample.
The tutorial samples (especially the optiX tutorials) in the NVIDIA OPTIX SDK are not enough to be described in the PDF.
Here are the questions.

  1. sutil_sdk: sampleConfig.h - This header declares the directory path. However, I do not understand how this path is used in the samples (OptiX-Tutorial Porject). Most of the samples are taken for granted, but I do not know.

Here are some things I did not understand (in the sample optixTutorial.cpp):

// load the ptx source associated with tutorial number
        std :: stringstream ss;
        ss << “tutorial” << tutorial_number << “.cu”;
        std :: string tutorial_ptx_path = ss.str ();
        tutorial_ptx = sutil :: getPtxString (SAMPLE_NAME, tutorial_ptx_path.c_str ());

// originally what is needed for the variable tutorial_ptx?
// ss is the name of the .cu file, getPtxString’ s output is may be the file path.

ptx = sutil :: getPtxString (SAMPLE_NAME, “parallelogram.cu”);

const char * ptx = sutil :: getPtxString (SAMPLE_NAME, “box.cu”);

Exactly I want to change (sutil :: getPtxString) instead.
For example,

createProgramFromPTXString (sutil :: getPtxString (NULL, “triangle_mesh.cu”), “mesh_bounds”)

I am sorry for the rudimentary question. But I should have asked.

That is one of my pet peeves in the OptiX SDK examples and also in the OptiX Advanced Samples on github.

They both hardcode the locations of the sample’s directory and location of the *.ptx files into the compiled samples, which means they only run where you actually built them, unless you set the two environment values OPTIX_SAMPLES_DIR and OPTIX_SAMPLES_PTX_DIR.
Search for these in the code to find how the folder names for SAMPLES_DIR and SAMPLES_PTX_DIR are generated.

In my own OptiX application frameworks, I store all *.ptx files in an application specific folder relative to the executable, e.g. my_app.exe loads the raygeneration code from “./my_app_ptx/raygeneration.ptx”. I also do that for runtime generated material shaders using NVRTC.
Works anywhere when copied around!
Looks like that inside the code then:

m_mapOfPrograms["raygeneration"] = m_context->createProgramFromPTXFile("./my_app_ptx/raygeneration.ptx", "raygeneration");

Additionally the *.cu to *.ptx CUDA compilation rule bloats the name of the generated *.ptx file to uniquely identify it per application and *.cu file because they are all stored in a single folder of the SDK and some of the programs in the OptiX SDK 6.0.0\SDK\cuda folder are shared among multiple examples.
In the precompiled examples those resulting *.ptx files are all in OptiX SDK 6.0.0\SDK-precompiled-samples\ptx including your optixTutorial ones.

I’m not using any of that sutil functionality but only link against OptiX. With separate folders for the *.ptx files per application a raygen.cu is simply compiled to raygen.ptx.

If you’re starting with OptiX, please have a look at the OptiX Introduction presentation video and open source samples from the GTC 2018.
All links here: https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/
That code also contains a comment about those hardcoded paths.
https://github.com/nvpro-samples/optix_advanced_samples/blob/master/src/optixIntroduction/optixIntro_07/src/Application.cpp#L55

1 Like

Thank you very much.

I got inspired by your answer and figured out my problem.
And I was able to find out more clearly by your answer.

Thanks again. :)