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

remove boost::aligned_alloc #1094

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/alpaka/acc/AccCpuFibers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <alpaka/atomic/AtomicStdLibLock.hpp>
#include <alpaka/atomic/AtomicHierarchy.hpp>
#include <alpaka/math/MathStdLib.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynBoostAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynAlignedAlloc.hpp>
#include <alpaka/block/shared/st/BlockSharedMemStMasterSync.hpp>
#include <alpaka/block/sync/BlockSyncBarrierFiber.hpp>
#include <alpaka/intrinsic/IntrinsicCpu.hpp>
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace alpaka
atomic::AtomicNoOp // thread atomics
>,
public math::MathStdLib,
public block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc,
public block::shared::dyn::BlockSharedMemDynAlignedAlloc,
public block::shared::st::BlockSharedMemStMasterSync,
public block::sync::BlockSyncBarrierFiber<TIdx>,
public intrinsic::IntrinsicCpu,
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace alpaka
atomic::AtomicNoOp // atomics between threads
>(),
math::MathStdLib(),
block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::dyn::BlockSharedMemDynAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::st::BlockSharedMemStMasterSync(
[this](){block::sync::syncBlockThreads(*this);},
[this](){return (m_masterFiberId == boost::this_fiber::get_id());}),
Expand Down
6 changes: 3 additions & 3 deletions include/alpaka/acc/AccCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <alpaka/atomic/AtomicOmpBuiltIn.hpp>
#include <alpaka/atomic/AtomicHierarchy.hpp>
#include <alpaka/math/MathStdLib.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynBoostAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynAlignedAlloc.hpp>
#include <alpaka/block/shared/st/BlockSharedMemStMasterSync.hpp>
#include <alpaka/block/sync/BlockSyncBarrierOmp.hpp>
#include <alpaka/intrinsic/IntrinsicCpu.hpp>
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace alpaka
atomic::AtomicOmpBuiltIn // thread atomics
>,
public math::MathStdLib,
public block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc,
public block::shared::dyn::BlockSharedMemDynAlignedAlloc,
public block::shared::st::BlockSharedMemStMasterSync,
public block::sync::BlockSyncBarrierOmp,
public intrinsic::IntrinsicCpu,
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace alpaka
atomic::AtomicOmpBuiltIn // atomics between threads
>(),
math::MathStdLib(),
block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::dyn::BlockSharedMemDynAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::st::BlockSharedMemStMasterSync(
[this](){block::sync::syncBlockThreads(*this);},
[](){return (::omp_get_thread_num() == 0);}),
Expand Down
6 changes: 3 additions & 3 deletions include/alpaka/acc/AccCpuOmp4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <alpaka/atomic/AtomicOmpBuiltIn.hpp>
#include <alpaka/atomic/AtomicHierarchy.hpp>
#include <alpaka/math/MathStdLib.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynBoostAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynAlignedAlloc.hpp>
#include <alpaka/block/shared/st/BlockSharedMemStMasterSync.hpp>
#include <alpaka/block/sync/BlockSyncBarrierOmp.hpp>
#include <alpaka/intrinsic/IntrinsicCpu.hpp>
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace alpaka
atomic::AtomicOmpBuiltIn // thread atomics
>,
public math::MathStdLib,
public block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc,
public block::shared::dyn::BlockSharedMemDynAlignedAlloc,
public block::shared::st::BlockSharedMemStMasterSync,
public block::sync::BlockSyncBarrierOmp,
public intrinsic::IntrinsicCpu,
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace alpaka
atomic::AtomicOmpBuiltIn // atomics between threads
>(),
math::MathStdLib(),
block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::dyn::BlockSharedMemDynAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::st::BlockSharedMemStMasterSync(
[this](){block::sync::syncBlockThreads(*this);},
[](){return (::omp_get_thread_num() == 0);}),
Expand Down
6 changes: 3 additions & 3 deletions include/alpaka/acc/AccCpuThreads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <alpaka/atomic/AtomicStdLibLock.hpp>
#include <alpaka/atomic/AtomicHierarchy.hpp>
#include <alpaka/math/MathStdLib.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynBoostAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynAlignedAlloc.hpp>
#include <alpaka/block/shared/st/BlockSharedMemStMasterSync.hpp>
#include <alpaka/block/sync/BlockSyncBarrierThread.hpp>
#include <alpaka/intrinsic/IntrinsicCpu.hpp>
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace alpaka
atomic::AtomicStdLibLock<16> // thread atomics
>,
public math::MathStdLib,
public block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc,
public block::shared::dyn::BlockSharedMemDynAlignedAlloc,
public block::shared::st::BlockSharedMemStMasterSync,
public block::sync::BlockSyncBarrierThread<TIdx>,
public intrinsic::IntrinsicCpu,
Expand Down Expand Up @@ -109,7 +109,7 @@ namespace alpaka
atomic::AtomicStdLibLock<16> // atomics between threads
>(),
math::MathStdLib(),
block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::dyn::BlockSharedMemDynAlignedAlloc(static_cast<std::size_t>(blockSharedMemDynSizeBytes)),
block::shared::st::BlockSharedMemStMasterSync(
[this](){block::sync::syncBlockThreads(*this);},
[this](){return (m_idMasterThread == std::this_thread::get_id());}),
Expand Down
5 changes: 3 additions & 2 deletions include/alpaka/alpaka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//-----------------------------------------------------------------------------
// dynamic
#include <alpaka/block/shared/dyn/BlockSharedMemDynUniformCudaHipBuiltIn.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynBoostAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynAlignedAlloc.hpp>
#include <alpaka/block/shared/dyn/BlockSharedMemDynMember.hpp>
#include <alpaka/block/shared/dyn/Traits.hpp>
//-----------------------------------------------------------------------------
Expand All @@ -67,6 +67,7 @@
// core
#include <alpaka/core/Assert.hpp>
#include <alpaka/core/Align.hpp>
#include <alpaka/core/AlignedAlloc.hpp>
#include <alpaka/core/BarrierThread.hpp>
#include <alpaka/core/BoostPredef.hpp>
#include <alpaka/core/ClipCast.hpp>
Expand Down Expand Up @@ -130,7 +131,7 @@
#include <alpaka/math/MathStdLib.hpp>
//-----------------------------------------------------------------------------
// mem
#include <alpaka/mem/alloc/AllocCpuBoostAligned.hpp>
#include <alpaka/mem/alloc/AllocCpuAligned.hpp>
#include <alpaka/mem/alloc/AllocCpuNew.hpp>
#include <alpaka/mem/alloc/Traits.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
#include <alpaka/core/Vectorize.hpp>
#include <alpaka/block/shared/dyn/Traits.hpp>

#include <alpaka/core/AlignedAlloc.hpp>
#include <alpaka/core/Common.hpp>

#include <boost/align.hpp>

#include <vector>
#include <memory>

Expand All @@ -29,35 +28,35 @@ namespace alpaka
{
//#############################################################################
//! The block shared dynamic memory allocator without synchronization.
class BlockSharedMemDynBoostAlignedAlloc : public concepts::Implements<ConceptBlockSharedDyn, BlockSharedMemDynBoostAlignedAlloc>
class BlockSharedMemDynAlignedAlloc : public concepts::Implements<ConceptBlockSharedDyn, BlockSharedMemDynAlignedAlloc>
{
public:
//-----------------------------------------------------------------------------
BlockSharedMemDynBoostAlignedAlloc(
BlockSharedMemDynAlignedAlloc(
std::size_t const & blockSharedMemDynSizeBytes)
{
if(blockSharedMemDynSizeBytes > 0u)
{
m_blockSharedMemDyn.reset(
reinterpret_cast<uint8_t *>(
boost::alignment::aligned_alloc(core::vectorization::defaultAlignment, blockSharedMemDynSizeBytes)));
core::alignedAlloc(core::vectorization::defaultAlignment, blockSharedMemDynSizeBytes)));
}
}
//-----------------------------------------------------------------------------
BlockSharedMemDynBoostAlignedAlloc(BlockSharedMemDynBoostAlignedAlloc const &) = delete;
BlockSharedMemDynAlignedAlloc(BlockSharedMemDynAlignedAlloc const &) = delete;
//-----------------------------------------------------------------------------
BlockSharedMemDynBoostAlignedAlloc(BlockSharedMemDynBoostAlignedAlloc &&) = delete;
BlockSharedMemDynAlignedAlloc(BlockSharedMemDynAlignedAlloc &&) = delete;
//-----------------------------------------------------------------------------
auto operator=(BlockSharedMemDynBoostAlignedAlloc const &) -> BlockSharedMemDynBoostAlignedAlloc & = delete;
auto operator=(BlockSharedMemDynAlignedAlloc const &) -> BlockSharedMemDynAlignedAlloc & = delete;
//-----------------------------------------------------------------------------
auto operator=(BlockSharedMemDynBoostAlignedAlloc &&) -> BlockSharedMemDynBoostAlignedAlloc & = delete;
auto operator=(BlockSharedMemDynAlignedAlloc &&) -> BlockSharedMemDynAlignedAlloc & = delete;
//-----------------------------------------------------------------------------
/*virtual*/ ~BlockSharedMemDynBoostAlignedAlloc() = default;
/*virtual*/ ~BlockSharedMemDynAlignedAlloc() = default;

public:
std::unique_ptr<
uint8_t,
boost::alignment::aligned_delete> mutable
core::AlignedDelete> mutable
m_blockSharedMemDyn; //!< Block shared dynamic memory.
};

Expand All @@ -72,11 +71,11 @@ namespace alpaka
typename T>
struct GetMem<
T,
BlockSharedMemDynBoostAlignedAlloc>
BlockSharedMemDynAlignedAlloc>
{
//-----------------------------------------------------------------------------
ALPAKA_FN_HOST static auto getMem(
block::shared::dyn::BlockSharedMemDynBoostAlignedAlloc const & blockSharedMemDyn)
block::shared::dyn::BlockSharedMemDynAlignedAlloc const & blockSharedMemDyn)
-> T *
{
static_assert(
Expand Down
7 changes: 3 additions & 4 deletions include/alpaka/block/shared/st/BlockSharedMemStMasterSync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
#include <alpaka/core/Vectorize.hpp>
#include <alpaka/block/shared/st/Traits.hpp>

#include <alpaka/core/AlignedAlloc.hpp>
#include <alpaka/core/Common.hpp>

#include <boost/align.hpp>

#include <vector>
#include <memory>
#include <functional>
Expand Down Expand Up @@ -57,7 +56,7 @@ namespace alpaka
std::vector<
std::unique_ptr<
uint8_t,
boost::alignment::aligned_delete>> mutable
core::AlignedDelete>> mutable
m_sharedAllocs;

std::function<void()> m_syncFn;
Expand Down Expand Up @@ -93,7 +92,7 @@ namespace alpaka
{
blockSharedMemSt.m_sharedAllocs.emplace_back(
reinterpret_cast<uint8_t *>(
boost::alignment::aligned_alloc(alignmentInBytes, sizeof(T))));
core::alignedAlloc(alignmentInBytes, sizeof(T))));
}
blockSharedMemSt.m_syncFn();

Expand Down
7 changes: 3 additions & 4 deletions include/alpaka/block/shared/st/BlockSharedMemStNoSync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
#include <alpaka/core/Vectorize.hpp>
#include <alpaka/block/shared/st/Traits.hpp>

#include <alpaka/core/AlignedAlloc.hpp>
#include <alpaka/core/Common.hpp>

#include <boost/align.hpp>

#include <vector>
#include <memory>

Expand Down Expand Up @@ -51,7 +50,7 @@ namespace alpaka
std::vector<
std::unique_ptr<
uint8_t,
boost::alignment::aligned_delete>> mutable
core::AlignedDelete>> mutable
m_sharedAllocs;
};

Expand Down Expand Up @@ -79,7 +78,7 @@ namespace alpaka

blockSharedMemSt.m_sharedAllocs.emplace_back(
reinterpret_cast<uint8_t *>(
boost::alignment::aligned_alloc(alignmentInBytes, sizeof(T))));
core::alignedAlloc(alignmentInBytes, sizeof(T))));
return
std::ref(
*reinterpret_cast<T*>(
Expand Down
72 changes: 72 additions & 0 deletions include/alpaka/core/AlignedAlloc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Copyright 2020 René Widera
*
* This file is part of alpaka.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

#include <alpaka/core/BoostPredef.hpp>
#include <alpaka/core/Common.hpp>

#if BOOST_COMP_MSVC
#include <malloc.h>
#else
#include <cstdlib>
#endif

namespace alpaka
{
namespace core
{
//-----------------------------------------------------------------------------
//! Rounds to the next higher power of two (if not already power of two).
// Adapted from llvm/ADT/SmallPtrSet.h
ALPAKA_FN_INLINE ALPAKA_FN_HOST
void* alignedAlloc(size_t alignment, size_t size)
{
#if BOOST_OS_WINDOWS
return _aligned_malloc(size, alignment);
#elif BOOST_OS_MACOS
void * ptr = nullptr;
posix_memalign(&ptr, alignment, size);
return ptr;
#else
// the amount of bytes to allocate must be a multiple of the alignment
size_t sizeToAllocate = ((size + alignment - 1u) / alignment) * alignment;
return ::aligned_alloc(alignment, sizeToAllocate);
#endif
}

ALPAKA_FN_INLINE ALPAKA_FN_HOST
void alignedFree(void* ptr)
{
#if BOOST_OS_WINDOWS
_aligned_free(ptr);
#else
// linux and macos
free(ptr);
#endif
}

//#############################################################################
//! destroy aligned object and free aligned memory
struct AlignedDelete
{
constexpr AlignedDelete() = default;

//-----------------------------------------------------------------------------
//! Calls ~T() on ptr to destroy the object and then calls aligned_free to free the allocated memory.
template<typename T>
void operator()(T* ptr) const
{
if (ptr)
ptr->~T();
alignedFree(reinterpret_cast<void*>(ptr));
}
};
}
}
Loading