nvpro-samples / optix_advanced_samples

417 stars 87 forks source link

PTX error: File not found #14

Closed coramat closed 2 years ago

coramat commented 3 years ago

Hey,

I built the project successfully, however, when I tried to run the basic examples the application terminated and I got this error:

File not found (Details: Function "RTresult _rtProgramCreateFromPTXFile(RTcontext, const char, const char, RTprogram_api**)" caught exception: File not found - ./optix_advanced_samples-master/src/lib/ptx/optixIntro_01_generated_raygeneration.cu.ptx)

I have Optix 6.0.0 and CUDA 11.1.

Have you ever encountered this problem?

Thank you in advance.

droettger commented 3 years ago

First, I'm assuming you synced the whole optix_advanced_samples repository and built the solution with the the top-most CMakeLists.txt to contain all examples in the repository? The projects won't be configured correctly when using other CMakeLists.txt files as root.

The issue is most likely that the CUDA 11.x toolkits removed support for the Streaming Multiprocessor target 3.0 (first Kepler GPU) while these old OptiX Advanced Samples are still building PTX for SM 3.0 targets by default. There should have been a lot of NVCC errors about that while compiling the projects with CUDA 11.

Note that OptiX 6.0.0 does not officially support CUDA 11.1. That version of the SDK itself has been built with with CUDA 10.0. (Always read the OptiX Release Notes below each SDK version's download button before setting up an OptiX development environment.)

The OPTIX_add_sample_executable CMake function used to build the individual examples uses the CUDA_WRAP_SRCS macro to generate custom build rules for each generated PTX file. The SM version handling in there is quite involved.

The simplest solution would be to use a CUDA 10.x version to compile the input PTX, since that still supports the SM 3.0 target.

OptiX 6 and newer do not support Kepler GPUs anymore, so SM targets can be set to Maxwell SM 5.0 or higher.

Using CUDA 11 would require to change the SM target. The easiest method seems to be via the default_nvcc_flags. (Not tried myself.)

Search for this line inside the optix_advanced_samples/src/CMakeLists.txt: list(APPEND default_nvcc_flags "--use_fast_math" "-arch sm_30" "-lineinfo") and change it to sm_50 (first Maxwell) list(APPEND default_nvcc_flags "--use_fast_math" "-arch sm_50" "-lineinfo")

Then delete the CMake Cache and configure and generate the solution again.

While that SM 5.0 version is deprecated inside CUDA 11, it should still build the PTX files but with deprecation warnings. If you have a newer GPU than Maxwell, you can also set it to sm_60 (first Pascal GPU) to get rid of the deprecation warnings.

Note that these old OptiX examples use the same mechanism to find the data and ptx sources as the OptiX SDK examples via two hardcoded paths and won't work when not run at the location where they have been built, unless two environment variables are set. See this forum thread for explanations: https://forums.developer.nvidia.com/t/sdk-samples-sutil-getptxstring-file-path/70963/3

Additionally these old OptiX examples have been built against the OptiX SDK 5.1.0 version originally and do not make use of the hardware ray-triangle intersection available on RTX boards, because they are not using the built-in triangle primitives added since OptiX 6.

I would seriously recommend to switch to the newer OptiX 7.x API which uses a more modern and flexible API and is generally faster than previous OptiX versions. I've ported some of the OptiX Introduction examples to the OptiX 7.x API for that reason and they can be found here: https://github.com/NVIDIA/OptiX_Apps

They are using a different application framework where changing NVCC options is much simpler and the PTX files are handled with relative paths as I described in the above forum link.

Find more OptiX 7 resources inside the sticky posts of the OptiX developer forum. https://forums.developer.nvidia.com/c/professional-graphics-and-rendering/advanced-graphics/optix/167