choice.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief gemv: cta, direct, vendor. evidence: docs/perf/gemv.md @ingroup api_selection_ops
5
7
8#include <array>
9#include <string_view>
10#include <variant>
11
13
14struct Cta : select::NoFields<"cta"> {}; ///< sycl_gemv::gemv_native_cta, sub-group per output; Trans/ConjTrans
15struct Direct : select::NoFields<"direct"> {}; ///< sycl_gemv::gemv_native_direct, item per output; every device
16struct Vendor : select::NoFields<"vendor"> {}; ///< backend::gemv_vendor; any shape, needs the library
17
18using GemvChoice = std::variant<Cta, Direct, Vendor>; ///< fieldless: body and segment width W derived in the drivers
19
20template <class T> /// Every compiled choice, in tie-break order: the transcribed ladder.
21constexpr auto candidates() { return select::all_of<GemvChoice>(); }
22
23/// can_run's device terms (host-callable for tests). Cta body 3 is reqd_sub_group_size(32).
24inline bool device_allows(const GemvChoice& c, const select::Device& d, bool transposed) {
25 if (std::holds_alternative<Cta>(c)) return d.is_gpu && d.has_sg32 && transposed;
26 if (std::holds_alternative<Vendor>(c)) return d.has_vendor;
27 return true;
28}
29
30inline constexpr std::array<std::string_view, 2> last_resort{"vendor", "direct"}; ///< CPU: vendor, else direct (no GPU gate)
31inline constexpr select::OpSpec spec{Op::gemv, select::Lib::level3, {last_resort}}; ///< op, vendor library, rules
32
33/// Keys: trans exact (ConjTrans folds to T); out, red: y and x lengths (swap with trans). Work ~ out red batch.
34inline constexpr std::array<std::string_view, 4> key_names{"trans:exact", "out:log", "red:log", "batch:log"};
35
36/// Both sides of every transcribed threshold plus a coarse log grid; the transcriber spells the same.
37inline constexpr std::array<int, 8> grid_out{1, 8, 64, 255, 256, 1024, 4096, 32768};
38inline constexpr std::array<int, 11> grid_red{1, 8, 32, 63, 64, 128, 352, 353, 1024, 4096, 32768};
39inline constexpr std::array<int, 8> grid_batch{1, 16, 128, 319, 320, 1024, 8192, 32768};
40
41} // namespace batchlas::ops::gemv
constexpr auto all_of()
Every alternative of a field-less choice variant, in declaration (= tie-break) order.
Definition select.hh:110
constexpr std::array< std::string_view, 4 > key_names
Keys: trans exact (ConjTrans folds to T); out, red: y and x lengths (swap with trans)....
Definition choice.hh:34
constexpr std::array< std::string_view, 2 > last_resort
CPU: vendor, else direct (no GPU gate).
Definition choice.hh:30
bool device_allows(const GemvChoice &c, const select::Device &d, bool transposed)
can_run's device terms (host-callable for tests). Cta body 3 is reqd_sub_group_size(32).
Definition choice.hh:24
constexpr select::OpSpec spec
op, vendor library, rules
Definition choice.hh:31
constexpr std::array< int, 8 > grid_out
Both sides of every transcribed threshold plus a coarse log grid; the transcriber spells the same.
Definition choice.hh:37
std::variant< Cta, Direct, Vendor > GemvChoice
fieldless: body and segment width W derived in the drivers
Definition choice.hh:18
constexpr auto candidates()
Every compiled choice, in tie-break order: the transcribed ladder.
Definition choice.hh:21
constexpr std::array< int, 11 > grid_red
Definition choice.hh:38
constexpr std::array< int, 8 > grid_batch
Definition choice.hh:39
Flat kernel selection: one choose() per op over measured per-device tables.
sycl_gemv::gemv_native_cta, sub-group per output; Trans/ConjTrans
Definition choice.hh:14
sycl_gemv::gemv_native_direct, item per output; every device
Definition choice.hh:15
backend::gemv_vendor; any shape, needs the library
Definition choice.hh:16
The device facts a can_run predicate and the table lookup read (§5.1).
Definition select.hh:44
bool has_vendor
the asking op's library group (OpSpec::vendor) is compiled in
Definition select.hh:50
Base of a family with no knobs: struct Cta : NoFields<"cta"> {};.
Definition select.hh:101
What an op's choice.hh declares once: its name, the library its Vendor family calls (one gate for can...
Definition select.hh:529