I have had little luck getting Ingo Wald’s turorial demos to build using cmake under Scientific Linux/CentOS 7.
Here’s a quick list the the problems I’ve hit so far.
1) Download: link on https://gitlab.com/ingowald/optix7course is bad
Says: git clone Ingo Wald / optix7course · GitLab
Should be: git clone Ingo Wald / optix7course · GitLab
2) CMAKE: I have CUDA 10.2 installed in /usr/local/cuda, and the OptiX 7 headers is /usr/local/optix/include
mkdir build
cd build
ccmake3 …
Brings up the GNU curses interface. I press [c] to configure and get:
CMake Error at /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (found
version “10.2”)
Call Stack (most recent call first):
/usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake3/Modules/FindCUDA.cmake:1092 (find_package_handle_standard_args)
common/gdt/cmake/configure_optix.cmake:23 (find_package)
CMakeLists.txt:32 (include)
So, I try instead:
ccmake3 … -DCUDA_CUDART_LIBRARY=/usr/local/cuda/lib64/libcudart.so -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -DOptiX_INSTALL_DIR=/usr/local/optix -DOptiX_INCLUDE=/usr/local/optix/include
This time pressing [c]onfigure (twice!?!) gives the option to [g]enerate. I do that and ccmake3 exits.
3) Make (and undefined constants)
I type
make
and get
Scanning dependencies of target gdt
[ 1%] Building CXX object common/gdt/CMakeFiles/gdt.dir/gdt/gdt.cpp.o
[ 2%] Linking CXX static library …/…/libgdt.a
[ 2%] Built target gdt
Scanning dependencies of target ex01_helloOptix
[ 3%] Building CXX object example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o
In file included from /home/squeen/Downloads/NVIDIA/optix/optix7course/example01_helloOptix/main.cpp:18:0:
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h:142:19: error: ‘uint32_t’ does not name a type
inline both uint32_t divRoundUp(uint32_t a, uint32_t b) { return (a+b-1)/b; }
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h:144:19: error: ‘uint64_t’ does not name a type
inline both uint64_t divRoundUp(uint64_t a, uint64_t b) { return (a+b-1)/b; }
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h: In function ‘double gdt::getCurrentTime()’:
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h:218:41: error: ‘nullptr’ was not declared in this scope
struct timeval tp; gettimeofday(&tp,nullptr);
^
make[2]: *** [example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o] Error 1
make[1]: *** [example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/all] Error 2
make: *** [all] Error 2
4) HACK#1: Using standard integer data types.
I change the ‘uint32_t’ in optix7course/common/gdt/gdt/gdt.h to the standard “unsigned” type and similiarly the ‘uint64_t’ “unsigned long” types (is this Windows baggage?) and I am able to get a bit further…
Scanning dependencies of target ex01_helloOptix
[ 3%] Building CXX object example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o
In file included from /home/squeen/Downloads/NVIDIA/optix/optix7course/example01_helloOptix/main.cpp:18:0:
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h: In function ‘double gdt::getCurrentTime()’:
/home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/gdt.h:218:41: error: ‘nullptr’ was not declared in this scope
struct timeval tp; gettimeofday(&tp,nullptr);
^
make[2]: *** [example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o] Error 1
make[1]: *** [example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/all] Error 2
make: *** [all] Error 2
5) HACK#2: nullptr becomes the C standard NULL
Fixing line 218 I meet with some success:
make
[ 1%] Building CXX object common/gdt/CMakeFiles/gdt.dir/gdt/gdt.cpp.o
[ 2%] Linking CXX static library …/…/libgdt.a
[ 2%] Built target gdt
[ 3%] Building CXX object example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o
[ 5%] Linking CXX executable …/ex01_helloOptix
/usr/bin/ld: CMakeFiles/ex01_helloOptix.dir/main.cpp.o: undefined reference to symbol ‘dlsym@@GLIBC_2.2.5’
//usr/lib64/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [ex01_helloOptix] Error 1
make[1]: *** [example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/all] Error 2
make: *** [all] Error 2
6) Adding -ldl to CMAKE
I tried
ccmake3 … -DCUDA_CUDART_LIBRARY=/usr/local/cuda/lib64/libcudart.so -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -DOptiX_INSTALL_DIR=/usr/local/optix -DOptiX_INCLUDE=/usr/local/optix/include -DBIN2C=/usr/local/cuda/bin/bin2c -DCMAKE_CXX_FLAGS=-ldl
Now the make error became…
Scanning dependencies of target gdt
[ 1%] Building CXX object common/gdt/CMakeFiles/gdt.dir/gdt/gdt.cpp.o
[ 2%] Linking CXX static library …/…/libgdt.a
[ 2%] Built target gdt
Scanning dependencies of target ex01_helloOptix
[ 3%] Building CXX object example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o
[ 5%] Linking CXX executable …/ex01_helloOptix
[ 5%] Built target ex01_helloOptix
[ 6%] Building NVCC ptx file example02_pipelineAndRayGen/cuda_compile_ptx_1_generated_devicePrograms.cu.ptx
In file included from /usr/local/optix/include/optix_device.h:43:0,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/devicePrograms.cu:17:
/usr/local/optix/include/optix_7_device.h:36:2: error: #error Device code for OptiX requires at least C++11. Consider adding “–std c++11” to the nvcc command-line.
#error Device code for OptiX requires at least C++11. Consider adding “–std c++11” to the nvcc command-line.
^
In file included from /usr/include/c++/4.8.2/type_traits:35:0,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/math/vec/functors.h:19,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/math/vec.h:378,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/LaunchParams.h:19,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/devicePrograms.cu:19:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the
^
CMake Error at cuda_compile_ptx_1_generated_devicePrograms.cu.ptx.Release.cmake:211 (message):
Error generating
/home/squeen/Downloads/NVIDIA/optix/optix7course/build/example02_pipelineAndRayGen/cuda_compile_ptx_1_generated_devicePrograms.cu.ptx
make[2]: *** [example02_pipelineAndRayGen/cuda_compile_ptx_1_generated_devicePrograms.cu.ptx] Error 1
make[1]: *** [example02_pipelineAndRayGen/CMakeFiles/ex02_pipelineAndRayGen.dir/all] Error 2
make: *** [all] Error 2
7) Adding -std=c++11 to nvcc
Tried again with a new CMake command…
ccmake3 … -DCUDA_CUDART_LIBRARY=/usr/local/cuda/lib64/libcudart.so -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -DOptiX_INSTALL_DIR=/usr/local/optix -DOptiX_INCLUDE=/usr/local/optix/include -DBIN2C=/usr/local/cuda/bin/bin2c -DCMAKE_CXX_FLAGS=-ldl -DCUDA_NVCC_FLAGS=-std=c++11
‘make’ produces…
Scanning dependencies of target gdt
[ 1%] Building CXX object common/gdt/CMakeFiles/gdt.dir/gdt/gdt.cpp.o
[ 2%] Linking CXX static library …/…/libgdt.a
[ 2%] Built target gdt
Scanning dependencies of target ex01_helloOptix
[ 3%] Building CXX object example01_helloOptix/CMakeFiles/ex01_helloOptix.dir/main.cpp.o
[ 5%] Linking CXX executable …/ex01_helloOptix
[ 5%] Built target ex01_helloOptix
[ 6%] Building NVCC ptx file example02_pipelineAndRayGen/cuda_compile_ptx_1_generated_devicePrograms.cu.ptx
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/devicePrograms.cu(28): warning: extern declaration of the entity optixLaunchParams is treated as a static definition
[ 7%] compiling (and embedding ptx from) devicePrograms.cu
Scanning dependencies of target ex02_pipelineAndRayGen
[ 8%] Building C object example02_pipelineAndRayGen/CMakeFiles/ex02_pipelineAndRayGen.dir/cuda_compile_ptx_1_generated_devicePrograms.cu.ptx_embedded.c.o
[ 10%] Building CXX object example02_pipelineAndRayGen/CMakeFiles/ex02_pipelineAndRayGen.dir/SampleRenderer.cpp.o
In file included from /usr/include/c++/4.8.2/type_traits:35:0,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/math/vec/functors.h:19,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/common/gdt/gdt/math/vec.h:378,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/LaunchParams.h:19,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.h:21,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.cpp:17:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the
^
In file included from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.h:20:0,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.cpp:17:
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:81:28: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
size_t sizeInBytes { 0 };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:82:28: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
void *d_ptr { nullptr };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:81:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
size_t sizeInBytes { 0 };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:81:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
size_t sizeInBytes { 0 };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:82:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
void d_ptr { nullptr };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:82:20: error: ‘nullptr’ was not declared in this scope
void d_ptr { nullptr };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:82:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
void d_ptr { nullptr };
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:82:28: error: cannot convert ‘’ to 'void’ in initialization
In file included from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:19:0,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.h:20,
from /home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/SampleRenderer.cpp:17:
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h: In member function ‘void osc::CUDABuffer::alloc(size_t)’:
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/optix7.h:33:15: error: ‘runtime_error’ is not a member of ‘std’
throw std::runtime_error(txt.str());
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h:45:7: note: in expansion of macro ‘CUDA_CHECK’
CUDA_CHECK(Malloc( (void)&d_ptr, sizeInBytes));
^
/home/squeen/Downloads/NVIDIA/optix/optix7course/example02_pipelineAndRayGen/CUDABuffer.h: In member function ‘void osc::CUDABuffer::free()’:
…this goes one for hundreds of additional errors…
8) HACK #3: To Hell with Cmake!
I created a good old fashioned GNU Makefile (below) and was able to make an executable of example01!
SHELL = /bin/sh
# add CUDA to path
CUDA_PATH :=/usr/local/cuda
CUDA_INC_PATH :=$(CUDA_PATH)/include
CUDA_LIB_PATH :=$(CUDA_PATH)/lib64
PATH := $(CUDA_BIN_PATH):$(PATH)
# add OptiX to path
OPTIX_PATH := /usr/local/optix
OPTIX_INC_PATH :=$(OPTIX_PATH)/include
CC = g++
CFLAGS = -std=c++11 -Wall
CPPFLAGS = -I. -I.. -I../common/gdt -I../common -I$(CUDA_INC_PATH) -I$(OPTIX_INC_PATH)
LD = gcc
LDFLAGS = -L. -L.. -L/lib64/ -L$(CUDA_LIB_PATH) -lrt -lm -ldl -lcudart
.PHONY: all
all: ex01 ex02
ex01:
@echo "building: example01_helloOptix"
cd example01_helloOptix; $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ main.cpp $(LDFLAGS)
@mv example01_helloOptix/ex01 .
ex02:
@echo "building: example02_pipelineAndRayGen"
cd example02_pipelineAndRayGen; $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ main.cpp SampleRenderer.cpp $(LDFLAGS)
@mv example02_pipelineAndRayGen/ex02 .
.PHONY: clean
clean:
rm -f ./ex[0-9][0-9];
Ran it and got:
ex01
#osc: initializing optix…
#osc: found 1 CUDA devices
#osc: successfully initialized optix… yay!
#osc: done. clean exit.
Yippee! but…
Example02 won’t build.
building: example02_pipelineAndRayGen
cd example02_pipelineAndRayGen;
g++ -std=c++11 -Wall -I. -I… -I…/common/gdt -I…/common -I/usr/local/cuda/include -I/usr/local/optix/include -o ex02 main.cpp -L. -L… -L/lib64/ -L/usr/local/cuda/lib64 -lrt -lm -ldl -lcudart
In file included from LaunchParams.h:19:0,
from SampleRenderer.h:21,
from main.cpp:17:
…/common/gdt/gdt/math/vec.h:356:1: warning: multi-line comment [-Wcomment]
//#define _define_vec_types(T,t)
^
In file included from CUDABuffer.h:19:0,
from SampleRenderer.h:20,
from main.cpp:17:
CUDABuffer.h: In member function ‘void osc::CUDABuffer::alloc(size_t)’:
optix7.h:33:15: error: ‘runtime_error’ is not a member of ‘std’
throw std::runtime_error(txt.str());
^
CUDABuffer.h:45:7: note: in expansion of macro ‘CUDA_CHECK’
CUDA_CHECK(Malloc( (void**)&d_ptr, sizeInBytes));
^
CUDABuffer.h: In member function ‘void osc::CUDABuffer::free()’:
optix7.h:33:15: error: ‘runtime_error’ is not a member of ‘std’
throw std::runtime_error(txt.str());
^
CUDABuffer.h:51:7: note: in expansion of macro ‘CUDA_CHECK’
CUDA_CHECK(Free(d_ptr));
^
CUDABuffer.h: In member function ‘void osc::CUDABuffer::upload(const T*, size_t)’:
optix7.h:33:15: error: ‘runtime_error’ is not a member of ‘std’
throw std::runtime_error(txt.str());
^
CUDABuffer.h:68:7: note: in expansion of macro ‘CUDA_CHECK’
CUDA_CHECK(Memcpy(d_ptr, (void )t,
^
CUDABuffer.h: In member function 'void osc::CUDABuffer::download(T, size_t)':
optix7.h:33:15: error: ‘runtime_error’ is not a member of ‘std’
throw std::runtime_error(txt.str());
^
CUDABuffer.h:77:7: note: in expansion of macro ‘CUDA_CHECK’
CUDA_CHECK(Memcpy((void *)t, d_ptr,
^
make: *** [ex02] Error 1
More C++ mangled garabge — ever considered a nice, simple, little C-based tutorial with no custom data types, invented classes, utility libraries, etc. — just core language C99 and C CUDA? Pedantic, yes…but kind to the new users too.
Ouch!