cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
unique_region.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #ifndef MULTI_WRAPPER_IMPLS_UNIQUE_REGION_HPP_
9 #define MULTI_WRAPPER_IMPLS_UNIQUE_REGION_HPP_
10 
11 #include "../unique_region.hpp"
12 #include "../types.hpp"
13 #include "../device.hpp"
14 
15 namespace cuda {
16 
17 namespace memory {
18 
19 namespace device {
20 
21 inline unique_region make_unique_region(const context_t& context, cuda::size_t num_elements)
22 {
23  return detail_::make_unique_region(context.handle(), num_elements);
24 }
25 
36 inline unique_region make_unique_region(const device_t& device, size_t num_elements)
37 {
38  auto pc = device.primary_context();
39  return make_unique_region(pc, num_elements);
40 }
41 
55 inline unique_region make_unique_region(size_t num_elements)
56 {
57  auto current_device_id = cuda::device::current::detail_::get_id();
58  auto pc = cuda::device::primary_context::detail_::leaky_get(current_device_id);
59  return make_unique_region(pc, num_elements);
60 }
61 
62 } // namespace device
63 
64 namespace host {
65 
66 inline unique_region make_unique_region(size_t num_bytes)
67 {
68  return unique_region { allocate(num_bytes) };
69 }
70 
71 } // namespace host
72 
73 namespace managed {
74 
84  const context_t& context,
85  size_t num_bytes,
86  initial_visibility_t initial_visibility)
87 {
88  CAW_SET_SCOPE_CONTEXT(context.handle());
89  return unique_region { detail_::allocate_in_current_context(num_bytes, initial_visibility) };
90 }
91 
101  const device_t& device,
102  size_t num_bytes,
103  initial_visibility_t initial_visibility)
104 {
105  auto pc = device.primary_context();
106  return make_unique_region(pc, num_bytes, initial_visibility);
107 }
108 
110  size_t num_bytes,
111  initial_visibility_t initial_visibility)
112 {
113  auto current_device_id = cuda::device::current::detail_::get_id();
114  auto pc = cuda::device::primary_context::detail_::leaky_get(current_device_id);
115  return make_unique_region(pc, num_bytes, initial_visibility);
116 }
117 
118 } // namespace managed
119 
120 } // namespace memory
121 
122 } // namespace cuda
123 
124 #endif // MULTI_WRAPPER_IMPLS_UNIQUE_REGION_HPP_
125 
Wrapper class for a CUDA context.
Definition: context.hpp:244
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
region_t allocate(const context_t &context, size_t size_in_bytes)
Allocate device-side memory on a CUDA device context.
Definition: memory.hpp:106
unique_region make_unique_region(const context_t &context, cuda::size_t num_elements)
Allocate a region in device-global memory.
Definition: unique_region.hpp:21
A class for holding a region_t of memory owned "uniquely" by its creator - similar to how ::std::uniq...
Definition: unique_region.hpp:41
::std::size_t size_t
A size type for use throughout the wrappers library (except when specific API functions limit the siz...
Definition: types.hpp:81
device::primary_context_t primary_context(bool hold_pc_refcount_unit=false) const
Produce a proxy for the device's primary context - the one used by runtime API calls.
Definition: device.hpp:152
Wrapper class for a CUDA device.
Definition: device.hpp:135
initial_visibility_t
The choices of which categories CUDA devices must a managed memory region be visible to...
Definition: types.hpp:753
unique_region make_unique_region(size_t num_bytes)
Allocate a region of managed memory, accessible both from CUDA devices and from the CPU...
Definition: unique_region.hpp:55