#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION) #pragma once #include template struct OrgqrParams { int32_t num_batch_dims; uint32_t m; uint32_t m2; uint32_t n; uint32_t k; ::c10::metal::array A_strides; ::c10::metal::array tau_strides; ::c10::metal::array H_strides; ::c10::metal::array H_sizes; }; struct UnpackPivotsParams { uint32_t perm_batch_stride; uint32_t pivots_batch_stride; uint32_t dim_size; }; // Parameters for batched triangular solves. // Solves op(A) X = B (left) or X op(A) = B (right), where op applies an // optional transpose and/or conjugation. struct TriangularSolveParams { uint32_t nbatch; // number of batch matrices uint32_t n; // triangular dimension (A is n x n) uint32_t k; // number of independent RHS vectors per batch bool upper; // A is upper-triangular (before op) bool transpose; // op transposes A bool conj; // op conjugates A (adjoint when combined with transpose) bool unit; // unit (implicit 1) diagonal bool b_col_major; // B is column-major (element (r, c) at r + c * n) bool x_col_major; // X is column-major }; C10_METAL_CONSTEXPR uint32_t kTriangularSolveTileSize = 8; C10_METAL_CONSTEXPR uint32_t kTriangularSolveMppRows = 16; C10_METAL_CONSTEXPR uint32_t kTriangularSolveMppCols = 32; template struct GeqrfParams { int32_t num_batch_dims; ::c10::metal::array A_sizes; ::c10::metal::array A_strides; ::c10::metal::array tau_strides; }; enum class GemmEpilogue : int { None = 0, Bias = 1 }; // n - output length // ld - matrix row stride // ms - matrix stride along the reduction/output dimension // xs - vector stride // bias_r/bias_c - row/col strides of the bias (for addmm) // 64-bit so huge operands fit; kernels narrow to their IDX template width. struct GemvDims { int64_t n, K, ld, ms, xs; int64_t bias_r, bias_c; }; struct SvdParams { uint32_t m; // staged rows = max(orig m,n) >= n uint32_t n; // staged cols = k = min(orig m,n) uint32_t max_sweeps; float tol; uint32_t u_ld; uint32_t u_bstride; uint32_t v_ld; uint32_t v_bstride; bool compute_uv; bool transposed; // SVD ran on A^H (left/right vectors swap targets) bool stage_v; // V accumulator in threadgroup mem (Vtg) vs device mem (Vacc) }; struct EighParams { uint32_t n; uint32_t max_sweeps; float tol; bool compute_v; bool upper; // UPLO: true read upper triangle, false read lower }; // Per-thread small-matrix inverse kernel: up to this size one thread inverts a // whole matrix from registers. LinearAlgebra.metal instantiates exact sizes // 1..4 and static_asserts the list against this constant. Strides are in // elements. C10_METAL_CONSTEXPR int64_t kLUSmallInvMax = 4; template struct LUSmallInvParams { index_t A_bstride; index_t A_rstride; index_t A_cstride; index_t X_bstride; index_t X_rstride; index_t X_cstride; }; // for LU streaming-panel kernels C10_METAL_CONSTEXPR unsigned kLUStreamNT = 256; C10_METAL_CONSTEXPR unsigned kLUStreamWarpsPerTG = kLUStreamNT / c10::metal::simdgroup_size; // Per-batch streaming LU scratch: argmax value partials (float magnitudes), // argmax index partials (uint), then the U row in the element type. Shared // host/device so the host allocates B * sizeof(LUStreamScratch) bytes and // binds it untyped; the kernel indexes scratch[batch] and the compiler owns the // stride. T is float or c10::metal::complex (float2 on Metal). template struct LUStreamScratch { ::c10::metal::array vpart; ::c10::metal::array ipart; ::c10::metal::array uRow; }; #else #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined." #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)