|
rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
|
Scoped, configurable view over a device_session. More...
#include <rexlib/core/hardware/device_context.hpp>
Public Member Functions | |
| device_context () noexcept=default | |
| Construct an empty context holding no session. | |
| device_context (std::shared_ptr< const device_session > session) | |
Construct a context for session. | |
| device_context (const device_context &other)=default | |
| device_context (device_context &&other) noexcept=default | |
| device_context & | operator= (const device_context &other)=default |
| device_context & | operator= (device_context &&other) noexcept=default |
| const std::shared_ptr< const device_session > & | get_device_session () const noexcept |
| Retrieve the wrapped device session. | |
| const std::shared_ptr< command_queue > & | get_active_queue () const noexcept |
| Retrieve the active command queue. | |
| const std::shared_ptr< memory_allocator > & | get_allocator (memory_resource_affinity affinity) const noexcept |
| Retrieve the allocator for the given affinity. | |
| device_context | on_queue (std::shared_ptr< command_queue > queue) const |
| Derive a context that submits onto a different queue. | |
| 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. | |
Scoped, configurable view over a device_session.
A device_context layers the per-use, configurable state on top of the immutable device_session. That state is the active command_queue that work is submitted to, and the memory_allocator selected for each memory_resource_affinity.
The context is a lightweight, copyable value with functional-update semantics: on_queue and with_allocator do not mutate the receiver, they return a modified copy. This makes a context safe to share (including across threads) while still allowing callers to derive scoped variants, e.g. to bind a special-purpose allocator for a single operation without disturbing any other user of the original context. Copies are cheap: the session, the queue and the allocators are all shared pointers.
|
defaultnoexcept |
Construct an empty context holding no session.
Every accessor of the resulting context returns null until it is replaced by assignment.
|
explicit |
Construct a context for session.
The active queue is set to the default queue of the wrapped device and every allocator slot is seeded with the corresponding session allocator.
| session | Device session to wrap. Must not be null. |
| std::invalid_argument | if session is null. |
|
noexcept |
Retrieve the active command queue.
Work produced through this context is submitted onto this queue.
|
noexcept |
Retrieve the allocator for the given affinity.
Returns the override installed through with_allocator, or the device_session allocator when no override is in effect.
| affinity | The desired memory_resource_affinity (host or device). |
affinity, or to a null pointer if this context is empty.
|
noexcept |
Retrieve the wrapped device session.
| device_context rexlib::device_context::on_queue | ( | std::shared_ptr< command_queue > | queue | ) | const |
Derive a context that submits onto a different queue.
| queue | The active queue of the returned context. The provided queue must have been provided by the device held by this context. Passing null uses device_session's default queue on the returned device_context. |
queue as its active queue. | device_context rexlib::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.
Installs allocator as the allocator for affinity. Passing a null allocator reverts the slot to the device_session allocator for affinity (or to null when this context is empty).
The override must produce buffers reachable by the role implied by the slot: an allocator bound to memory_resource_affinity::host must be host-accessible, and one bound to memory_resource_affinity::device must be device-accessible.
| affinity | The affinity slot to update. |
| allocator | The override to install, or null to revert to the session allocator. Must satisfy the allocator requirements for the slot where it is being installed. |