potrf_native.hh
Go to the documentation of this file.
1#pragma once
2
3// Native batched POTRF, declarations only (no <sycl/sycl.hpp>). EVERY *_dispatch re-checks its
4// limits, and can_run() in src/ops/potrf/potrf.cc must agree exactly. evidence: docs/perf/potrf.md
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// TINY tier (potrf_tiny.cc): it owns NO local memory, so the ceiling takes no budget argument
20// and is a flat compile-time constant; 0 = absent. evidence: docs/perf/potrf.md#potrf-the-tiny-tier
21template <typename T>
22BATCHLAS_INTERNAL_API int potrf_tiny_max_n();
23
24// The tier's fixed work-group size; potrf_tiny_dispatch refuses a smaller MAX_WORK_GROUP_SIZE.
25inline constexpr int kPotrfTinyWgSize = 64;
26
27// NOT zero: an empty or SHORT caller `info` span means "not requested" and draws scratch.
28template <typename T>
29BATCHLAS_INTERNAL_API std::size_t potrf_tiny_buffer_size(
31
32template <typename T>
33BATCHLAS_INTERNAL_API unsigned potrf_tiny_debug_launch(Queue& ctx, int n); // G | S<<16
34
35template <typename T>
36BATCHLAS_INTERNAL_API Event potrf_tiny_dispatch(Queue& ctx,
38 Uplo uplo,
39 Span<std::byte> workspace,
40 Span<int32_t> info);
41
42// Per-type CTA capacity for a budget in BYTES: the budget is a device property, and a
43// hardcoded ceiling makes can_run promise an unlaunchable choice. `min_blocks_per_sm`
44// scales it to the ADVERTISED capacity; 1 asks the residency question, which has a different
45// answer. evidence: docs/perf/potrf.md#potrf-the-occupancy-rule
46template <typename T>
47BATCHLAS_INTERNAL_API int potrf_cta_max_n_for_slm(
48 std::size_t slm_budget_bytes,
49 int min_blocks_per_sm = resident::kMinBlocksPerSm);
50
51template <typename T>
53
54// LPANEL tier (potrf_lpanel.cc): ONE n x NB panel in local memory instead of the whole
55// matrix. TWO caps, hence the second argument -- the local-memory slice AND
56// MAX_WORK_GROUP_SIZE, because the body needs one work-item per row. nb_hint 0 means the
57// type's default NB; a value this build does not instantiate answers 0 here and throws at
58// dispatch. evidence: docs/perf/potrf.md#the-lpanel-tier
59template <typename T>
60BATCHLAS_INTERNAL_API int potrf_lpanel_max_n_for_slm(
61 std::size_t slm_budget_bytes,
62 int max_wg_size,
63 int min_blocks_per_sm = resident::kMinBlocksPerSm,
64 int nb_hint = 0);
65
66template <typename T>
67BATCHLAS_INTERNAL_API std::size_t potrf_lpanel_buffer_size( // short info span draws scratch
69
70template <typename T>
71BATCHLAS_INTERNAL_API unsigned potrf_lpanel_debug_launch( // NB<<16 | L<<4 | G, 0 if unfit
72 Queue& ctx, int n, int batch,
73 int min_blocks_per_sm = resident::kMinBlocksPerSm,
74 int nb_hint = 0);
75
76template <typename T>
77BATCHLAS_INTERNAL_API Event potrf_lpanel_dispatch(
78 Queue& ctx,
80 Uplo uplo, // LOWER ONLY: the left-looking update reads the already-factored triangle
81 Span<std::byte> workspace,
82 Span<int32_t> info, // LAPACK's: 1-based, GLOBAL to this view, first failure wins
83 int min_blocks_per_sm = resident::kMinBlocksPerSm,
84 int nb_hint = 0);
85
86template <typename T>
87BATCHLAS_INTERNAL_API bool potrf_blocked_available();
88
89// Replay the layout through BumpAllocator::measuring(): a hand-summed exact figure fails it.
90template <typename T>
91BATCHLAS_INTERNAL_API std::size_t potrf_cta_buffer_size(Queue& ctx,
93
94template <typename T>
95BATCHLAS_INTERNAL_API unsigned potrf_cta_debug_launch(
96 Queue& ctx, int n, int batch,
97 int min_blocks_per_sm = resident::kMinBlocksPerSm); // G | L<<16, 0 if unfit
98
99template <typename T>
100BATCHLAS_INTERNAL_API Event potrf_cta_dispatch(Queue& ctx,
102 Uplo uplo,
103 Span<std::byte> workspace,
104 Span<int32_t> info,
105 int min_blocks_per_sm = resident::kMinBlocksPerSm);
106
107// Trailing-update GEMM, REQUIRED (empty throws): pass the public gemm.
108template <typename T>
109using PotrfTrailingGemm = std::function<Event(
110 Queue&,
115
116// The panel solve, REQUIRED (empty throws): pass the public trsm. ALPHA IS IN POSITION 4.
117template <typename T>
118using PotrfPanelSolve = std::function<Event(
119 Queue&,
120 const MatrixView<T, MatrixFormat::Dense>&, // A: the ib x ib factored L11
121 const MatrixView<T, MatrixFormat::Dense>&, // B: the m2 x ib panel, in place
122 T, // alpha
123 Side, Uplo, Transpose, Diag)>;
124
125template <typename T>
126BATCHLAS_INTERNAL_API std::size_t potrf_blocked_buffer_size(Queue& ctx,
128 Uplo uplo);
129
130template <typename T>
131BATCHLAS_INTERNAL_API unsigned potrf_blocked_debug_params(Queue& ctx, int n); // nb | W<<16
132
133// Uplo::LOWER ONLY -- the right-looking schedule overwrites the wrong triangle for Upper,
134// so it throws. `info` is LAPACK's (1-based, GLOBAL, first failure wins) while the leaf
135// writes a sub-view-LOCAL index, so the driver translates and merges.
136template <typename T>
137BATCHLAS_INTERNAL_API Event potrf_blocked_dispatch(Queue& ctx,
139 Uplo uplo,
140 Span<std::byte> workspace,
141 Span<int32_t> info,
142 PotrfTrailingGemm<T> trailing_gemm,
143 PotrfPanelSolve<T> panel_solve);
144
145} // namespace batchlas::sycl_potrf
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
Diag
Whether a triangular operand's diagonal is read or assumed to be one.
Definition enums.hh:303
ComputePrecision
Internal compute precision of a GEMM (the cuBLAS cublasComputeType_t).
Definition enums.hh:505
Uplo
Which triangle of a symmetric, Hermitian or triangular operand is referenced.
Definition enums.hh:287
Side
Side on which a special operand multiplies: op(A) * B or B * op(A).
Definition enums.hh:319
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
BATCHLAS_INTERNAL_API unsigned potrf_blocked_debug_params(Queue &ctx, int n)
BATCHLAS_INTERNAL_API std::size_t potrf_cta_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
std::function< Event( Queue &, const MatrixView< T, MatrixFormat::Dense > &, const MatrixView< T, MatrixFormat::Dense > &, const MatrixView< T, MatrixFormat::Dense > &, T, T, Transpose, Transpose, ComputePrecision)> PotrfTrailingGemm
BATCHLAS_INTERNAL_API Event potrf_tiny_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info)
BATCHLAS_INTERNAL_API int potrf_lpanel_max_n_for_slm(std::size_t slm_budget_bytes, int max_wg_size, int min_blocks_per_sm=resident::kMinBlocksPerSm, int nb_hint=0)
BATCHLAS_INTERNAL_API Event potrf_blocked_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info, PotrfTrailingGemm< T > trailing_gemm, PotrfPanelSolve< T > panel_solve)
BATCHLAS_INTERNAL_API Event potrf_lpanel_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info, int min_blocks_per_sm=resident::kMinBlocksPerSm, int nb_hint=0)
constexpr int kPotrfTinyWgSize
BATCHLAS_INTERNAL_API std::size_t potrf_blocked_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo)
BATCHLAS_INTERNAL_API unsigned potrf_lpanel_debug_launch(Queue &ctx, int n, int batch, int min_blocks_per_sm=resident::kMinBlocksPerSm, int nb_hint=0)
BATCHLAS_INTERNAL_API bool potrf_blocked_available()
BATCHLAS_INTERNAL_API int potrf_tiny_max_n()
BATCHLAS_INTERNAL_API std::size_t potrf_tiny_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
BATCHLAS_INTERNAL_API std::size_t potrf_lpanel_buffer_size(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A)
BATCHLAS_INTERNAL_API int potrf_cta_max_n_for_slm(std::size_t slm_budget_bytes, int min_blocks_per_sm=resident::kMinBlocksPerSm)
BATCHLAS_INTERNAL_API unsigned potrf_cta_debug_launch(Queue &ctx, int n, int batch, int min_blocks_per_sm=resident::kMinBlocksPerSm)
std::function< Event( Queue &, const MatrixView< T, MatrixFormat::Dense > &, const MatrixView< T, MatrixFormat::Dense > &, T, Side, Uplo, Transpose, Diag)> PotrfPanelSolve
BATCHLAS_INTERNAL_API Event potrf_cta_dispatch(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, Uplo uplo, Span< std::byte > workspace, Span< int32_t > info, int min_blocks_per_sm=resident::kMinBlocksPerSm)
BATCHLAS_INTERNAL_API unsigned potrf_tiny_debug_launch(Queue &ctx, int n)
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.