sycl_interop.hh
Go to the documentation of this file.
1#pragma once
2/// @file
3/// @brief SYCL interop: batchlas::Queue and batchlas::Event to and from `sycl::queue` and
4/// `sycl::event`.
5///
6/// This is the one BatchLAS header that includes `<sycl/sycl.hpp>`, and it is deliberately not
7/// reachable from `<batchlas.hh>`. Include it only in the translation units that move a queue or
8/// an event across the boundary (they must be compiled with `-fsycl`), and do not include it from
9/// a header of your own that the rest of a project pulls in: that puts `sycl.hpp` back into every
10/// translation unit.
11///
12/// Not needed for the native stream (Queue::native_handle() returns it as `void*`) or for memory:
13/// USM pointers from `sycl::malloc_device`, `sycl::malloc_host`, `cudaMalloc` or
14/// `cudaMallocManaged` wrap zero-copy in a Span or MatrixView, provided they are reachable from
15/// the Queue's context. Everything here is single-threaded in the same sense as Queue.
16/// @ingroup api_core
17// Kept out of the umbrella for compile time. evidence: docs/design/build-performance.md#build-performance-the-umbrella-header-excludes-device-code
18#include <batchlas/export.hh>
19#include <sycl/sycl.hpp>
20
22
23namespace batchlas {
24
25/// @brief The `sycl::queue` BatchLAS submits this Queue's work on.
26///
27/// A reference to the live queue, not a copy: work submitted to it is ordered against BatchLAS's
28/// own work by the queue itself (for the default in-order Queue, after everything already
29/// submitted). Its context and device are the ones BatchLAS allocates against, so
30/// `get_context()` on it is the right context for USM that BatchLAS should read.
31/// @param ctx the Queue; must not be moved-from
32/// @return the underlying queue. Do not destroy it, hold it past `ctx`'s lifetime, or submit to
33/// it from another thread.
34/// @ingroup api_core
35BATCHLAS_API sycl::queue& sycl_queue(const Queue& ctx);
36
37/// @brief The `sycl::event` underlying a BatchLAS Event.
38///
39/// For handing BatchLAS's work to SYCL code: `depends_on()`, `wait_and_throw()`, a barrier on
40/// another queue.
41/// @param event the BatchLAS event
42/// @return the underlying event, or a default-constructed (already complete) `sycl::event` when
43/// `event` is default-constructed or moved-from
44/// @ingroup api_core
45BATCHLAS_API sycl::event sycl_event(const Event& event);
46
47/// @brief Wrap a foreign `sycl::event` as a BatchLAS Event, so BatchLAS work can be ordered after
48/// work BatchLAS did not submit, with no host synchronisation.
49///
50/// @code
51/// sycl::event mine = my_queue.submit(...);
52/// Event e = batchlas::event_from_sycl(mine);
53/// ctx.enqueue(e); // ctx now runs after mine, no host wait
54/// batchlas::potrf(ctx, A, ...);
55/// @endcode
56/// In the other direction, `sycl_event(ctx.get_event())` hands another queue an event to depend
57/// on.
58/// @param event the foreign event
59/// @return an Event that Queue::enqueue() accepts
60/// @pre Both queues live in the same SYCL context.
61/// @ingroup api_core
62BATCHLAS_API Event event_from_sycl(sycl::event event);
63
64} // namespace batchlas
Event event_from_sycl(sycl::event event)
Wrap a foreign sycl::event as a BatchLAS Event, so BatchLAS work can be ordered after work BatchLAS d...
sycl::event sycl_event(const Event &event)
The sycl::event underlying a BatchLAS Event.
sycl::queue & sycl_queue(const Queue &ctx)
The sycl::queue BatchLAS submits this Queue's work on.
Completion handle of enqueued work, returned by every entry point.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.