choice.hh
Go to the documentation of this file.
1#pragma once
2
3/// @file
4/// @brief symm: expand, vendor. evidence: docs/perf/level3.md @ingroup api_selection_ops
5
7
8#include <algorithm>
9#include <array>
10#include <cstdint>
11#include <string_view>
12#include <variant>
13
15
16struct Expand : select::NoFields<"expand"> {}; ///< expand_mirrored into scratch + the public gemm; scratch must fit
17struct Vendor : select::NoFields<"vendor"> {}; ///< backend::symm_vendor (cublas?symm / cblas_?symm loop)
18
19using SymmChoice = std::variant<Expand, Vendor>; ///< fieldless: expansion ld and gemm tile derived; native: CUDA GPU
20
21template <class T> /// Every compiled choice, in tie-break order (§6.3): the expansion, then the vendor loop.
22constexpr auto candidates() { return select::all_of<SymmChoice>(); }
23
24inline constexpr std::array<std::string_view, 2> last_resort{"expand", "vendor"}; ///< nothing in the row runs
25inline constexpr select::OpSpec spec{Op::symm, select::Lib::level3, {last_resort}}; ///< op, vendor library, rules
26
27/// Keys: form exact (the transcribed squareish test as an axis); m, n: C's extents; batch. Side is no key (never read).
28inline constexpr std::array<std::string_view, 4> key_names{"form:exact", "m:log", "n:log", "batch:log"};
29
30/// sq if 2 min >= max, else tall (a > 2b) or wide: the transcribed squareish ratio as an exact key.
31inline std::string_view form_of(std::int64_t a, std::int64_t b) {
32 return 2 * std::min(a, b) >= std::max(a, b) ? "sq" : (a > 2 * b ? "tall" : "wide");
33}
34
35// The transcriber's grid: 255|256 and 3|4 straddle the transcribed thresholds (flat-kernel-selection.md §12).
36inline constexpr std::array<std::string_view, 3> grid_form{"sq", "tall", "wide"}; ///< form axis of the grid
37inline constexpr std::array<int, 14> grid_mn{1, 2, 4, 8, 16, 32, 64, 128, 255, 256, 512, 1024, 2048, 4096}; ///< m, n
38inline constexpr std::array<int, 9> grid_batch{1, 2, 3, 4, 8, 128, 1024, 8192, 32768}; ///< batch axis of the grid
39
40inline constexpr std::int64_t kMaxGridBatch = 65535; ///< expand_mirrored puts the batch in SYCL dim 0 = CUDA grid z
41inline constexpr int kExpandWg = 256; ///< expand_mirrored's work-group: kMirrorGroupCols x kMirrorTile
42
43} // namespace batchlas::ops::symm
constexpr auto all_of()
Every alternative of a field-less choice variant, in declaration (= tie-break) order.
Definition select.hh:110
std::variant< Expand, Vendor > SymmChoice
fieldless: expansion ld and gemm tile derived; native: CUDA GPU
Definition choice.hh:19
constexpr std::array< int, 9 > grid_batch
batch axis of the grid
Definition choice.hh:38
constexpr std::array< int, 14 > grid_mn
m, n
Definition choice.hh:37
std::string_view form_of(std::int64_t a, std::int64_t b)
sq if 2 min >= max, else tall (a > 2b) or wide: the transcribed squareish ratio as an exact key.
Definition choice.hh:31
constexpr int kExpandWg
expand_mirrored's work-group: kMirrorGroupCols x kMirrorTile
Definition choice.hh:41
constexpr select::OpSpec spec
op, vendor library, rules
Definition choice.hh:25
constexpr std::int64_t kMaxGridBatch
expand_mirrored puts the batch in SYCL dim 0 = CUDA grid z
Definition choice.hh:40
constexpr auto candidates()
Every compiled choice, in tie-break order (§6.3): the expansion, then the vendor loop.
Definition choice.hh:22
constexpr std::array< std::string_view, 2 > last_resort
nothing in the row runs
Definition choice.hh:24
constexpr std::array< std::string_view, 4 > key_names
Keys: form exact (the transcribed squareish test as an axis); m, n: C's extents; batch....
Definition choice.hh:28
constexpr std::array< std::string_view, 3 > grid_form
form axis of the grid
Definition choice.hh:36
Flat kernel selection: one choose() per op over measured per-device tables.
expand_mirrored into scratch + the public gemm; scratch must fit
Definition choice.hh:16
backend::symm_vendor (cublas?symm / cblas_?symm loop)
Definition choice.hh:17
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