Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
copy_task.hpp
Go to the documentation of this file.
1#pragma once
2
13
14namespace uni20::linalg
15{
16namespace detail::cuda_reference
17{
18
19template <class Scalar> async::CudaTask co_copy_submission(CopyPlan<Scalar> plan)
20{
21 auto& resources = plan.output_buffer->resources();
22 co_await uni20::cuda::set_device(resources.device());
23 auto stream = co_await uni20::cuda::acquire_stream(resources.streams());
24 enqueue_device_copy(plan, stream);
25 co_return;
26}
27
29template <class OutputMdspan, class InputMdspan>
30 requires(SupportedCopyMdspans<OutputMdspan, InputMdspan> && is_raw_cuda_mdspec<OutputMdspan> &&
31 is_supported_cuda_mdspan<InputMdspan>)
32auto try_make_copy_task(OutputMdspan& output, InputMdspan& input) -> KernelTaskAttempt<async::CudaTask>
33{
34 auto preparation = prepare_copy(output, input);
35 if (!kernel_attempt_succeeded(preparation.attempt) || !preparation.has_work)
36 {
37 return KernelTaskAttempt<async::CudaTask>{preparation.attempt};
38 }
39
40 int const device = preparation.output_buffer->device().ordinal();
41 auto task = co_copy_submission(std::move(preparation));
42 async::cuda_promise(task.handle()).bind_device(device);
43 return KernelTaskAttempt<async::CudaTask>{std::move(task)};
44}
45} // namespace detail::cuda_reference
46
48template <uni20::MutableMdspecLike OutputMdspan, uni20::MdspecLike InputMdspan>
49 requires(detail::cuda_reference::SupportedCopyMdspans<OutputMdspan, InputMdspan> &&
50 detail::cuda_reference::is_raw_cuda_mdspec<OutputMdspan> &&
51 detail::cuda_reference::is_supported_cuda_mdspan<InputMdspan>)
52auto try_make_kernel_task(CudaReferenceBackend, copy_op const&, OutputMdspan& output,
53 InputMdspan& input) -> KernelTaskAttempt<async::CudaTask>
54{
55 return detail::cuda_reference::try_make_copy_task(output, input);
56}
57
58} // namespace uni20::linalg
void bind_device(int device)
Bind the CUDA device before the coroutine starts.
Definition async_task_promise.hpp:673
CUDA-constrained public task type used for typed initial admission.
Definition cuda_task.hpp:14
Runtime backend attempt optionally carrying a deferred kernel task.
Definition kernel_task.hpp:31
CUDA-specific awaiters for device and runtime resource scheduling.
Defines the CUDA task admission type and scheduler interface.
Deferred task result for an optional coroutine kernel implementation.
CUDA runtime backend for contiguous Tensor transfers.
CudaTaskPromise & cuda_promise(TaskHandle handle) noexcept
Narrow an erased task promise after verifying that it is CUDA-specific.
Definition async_task_promise.hpp:707
stream
Selects the ordinary display stream for a message.
Definition display.hpp:25
Definition linalg/async.hpp:28
constexpr bool kernel_attempt_succeeded(KernelAttempt attempt) noexcept
Return whether a backend performed the operation.
Definition kernel_attempt.hpp:40
auto try_make_kernel_task(CublasBackend, gemm_op const &, OutputMdspan &output, Scalar const &alpha, LhsMdspan &lhs, RhsMdspan &rhs, Scalar const &beta) -> KernelTaskAttempt< async::CudaTask >
Prepare asynchronous cuBLAS work from normalized mdspecs.
Definition gemm_task.hpp:59
Backend value for generic CUDA runtime kernels and transfers.
Definition backend_selector.hpp:48
Accessor-respecting element copy operation tag.
Definition operation_tags.hpp:33