pub struct LanczosPlan { /* private fields */ }Expand description
Lanczos iteration plan for symmetric sparse eigenvalue problems.
Generates PTX kernels for each phase of the Lanczos recurrence:
- SpMV:
w = A * v_j(delegated to the SpMV module) - Dot product:
alpha_j = w . v_j - Orthogonalization:
w = w - alpha_j * v_j - beta_{j-1} * v_{j-1} - Norm computation:
beta_j = ||w|| - Normalization:
v_{j+1} = w / beta_j
Additionally provides full reorthogonalization to maintain numerical stability.
Implementations§
Source§impl LanczosPlan
impl LanczosPlan
Sourcepub fn new(config: LanczosConfig, n: usize) -> SparseResult<Self>
pub fn new(config: LanczosConfig, n: usize) -> SparseResult<Self>
Creates a new Lanczos plan for an n x n symmetric matrix.
§Errors
Returns SparseError::InvalidArgument if configuration is invalid:
n == 0num_eigenvalues == 0max_iterations < num_eigenvaluesmax_iterations > ntolerance <= 0
Sourcepub fn config(&self) -> &LanczosConfig
pub fn config(&self) -> &LanczosConfig
Returns the configuration for this plan.
Sourcepub fn workspace_bytes_f64(&self) -> usize
pub fn workspace_bytes_f64(&self) -> usize
Returns the workspace size in bytes needed for f64 Lanczos vectors.
The workspace must hold:
max_iterations + 1Lanczos vectors of dimensionn(for reorthogonalization)- 1 work vector
wof dimensionn max_iterationsalpha valuesmax_iterationsbeta values
Sourcepub fn workspace_bytes_f32(&self) -> usize
pub fn workspace_bytes_f32(&self) -> usize
Returns the workspace size in bytes needed for f32 Lanczos vectors.
Sourcepub fn generate_lanczos_step_ptx(&self) -> SparseResult<String>
pub fn generate_lanczos_step_ptx(&self) -> SparseResult<String>
Generates PTX for a single Lanczos step kernel (f64).
The kernel performs the orthogonalization and normalization phases of one Lanczos iteration:
// Input: w = A * v_j (SpMV already done)
alpha_j = dot(w, v_j) // dot product
w = w - alpha_j * v_j - beta_{j-1} * v_{j-1} // orthogonalize
beta_j = ||w|| // norm
v_{j+1} = w / beta_j // normalize§Kernel Parameters
w_ptr: device pointer to work vector w (length n), modified in-placev_j_ptr: device pointer to current Lanczos vector v_j (length n)v_jm1_ptr: device pointer to previous Lanczos vector v_{j-1} (length n)v_jp1_ptr: device pointer to output vector v_{j+1} (length n)alpha_ptr: device pointer to output scalar alpha_jbeta_prev: the previous beta_{j-1} value (as bits)beta_out_ptr: device pointer to output scalar beta_jn: vector length
§Errors
Returns SparseError::PtxGeneration if kernel generation fails.
Sourcepub fn generate_lanczos_step_ptx_f32(&self) -> SparseResult<String>
pub fn generate_lanczos_step_ptx_f32(&self) -> SparseResult<String>
Generates PTX for a single Lanczos step kernel (f32).
Same semantics as generate_lanczos_step_ptx
but for single-precision floating point.
Sourcepub fn generate_reorthogonalize_ptx(&self) -> SparseResult<String>
pub fn generate_reorthogonalize_ptx(&self) -> SparseResult<String>
Generates PTX for full reorthogonalization against all previous Lanczos vectors.
This kernel applies modified Gram-Schmidt orthogonalization of w
against the first j Lanczos vectors stored column-major in V.
for i in 0..j:
h = dot(w, V[:, i])
w = w - h * V[:, i]Each thread handles one element of w and iterates over all j vectors,
using warp reductions for the dot products.
§Kernel Parameters
w_ptr: device pointer to vector to orthogonalize (length n), modified in-placev_basis_ptr: device pointer to basis matrix V stored column-major (n x j)coeffs_ptr: device pointer to output coefficients h_i (length j)num_vecs: number of basis vectors j to orthogonalize againstn: vector length
§Errors
Returns SparseError::PtxGeneration if kernel generation fails.
Sourcepub fn generate_reorthogonalize_ptx_f32(&self) -> SparseResult<String>
pub fn generate_reorthogonalize_ptx_f32(&self) -> SparseResult<String>
Generates PTX for full reorthogonalization (f32 variant).
Sourcepub fn generate_dot_product_ptx(&self) -> SparseResult<String>
pub fn generate_dot_product_ptx(&self) -> SparseResult<String>
Generates PTX for the dot product reduction kernel (f64).
Used to compute alpha_j = dot(w, v_j) in the Lanczos recurrence.
Sourcepub fn generate_dot_product_ptx_f32(&self) -> SparseResult<String>
pub fn generate_dot_product_ptx_f32(&self) -> SparseResult<String>
Generates PTX for the dot product reduction kernel (f32).
Sourcepub fn generate_norm_sq_ptx(&self) -> SparseResult<String>
pub fn generate_norm_sq_ptx(&self) -> SparseResult<String>
Generates PTX for the vector norm-squared reduction kernel (f64).
Used to compute beta_j = ||w|| (caller takes sqrt of the result).
Sourcepub fn generate_norm_sq_ptx_f32(&self) -> SparseResult<String>
pub fn generate_norm_sq_ptx_f32(&self) -> SparseResult<String>
Generates PTX for the vector norm-squared reduction kernel (f32).