9#include <batchlas/backend_config.h>
67 std::is_same_v<std::remove_cv_t<T>,
double> || std::is_same_v<std::remove_cv_t<T>, std::complex<double>>;
76 const std::string what = std::string(
"BatchLAS: ") + (op ? op :
"this call") +
77 " was called with double or complex<double> data on a queue whose device (" +
82 what +
" runs Backend::SYCL, and this build compiled no Backend::SYCL kernels for those "
83 "types. Use Backend::NETLIB (the default backend of a CPU Queue), or convert the data "
84 "to float or complex<float>.");
87 what +
" has no fp64 support, so this build compiled no Backend::SYCL kernels for those "
88 "types. Run double work on a CPU Queue (Queue(Device(\"cpu\"))), whose backend is "
89 "NETLIB, or convert the data to float or complex<float>.");
105template <
bool NeedsFp64,
typename F>
107 static_assert(BATCHLAS_HAS_CUDA_BACKEND || BATCHLAS_HAS_ROCM_BACKEND ||
108 BATCHLAS_HAS_SYCL_BACKEND || BATCHLAS_HAS_HOST_BACKEND,
109 "BatchLAS was built with no backends; nothing can be dispatched.");
112#if BATCHLAS_HAS_CUDA_BACKEND
114 return f(std::integral_constant<Backend, Backend::CUDA>{});
116#if BATCHLAS_HAS_ROCM_BACKEND
118 return f(std::integral_constant<Backend, Backend::ROCM>{});
120#if BATCHLAS_HAS_SYCL_BACKEND
122 if constexpr (NeedsFp64 && !BATCHLAS_HAS_DEVICE_FP64) {
125 return f(std::integral_constant<Backend, Backend::SYCL>{});
128#if BATCHLAS_HAS_HOST_BACKEND
130 return f(std::integral_constant<Backend, Backend::NETLIB>{});
137 " has no implementation in this build. "
138 "Check Queue::backend_available() before pinning a backend.");
170template <
typename T,
typename F>
191concept HasDataPtr =
requires(
const A& a) { { a.data_ptr() } -> std::convertible_to<const void*>; };
194 { a.data() } -> std::convertible_to<const void*>;
195 { a.size() } -> std::convertible_to<size_t>;
201 { a.rows() } -> std::convertible_to<long long>;
202 { a.cols() } -> std::convertible_to<long long>;
203 { a.batch_size() } -> std::convertible_to<long long>;
207 { a.size() } -> std::convertible_to<long long>;
208 { a.batch_size() } -> std::convertible_to<long long>;
214 using U = std::remove_cvref_t<A>;
216 return arg.rows() == 0 || arg.cols() == 0 || arg.batch_size() == 0;
218 return arg.size() == 0 || arg.batch_size() == 0;
232 if (arg.size() != 0) {
240template <
typename... Args>
244 (void)std::initializer_list<int>{
247 std::string(fn) +
": argument " + std::to_string(pos)),
253#if BATCHLAS_HAS_CUDA_BACKEND
255#elif BATCHLAS_HAS_ROCM_BACKEND
271#define BATCHLAS_DISPATCH_ON_QUEUE(NAME) \
272 template <typename... Args> \
273 requires requires(Queue& probe_ctx, Args&&... probe_args) { \
274 NAME<::batchlas::detail::kProbeBackend>(probe_ctx, \
275 std::forward<Args>(probe_args)...); \
277 inline auto NAME(Queue& ctx, Args&&... args) { \
278 ::batchlas::detail::require_pack_accessible(ctx, #NAME, args...); \
279 return ::batchlas::detail::with_backend_gated< \
280 ::batchlas::detail::needs_fp64_v<Args...>>(ctx, #NAME, [&](auto Back) { \
281 return NAME<Back.value>(ctx, std::forward<Args>(args)...); \
Non-owning view of a batch of matrices: the argument type of every entry point.
Owning batch of batch_size() matrices of equal (capacity) shape.
Non-owning view of a batch of strided vectors: the vector argument type of the entry points.
No kernel, backend or vendor entry point in this build on this device serves the request.
Enumerations, scalar traits and scalar concepts shared by every public header.
const Settings & settings()
The process-wide settings.
auto with_backend_for(Queue &ctx, const char *op, F &&f)
with_backend() for a call on element type T: throws batchlas::unsupported before dispatch when T is d...
auto with_backend(Queue &ctx, F &&f)
Call f with the queue's backend as a compile-time constant.
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.
@ NETLIB
Host CBLAS / LAPACKE; the fallback for any device.
@ SYCL
Native SYCL kernels on a GPU with no vendor library (AdaptiveCpp Metal); float and complex<float> onl...
@ ROCM
AMD GPU: rocBLAS / rocSOLVER / rocSPARSE and the native SYCL kernels.
@ CUDA
NVIDIA GPU: cuBLAS / cuSOLVER / cuSPARSE and the native SYCL kernels.
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
void throw_no_device_fp64(const Queue &ctx, const char *op)
void require_arg_accessible(const Queue &ctx, const A &arg, const std::string &what)
void require_device_fp64(const Queue &ctx, const char *op)
Throws throw_no_device_fp64 for a double or complex<double> T on a GPU without fp64.
bool pointer_checks_enabled()
constexpr Backend kProbeBackend
constexpr bool needs_fp64_v
bool addresses_no_elements(const A &arg)
constexpr bool is_fp64_scalar_v
void require_pack_accessible(const Queue &ctx, const char *fn, const Args &... args)
auto with_backend_gated(Queue &ctx, const char *op, F &&f)
Every BATCHLAS_* environment variable the library reads, captured once into batchlas::Settings,...
DeviceType type
The device's type.
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.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
batchlas::Backend backend() const
The backend calls dispatch to; never Backend::AUTO (an AUTO Queue resolves once, on first query,...
Device device() const
The device this Queue runs on.
void require_device_accessible(const void *ptr, const char *what) const
As is_device_accessible(), but throws.
UnsafeSettings unsafe
Overrides that remove a guarantee.
Non-owning view of size() contiguous elements of type T.
Owning, growable array of T in USM shared memory (sycl::malloc_shared).
bool skip_pointer_checks
BATCHLAS_SKIP_POINTER_CHECKS: disables the per-argument USM reachability check that turns host memory...
Owning batch of batch_size() vectors of length size() in USM shared memory.
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.
batchlas::Span, the non-owning pointer + length every entry point takes for 1-D data.
batchlas::UnifiedVector, an owning growable array in USM shared memory.