Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
dispatch_error.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#include <optional>
13#include <string>
14#include <string_view>
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19namespace uni20::linalg
20{
21
24{
25 no,
26 maybe,
27 yes
28};
29
31template <KernelTypeAcceptance Value> using KernelAcceptance = std::integral_constant<KernelTypeAcceptance, Value>;
32
35
38
41
48
51{
52 std::string backend;
54 std::optional<KernelAttempt> runtime_result = std::nullopt;
55};
56
57namespace detail
58{
59inline std::string_view kernel_dispatch_failure_name(KernelDispatchFailure failure) noexcept
60{
61 switch (failure)
62 {
64 return "no backend accepts these argument types";
66 return "all runtime candidates declined";
67 }
68 return "unknown dispatch failure";
69}
70
71inline std::string_view kernel_type_acceptance_name(KernelTypeAcceptance acceptance) noexcept
72{
73 switch (acceptance)
74 {
76 return "no";
78 return "maybe";
80 return "yes";
81 }
82 return "unknown";
83}
84
85inline std::string kernel_dispatch_error_message(std::string_view operation, KernelDispatchFailure failure)
86{
87 return "kernel dispatch failed for operation '" + std::string(operation) +
88 "': " + std::string(kernel_dispatch_failure_name(failure));
89}
90} // namespace detail
91
94 public:
97 std::vector<KernelBackendAttempt> backend_attempts)
98 : diagnostic_error(detail::kernel_dispatch_error_message(operation, failure)), operation_(std::move(operation)),
99 failure_(failure), backend_attempts_(std::move(backend_attempts))
100 {}
101
103 [[nodiscard]] std::string const& operation() const noexcept { return operation_; }
104
106 [[nodiscard]] KernelDispatchFailure failure() const noexcept { return failure_; }
107
109 [[nodiscard]] std::vector<KernelBackendAttempt> const& backend_attempts() const noexcept
110 {
111 return backend_attempts_;
112 }
113
114 private:
115 std::string operation_;
116 KernelDispatchFailure failure_;
117 std::vector<KernelBackendAttempt> backend_attempts_;
118};
119
120} // namespace uni20::linalg
Base class for exceptions raised through Uni20's diagnostic boundary.
Definition diagnostic_error.hpp:25
Exception carrying structured information about a failed backend walk.
Definition dispatch_error.hpp:93
std::string const & operation() const noexcept
Return the stable diagnostic operation name.
Definition dispatch_error.hpp:103
KernelDispatchFailure failure() const noexcept
Return the dispatch failure category.
Definition dispatch_error.hpp:106
std::vector< KernelBackendAttempt > const & backend_attempts() const noexcept
Return the ordered backend acceptance and attempt records.
Definition dispatch_error.hpp:109
KernelDispatchError(std::string operation, KernelDispatchFailure failure, std::vector< KernelBackendAttempt > backend_attempts)
Construct a dispatch failure from its operation and backend attempts.
Definition dispatch_error.hpp:96
Structured exception base carrying diagnostic source context.
Allocation-free runtime results for kernel backend attempts.
Definition qnum.hpp:403
Definition linalg/async.hpp:28
KernelDispatchFailure
Classify why an ordered kernel-dispatch walk failed.
Definition dispatch_error.hpp:44
std::integral_constant< KernelTypeAcceptance, Value > KernelAcceptance
Type-level result returned by kernel_accepts_types customizations.
Definition dispatch_error.hpp:31
constexpr KernelAcceptance< KernelTypeAcceptance::no > kernel_types_no
Report that a backend rejects the argument types.
Definition dispatch_error.hpp:34
KernelTypeAcceptance
Type-level backend eligibility for an operation and argument set.
Definition dispatch_error.hpp:24
constexpr KernelAcceptance< KernelTypeAcceptance::maybe > kernel_types_maybe
Report that runtime operand values determine backend acceptance.
Definition dispatch_error.hpp:37
constexpr KernelAcceptance< KernelTypeAcceptance::yes > kernel_types_yes
Report that a backend accepts every instance of the argument types.
Definition dispatch_error.hpp:40
Describe one backend's role in a failed dispatch walk.
Definition dispatch_error.hpp:51
KernelTypeAcceptance type_acceptance
Definition dispatch_error.hpp:53
std::string backend
Definition dispatch_error.hpp:52
std::optional< KernelAttempt > runtime_result
Definition dispatch_error.hpp:54