27#include <batchlas/export.hh>
85 return "DeviceType(?)";
106template <
typename CharT,
typename Traits>
107std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
Policy value) {
113template <
typename CharT,
typename Traits>
114std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
DeviceType value) {
120template <
typename CharT,
typename Traits>
121std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
Vendor value) {
130 std::transform(v.begin(), v.end(), v.begin(), ::tolower);
131 if (v.find(
"amd") != std::string::npos || v.find(
"advanced micro devices") != std::string::npos) {
133 }
else if (v.find(
"apple") != std::string::npos) {
135 }
else if (v.find(
"arm") != std::string::npos) {
137 }
else if (v.find(
"intel") != std::string::npos) {
139 }
else if (v.find(
"nvidia") != std::string::npos) {
169constexpr bool is_sm120_family(
int cuda_cc) {
return cuda_cc >= 120 && cuda_cc < 130; }
194 std::transform(
type.begin(),
type.end(),
type.begin(), ::tolower);
195 auto pick = [](std::vector<Device> devs,
const std::string& name) ->
Device {
201 }
else if(
type ==
"gpu") {
203 }
else if(
type ==
"accelerator") {
226 template <
typename T>
229 if constexpr (std::is_same_v<T, double> || std::is_same_v<T, std::complex<double>>) {
286 BATCHLAS_API
Event(EventImpl&& impl);
291 BATCHLAS_API
void wait()
const;
357 template <
typename EventContainer>
359 for(
auto& event : events){
441#ifndef BATCHLAS_NO_GLOBAL_NAMES
446using batchlas::EventImpl;
449using batchlas::QueueImpl;
A borrow of scratch memory from a Queue's workspace arena, returned to the arena when the handle goes...
The device or its vendor runtime failed.
The call violates the API contract.
Enumerations, scalar traits and scalar concepts shared by every public header.
The BatchLAS exception hierarchy.
Vendor str_to_vendor(std::string &&v)
Classify a SYCL vendor string (case-insensitive substring match).
constexpr bool is_sm120_family(int cuda_cc)
True for consumer Blackwell (RTX 50xx / RTX PRO 6000, sm_120/121).
DeviceType
The kind of SYCL device.
Vendor
Device vendor, parsed from the SYCL vendor string by str_to_vendor().
DeviceProperty
A device property queryable with Device::get_property(); each maps to the SYCL sycl::info::device des...
Policy
Synchronous or asynchronous execution policy.
@ NUM_DEV_TYPES
Number of device types (not a device type).
@ HOST
The SYCL host device.
@ ACCELERATOR
An accelerator device.
@ APPLE
Apple (Apple-silicon GPUs through AdaptiveCpp Metal).
@ GLOBAL_MEM_CACHE_LINE_SIZE
Global memory cache line (bytes).
@ MAX_WORK_GROUP_SIZE
Maximum work-group size.
@ MAX_NUM_SUB_GROUPS
Maximum sub-groups per work-group.
@ MAX_COMPUTE_UNITS
Number of compute units.
@ MAX_SUB_GROUP_SIZE
Largest supported sub-group size; see Device::supports_sub_group_size().
@ MAX_CLOCK_FREQUENCY
Maximum clock frequency (MHz).
@ GLOBAL_MEM_SIZE
Global memory size (bytes).
@ MAX_MEM_ALLOC_SIZE
Largest single allocation (bytes).
@ GLOBAL_MEM_CACHE_SIZE
Global memory cache size (bytes).
@ MEM_BASE_ADDR_ALIGN
Base address alignment (bits).
@ NUMBER_OF_PROPERTIES
Number of properties (not a property).
@ LOCAL_MEM_SIZE
Local (shared) memory per work-group (bytes).
@ SYNC
Wait for completion.
@ ASYNC
Return after enqueueing.
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, E value)
Prints any BatchLAS enum as its enumerator spelling, via its to_string().
constexpr std::string_view to_string(MatrixFormat v)
Spelling of v as in source.
Backend
Library family an entry point dispatches to, used as a template argument.
@ AUTO
A request, not a backend: the Queue resolves it from its device on first query.
A handle to one SYCL device: its type and its index among devices of that type.
size_t idx
Index among devices of type.
Device()=default
The host device (index 0).
static std::vector< Device > get_devices(DeviceType type)
Every device of type, in the SYCL runtime's order.
int cuda_compute_capability() const
CUDA compute capability as major*10+minor (89 = sm_89, 120 = sm_120), or 0 for a non-CUDA device.
static Device default_device()
The first GPU, else the first CPU, else the host device.
static Device default_device_for()
default_device(), except the first CPU device for a double or complex<double> T when that default is ...
Device(std::string type)
The first device of the named type.
Device(const char *type)
As Device(std::string).
DeviceType type
The device's type.
Device(size_t idx, DeviceType type)
The idx-th device of type, as numbered by get_devices().
Vendor get_vendor() const
The device's vendor.
bool supports_fp64() const
True when the device runs double-precision kernels (sycl::aspect::fp64).
std::string get_name() const
The device's name as reported by SYCL.
size_t get_property(DeviceProperty property) const
The value of one device property (units as documented on DeviceProperty).
bool supports_sub_group_size(size_t size) const
True when size is one of the device's supported sub-group sizes.
Completion handle of enqueued work, returned by every entry point.
Event & operator=(Event &&other)
EventImpl * operator->() const
void wait() const
Block until the work this Event tracks has completed.
Event()
An empty Event, already complete.
std::unique_ptr< EventImpl > impl_
Implementation; null only for a moved-from Event.
std::optional< std::pair< std::uint64_t, std::uint64_t > > profiling_command_start_end_ns() const
{command_start, command_end} in nanoseconds, or std::nullopt when profiling is not enabled on the und...
Event & operator=(EventImpl &&impl)
EventImpl & operator*() const
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
Event get_event() const
An Event that completes after everything enqueued on this Queue so far.
QueueImpl & operator*() const
size_t workspace_capacity() const
Bytes the arena currently holds. It grows to the peak requested and keeps it.
void wait_and_throw() const
As wait(), then rethrow any asynchronous error the device reported.
Queue(Device device, batchlas::Backend backend, bool in_order=true)
A Queue on device pinned to backend.
static bool backend_available(batchlas::Backend backend)
True when backend is compiled into this build.
QueueImpl * operator->() const
batchlas::Backend backend() const
The backend calls dispatch to; never Backend::AUTO (an AUTO Queue resolves once, on first query,...
bool 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 devic...
Queue()
A Queue on Device::default_device(), in-order, backend AUTO.
void * native_handle() const
The native stream as an opaque pointer: a CUstream when the device runs on the CUDA SYCL backend,...
Queue(const Queue &other)=delete
Queue & operator=(Queue &&other)
void set_backend(batchlas::Backend backend)
Pin this Queue to backend, or pass Backend::AUTO to hand it back to automatic selection.
Queue(const Queue &base, bool in_order)
A Queue sharing base's SYCL context and device, so USM pointers and workspaces allocated for base sta...
std::unique_ptr< QueueImpl > impl_
Implementation (SYCL queue, arena, event chain).
Event create_event_after_external_work()
Like get_event(), but also ordered after work submitted directly to the native stream (cuBLAS,...
Queue(Device device, bool in_order=true)
A Queue on device with backend AUTO.
void enqueue(Event &event)
Order all later work on this Queue after event, without a host wait.
Queue & operator=(const Queue &other)=delete
batchlas::Backend requested_backend() const
The backend as requested, possibly Backend::AUTO.
bool in_order() const
True for an in-order Queue.
void enqueue(EventContainer &events)
enqueue() each Event in events.
Device device() const
The device this Queue runs on.
void wait() const
Block until all work enqueued on this Queue has completed.
void attach_to_current_thread()
Transfer single-thread ownership to the calling thread (a move, not a share).
void require_device_accessible(const void *ptr, const char *what) const
As is_device_accessible(), but throws.
batchlas::WorkspaceLease workspace(size_t bytes)
Borrow bytes of device scratch from this Queue's arena.
bool trim_workspace()
Return the arena's memory to the runtime (otherwise it is freed only in ~Queue).
WorkspaceLease: a scoped borrow of scratch memory from a Queue's workspace arena.