CUDA with Eigen3?

I’m trying to build Open3D with CUDA enabled, but met a lot of error messages:

[  8%] Building CXX object cpp/open3d/visualization/CMakeFiles/visualization_impl.dir/shader/GeometryRenderer.cpp.o
cd ....../Open3D/build/cpp/open3d/visualization && /usr/bin/ccache /usr/local/llvm/bin/clang++ -DFMT_SHARED -DMSGPACK_DEFAULT_API_VERSION=3 -DOPEN3D_CUDA_COMPILER_ID=\"\" -DOPEN3D_CUDA_COMPILER_VERSION=\"\" -DOPEN3D_CXX_COMPILER_ID=\"Clang\" -DOPEN3D_CXX_COMPILER_VERSION=\"18.1.8\" -DOPEN3D_CXX_STANDARD=\"17\" -DOPEN3D_ENABLE_DLL_EXPORTS -DUNIX -DUSE_BLAS -DZMQ_STATIC -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=1 -D__CUDACC__ -Dkiss_fft_scalar=double -I/usr/local/cuda/include -I....../Open3D/cpp -isystem ....../Open3D/3rdparty/tomasakeninemoeller/include -isystem /usr/local/include/vtk-9.4 -isystem /usr/local/include/vtk-9.4/token -isystem /usr/local/include/vtk-9.4/vtknlohmannjson/include -isystem /usr/local/include/vtk-9.4/vtknlohmannjson -isystem /usr/local/include/vtk-9.4/vtkkissfft -isystem /usr/local/include/vtk-9.4/vtkpugixml -isystem /usr/include/jsoncpp -isystem /usr/include/liblzf -isystem /usr/include/minizip -isystem /usr/include/pgm-5.3 -isystem /usr/include/libxml2 -isystem /usr/include/mit-krb5 -isystem /usr/local/include/eigen3 -std=c++17 -O3 -DNDEBUG -std=c++17 -fPIC -fvisibility=hidden -Wall -Wextra -Werror -Wno-unused-parameter -fcolor-diagnostics -fstack-protector -Wformat -Wformat-security -fopenmp=libomp -MD -MT cpp/open3d/visualization/CMakeFiles/visualization_impl.dir/shader/GeometryRenderer.cpp.o -MF CMakeFiles/visualization_impl.dir/shader/GeometryRenderer.cpp.o.d -o CMakeFiles/visualization_impl.dir/shader/GeometryRenderer.cpp.o -c ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:19:
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:956:1: error: unknown type name '__host__'
  956 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(const T&) {}
      | ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:883:27: note: expanded from macro 'EIGEN_DEVICE_FUNC'
  883 | #define EIGEN_DEVICE_FUNC __host__ __device__
      |                           ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:956:18: error: expected ';' at end of declaration
  956 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(const T&) {}
      |                  ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:956:83: error: unknown type name 'T'
  956 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(const T&) {}
      |                                                                                   ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1272:1: error: unknown type name '__host__'
 1272 | EIGEN_DEVICE_FUNC inline bool all() { return true; }
      | ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:883:27: note: expanded from macro 'EIGEN_DEVICE_FUNC'
  883 | #define EIGEN_DEVICE_FUNC __host__ __device__
      |                           ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1272:18: error: expected ';' after top level declarator
 1272 | EIGEN_DEVICE_FUNC inline bool all() { return true; }
      |                  ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1275:1: error: unknown type name '__host__'
 1275 | EIGEN_DEVICE_FUNC bool all(T t, Ts... ts) {
      | ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:883:27: note: expanded from macro 'EIGEN_DEVICE_FUNC'
  883 | #define EIGEN_DEVICE_FUNC __host__ __device__
      |                           ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1275:18: error: expected ';' at end of declaration
 1275 | EIGEN_DEVICE_FUNC bool all(T t, Ts... ts) {
      |                  ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1275:28: error: unknown type name 'T'
 1275 | EIGEN_DEVICE_FUNC bool all(T t, Ts... ts) {
      |                            ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1275:33: error: unknown type name 'Ts'
 1275 | EIGEN_DEVICE_FUNC bool all(T t, Ts... ts) {
      |                                 ^
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1275:35: error: type 'int' of function parameter pack does not contain any unexpanded parameter packs
 1275 | EIGEN_DEVICE_FUNC bool all(T t, Ts... ts) {
      |                                 ~~^~~~~~
/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h:1276:21: error: pack expansion does not contain any unexpanded parameter packs
 1276 |   return t && all(ts...);
      |                   ~~^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5267:70: error: non-constexpr declaration of 'abs' follows constexpr declaration
 5267 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl abs(float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_abs.h:75:3: note: previous declaration is here
   75 |   abs(float __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5268:70: error: non-constexpr declaration of 'abs' follows constexpr declaration
 5268 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ double   __cdecl abs(double);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_abs.h:71:3: note: previous declaration is here
   71 |   abs(double __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5269:70: error: non-constexpr declaration of 'fabs' follows constexpr declaration
 5269 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl fabs(float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:234:3: note: previous declaration is here
  234 |   fabs(float __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5270:70: error: non-constexpr declaration of 'ceil' follows constexpr declaration
 5270 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl ceil(float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:158:3: note: previous declaration is here
  158 |   ceil(float __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5271:70: error: non-constexpr declaration of 'floor' follows constexpr declaration
 5271 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl floor(float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:253:3: note: previous declaration is here
  253 |   floor(float __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5272:70: error: non-constexpr declaration of 'sqrt' follows constexpr declaration
 5272 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl sqrt(float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:438:3: note: previous declaration is here
  438 |   sqrt(float __x)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5273:70: error: non-constexpr declaration of 'pow' follows constexpr declaration
 5273 | extern __DEVICE_FUNCTIONS_DECL__ __cudart_builtin__ float    __cdecl pow(float, float);
      |                                                                      ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:372:3: note: previous declaration is here
  372 |   pow(float __x, float __y)
      |   ^
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.cpp:8:
In file included from ....../Open3D/cpp/open3d/visualization/shader/GeometryRenderer.h:11:
In file included from ....../Open3D/cpp/open3d/visualization/shader/ImageMaskShader.h:10:
In file included from ....../Open3D/cpp/open3d/geometry/Image.h:10:
In file included from /usr/local/include/eigen3/Eigen/Core:22:
In file included from /usr/local/include/eigen3/Eigen/src/Core/util/ConfigureVectorization.h:477:
In file included from /usr/local/cuda/include/cuda_runtime.h:117:
In file included from /usr/local/cuda/include/crt/common_functions.h:303:
/usr/local/cuda/include/crt/math_functions.h:5280:51: error: non-constexpr declaration of 'pow' follows constexpr declaration
 5280 | typename __gnu_cxx::__promote_2<_Tp, _Up>::__type pow(_Tp, _Up);
      |                                                   ^
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:1070:5: note: previous declaration is here
 1070 |     pow(_Tp __x, _Up __y)
      |     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [cpp/open3d/visualization/CMakeFiles/visualization_impl.dir/build.make:82: cpp/open3d/visualization/CMakeFiles/visualization_impl.dir/shader/GeometryRenderer.cpp.o] Error 1
make[2]: Leaving directory '....../Open3D/build'
make[1]: *** [CMakeFiles/Makefile2:1496: cpp/open3d/visualization/CMakeFiles/visualization_impl.dir/all] Error 2
make[1]: Leaving directory '....../Open3D/build'
make: *** [Makefile:159: all] Error 2
➜  build git:(main) ✗ 

It looks to me: CUDA-12.6 and Eigen-3.4.90 conflict a lot. Maybe, it’s just an issue of compilation configuration parameters.

Oh, My working environment:

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.1 LTS
Release:	24.04
Codename:	noble
➜  ~ gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜  ~ clang --version
clang version 18.1.8
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/llvm/bin
➜  ~ nvcc --version 
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Oct_29_23:50:19_PDT_2024
Cuda compilation tools, release 12.6, V12.6.85
Build cuda_12.6.r12.6/compiler.35059454_0

Did anybody meet these types of errors before?

Cheers

The errors indicate that CUDA code in header files is pulled into C++ compilations, leading the C++ compiler to complain, with good reason. Presumably, CUDA-specific code in header files is protected by conditional compilation wit #ifdef. If so, macros controlling the conditional compilation seem to set incorrectly. It therefore appears that your build configuration is somehow inconsistent.

Double check the Eigen requirements so see what CUDA versions are supported for this particular version of Eigen. Only use officially supported and/or recommended version combinations.

You might want to re-read relevant Eigen documentation to make sure nothing was overlooked, or use the support infrastructure for Eigen to ask for advice. It seems there is a mailing list and a Discord server for this project.