batchlas::Queue Struct Reference

Overview

Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.

Queue ctx; // default device, in-order, backend AUTO
Queue ooo(device, /*in_order=*/false); // out-of-order
Queue host(device, Backend::NETLIB); // backend pinned
Queue sibling(ctx, /*in_order=*/true); // shares ctx's context and device
@ NETLIB
Host CBLAS / LAPACKE; the fallback for any device.
Definition enums.hh:119
Queue()
A Queue on Device::default_device(), in-order, backend AUTO.
Device device() const
The device this Queue runs on.

Every entry point takes its backend from the Queue and leases its default workspace from the Queue's arena (see WorkspaceLease). Movable, not copyable. Constructing the first Queue in the process closes batchlas::configure().

Warning
A Queue is single-threaded: it owns an unsynchronised arena and a cached last event, and workspace(), trim_workspace(), submissions, enqueue(), get_event() and create_event_after_external_work() throw batchlas::api_misuse when called from a thread other than the owner. Use one Queue per thread, or hand one over with attach_to_current_thread().
See also
"Synchronisation and threading" in docs/cpp-api.md

Definition at line 321 of file sycl-device-queue.hh.

#include <batchlas/util/sycl-device-queue.hh>

Constructors

◆ Queue() [1/6]

batchlas::Queue::Queue ( )

A Queue on Device::default_device(), in-order, backend AUTO.

◆ ~Queue()

batchlas::Queue::~Queue ( )

◆ Queue() [2/6]

batchlas::Queue::Queue ( Device device,
bool in_order = true )

A Queue on device with backend AUTO.

Parameters
devicethe device
in_ordertrue (default) for an in-order queue; out-of-order queues make arena-backed workspace releases drain the queue

◆ Queue() [3/6]

batchlas::Queue::Queue ( Device device,
batchlas::Backend backend,
bool in_order = true )

A Queue on device pinned to backend.

Exceptions
batchlas::unsupportedif backend is not compiled in (see set_backend())

◆ Queue() [4/6]

batchlas::Queue::Queue ( const Queue & base,
bool in_order )

A Queue sharing base's SYCL context and device, so USM pointers and workspaces allocated for base stay usable.

It has its own arena and event chain.

◆ Queue() [5/6]

batchlas::Queue::Queue ( Queue && other)

◆ Queue() [6/6]

batchlas::Queue::Queue ( const Queue & other)
delete

Functions

◆ operator=() [1/2]

Queue & batchlas::Queue::operator= ( Queue && other)

◆ operator=() [2/2]

Queue & batchlas::Queue::operator= ( const Queue & other)
delete

◆ operator->()

QueueImpl * batchlas::Queue::operator-> ( ) const

◆ operator*()

QueueImpl & batchlas::Queue::operator* ( ) const

◆ enqueue() [1/2]

void batchlas::Queue::enqueue ( Event & event)

Order all later work on this Queue after event, without a host wait.

A moved-from Event is ignored; a default-constructed one is already complete.

◆ get_event()

Event batchlas::Queue::get_event ( ) const

An Event that completes after everything enqueued on this Queue so far.

◆ create_event_after_external_work()

Event batchlas::Queue::create_event_after_external_work ( )

Like get_event(), but also ordered after work submitted directly to the native stream (cuBLAS, rocBLAS, your own kernels) that bypassed SYCL submission.

◆ enqueue() [2/2]

template<typename EventContainer>
void batchlas::Queue::enqueue ( EventContainer & events)
inline

enqueue() each Event in events.

Definition at line 358 of file sycl-device-queue.hh.

◆ wait()

void batchlas::Queue::wait ( ) const

Block until all work enqueued on this Queue has completed.

◆ wait_and_throw()

void batchlas::Queue::wait_and_throw ( ) const

As wait(), then rethrow any asynchronous error the device reported.

◆ attach_to_current_thread()

void batchlas::Queue::attach_to_current_thread ( )

Transfer single-thread ownership to the calling thread (a move, not a share).

Precondition
No other thread uses the Queue during or after the call (unchecked).
Exceptions
batchlas::api_misuseif a workspace lease is outstanding

◆ workspace()

batchlas::WorkspaceLease batchlas::Queue::workspace ( size_t bytes)
nodiscard

Borrow bytes of device scratch from this Queue's arena.

The Queue owns the memory: it stays valid until the lease is released, not until the caller returns. Keep the lease in a named variable (auto ws = ctx.workspace(n);).

◆ workspace_capacity()

size_t batchlas::Queue::workspace_capacity ( ) const

Bytes the arena currently holds. It grows to the peak requested and keeps it.

◆ trim_workspace()

bool batchlas::Queue::trim_workspace ( )
nodiscard

Return the arena's memory to the runtime (otherwise it is freed only in ~Queue).

Returns
false, doing nothing, while any lease is outstanding
Note
Waits for the queue to be idle first, so it can throw an asynchronous error.

◆ device()

Device batchlas::Queue::device ( ) const
inline

The device this Queue runs on.

Definition at line 393 of file sycl-device-queue.hh.

◆ in_order()

bool batchlas::Queue::in_order ( ) const
inline

True for an in-order Queue.

Definition at line 395 of file sycl-device-queue.hh.

◆ backend()

batchlas::Backend batchlas::Queue::backend ( ) const

The backend calls dispatch to; never Backend::AUTO (an AUTO Queue resolves once, on first query, from the device vendor and the compiled-in backends).

Exceptions
batchlas::unsupportedif AUTO finds no compiled-in backend that serves the device

◆ requested_backend()

batchlas::Backend batchlas::Queue::requested_backend ( ) const
inline

The backend as requested, possibly Backend::AUTO.

Definition at line 402 of file sycl-device-queue.hh.

◆ set_backend()

void batchlas::Queue::set_backend ( batchlas::Backend backend)

Pin this Queue to backend, or pass Backend::AUTO to hand it back to automatic selection.

Exceptions
batchlas::unsupportedif backend is not compiled into this build

◆ backend_available()

bool batchlas::Queue::backend_available ( batchlas::Backend backend)
static

True when backend is compiled into this build.

◆ is_device_accessible()

bool batchlas::Queue::is_device_accessible ( const void * ptr) const

True for any USM allocation in this Queue's context, and for any non-null pointer on a host/CPU device.

◆ require_device_accessible()

void batchlas::Queue::require_device_accessible ( const void * ptr,
const char * what ) const

As is_device_accessible(), but throws.

Parameters
ptrthe pointer to check
whatnames the call-site parameter in the message, e.g. "gemm: A"
Exceptions
batchlas::invalid_argumentif ptr is null or not reachable from the device

◆ native_handle()

void * batchlas::Queue::native_handle ( ) const

The native stream as an opaque pointer: a CUstream when the device runs on the CUDA SYCL backend, a hipStream_t on HIP, nullptr elsewhere.

Keyed off the device, not backend(). Owned by the Queue: do not destroy it or use it past the Queue's lifetime. Work pushed to it runs after BatchLAS's; to make BatchLAS wait for that work, call create_event_after_external_work().

Variables

◆ impl_

std::unique_ptr<QueueImpl> batchlas::Queue::impl_

Implementation (SYCL queue, arena, event chain).

Definition at line 390 of file sycl-device-queue.hh.