mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
593 stars 43 forks source link

Fail to compile with GCC 12 #89

Closed c8ef closed 2 years ago

c8ef commented 2 years ago

My OS:

$ uname -a
Linux x 5.19.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.6-1 (2022-09-01) x86_64 GNU/Linux

drjit version: dbdb578 My compiler version:

$ gcc --version
gcc (Debian 12.2.0-3) 12.2.0
Copyright (C) 2022 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
Debian clang version 14.0.6-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

When building with GCC, I got error as follows:

[12/22] Building CXX object src/python/CMakeFiles/drjit-python.dir/implicit.cpp.o
FAILED: src/python/CMakeFiles/drjit-python.dir/implicit.cpp.o
/usr/bin/c++ -DDRJIT_ENABLE_AUTODIFF=1 -DDRJIT_ENABLE_CUDA=1 -DDRJIT_ENABLE_JIT=1 -DDRJIT_UNROLL=" " -Ddrjit_python_EXPORTS -I/tmp/drjit/include -I/tmp/drjit/ext/drjit-core/include -I/tmp/drjit/ext/drjit-core/ext/nanothread/include -isystem /usr/include/python3.10 -isystem /tmp/drjit/ext/pybind11/include -fdiagnostics-color=always -O3 -DNDEBUG -fPIC -fvisibility=hidden   -fno-math-errno -ffp-contract=fast -fno-trapping-math -march=native -Wall -Wextra -Wno-unused-local-typedefs -flto -fno-fat-lto-objects -Os -fno-strict-aliasing -MD -MT src/python/CMakeFiles/drjit-python.dir/implicit.cpp.o -MF src/python/CMakeFiles/drjit-python.dir/implicit.cpp.o.d -o src/python/CMakeFiles/drjit-python.dir/implicit.cpp.o -c /tmp/drjit/src/python/implicit.cpp
In file included from /tmp/drjit/include/drjit/packet_intrin.h:44,
                 from /tmp/drjit/include/drjit/packet.h:16,
                 from /tmp/drjit/src/python/common.h:8,
                 from /tmp/drjit/src/python/implicit.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmiintrin.h:25:3: error: #error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~
In file included from /tmp/drjit/include/drjit/packet_intrin.h:48:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmi2intrin.h:25:3: error: #error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~
[13/22] Building CXX object src/python/CMakeFiles/drjit-python.dir/reinterpret.cpp.o
FAILED: src/python/CMakeFiles/drjit-python.dir/reinterpret.cpp.o
/usr/bin/c++ -DDRJIT_ENABLE_AUTODIFF=1 -DDRJIT_ENABLE_CUDA=1 -DDRJIT_ENABLE_JIT=1 -DDRJIT_UNROLL=" " -Ddrjit_python_EXPORTS -I/tmp/drjit/include -I/tmp/drjit/ext/drjit-core/include -I/tmp/drjit/ext/drjit-core/ext/nanothread/include -isystem /usr/include/python3.10 -isystem /tmp/drjit/ext/pybind11/include -fdiagnostics-color=always -O3 -DNDEBUG -fPIC -fvisibility=hidden   -fno-math-errno -ffp-contract=fast -fno-trapping-math -march=native -Wall -Wextra -Wno-unused-local-typedefs -flto -fno-fat-lto-objects -Os -fno-strict-aliasing -MD -MT src/python/CMakeFiles/drjit-python.dir/reinterpret.cpp.o -MF src/python/CMakeFiles/drjit-python.dir/reinterpret.cpp.o.d -o src/python/CMakeFiles/drjit-python.dir/reinterpret.cpp.o -c /tmp/drjit/src/python/reinterpret.cpp
In file included from /tmp/drjit/include/drjit/packet_intrin.h:44,
                 from /tmp/drjit/include/drjit/packet.h:16,
                 from /tmp/drjit/src/python/common.h:8,
                 from /tmp/drjit/src/python/reinterpret.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmiintrin.h:25:3: error: #error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~
In file included from /tmp/drjit/include/drjit/packet_intrin.h:48:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmi2intrin.h:25:3: error: #error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~
[14/22] Building CXX object src/python/CMakeFiles/drjit-python.dir/dlpack.cpp.o
FAILED: src/python/CMakeFiles/drjit-python.dir/dlpack.cpp.o
/usr/bin/c++ -DDRJIT_ENABLE_AUTODIFF=1 -DDRJIT_ENABLE_CUDA=1 -DDRJIT_ENABLE_JIT=1 -DDRJIT_UNROLL=" " -Ddrjit_python_EXPORTS -I/tmp/drjit/include -I/tmp/drjit/ext/drjit-core/include -I/tmp/drjit/ext/drjit-core/ext/nanothread/include -isystem /usr/include/python3.10 -isystem /tmp/drjit/ext/pybind11/include -fdiagnostics-color=always -O3 -DNDEBUG -fPIC -fvisibility=hidden   -fno-math-errno -ffp-contract=fast -fno-trapping-math -march=native -Wall -Wextra -Wno-unused-local-typedefs -flto -fno-fat-lto-objects -Os -fno-strict-aliasing -MD -MT src/python/CMakeFiles/drjit-python.dir/dlpack.cpp.o -MF src/python/CMakeFiles/drjit-python.dir/dlpack.cpp.o.d -o src/python/CMakeFiles/drjit-python.dir/dlpack.cpp.o -c /tmp/drjit/src/python/dlpack.cpp
In file included from /tmp/drjit/include/drjit/packet_intrin.h:44,
                 from /tmp/drjit/include/drjit/packet.h:16,
                 from /tmp/drjit/src/python/common.h:8,
                 from /tmp/drjit/src/python/dlpack.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmiintrin.h:25:3: error: #error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~
In file included from /tmp/drjit/include/drjit/packet_intrin.h:48:
/usr/lib/gcc/x86_64-linux-gnu/12/include/bmi2intrin.h:25:3: error: #error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
   25 | # error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
      |   ^~~~~

It seems that gcc dislike some intrinsic header file. But when build with clang(I use cmake .. -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++), there is no such error. Is there any ideas to fix this?

c8ef commented 2 years ago

This is what clang does:

[30/55] Building CXX object src/autodiff/CMakeFiles/drjit-autodiff-scalar-f32.dir/autodiff.cpp.o
In file included from /tmp/drjit/src/autodiff/autodiff.cpp:58:
/tmp/drjit/include/drjit/math.h:660:13: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
            IntMask(neq(x, zeros<Value>())) & neq(exponent_bits, exponent_mask);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                            &&
/tmp/drjit/include/drjit/math.h:1437:25: note: in instantiation of function template specialization 'drjit::frexp<float>' requested here
        auto [xm, xe] = frexp(xa);
                        ^
/tmp/drjit/include/drjit/autodiff.h:475:27: note: in instantiation of function template specialization 'drjit::cbrt<float>' requested here
            Type result = cbrt(m_value);
                          ^
/tmp/drjit/include/drjit/math.h:660:13: note: cast one or both operands to int to silence this warning
            IntMask(neq(x, zeros<Value>())) & neq(exponent_bits, exponent_mask);
            ^
1 warning generated.
[31/55] Building CXX object src/autodiff/CMakeFiles/drjit-autodiff-scalar-f64.dir/autodiff.cpp.o
In file included from /tmp/drjit/src/autodiff/autodiff.cpp:58:
/tmp/drjit/include/drjit/math.h:660:13: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
            IntMask(neq(x, zeros<Value>())) & neq(exponent_bits, exponent_mask);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                            &&
/tmp/drjit/include/drjit/math.h:1437:25: note: in instantiation of function template specialization 'drjit::frexp<double>' requested here
        auto [xm, xe] = frexp(xa);
                        ^
/tmp/drjit/include/drjit/autodiff.h:475:27: note: in instantiation of function template specialization 'drjit::cbrt<double>' requested here
            Type result = cbrt(m_value);
                          ^
/tmp/drjit/include/drjit/math.h:660:13: note: cast one or both operands to int to silence this warning
            IntMask(neq(x, zeros<Value>())) & neq(exponent_bits, exponent_mask);
            ^
1 warning generated.
[55/55] Generating ../../drjit/__init__.pyi

By the way, I found this issue when building the mitsuba3 renderer.🤣

merlinND commented 2 years ago

Hi @c8ef,

Could you please try cherry-picking the following patch and compile again? https://github.com/mitsuba-renderer/drjit/pull/55

@njroussel, if this works, I think we could merge that PR?

c8ef commented 2 years ago

Hi, After cherry-picking this patch, the project can be successfully built on my laptop with both gcc and clang.👌🏻 (sorry for reporting the issue that someone else has already reported)

njroussel commented 2 years ago

Thanks for reporting this for GCC 12 aswell @c8ef. This is now fixed with #55 (https://github.com/mitsuba-renderer/drjit/commit/942dfb5e7b56bfc86ec2a3a07a2535096ca7e87c).