I noticed that some of the examples in the SDK, even though they seem to build fine, run into compiling issues when those examples are run (optixHair, optixTriangle, et al). The error message says that float_as_int is not found. This occurs in the runtime compiling. I fixed this in my source code trees by adding the following snippet at the end of SDK/cuda/helpers.h, and then (depending on the particular OptiX SDK version, making sure that file is included in any .cu files that give errors. I also had to create float_as_uint and uint_as_float functions as well, not shown here, but easy to create by just copying the below and change âintâ to uint"
=============================== forceinlinedevice int float_as_int(const float f)
{
union {
float f;
int i;
} v1;
v1.f = f;
return v1.i;
}
forceinlinedevice float int_as_float(int i)
{
union {
float f;
int i;
} v1;
v1.i = i;
return v1.f;
}
============================
There may be a better way to do this as there are supposedly built-in cuda functions but this did the trick for me for now. I verified this approach worked in 7.2, 7.3, 7.4. There seems to be other issues for me at least in 7.7 and 8.0, thatâs for another day. My goal was to get OptiX anything to work.
Which CUDA toolkit are you using? And can you list a specific 7.x SDK version that has the issue?
I just tried building 7.5 and 8.0 fresh on Linux and I donât get any errors with float_as_int.
The function call float_as_int() is deprecated as of CUDA 11.5. Please use the intrinsic version with a double-underscore prefix from now on: __float_as_int().
As an additional note: here is what happens for me on OptiX SDK v 8.0.0. It builds, but when I try to run optixHello, I get:
chris@chris-MS-7C56:~/NVIDIA_Stuff/NVIDIA-OptiX-SDK-8.0.0-linux64-x86_64/SDK/build$ bin/optixHello
[ 4][ KNOBS]: All knobs on default.
[ 4][ DISKCACHE]: Opened database: â/var/tmp/OptixCache_chris/optix7cache.dbâ
[ 4][ DISKCACHE]: Cache data size: â3.9 MiBâ
[ 4][ DISKCACHE]: Cache miss for key: ptx-6584-keyb5ef4d3eaa9b124ce715726298ffb46b-sm_89-rtc1-drv535.154.05
minor Version (60) newer than tool (should be 59)
minor NvvmIRVersion (63) newer than tool (should be 58)
[ 2][ COMPILER]: COMPILE ERROR:
You may need a newer driver with CUDA 12.3. There are version 545 and 550 drivers for Linux available via the âBeta and Older driversâ link from the Drivers download page.
BTW, for posterity, another option is to use the most recent CUDA toolkit that is mentioned in the OptiX SDK release for whichever version of OptiX you want to use. For OptiX 8.0, the release notes mention CUDA 12.0. Itâs usually fine to use the latest toolkit, but our general recommendation, if there are any issues, is to pick the last toolkit version that predates the OptiX release, just to be safe.
Thank you! That is very helpful! I did get rid of the âcuda-toolkitâ packages and now just have the nvidia-cuda-toolkit one. After that, and cleaning up the tree, I was able to build and run Optix SDK v7.7.0 and v8.0.0. Your fast and useful help is much appreciated!
As a sidenote, all intersection attribute and optixTrace payload registers inside the OptiX device code are unsigned int, so for these the proper CUDA reinterpretation functions are __float_as_uint() and __uint_as_float() .
The OptiX SDK 8.0.0 examplesâ source code corrected most of these occurrences. (Well, optixCustomPrimitive.cu still uses the integer versions.)
Thatâs not really a functional change since these are all just 32bit bitcasts in the end, but for code cleanliness better use the proper types.
Also strictly speaking, the functions float_as_int() and int_as_float() in the first post with the union are not correct C++ code. Itâs undefined behavior to read a different type from a union than was most recently written to, but most compilers do exactly what that code intended and I used such method as well.
See the Explanation section here: https://en.cppreference.com/w/cpp/language/union