kai-neumann / GAAlign

Robust Sampling-based Point Cloud Registration using Geometric Algebra
MIT License
5 stars 3 forks source link

Error during compilation with CUDA enabled #1

Open wetoo-cando opened 1 year ago

wetoo-cando commented 1 year ago

Hi @kai-neumann, thanks for the very interesting work!

I am trying to build the GAAlign app with CUDA enabled. I think I have the right flags set during the cmake command, and I have also uncommented/commented the necessary lines in app/main.cpp.

When I try to compile, I get the following error:

[100%] Linking CXX executable gaalign-app
/usr/bin/ld: ../optimization/libgaalign-optimization-cuda.a(gradient_descent_cuda.cug.cu.o): in function `gaalign::GradientDescentOptimizerCUDA::optimize(std::vector<gaalign::Correspondence, std::allocator<gaalign::Correspondence> > const&) const':
tmpxft_000242ad_00000000-6_gradient_descent_cuda.cug.cudafe1.cpp:(.text+0x1153): undefined reference to `gaalign::shuffle_pcg_divisionless_with_slight_bias(unsigned int*, unsigned int)'
/usr/bin/ld: tmpxft_000242ad_00000000-6_gradient_descent_cuda.cug.cudafe1.cpp:(.text+0x1422): undefined reference to `gaalign::shuffle_pcg_divisionless_with_slight_bias(unsigned int*, unsigned int)'
collect2: error: ld returned 1 exit status
make[2]: *** [src/app/CMakeFiles/gaalign-app.dir/build.make:186: src/app/gaalign-app] Error 1
make[1]: *** [CMakeFiles/Makefile2:352: src/app/CMakeFiles/gaalign-app.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

The problem is with the function gaalign::shuffle_pcg_divisionless_with_slight_bias that's being included from the <optimization/fast_shuffle.h> header.

Can you say what's wrong?

kai-neumann commented 1 year ago

Hi there! Thank you for your interest in GAAlign :)

I think this is a linker error caused by the library only having been tested on the windows toolchain. Even though I could not reproduce the error, I think the issue lies in the CMake file for the gaalign-optimization-cuda library. I would suggest replacing line 35 in src/optimization/CMakeLists.txt

GPC_CUDA_ADD_LIBRARY(gaalign-optimization-cuda gradient_descent_cuda/gradient_descent_cuda.h gradient_descent_cuda/gradient_descent_cuda.cug)

with

GPC_CUDA_ADD_LIBRARY(gaalign-optimization-cuda gradient_descent_cuda/gradient_descent_cuda.h gradient_descent_cuda/gradient_descent_cuda.cug fast_shuffle.cpp fast_shuffle.h fast_shuffle_pcg.h)

I hope this solves your issues.

Best, Kai

wetoo-cando commented 12 months ago

Thanks for the reply @kai-neumann

After that change, I get:

Consolidate compiler generated dependencies of target gaalign-optimization-cuda
[ 59%] Building CXX object src/optimization/CMakeFiles/gaalign-optimization-cuda.dir/fast_shuffle.cpp.o

c++: error: unrecognized command line option ‘-Xcompiler="-fopenmp"’

make[2]: *** [src/optimization/CMakeFiles/gaalign-optimization-cuda.dir/build.make:80: src/optimization/CMakeFiles/gaalign-optimization-cuda.dir/fast_shuffle.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:268: src/optimization/CMakeFiles/gaalign-optimization-cuda.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Do you know if the error above referring to nvcc or g++? Unfortunately I am not so familiar with cuda compilation.

kai-neumann commented 12 months ago

Hi,

the "-Xcompiler" command is an argument of nvcc that is used to pass arguments to the underlying c++ compiler (in your case g++). I think the error is caused by the argument accidentally being passed directly to g++ instead of nvcc.

The easiest fix for this would be commenting out line 41 in src/optimization/CMakeLists.txt. However, this probably disables CPU-based parallelization using OpenMP for the submodule, resulting in a slight loss of performance. Nevertheless, as the CUDA-based optimization is mostly performed on the GPU, this should not be significant.

I'll look into setting up a Linux development environment on my end in the future to ensure that GAAlign can compile on both Windows and Linux without any problems.

Best, Kai