Skip to content

Commit

Permalink
Merge pull request #37111 from trackreco/from-CMSSW_12_3_X_2022-02-28…
Browse files Browse the repository at this point in the history
…-1100_mkFit_X

[MkFit] round up size arguments to aligned_alloc upwards to align value.
  • Loading branch information
cmsbuild authored Mar 2, 2022
2 parents ced3550 + 4c2f7f8 commit 0ee444a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions RecoTracker/MkFitCore/src/HitStructures.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "RecoTracker/MkFitCore/interface/HitStructures.h"

#include "RecoTracker/MkFitCore/interface/IterationConfig.h"

#include "Matriplex/Memory.h"
#include "Ice/IceRevisitedRadix.h"

#include "Debug.h"
Expand All @@ -17,7 +17,7 @@ namespace mkfit {

#ifdef COPY_SORTED_HITS
void LayerOfHits::alloc_hits(int size) {
m_hits = (Hit *)std::aligned_alloc(64, sizeof(Hit) * size);
m_hits = (Hit *)Matriplex::aligned_alloc64(sizeof(Hit) * size);
m_capacity = size;
for (int ihit = 0; ihit < m_capacity; ihit++) {
m_hits[ihit] = Hit();
Expand Down
5 changes: 1 addition & 4 deletions RecoTracker/MkFitCore/src/Matriplex/MatriplexCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
#if defined(__x86_64__)
#include "immintrin.h"
#else
#include <stdlib.h>
#define _mm_malloc(a, b) aligned_alloc(b, a)
#define _mm_free(p) free(p)
#define _mm_prefetch(a, b) __builtin_prefetch(a)
#include <cstdlib>
#endif

#if defined(MPLEX_USE_INTRINSICS)
Expand Down
4 changes: 2 additions & 2 deletions RecoTracker/MkFitCore/src/Matriplex/MatriplexVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RecoTracker_MkFitCore_src_Matriplex_MatriplexVector_h

#include "Matriplex.h"

#include "Memory.h"
#include <vector>
#include <cassert>

Expand All @@ -18,7 +18,7 @@ namespace Matriplex {
typedef typename MP::value_type T;

public:
MatriplexVector(idx_t n) : fN(n) { fV = (MP*)std::aligned_alloc(64, sizeof(MP) * fN); }
MatriplexVector(idx_t n) : fN(n) { fV = (MP*)aligned_alloc64(sizeof(MP) * fN); }

~MatriplexVector() { std::free(fV); }

Expand Down
17 changes: 17 additions & 0 deletions RecoTracker/MkFitCore/src/Matriplex/Memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef RecoTracker_MkFitCore_src_Matriplex_Memory_h
#define RecoTracker_MkFitCore_src_Matriplex_Memory_h

#include <cstdlib>

namespace Matriplex {

constexpr std::size_t round_up_align64(std::size_t size) {
constexpr std::size_t mask = 64 - 1;
return size & mask ? (size & ~mask) + 64 : size;
}

inline void* aligned_alloc64(std::size_t size) { return std::aligned_alloc(64, round_up_align64(size)); }

} // namespace Matriplex

#endif
3 changes: 2 additions & 1 deletion RecoTracker/MkFitCore/src/Pool.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RecoTracker_MkFitCore_src_Pool_h
#define RecoTracker_MkFitCore_src_Pool_h

#include "Matriplex/Memory.h"
#include "oneapi/tbb/concurrent_queue.h"

namespace mkfit {
Expand Down Expand Up @@ -38,7 +39,7 @@ namespace mkfit {
}

private:
TT *create() { return new (std::aligned_alloc(64, sizeof(TT))) TT; };
TT *create() { return new (Matriplex::aligned_alloc64(sizeof(TT))) TT; };

void destroy(TT *x) {
x->~TT();
Expand Down

0 comments on commit 0ee444a

Please sign in to comment.