Skip to content

Commit

Permalink
Merge pull request #33355 from VinInn/SilenceClangWarning
Browse files Browse the repository at this point in the history
Solve vectorization issue by forcing inlining and Silence CLANG Warning by making pragma optional
  • Loading branch information
cmsbuild authored Apr 8, 2021
2 parents 2baff3b + 57d7dfd commit 55c4efe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
25 changes: 13 additions & 12 deletions DataFormats/Math/interface/choleskyInversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace math {
namespace cholesky {

template <typename M1, typename M2>
inline constexpr void invert11(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert11(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
dst(0, 0) = F(1.0) / src(0, 0);
}

template <typename M1, typename M2>
inline constexpr void invert22(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert22(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
auto luc0 = F(1.0) / src(0, 0);
auto luc1 = src(1, 0) * src(1, 0) * luc0;
Expand All @@ -40,7 +40,7 @@ namespace math {
}

template <typename M1, typename M2>
inline constexpr void invert33(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert33(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
auto luc0 = F(1.0) / src(0, 0);
auto luc1 = src(1, 0);
Expand All @@ -64,7 +64,7 @@ namespace math {
}

template <typename M1, typename M2>
inline constexpr void invert44(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert44(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
auto luc0 = F(1.0) / src(0, 0);
auto luc1 = src(1, 0);
Expand Down Expand Up @@ -100,7 +100,7 @@ namespace math {
}

template <typename M1, typename M2>
inline constexpr void invert55(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert55(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
auto luc0 = F(1.0) / src(0, 0);
auto luc1 = src(1, 0);
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace math {
}

template <typename M1, typename M2>
inline __attribute__((always_inline)) constexpr void invert66(M1 const& src, M2& dst) {
inline constexpr void __attribute__((always_inline)) invert66(M1 const& src, M2& dst) {
using F = decltype(src(0, 0));
auto luc0 = F(1.0) / src(0, 0);
auto luc1 = src(1, 0);
Expand Down Expand Up @@ -297,47 +297,48 @@ namespace math {

template <typename M1, typename M2>
struct Inverter<M1, M2, 2> {
static constexpr void eval(M1 const& src, M2& dst) {
static constexpr void __attribute__((always_inline)) eval(M1 const& src, M2& dst) {
invert22(src, dst);
symmetrize22(dst);
}
};

template <typename M1, typename M2>
struct Inverter<M1, M2, 3> {
static constexpr void eval(M1 const& src, M2& dst) {
static constexpr void __attribute__((always_inline)) eval(M1 const& src, M2& dst) {
invert33(src, dst);
symmetrize33(dst);
}
};

template <typename M1, typename M2>
struct Inverter<M1, M2, 4> {
static constexpr void eval(M1 const& src, M2& dst) {
static constexpr void __attribute__((always_inline)) eval(M1 const& src, M2& dst) {
invert44(src, dst);
symmetrize44(dst);
}
};

template <typename M1, typename M2>
struct Inverter<M1, M2, 5> {
static constexpr void eval(M1 const& src, M2& dst) {
static constexpr void __attribute__((always_inline)) eval(M1 const& src, M2& dst) {
invert55(src, dst);
symmetrize55(dst);
}
};

template <typename M1, typename M2>
struct Inverter<M1, M2, 6> {
static constexpr void eval(M1 const& src, M2& dst) {
static constexpr void __attribute__((always_inline)) eval(M1 const& src, M2& dst) {
invert66(src, dst);
symmetrize66(dst);
}
};

// Eigen interface
template <typename D1, typename D2>
inline constexpr void invert(Eigen::DenseBase<D1> const& src, Eigen::DenseBase<D2>& dst) {
inline constexpr void __attribute__((always_inline))
invert(Eigen::DenseBase<D1> const& src, Eigen::DenseBase<D2>& dst) {
using M1 = Eigen::DenseBase<D1>;
using M2 = Eigen::DenseBase<D2>;
Inverter<M1, M2, M2::ColsAtCompileTime>::eval(src, dst);
Expand Down
7 changes: 7 additions & 0 deletions DataFormats/Math/test/CholeskyInvert_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,23 @@ void go(bool soa) {
for (int kk = 0; kk < NKK; ++kk) {
delta -= (std::chrono::high_resolution_clock::now() - start);
if (soa)
#ifdef USE_VECTORIZATION_PRAGMA
#pragma GCC ivdep
#ifdef __clang__
#pragma clang loop vectorize(enable) interleave(enable)
#endif
#endif
for (unsigned int i = 0; i < SIZE; ++i) {
MapMX<N> m(p + i);
math::cholesky::invert(m, m);
}
else
#ifdef USE_VECTORIZATION_PRAGMA
#pragma GCC ivdep
#ifdef __clang__
#pragma clang loop vectorize(enable) interleave(enable)
#endif
#endif
for (auto& m : mm) {
math::cholesky::invert(m, m);
}
Expand Down

0 comments on commit 55c4efe

Please sign in to comment.