rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
device_context.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "memory_resource_affinity.hpp"
6#include "../platform/dynamic_shared_object.h"
7
8#include <array>
9#include <cstddef>
10#include <memory>
11
12namespace rexlib
13{
14
15class device_session;
16class command_queue;
17class memory_allocator;
18
49{
50public:
57 device_context() noexcept = default;
58
70 REXLIB_API
71 explicit device_context(std::shared_ptr<const device_session> session);
72
73 device_context(const device_context &other) = default;
74 device_context(device_context &&other) noexcept = default;
75 ~device_context() = default;
76
77 device_context& operator=(const device_context &other) = default;
78 device_context& operator=(device_context &&other) noexcept = default;
79
86 REXLIB_API
87 const std::shared_ptr<const device_session>&
88 get_device_session() const noexcept;
89
98 REXLIB_API
99 const std::shared_ptr<command_queue>& get_active_queue() const noexcept;
100
111 REXLIB_API
112 const std::shared_ptr<memory_allocator>&
113 get_allocator(memory_resource_affinity affinity) const noexcept;
114
123 REXLIB_API
124 device_context on_queue(std::shared_ptr<command_queue> queue) const;
125
144 REXLIB_API
147 std::shared_ptr<memory_allocator> allocator
148 ) const;
149
150private:
151 using allocator_array_type = std::array<
152 std::shared_ptr<memory_allocator>,
153 static_cast<std::size_t>(memory_resource_affinity::count)
154 >;
155
156 std::shared_ptr<const device_session> m_session;
157 std::shared_ptr<command_queue> m_active_queue;
158 allocator_array_type m_allocators;
159};
160
161} // namespace rexlib
Container for multidimensional numeric data.
Definition array.hpp:31
Abstract command queue belonging to a device.
Definition command_queue.hpp:27
Scoped, configurable view over a device_session.
Definition device_context.hpp:49
const std::shared_ptr< const device_session > & get_device_session() const noexcept
Retrieve the wrapped device session.
device_context with_allocator(memory_resource_affinity affinity, std::shared_ptr< memory_allocator > allocator) const
Derive a context with a different allocator for an affinity.
const std::shared_ptr< command_queue > & get_active_queue() const noexcept
Retrieve the active command queue.
device_context on_queue(std::shared_ptr< command_queue > queue) const
Derive a context that submits onto a different queue.
const std::shared_ptr< memory_allocator > & get_allocator(memory_resource_affinity affinity) const noexcept
Retrieve the allocator for the given affinity.
device_context() noexcept=default
Construct an empty context holding no session.
Immutable aggregate of a device handle and its associated objects.
Definition device_session.hpp:29
Abstract allocator of buffer objects on a memory_resource.
Definition memory_allocator.hpp:30
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
memory_resource_affinity
Enumeration to query memory_resource according to its intended usage.
Definition memory_resource_affinity.hpp:12