-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove dependency to boost aligned allocation - remove boost in filenames which was providing aligned memory via boost implementations - add `AlignedAlloc.hpp`
- Loading branch information
1 parent
b3da237
commit 1be21fb
Showing
11 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* 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_COMP_MSVC | ||
return _aligned_malloc(size, alignment); | ||
#else | ||
return ::aligned_alloc(alignment, size); | ||
#endif | ||
} | ||
|
||
ALPAKA_FN_INLINE ALPAKA_FN_HOST | ||
void alignedFree(void* ptr) | ||
{ | ||
#if BOOST_COMP_MSVC | ||
_aligned_free(ptr); | ||
#else | ||
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)); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.