Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProxQP on old Clang/GCC #253

Closed
costashatz opened this issue Aug 8, 2023 · 8 comments
Closed

ProxQP on old Clang/GCC #253

costashatz opened this issue Aug 8, 2023 · 8 comments

Comments

@costashatz
Copy link
Contributor

costashatz commented Aug 8, 2023

Hello guys,

Thanks for the great work! I have been very satisfied by this solver so far.

I am having trouble getting it compiled in old compilers. Long story but I need to compile it with clang5. I am getting many errors related to std::launder, std::aligned_alloc, etc..

I am attaching a Dockerfile with the system that I need ProxQP to compile with. I hope this will help you to fix the compilation errors.

Any help will be appreciated.

Thanks in advance!

@jcarpent
Copy link
Member

jcarpent commented Aug 9, 2023

I've tried, but there are many places where the code needs to be changed and at some point, I think those compilers are not fully compatible with C++14 or C++17.
@costashatz Why you cannot select a more recent compiler? This point is not clear to me.

@jcarpent
Copy link
Member

jcarpent commented Aug 9, 2023

Looking closely at the issue, it seems to be a bug of clang-5 with respect to null pointer deferencing:

note: read of dereferenced null pointer is not allowed in a constant expression

@costashatz
Copy link
Contributor Author

costashatz commented Aug 10, 2023

Thanks a lot for the investigation so far.

So I managed to update to Clang 7.1.0 and gcc 7.3.1 (that's the most that I can go). More specifically:

g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

clang version 7.1.0, Target: x86_64-unknown-linux-gnu

I am still getting errors like the following:

In file included from proxsuite/examples/cpp/first_example_dense.cpp:7:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/dense/dense.hpp:8:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/dense/wrapper.hpp:10:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/dense/solver.hpp:13:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/dense/linesearch.hpp:9:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/dense/model.hpp:11:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/proxqp/sparse/model.hpp:9:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/sparse/core.hpp:9:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/veg/memory/dynamic_stack.hpp:6:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/veg/internal/collection_algo.hpp:4:
In file included from /workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/veg/memory/alloc.hpp:10:
/workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/veg/memory/placement.hpp:63:35: error: no member named 'launder' in namespace 'std'
  const VEG_NOEXCEPT->T* { return VEG_LAUNDER(mem); }
                                  ^~~~~~~~~~~~~~~~
/workdir/proxsuite/build/install/lib/pkgconfig/../../include/proxsuite/linalg/veg/memory/placement.hpp:46:32: note: expanded from macro 'VEG_LAUNDER'
#define VEG_LAUNDER(p) (::std::launder(p))
                        ~~~~~~~^

I am using this command to compile the example: clang++ -O3 -march=native -DNDEBUG -std=gnu++17 proxsuite/examples/cpp/first_example_dense.cpp -o first_example_dense $(pkg-config --cflags proxsuite)

I have built proxsuite from source with cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DBUILD_WITH_VECTORIZATION_SUPPORT=OFF. Also, I get exactly the same errors with g++.

A Dockerfile to reproduce is:

FROM mottosso/mayabase-centos7

# Expose ninja, cmake3
RUN yum install -y http://repo.okay.com.mx/centos/7/x86_64/release/okay-release-1-1.noarch.rpm

# Build dependencies
RUN yum install -y centos-release-scl centos-release-scl-rh scl-utils
RUN yum install -y \
    ninja-build \
    cmake3 \
    libXt-devel \
    freeglut-devel \
    devtoolset-7

RUN ln -s /usr/bin/cmake3 /usr/bin/cmake

ENV CC=/opt/rh/devtoolset-7/root/usr/bin/gcc
ENV CXX=/opt/rh/devtoolset-7/root/usr/bin/g++

Update: (@jcarpent @Bambade) There is a difference between compilers:

clang gives the above error, while g++ gives the following:

/workdir/proxsuite/build/install/lib64/pkgconfig/../../include/proxsuite/linalg/veg/memory/alloc.hpp:175:15: error: 'aligned_alloc' is not a member of 'std'
   return std::aligned_alloc(align, (size + mask) & ~mask);

By the way (although it cannot solve my issue), if I use devtoolset-11 (gcc 11.2) and clang11 everything works like a charm, but I cannot use this version of the compiler.

@costashatz
Copy link
Contributor Author

costashatz commented Aug 10, 2023

Making the following patch:

diff --git a/include/proxsuite/linalg/veg/memory/alloc.hpp b/include/proxsuite/linalg/veg/memory/alloc.hpp
index 4c9056847..3ed961ad9 100644
--- a/include/proxsuite/linalg/veg/memory/alloc.hpp
+++ b/include/proxsuite/linalg/veg/memory/alloc.hpp
@@ -171,7 +171,7 @@ aligned_alloc(usize align, usize size) noexcept -> void*
   return alignment::detail::aligned_alloc(align, (size + mask) & ~mask);
 #endif
 #else
-#ifdef PROXSUITE_WITH_CPP_17
+#if defined(PROXSUITE_WITH_CPP_17) && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
   return std::aligned_alloc(align, (size + mask) & ~mask);
 #else
   return alignment::detail::aligned_alloc(align, (size + mask) & ~mask);
diff --git a/include/proxsuite/linalg/veg/memory/placement.hpp b/include/proxsuite/linalg/veg/memory/placement.hpp
index 0ec1708cf..cb1afbc8a 100644
--- a/include/proxsuite/linalg/veg/memory/placement.hpp
+++ b/include/proxsuite/linalg/veg/memory/placement.hpp
@@ -41,7 +41,7 @@
 
 #if VEG_HAS_BUILTIN(__builtin_launder) || __GNUC__ >= 7
 #define VEG_LAUNDER(p) (__builtin_launder(p))
-#elif defined(VEG_WITH_CXX17_SUPPORT)
+#elif defined(VEG_WITH_CXX17_SUPPORT) && __GNUC__ >= 6
 #include <new>
 #define VEG_LAUNDER(p) (::std::launder(p))
 #else

I was able to make ProxSuite compile and run using both g++ and clang. I am not sure if the patch is good but checking just for c++17 seems to not be enough.

@jcarpent
Copy link
Member

@costashatz Could you open a PR? Your fix looks good to me.

@costashatz
Copy link
Contributor Author

@costashatz Could you open a PR? Your fix looks good to me.

Sure. Here it is: #255

@costashatz
Copy link
Contributor Author

Partly solved by #255.. clang5/gcc 4.8 are too old for ProxQP.

@costashatz
Copy link
Contributor Author

Thanks a lot @jcarpent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants