CMS 3D CMS Logo

host_unique_ptr.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_interface_host_unique_ptr_h
2 #define HeterogeneousCore_CUDAUtilities_interface_host_unique_ptr_h
3 
4 #include <memory>
5 #include <functional>
6 
8 
9 namespace cms {
10  namespace cuda {
11  namespace host {
12  namespace impl {
13  // Additional layer of types to distinguish from host::unique_ptr
14  class HostDeleter {
15  public:
16  void operator()(void *ptr) { cms::cuda::free_host(ptr); }
17  };
18  } // namespace impl
19 
20  template <typename T>
21  using unique_ptr = std::unique_ptr<T, impl::HostDeleter>;
22 
23  namespace impl {
24  template <typename T>
27  };
28  template <typename T>
31  };
32  template <typename T, size_t N>
34  struct bounded_array {};
35  };
36  } // namespace impl
37  } // namespace host
38 
39  // Allocate pinned host memory
40  template <typename T>
43  "Allocating with non-trivial constructor on the pinned host memory is not supported");
44  void *mem = allocate_host(sizeof(T), stream);
45  return typename host::impl::make_host_unique_selector<T>::non_array{reinterpret_cast<T *>(mem)};
46  }
47 
48  template <typename T>
50  using element_type = typename std::remove_extent<T>::type;
52  "Allocating with non-trivial constructor on the pinned host memory is not supported");
53  void *mem = allocate_host(n * sizeof(element_type), stream);
54  return typename host::impl::make_host_unique_selector<T>::unbounded_array{reinterpret_cast<element_type *>(mem)};
55  }
56 
57  template <typename T, typename... Args>
58  typename host::impl::make_host_unique_selector<T>::bounded_array make_host_unique(Args &&...) = delete;
59 
60  // No check for the trivial constructor, make it clear in the interface
61  template <typename T>
63  void *mem = allocate_host(sizeof(T), stream);
64  return typename host::impl::make_host_unique_selector<T>::non_array{reinterpret_cast<T *>(mem)};
65  }
66 
67  template <typename T>
69  size_t n, cudaStream_t stream) {
70  using element_type = typename std::remove_extent<T>::type;
71  void *mem = allocate_host(n * sizeof(element_type), stream);
72  return typename host::impl::make_host_unique_selector<T>::unbounded_array{reinterpret_cast<element_type *>(mem)};
73  }
74 
75  template <typename T, typename... Args>
76  typename host::impl::make_host_unique_selector<T>::bounded_array make_host_unique_uninitialized(Args &&...) = delete;
77  } // namespace cuda
78 } // namespace cms
79 
80 #endif
cms::cuda::host::impl::make_host_unique_selector
Definition: host_unique_ptr.h:25
cms::cuda::n
cudaStream_t T uint32_t const T *__restrict__ const uint32_t *__restrict__ uint32_t int cudaStream_t Func V int n
Definition: HistoContainer.h:124
allocate_host.h
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
mem
uint16_t mem[nChs][nEvts]
Definition: recycleTccEmu.cc:13
cms::cuda::allocate_host
void * allocate_host(size_t nbytes, cudaStream_t stream)
Definition: allocate_host.cc:15
query.host
host
Definition: query.py:115
cms::cuda::host::impl::make_host_unique_selector< T[]>::unbounded_array
cms::cuda::host::unique_ptr< T[]> unbounded_array
Definition: host_unique_ptr.h:30
cms::cuda::make_host_unique_uninitialized
host::impl::make_host_unique_selector< T >::non_array make_host_unique_uninitialized(cudaStream_t stream)
Definition: host_unique_ptr.h:62
N
#define N
Definition: blowfish.cc:9
prod1Switch_cff.cuda
cuda
Definition: prod1Switch_cff.py:11
cms::cuda::host::impl::HostDeleter
Definition: host_unique_ptr.h:14
type
type
Definition: HCALResponse.h:21
cms::cuda::host::impl::make_host_unique_selector::non_array
cms::cuda::host::unique_ptr< T > non_array
Definition: host_unique_ptr.h:26
impl
Definition: trackAlgoPriorityOrder.h:18
T
long double T
Definition: Basic3DVectorLD.h:48
cms::cuda::host::unique_ptr
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: host_unique_ptr.h:21
relativeConstraints.value
value
Definition: relativeConstraints.py:53
cms::cuda::make_host_unique
host::impl::make_host_unique_selector< T >::non_array make_host_unique(cudaStream_t stream)
Definition: host_unique_ptr.h:41
cms::cuda::host::impl::HostDeleter::operator()
void operator()(void *ptr)
Definition: host_unique_ptr.h:16
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
cms::cuda::free_host
void free_host(void *ptr)
Definition: allocate_host.cc:29