MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::DeviceRuntime Concept Reference

A device runtime: the programming model behind a device memory kind. More...

#include <runtime.hpp>

Concept definition

template<typename R>
concept mtl::DeviceRuntime = requires(void* dst, const void* src, std::size_t bytes) {
{ R::name } -> std::convertible_to<const char*>;
R::copy_bytes(dst, src, bytes);
{ R::template supports<double> } -> std::convertible_to<bool>;
}
A device runtime: the programming model behind a device memory kind.
Definition runtime.hpp:112

Detailed Description

A device runtime: the programming model behind a device memory kind.

Required:

  • name: for diagnostics and benchmark provenance.
  • copy_bytes(dst, src, bytes): copies bytes bytes and returns when the copy is complete. Either side may be host memory or any memory of this runtime. Source and target do not overlap.
  • Address spaces: all memory of one kind of one runtime (all of its device<R> memory, say) is one address space, so ranges in it can be compared; memory of different kinds, or host and device memory, need not be, and mtl::copy never compares their addresses.
  • supports<T>: whether the runtime's devices can compute in T (a device without FP64 says false for double).

Optional, one pair per memory kind the runtime can allocate: allocate_device<T>(n) / deallocate_device<T>(p, n) allocate_shared<T>(n) / deallocate_shared<T>(p, n) allocate_pinned<T>(n) / deallocate_pinned<T>(p, n) with the contract of AllocatingMemorySpace: n value-initialized elements, nullptr for n == 0, aligned for SIMD loads. A runtime that zero-fills its memory accepts only the types whose value is zero bytes (detail::zero_fill_is_value_init_v, memory/zero_fill.hpp). A kind without its pair cannot own storage, so an owning container in it fails to compile.

Optional, for a runtime whose memory is not addressed by a pointer (a Metal buffer, an OpenCL cl_mem, a Vulkan VkBuffer):

  • device_handle<T>, shared_handle<T>: the handle that names device or shared memory, T* when absent. Pinned memory is host memory, named by a pointer. A handle follows std::mdspan's data_handle_type contract (copyable, nothrow movable), and a value-initialized one names no storage; the allocation pair for that kind takes and returns it.
  • offset(h, i): the handle of element i.
  • address(h): the host address, for a shared_handle.
  • copy_bytes overloads for each pair of handle and pointer it copies between; overlaps(a, b, bytes), with == on the handle, to copy within one device space.