23 #if !defined(NRN_SOA_BYTE_ALIGN)
26 #define NRN_SOA_BYTE_ALIGN (8 * sizeof(double))
70 template <
typename T,
typename U>
75 template <
typename T,
typename U>
88 template <
typename Alloc>
94 using pointer =
typename std::allocator_traits<Alloc>::pointer;
98 std::allocator_traits<Alloc>::destroy(aa, std::addressof(*
p));
99 std::allocator_traits<Alloc>::deallocate(aa,
p, 1);
106 template <
typename T,
typename Alloc,
typename... Args>
108 using AT = std::allocator_traits<Alloc>;
109 static_assert(std::is_same<
typename AT::value_type, std::remove_cv_t<T>>{}(),
110 "Allocator has the wrong value_type");
113 auto p = AT::allocate(a, 1);
115 AT::construct(a, std::addressof(*
p), std::forward<Args>(args)...);
117 return std::unique_ptr<T, D>(
p,
D(a));
119 AT::deallocate(a,
p, 1);
126 #ifdef CORENEURON_UNIFIED_MEMORY
128 #include <cuda_runtime_api.h>
131 inline void alloc_memory(
void*& pointer,
size_t num_bytes,
size_t ) {
132 cudaMallocManaged(&pointer, num_bytes);
135 inline void calloc_memory(
void*& pointer,
size_t num_bytes,
size_t ) {
137 cudaMemset(pointer, 0, num_bytes);
153 void*
operator new(
size_t len) {
155 cudaMallocManaged(&ptr, len);
156 cudaDeviceSynchronize();
160 void*
operator new[](
size_t len) {
162 cudaMallocManaged(&ptr, len);
163 cudaDeviceSynchronize();
167 void operator delete(
void* ptr) {
168 cudaDeviceSynchronize();
172 void operator delete[](
void* ptr) {
173 cudaDeviceSynchronize();
187 inline void alloc_memory(
void*& pointer,
size_t num_bytes,
size_t alignment) {
190 if (num_bytes % alignment != 0) {
191 size_t multiple = num_bytes / alignment;
192 fill = alignment * (multiple + 1) - num_bytes;
195 pointer = aligned_alloc(alignment, num_bytes + fill);
200 fprintf(stderr,
"Windows has no std::aligned_alloc\n");
201 nrn_assert((pointer = std::malloc(num_bytes)) !=
nullptr);
204 nrn_assert((pointer = std::malloc(num_bytes)) !=
nullptr);
208 inline void calloc_memory(
void*& pointer,
size_t num_bytes,
size_t alignment) {
210 memset(pointer, 0, num_bytes);
229 inline int soa_padded_size(
int cnt,
int layout) {
234 return ((
cnt + chunk - 1) / chunk) * chunk;
237 return ((
cnt + chunk - 1) / chunk) * chunk;
243 inline bool is_aligned(
void* pointer, std::size_t alignment) {
244 return (
reinterpret_cast<std::uintptr_t
>(pointer) % alignment) == 0;
257 if (alignment != 0) {
280 if (alignment != 0) {
for gpu builds with unified memory support
void free_memory(void *pointer)
void alloc_memory(void *&pointer, size_t num_bytes, size_t alignment)
#define NRN_SOA_BYTE_ALIGN
void calloc_memory(void *&pointer, size_t num_bytes, size_t alignment)
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void * emalloc_align(size_t size, size_t alignment)
void * allocate_unified(std::size_t num_bytes)
void * ecalloc_align(size_t n, size_t size, size_t alignment)
void deallocate_unified(void *ptr, std::size_t num_bytes)
In mechanism libraries, cannot use auto const token = nrn_ensure_model_data_are_sorted(); because the...
auto allocate_unique(const Alloc &alloc, Args &&... args)
bool operator==(unified_allocator< T > const &, unified_allocator< U > const &) noexcept
bool operator!=(unified_allocator< T > const &x, unified_allocator< U > const &y) noexcept
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
int const size_t const size_t n
Allocator-aware deleter for use with std::unique_ptr.
typename std::allocator_traits< Alloc >::pointer pointer
alloc_deleter(const Alloc &a)
void operator()(pointer p) const
C++ allocator that uses [de]allocate_unified.
unified_allocator()=default
unified_allocator(unified_allocator< U > const &) noexcept
value_type * allocate(std::size_t n)
void deallocate(value_type *p, std::size_t n) noexcept