Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
kernel_task.hpp
Go to the documentation of this file.
1#pragma once
2
12
13#include <concepts>
14#include <optional>
15#include <type_traits>
16#include <utility>
17
18namespace uni20::linalg
19{
20
29template <class Task>
30 requires std::derived_from<Task, async::BasicTask>
32 public:
33 using task_type = Task;
34
36 explicit KernelTaskAttempt(KernelAttempt attempt) noexcept : attempt_(attempt) {}
37
39 explicit KernelTaskAttempt(Task task) noexcept : task_(std::move(task)) {}
40
43 KernelTaskAttempt(KernelTaskAttempt&&) noexcept = default;
44 KernelTaskAttempt& operator=(KernelTaskAttempt&&) noexcept = default;
45
47 [[nodiscard]] KernelAttempt attempt() const noexcept { return attempt_; }
48
50 [[nodiscard]] bool has_task() const noexcept { return task_.has_value(); }
51
53 [[nodiscard]] Task take_task() &&
54 {
56 CHECK(task_.has_value());
57 return std::move(*task_);
58 }
59
60 private:
62 std::optional<Task> task_{};
63};
64
65namespace detail
66{
67template <class T> struct IsKernelTaskAttempt : std::false_type
68{};
69
70template <class Task> struct IsKernelTaskAttempt<KernelTaskAttempt<Task>> : std::true_type
71{};
72
73template <class T> inline constexpr bool is_kernel_task_attempt = IsKernelTaskAttempt<std::remove_cvref_t<T>>::value;
74} // namespace detail
75
76} // namespace uni20::linalg
Promise-neutral coroutine task ownership and the public AsyncTask type.
Runtime backend attempt optionally carrying a deferred kernel task.
Definition kernel_task.hpp:31
KernelTaskAttempt(Task task) noexcept
Construct a successful attempt with deferred work.
Definition kernel_task.hpp:39
KernelTaskAttempt(KernelTaskAttempt &&) noexcept=default
Task task_type
Definition kernel_task.hpp:33
KernelAttempt attempt() const noexcept
Return the runtime acceptance result.
Definition kernel_task.hpp:47
KernelTaskAttempt(KernelTaskAttempt const &)=delete
KernelTaskAttempt & operator=(KernelTaskAttempt const &)=delete
bool has_task() const noexcept
Return whether successful execution still requires awaiting a task.
Definition kernel_task.hpp:50
Task take_task() &&
Transfer the deferred task from a successful attempt.
Definition kernel_task.hpp:53
KernelTaskAttempt(KernelAttempt attempt) noexcept
Construct a completed attempt without deferred work.
Definition kernel_task.hpp:36
locale_t value
Definition data_table.cpp:49
Allocation-free runtime results for kernel backend attempts.
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
KernelAttempt
Result of one runtime kernel backend attempt.
Definition kernel_attempt.hpp:27
#define CHECK(cond,...)
Definition trace.hpp:299