Documentation a537f1bdf2
Loading...
Searching...
No Matches
CSysMatrix.hpp File Reference

Declaration of the block-sparse matrix class. The implemtation is in CSysMatrix.cpp. More...

#include "../CConfig.hpp"
#include "../code_config.hpp"
#include "CSysVector.hpp"
#include "CPastixWrapper.hpp"
#include "../toolboxes/graph_toolbox.hpp"
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <cassert>
#include <optional>

Go to the source code of this file.

Classes

struct  CSysMatrixComms
 Helper to communicate distributed vectors. More...
 
struct  CBlockView< ScalarType >
 View of one matrix block, const-correct via the ScalarType template parameter. CBlockView<const ScalarType> is read-only; CBlockView<ScalarType> is mutable and exposes apply<Overwrite>(f) for writing with on-the-fly quantized encoding. Evaluates to false if the block is absent from the sparsity pattern. More...
 
class  CSysMatrix< ScalarType >
 Main class for defining block-compressed-row-storage sparse matrices. More...
 

Macros

#define EQR_PASSIVE(ROW, COL)   SU2_TYPE::PassiveValue(f(ROW, COL))
 
#define GET_BLOCK_VIEW_IMPL
 

Functions

float DecodeQuantScale (uint8_t e) noexcept
 Reconstruct the float row-scale from a stored uint8 binary exponent. e is stored already biased, i.e. it is the IEEE 754 biased-exponent field itself, so shifting it into place with a zero mantissa gives the exact power of two 2^(e-127). This is the inverse of the encoding in EncodeQuantBlock.
 
template<class F >
void EncodeQuantRow (const F &f, uint8_t &qs, int8_t *__restrict qv, unsigned long nVar, unsigned long r) noexcept
 Encode one row of an nVar×nVar block into int8 quantized storage: qs receives the row's scale exponent, qv (nVar entries) the clamped int8 values for row r. f(r,c) is called twice per entry (max-abs scan then encoding); it should be cheap.
 
template<class F >
void EncodeQuantBlock (const F &f, uint8_t *__restrict qs, int8_t *__restrict qv, unsigned long nVar) noexcept
 Encode one nVar×nVar block into per-row int8 quantized storage, see EncodeQuantRow (each row's scale/quantization is independent, this just loops over all of them serially for the host path).
 

Detailed Description

Declaration of the block-sparse matrix class. The implemtation is in CSysMatrix.cpp.

Author
F. Palacios, A. Bueno, T. Economon, P. Gomes
Version
8.5.0 "Harrier"

SU2 Project Website: https://su2code.github.io

The SU2 Project is maintained by the SU2 Foundation (http://su2foundation.org)

Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)

SU2 is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

SU2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with SU2. If not, see http://www.gnu.org/licenses/.

Macro Definition Documentation

◆ EQR_PASSIVE

#define EQR_PASSIVE (   ROW,
  COL 
)    SU2_TYPE::PassiveValue(f(ROW, COL))

◆ GET_BLOCK_VIEW_IMPL

#define GET_BLOCK_VIEW_IMPL
Value:
if (!quantized_mode || block_i == block_j) { \
return {GetBlock(block_i, block_j), nullptr, nullptr, nVar}; \
} \
if (block_j < block_i) { \
for (auto k = mat.row_ptr_l[block_i]; k < mat.row_ptr_l[block_i + 1]; ++k) \
if (mat.col_ind_l[k] == block_j) return {nullptr, &q_scale.l[k * nVar], &q_blocks.l[k * nVar * nVar], nVar}; \
} else { \
for (auto k = mat.row_ptr_u[block_i]; k < mat.row_ptr_u[block_i + 1]; ++k) \
if (mat.col_ind_u[k] == block_j) return {nullptr, &q_scale.u[k * nVar], &q_blocks.u[k * nVar * nVar], nVar}; \
} \
return {}

Function Documentation

◆ DecodeQuantScale()

float DecodeQuantScale ( uint8_t  e)
inlinenoexcept

Reconstruct the float row-scale from a stored uint8 binary exponent. e is stored already biased, i.e. it is the IEEE 754 biased-exponent field itself, so shifting it into place with a zero mantissa gives the exact power of two 2^(e-127). This is the inverse of the encoding in EncodeQuantBlock.

Note
Branches on CUDA_ARCH, plain memcpy compiles for the device but does not work!

◆ EncodeQuantBlock()

template<class F >
void EncodeQuantBlock ( const F &  f,
uint8_t *__restrict  qs,
int8_t *__restrict  qv,
unsigned long  nVar 
)
inlinenoexcept

Encode one nVar×nVar block into per-row int8 quantized storage, see EncodeQuantRow (each row's scale/quantization is independent, this just loops over all of them serially for the host path).

◆ EncodeQuantRow()

template<class F >
void EncodeQuantRow ( const F &  f,
uint8_t &  qs,
int8_t *__restrict  qv,
unsigned long  nVar,
unsigned long  r 
)
inlinenoexcept

Encode one row of an nVar×nVar block into int8 quantized storage: qs receives the row's scale exponent, qv (nVar entries) the clamped int8 values for row r. f(r,c) is called twice per entry (max-abs scan then encoding); it should be cheap.

Note
Shared with the device and thus same CUDA_ARCH branches as DecodeQuantScale. f's return type is cast to float directly on device (only ever instantiated there for plain ScalarType, never AD-active); on host it goes through SU2_TYPE::PassiveValue first, since ScalarType can be AD-active there (quantized_mode is only compiled out for reverse-mode AD, not forward-mode, see quantized_offdiag_needed in CSysMatrix.cpp) and PassiveValue is host-only (not SU2_CUDA_HOST_DEVICE).