Project
Loading...
Searching...
No Matches
GPUCommonAlignedAlloc.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUCOMMONAKUGBEDALLOC_H
16#define GPUCOMMONAKUGBEDALLOC_H
17
18#include <memory>
19
20namespace o2::gpu
21{
22
23template <typename T, std::size_t MIN_ALIGN = 0>
25 void operator()(void* ptr) { ::operator delete(ptr, std::align_val_t(std::max(MIN_ALIGN, alignof(T)))); }; // TODO: Make this static once we go to C++ 23
26};
27
28template <typename T, std::size_t MIN_ALIGN = 0>
30 using value_type = T;
31 static T* allocate(std::size_t n)
32 {
33 return (T*)::operator new(n, std::align_val_t(std::max(MIN_ALIGN, alignof(T))));
34 }
35 static void deallocate(T* ptr, std::size_t)
36 {
38 }
39};
40
41template <typename T>
42struct aligned_unique_buffer_ptr : public std::unique_ptr<char[], alignedDeleter<T>> {
45 aligned_unique_buffer_ptr(T* ptr) { std::unique_ptr<char[], alignedDeleter<T>>::reset((char*)ptr); }
46 char* getraw() { return std::unique_ptr<char[], alignedDeleter<T>>::get(); }
47 const char* getraw() const { return std::unique_ptr<char[], alignedDeleter<T>>::get(); }
48 T* get() { return (T*)std::unique_ptr<char[], alignedDeleter<T>>::get(); }
49 const T* get() const { return (T*)std::unique_ptr<char[], alignedDeleter<T>>::get(); }
50 T* operator->() { return get(); }
51 const T* operator->() const { return get(); }
52 T* alloc(std::size_t n)
53 {
54 std::unique_ptr<char[], alignedDeleter<T>>::reset((char*)alignedAllocator<T>().allocate(n));
55 return get();
56 }
57};
58
59} // namespace o2::gpu
60
61#endif // GPUCOMMONAKUGBEDALLOC_H
TBranch * ptr
GLdouble n
Definition glcorearb.h:1982
static void deallocate(T *ptr, std::size_t)
static T * allocate(std::size_t n)