Skip to content
Snippets Groups Projects
Commit 7a981570 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'aligned_vector.CxxUtils-20200302' into 'master'

CxxUtils: Add aligned_vector.

See merge request atlas/athena!30798
parents df06b470 186be0ec
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,7 @@ foreach( test sincos_test copyif_test ArrayScanner_test Arrayrep_test
CachedValue_test CachedPointer_test CachedUniquePtr_test
atomic_fetch_minmax_test
MurmurHash2_test bitmask_test crc64_test Ring_test
restrict_test vectorize_test get_unaligned_test )
restrict_test vectorize_test get_unaligned_test aligned_vector_test )
atlas_add_test( ${test}
SOURCES test/${test}.cxx
LOG_IGNORE_PATTERN "no version information available"
......
// This file's extension implies that it's C, but it's really -*- C++ -*-.
/*
* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
*/
/**
* @file CxxUtils/aligned_vector.h
* @author scott snyder <snyder@bnl.gov>
* @date Feb, 2020
* @brief @c std::vector with extra alignment.
*
* The payload of a @c std::vector<T> is aligned appropriately for @c T.
* However, there are some times when one would like to force a larger
* alignment, for example if the vector is being used to hold data
* to be processed with vector instructions. @c aligned_vector
* defined here is a @c std::vector with higher alignment.
* @c vec_aligned_vector is a vector that should be sufficiently
* aligned for any vector instructions on this platform.
*/
#ifndef CXXUTILS_ALIGNED_VECTOR_H
#define CXXUTILS_ALIGNED_VECTOR_H
#include "boost/align/aligned_allocator.hpp"
#include <vector>
namespace CxxUtils {
/**
* @brief A @c std::vector with extra alignment.
*
* The alignment for the payload will be at least either that required by @c T
* or @c Alignment, whichever is greater.
*/
template <class T, size_t Alignment=1>
using aligned_vector = std::vector<T, boost::alignment::aligned_allocator<T, Alignment> >;
/**
* @brief A @c std::vector with alignment sufficienct for any vector
* instructions on this platform.
*
* For now, just hardcode 64, which is sufficient for a 512-bit vector,
* the largest supported by any x86 processors. We may want to make this
* platform-dependent in the future.
*/
template <class T>
using vec_aligned_vector = aligned_vector<T, 64>;
} // namespace CxxUtils
#endif // not CXXUTILS_ALIGNED_VECTOR_H
test1
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
/**
* @file CxxUtils/test/aligned_vector_test.cxx
* @author scott snyder <snyder@bnl.gov>
* @date Feb, 2020
* @brief Unit test for aligned_vector.
*/
#undef NDEBUG
#include "CxxUtils/aligned_vector.h"
#include <cassert>
#include <iostream>
template <size_t N>
void testone()
{
std::vector<CxxUtils::aligned_vector<float, N> > v;
v.resize (10);
for (auto& vv : v) {
vv.resize (10);
assert ((reinterpret_cast<unsigned long>(vv.data()) & (N-1)) == 0);
}
}
void test1()
{
std::cout << "test1\n";
testone<4>();
testone<8>();
testone<16>();
testone<32>();
testone<64>();
testone<128>();
testone<256>();
testone<512>();
testone<1024>();
testone<2048>();
testone<4096>();
testone<8192>();
testone<16384>();
testone<32768>();
testone<65536>();
}
int main()
{
test1();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment