geqrf_native.hh
Go to the documentation of this file.
1#pragma once
2
3// Native batched GEQRF: the CTA tier and the blocked driver, whose panel leaf IS the CTA device
4// function -- both TUs must share one device-code cluster. evidence: docs/perf/qr.md#qr-route-arms
5
6#include <src/util/internal-api.hh>
7#include <src/util/resident_capacity.hh>
12
13#include <cstddef>
14#include <cstdint>
15#include <functional>
16
18
19// 2, not resident::kMinBlocksPerSm's 4: this ceiling is a ROUTING cut wearing a capacity's
20// clothes, placed at the measured CTA-vs-Blocked crossover. GeqrfTest.OccupancyTargetIsPinned
21// fails if it moves. evidence: docs/perf/qr.md#settling-the-target-on-the-tall-panels
22inline constexpr int kGeqrfMinBlocksPerSm = 2;
23
24// The WHOLE budget (0 = tier absent); min_blocks_per_sm cuts the slice the tier ADVERTISES.
25template <typename T>
26BATCHLAS_INTERNAL_API int geqrf_cta_max_m_for_slm(
27 std::size_t slm_budget_bytes, int min_blocks_per_sm = kGeqrfMinBlocksPerSm);
28
29template <typename T>
30BATCHLAS_INTERNAL_API int64_t geqrf_cta_max_elems_for_slm(
31 std::size_t slm_budget_bytes, int min_blocks_per_sm = kGeqrfMinBlocksPerSm);
32
33template <typename T>
34BATCHLAS_INTERNAL_API bool geqrf_blocked_available();
35
36// TINY tier (square m == n <= 32): the ONE predicate for its ceiling -- the shape builder, the
37// entry point and the tests all call it. evidence: docs/perf/qr.md#the-tiny-ceiling-predicate
38template <typename T>
39BATCHLAS_INTERNAL_API int geqrf_tiny_max_n_for_slm(std::size_t slm_budget_bytes);
40
41// Zero and constant (monotone, as band_reduction.cc's sizing replay needs); never reads A.
42template <typename T>
43BATCHLAS_INTERNAL_API std::size_t geqrf_tiny_buffer_size(
45
46template <typename T>
47BATCHLAS_INTERNAL_API unsigned geqrf_tiny_debug_launch(Queue& ctx, int n); // G | N<<16
48
49template <typename T>
50BATCHLAS_INTERNAL_API Event geqrf_tiny_dispatch(Queue& ctx,
52 Span<T> tau,
53 Span<std::byte> workspace);
54
55// A BumpAllocator::measuring() replay, monotone in (rows, cols, batch); deref neither A nor tau.
56template <typename T>
57BATCHLAS_INTERNAL_API std::size_t geqrf_cta_buffer_size(Queue& ctx,
59
60template <typename T>
61BATCHLAS_INTERNAL_API std::size_t geqrf_blocked_buffer_size(Queue& ctx,
63
64template <typename T>
65BATCHLAS_INTERNAL_API unsigned geqrf_blocked_debug_params(
66 Queue& ctx, int m, int n); // nb | leaf<<16; high half 1 = resident, 2 = global, 0 = absent
67
68// Auto answers Register only inside a measured height window, and used_resident_out keeps
69// meaning LOCAL-memory residency. evidence: docs/perf/qr.md#the-panel-height-window
70enum class GeqrfPanelLeaf : int { Auto = 0, Resident = 1, Global = 2, Register = 3 };
71
72template <typename T>
73BATCHLAS_INTERNAL_API int geqrf_panel_reg_cols(); // 0 = absent for this scalar
74
75template <typename T>
76BATCHLAS_INTERNAL_API int geqrf_panel_reg_max_m();
77
78template <typename T> // THE ONE fit predicate: launcher, driver and tests all share it
79BATCHLAS_INTERNAL_API bool geqrf_panel_reg_fits(int m, int n, int device_max_wg = 1024);
80
81// SHOULD, not CAN: a window strictly inside `fits`. evidence: docs/perf/qr.md#the-panel-height-window
82template <typename T>
83BATCHLAS_INTERNAL_API bool geqrf_panel_reg_preferred(int m, int n, int device_max_wg = 1024);
84
85template <typename T>
86BATCHLAS_INTERNAL_API unsigned geqrf_panel_reg_debug_launch(
87 Queue& ctx, int m, int n); // wg | leaf<<16; 0 = no fit
88
89// REQUIRED (empty throws): pass the public gemm, which makes its own table-driven choice.
90template <typename T>
91using GeqrfTrailingGemm = std::function<Event(
92 Queue&,
97
98template <typename T>
99BATCHLAS_INTERNAL_API Event geqrf_cta_dispatch(Queue& ctx,
101 Span<T> tau,
102 Span<std::byte> workspace);
103
104template <typename T>
105BATCHLAS_INTERNAL_API Event geqrf_blocked_dispatch(Queue& ctx,
107 Span<T> tau,
108 Span<std::byte> workspace,
109 GeqrfTrailingGemm<T> trailing_gemm,
110 GeqrfPanelLeaf panel_leaf =
112
113// Raw pointers, not a MatrixView: a slice carries the PARENT pointer array. tau is indexed
114// tau_ptr[b * tau_batch_stride + tau_offset + j] with k = min(rows, cols) of the WHOLE matrix;
115// a panel-derived stride scatters tau silently, and only for batch > 1.
116template <typename T>
118 T* a_ptr, int ld, int stride,
119 int m, int n, int batch,
120 T* tau_ptr, int tau_batch_stride, int tau_offset,
121 bool* used_resident_out = nullptr,
123 GeqrfPanelLeaf* leaf_used_out = nullptr);
124
125// The CTA TIER's predicate, occupancy-scaled: capacity, this gate and the launcher's are ONE.
126template <typename T>
127BATCHLAS_INTERNAL_API bool geqrf_cta_fits(
128 int m, int n, std::size_t slm_budget_bytes,
129 int min_blocks_per_sm = kGeqrfMinBlocksPerSm);
130
131// The RESIDENCY predicate, at the whole budget: what chooses the resident leaf, not the tier.
132template <typename T>
133BATCHLAS_INTERNAL_API bool geqrf_leaf_fits(int m, int n, std::size_t slm_budget_bytes);
134
135} // namespace batchlas::sycl_geqrf
Non-owning view of a batch of matrices: the argument type of every entry point.
Definition matrix.hh:485
Enumerations, scalar traits and scalar concepts shared by every public header.
Transpose
The operator op() applied to an operand: op(A) = A, A^T or A^H.
Definition enums.hh:171
ComputePrecision
Internal compute precision of a GEMM (the cuBLAS cublasComputeType_t).
Definition enums.hh:505
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
BATCHLAS_INTERNAL_API unsigned geqrf_panel_reg_debug_launch(Queue &ctx, int m, int n)
BATCHLAS_INTERNAL_API bool geqrf_leaf_fits(int m, int n, std::size_t slm_budget_bytes)
BATCHLAS_INTERNAL_API int geqrf_panel_reg_cols()
BATCHLAS_INTERNAL_API int64_t geqrf_cta_max_elems_for_slm(std::size_t slm_budget_bytes, int min_blocks_per_sm=kGeqrfMinBlocksPerSm)
Event geqrf_panel_factorize(Queue &ctx, T *a_ptr, int ld, int stride, int m, int n, int batch, T *tau_ptr, int tau_batch_stride, int tau_offset, bool *used_resident_out=nullptr, GeqrfPanelLeaf leaf=GeqrfPanelLeaf::Auto, GeqrfPanelLeaf *leaf_used_out=nullptr)
BATCHLAS_INTERNAL_API Event geqrf_cta_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > workspace)
std::function< Event( Queue &, const MatrixView< T, MatrixFormat::Dense > &, const MatrixView< T, MatrixFormat::Dense > &, const MatrixView< T, MatrixFormat::Dense > &, T, T, Transpose, Transpose, ComputePrecision)> GeqrfTrailingGemm
BATCHLAS_INTERNAL_API bool geqrf_panel_reg_preferred(int m, int n, int device_max_wg=1024)
BATCHLAS_INTERNAL_API unsigned geqrf_tiny_debug_launch(Queue &ctx, int n)
BATCHLAS_INTERNAL_API Event geqrf_blocked_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > workspace, GeqrfTrailingGemm< T > trailing_gemm, GeqrfPanelLeaf panel_leaf=GeqrfPanelLeaf::Auto)
BATCHLAS_INTERNAL_API bool geqrf_cta_fits(int m, int n, std::size_t slm_budget_bytes, int min_blocks_per_sm=kGeqrfMinBlocksPerSm)
BATCHLAS_INTERNAL_API std::size_t geqrf_cta_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
BATCHLAS_INTERNAL_API Event geqrf_tiny_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Span< T > tau, Span< std::byte > workspace)
BATCHLAS_INTERNAL_API int geqrf_panel_reg_max_m()
BATCHLAS_INTERNAL_API unsigned geqrf_blocked_debug_params(Queue &ctx, int m, int n)
BATCHLAS_INTERNAL_API std::size_t geqrf_blocked_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
constexpr int kGeqrfMinBlocksPerSm
BATCHLAS_INTERNAL_API bool geqrf_panel_reg_fits(int m, int n, int device_max_wg=1024)
BATCHLAS_INTERNAL_API int geqrf_cta_max_m_for_slm(std::size_t slm_budget_bytes, int min_blocks_per_sm=kGeqrfMinBlocksPerSm)
BATCHLAS_INTERNAL_API std::size_t geqrf_tiny_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
BATCHLAS_INTERNAL_API int geqrf_tiny_max_n_for_slm(std::size_t slm_budget_bytes)
BATCHLAS_INTERNAL_API bool geqrf_blocked_available()
Completion handle of enqueued work, returned by every entry point.
Event()
An empty Event, already complete.
Where BatchLAS work runs: a device, a backend, an ordered SYCL queue and a workspace arena.
Non-owning view of size() contiguous elements of type T.
Definition sycl-span.hh:39
batchlas::Device, batchlas::Event and batchlas::Queue: where work runs and how it is ordered.
batchlas::Span, the non-owning pointer + length every entry point takes for 1-D data.