ingowald / optix7course

Apache License 2.0
452 stars 80 forks source link

Enable Direct Callable by Updating one of the CMAKE macro #27

Closed Han-ga86caq closed 1 year ago

Han-ga86caq commented 2 years ago

Hello Prof. Wald,

I am recently trying-out the feature of "callable" of OptiX, however, when I wrote a direct callable in "devicePrograms.cu", the function name does not appear in the corresponding ptx code, so optixProgramGroupCreate() fails with error message "__direct_callable__EMCalc" not found in programDescriptions[0].callables.moduleDC.

After some googling, I found that the problem is because of not enabling the "relocatable-device-code" when compiling the PTX code. For my application, I could make it work by changing line 51 of file common/gdt/cmake/configure_optix.cmake to

cuda_compile_ptx(ptx_files ${cuda_file} OPTIONS --generate-line-info -use_fast_math --keep --relocatable-device-code=true)

(added flag --relocatable-device-code=true)

However, I understand it might not be a good idea to enable this flag all the time, since it prevent the compiler to optimize away inline calls... So I suggest that you can add an option to the macro cuda_compile_and_embed so that user can decide whether or not to enable relocatable-device-code dependent on their need.

Best regards, Han