librascal
librascal copied to clipboard
Fails to build with Eigen 3.4
If the user has Eigen installed globally, we will pick the global install instead of downloading a different one: https://github.com/cosmo-epfl/librascal/blob/db2e2445d34c196c94731249061740123f9fbc28/cmake/rascalTools.cmake#L218
On macOS, the default Eigen distributed by homebrew is now 3.4.0, and the tests fail to build with this version. The error looks like this:
/Users/guillaume/code/librascal/tests/test_properties.cc:190:42: error: invalid operands to binary expression (‘typename internal::enable_if<internal::valid_indexed_view_overload<int, double>::value && internal::traits<typename ConstIndexedViewType<int, double>::type>::ReturnAsIndexedView, typename ConstIndexedViewType<int, double>::type>::type’ (aka ‘Eigen::IndexedView<const Eigen::Map<const Eigen::Matrix<double, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> >, Eigen::internal::SingleRange, double>’) and ‘double’)
BOOST_CHECK(values_2(0, counter) == counter);
...... 3000 lines of error
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:290:35: note: candidate template ignored: could not match 'MatrixBase<type-parameter-0-0>' against 'double'
EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase<OtherDerived>& other) const
^
If I comment out the block looking for a global Eigen in cmake/rascalTools.cmake
, Eigen 3.3 is downloaded, and I get the code to build.
Just to note this is still an issue, and now it interacts with src/rascal/math/kvec_generator.cc
spewing all sorts of incomprehensible garbage about a mysterious apparently-internal Eigen variable being outside of array bounds.
In lieu of making our code compatible with Eigen 3.4, the following quick-fix is easy to implement. Change this line: https://github.com/lab-cosmo/librascal/blob/5f6dd49c91e0e9750be3fbb1d601ec97cfac6097/CMakeLists.txt#L71 to:
add_external_package(Eigen3 IGNORE_SYSTEM VERSION 3.3.4 CONFIG)
and it will download and use the working version, regardless of what is installed on the system.
Here is the error message from compiling kvec_generator.cc
with Eigen 3.4, in case anyone likes inspecting runes:
In function ‘__m256d _mm256_loadu_pd(const double*)’,
inlined from ‘Packet Eigen::internal::ploadu(const typename unpacket_traits<T>::type*) [with Packet = __vector(4) double]’ at /usr/include/eigen3/Eigen/src/Core/arch/AVX/PacketMath.h:582:129,
inlined from ‘Packet Eigen::internal::ploadt(const typename unpacket_traits<T>::type*) [with Packet = __vector(4) double; int Alignment = 0]’ at /usr/include/eigen3/Eigen/src/Core/GenericPacketMath.h:969:26,
inlined from ‘PacketType Eigen::internal::evaluator<Eigen::PlainObjectBase<Derived> >::packet(Eigen::Index) const [with int LoadMode = 0; PacketType = __vector(4) double; Derived = Eigen::Matrix<double, 1, 3>]’ at /usr/include/eigen3/Eigen/src/Core/CoreEvaluators.h:245:40,
inlined from ‘void Eigen::internal::generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, Version>::assignPacket(Eigen::Index) [with int StoreMode = 32; int LoadMode = 0; PacketType = __vector(4) double; DstEvaluatorTypeT = Eigen::internal::evaluator<Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true> >; SrcEvaluatorTypeT = Eigen::internal::evaluator<Eigen::Matrix<double, 1, 3> >; Functor = Eigen::internal::assign_op<double, double>; int Version = 0]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:681:114,
inlined from ‘static void Eigen::internal::dense_assignment_loop<Kernel, 3, 0>::run(Kernel&) [with Kernel = Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true> >, Eigen::internal::evaluator<Eigen::Matrix<double, 1, 3> >, Eigen::internal::assign_op<double, double>, 0>]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:437:75,
inlined from ‘void Eigen::internal::call_dense_assignment_loop(DstXprType&, const SrcXprType&, const Functor&) [with DstXprType = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>; SrcXprType = Eigen::Matrix<double, 1, 3>; Functor = assign_op<double, double>]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:785:37,
inlined from ‘static void Eigen::internal::Assignment<DstXprType, SrcXprType, Functor, Eigen::internal::Dense2Dense, Weak>::run(DstXprType&, const SrcXprType&, const Functor&) [with DstXprType = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>; SrcXprType = Eigen::Matrix<double, 1, 3>; Functor = Eigen::internal::assign_op<double, double>; Weak = void]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:954:31,
inlined from ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>; Src = Eigen::Matrix<double, 1, 3>; Func = assign_op<double, double>]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:890:49,
inlined from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename enable_if<(! evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>; Src = Eigen::Matrix<double, 1, 3>; Func = assign_op<double, double>]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:858:27,
inlined from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>; Src = Eigen::Matrix<double, 1, 3>]’ at /usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:836:18,
inlined from ‘Derived& Eigen::MatrixBase<Derived>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 1, 3>; Derived = Eigen::Block<Eigen::Matrix<double, -1, -1, 1>, 1, -1, true>]’ at /usr/include/eigen3/Eigen/src/Core/Assign.h:66:28,
inlined from ‘rascal::math::Kvectors::Kvectors(double, Eigen::Matrix3d, bool, bool)’ at /local/scratch/mveit/codes/librascal/src/rascal/math/kvec_generator.cc:173:23:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/avxintrin.h:893:24: error: array subscript ‘__m256d_u[0]’ is partly outside array bounds of ‘Eigen::RowVector3d [1]’ {aka ‘Eigen::Matrix<double, 1, 3> [1]’} [-Werror=array-bounds]
893 | return *(__m256d_u *)__P;
| ^~~
/local/scratch/mveit/codes/librascal/src/rascal/math/kvec_generator.cc: In constructor ‘rascal::math::Kvectors::Kvectors(double, Eigen::Matrix3d, bool, bool)’:
/local/scratch/mveit/codes/librascal/src/rascal/math/kvec_generator.cc:154:22: note: object ‘kvec_new’ of size 24
154 | Eigen::RowVector3d kvec_new(0, 0, 0);
Update, now this seems to happen with Eigen 3.3 as well... I don't know what to do other than exclude kvec_generator.cc
from the build.
The error comes from -Werror=array-bounds
, so I would guess it is a question of the compiler which got better at this warning.
The simplest fix would be to remove -Werror
from the flags or add -Wno-array-bounds
when compiling with gcc
"got better"... well, that's debatable, depends on your definition of "better". I've checked the affected section of code several times and still don't understand where a potential out-of-bounds assignment would happen.
But since it seems to be coming from newer compiler versions, maybe this is something we need to keep an eye on, since more and more people will be upgrading their compilers and getting these confusing error messages. For the record, this was with gcc 11.2