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_bytes)
22 {
23  return detail_::make_unique_region(context.handle(), num_bytes);
24 }
25 
36 inline unique_region make_unique_region(const device_t& device, size_t num_bytes)
37 {
38  auto pc = device.primary_context();
39  return make_unique_region(pc, num_bytes);
40 }
41 
55 inline unique_region make_unique_region(size_t num_bytes)
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_bytes);
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 
94  const device_t& device,
95  size_t num_bytes,
96  initial_visibility_t initial_visibility)
97 {
98  auto pc = device.primary_context();
99  return make_unique_region(pc, num_bytes, initial_visibility);
100 }
101 
104  size_t num_bytes,
105  initial_visibility_t initial_visibility)
106 {
107  auto current_device_id = cuda::device::current::detail_::get_id();
108  auto pc = cuda::device::primary_context::detail_::leaky_get(current_device_id);
109  return make_unique_region(pc, num_bytes, initial_visibility);
110 }
112 
113 } // namespace managed
114 
115 } // namespace memory
116 
117 } // namespace cuda
118 
119 #endif // MULTI_WRAPPER_IMPLS_UNIQUE_REGION_HPP_
120 
Wrapper class for a CUDA context.
Definition: context.hpp:249
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:102
unique_region make_unique_region(const context_t &context, cuda::size_t num_bytes)
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:78
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:755