cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
array.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef MULTI_WRAPPER_IMPLS_ARRAY_HPP_
12 #define MULTI_WRAPPER_IMPLS_ARRAY_HPP_
13 
14 #include "../array.hpp"
15 #include "../device.hpp"
16 #include "../event.hpp"
17 #include "../primary_context.hpp"
18 #include "../current_context.hpp"
19 #include "../current_device.hpp"
20 #include "../texture_view.hpp"
21 
22 namespace cuda {
23 
24 namespace array {
25 
26 template <typename T, dimensionality_t NumDimensions>
28  const context_t& context,
29  dimensions_t<NumDimensions> dimensions)
30 {
31  handle_t handle = detail_::create<T, NumDimensions>(context.handle(), dimensions);
32  return wrap<T, NumDimensions>(context.device_id(), context.handle(), handle, dimensions);
33 }
34 
35 template <typename T, dimensionality_t NumDimensions>
37  const device_t& device,
38  dimensions_t<NumDimensions> dimensions)
39 {
40  auto pc = device.primary_context(do_not_hold_primary_context_refcount_unit);
41  return create<T, NumDimensions>(pc, dimensions);
42  // Note that we have no guarantee that the device's primary context
43  // will continue to exist/be active when returning from this call;
44  // that's the caller's responsibility
45 }
46 
47 } // namespace array
48 
50 {
51  return context::wrap(device_id_, context_handle_);
52 }
53 
55 {
56  return device::get(device_id_);
57 }
58 
59 template <typename T, dimensionality_t NumDimensions>
61 {
62  return device::get(device_id_);
63 }
64 
65 template <typename T, dimensionality_t NumDimensions>
67 {
68  // TODO: Save the device id in the array_t as well.
69  return context::wrap(device_id_, context_handle_);
70 }
71 
72 } // namespace cuda
73 
74 #endif // MULTI_WRAPPER_IMPLS_ARRAY_HPP_
75 
context_t context() const
Definition: array.hpp:49
Wrapper class for a CUDA context.
Definition: context.hpp:244
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
Owning wrapper for CUDA 2D and 3D arrays.
Definition: array.hpp:29
array_t< T, NumDimensions > create(const context_t &context, dimensions_t< NumDimensions > dimensions)
Create a new (typed) CUDA array of the specified dimensions.
Definition: array.hpp:27
device::primary_context_t primary_context(bool hold_pc_refcount_unit=false) const
Produce a proxy for the device&#39;s primary context - the one used by runtime API calls.
Definition: device.hpp:152
device_t get(id_t id)
Returns a proxy for the CUDA device with a given id.
Definition: device.hpp:837
CUarray handle_t
Raw CUDA driver handle for arrays (of any dimension)
Definition: array.hpp:34
array_t< T, NumDimensions > wrap(device::id_t device_id, context::handle_t context_handle, handle_t handle, dimensions_t< NumDimensions > dimensions) noexcept
Wrap an existing CUDA array in an array_t instance.
Definition: array.hpp:264
device_t device() const
Definition: array.hpp:54
Wrapper class for a CUDA device.
Definition: device.hpp:135
CUDA&#39;s array memory-objects are multi-dimensional; but their dimensions, or extents, are not the same as cuda::grid::dimensions_t ; they may be much larger in each axis.
Definition: types.hpp:105