Skip to main content

LanczosPlan

Struct LanczosPlan 

Source
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:

  1. SpMV: w = A * v_j (delegated to the SpMV module)
  2. Dot product: alpha_j = w . v_j
  3. Orthogonalization: w = w - alpha_j * v_j - beta_{j-1} * v_{j-1}
  4. Norm computation: beta_j = ||w||
  5. Normalization: v_{j+1} = w / beta_j

Additionally provides full reorthogonalization to maintain numerical stability.

Implementations§

Source§

impl LanczosPlan

Source

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 == 0
  • num_eigenvalues == 0
  • max_iterations < num_eigenvalues
  • max_iterations > n
  • tolerance <= 0
Source

pub fn config(&self) -> &LanczosConfig

Returns the configuration for this plan.

Source

pub fn dimension(&self) -> usize

Returns the matrix dimension.

Source

pub fn workspace_bytes_f64(&self) -> usize

Returns the workspace size in bytes needed for f64 Lanczos vectors.

The workspace must hold:

  • max_iterations + 1 Lanczos vectors of dimension n (for reorthogonalization)
  • 1 work vector w of dimension n
  • max_iterations alpha values
  • max_iterations beta values
Source

pub fn workspace_bytes_f32(&self) -> usize

Returns the workspace size in bytes needed for f32 Lanczos vectors.

Source

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-place
  • v_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_j
  • beta_prev: the previous beta_{j-1} value (as bits)
  • beta_out_ptr: device pointer to output scalar beta_j
  • n: vector length
§Errors

Returns SparseError::PtxGeneration if kernel generation fails.

Source

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.

Source

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-place
  • v_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 against
  • n: vector length
§Errors

Returns SparseError::PtxGeneration if kernel generation fails.

Source

pub fn generate_reorthogonalize_ptx_f32(&self) -> SparseResult<String>

Generates PTX for full reorthogonalization (f32 variant).

Source

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.

Source

pub fn generate_dot_product_ptx_f32(&self) -> SparseResult<String>

Generates PTX for the dot product reduction kernel (f32).

Source

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).

Source

pub fn generate_norm_sq_ptx_f32(&self) -> SparseResult<String>

Generates PTX for the vector norm-squared reduction kernel (f32).

Trait Implementations§

Source§

impl Debug for LanczosPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more