CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
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>
77  } // namespace cuda
78 } // namespace cms
79 
80 #endif
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type * mem
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void free_host(void *ptr)
cms::cuda::host::unique_ptr< T > non_array
host::impl::make_host_unique_selector< T >::non_array make_host_unique_uninitialized(cudaStream_t stream)
string host
Definition: query.py:115
#define N
Definition: blowfish.cc:9
cms::cuda::host::unique_ptr< T[]> unbounded_array
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int n
std::unique_ptr< T, impl::HostDeleter > unique_ptr
void * allocate_host(size_t nbytes, cudaStream_t stream)
host::impl::make_host_unique_selector< T >::non_array make_host_unique(cudaStream_t stream)
long double T