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

[MkFit] round up size arguments to aligned_alloc upwards to align value. #37111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions RecoTracker/MkFitCore/src/HitStructures.cc
@@ -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
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
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
@@ -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
@@ -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