docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg::fp_math::QuantizeContraction Class Reference

Computes a floating-point matmul (MatMul or GEMM node) on integers, quantized with a scale per row of A and per column of B. More...

#include <sdfg/fp_math/transformations/quantize_contraction.h>

Inheritance diagram for sdfg::fp_math::QuantizeContraction:
[legend]

Public Member Functions

 QuantizeContraction (data_flow::LibraryNode &node, int bits=8, Rescaling rescaling=Rescaling::Exponents)
virtual std::string name () const override
 Get the name of this transformation.
virtual bool can_be_applied (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
 Check if this transformation can be safely applied.
virtual void apply (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
 Apply this transformation to the SDFG.
virtual void to_json (nlohmann::json &j) const override
 Serialize this transformation to JSON.
int bits () const
Rescaling rescaling () const
Public Member Functions inherited from sdfg::transformations::Transformation
virtual ~Transformation ()=default
virtual void set_report (PassReportConsumer *report)
 Set the report consumer for transformation feedback.
virtual bool try_apply (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager)
 Attempt to apply the transformation if possible.

Static Public Member Functions

static QuantizeContraction from_json (builder::StructuredSDFGBuilder &builder, const nlohmann::json &j)

Additional Inherited Members

Protected Attributes inherited from sdfg::transformations::Transformation
PassReportConsumer * report_ = nullptr

Detailed Description

Computes a floating-point matmul (MatMul or GEMM node) on integers, quantized with a scale per row of A and per column of B.

With q = 2^(bits-1) - 1, s_A[i] = max_k |A[i, k]| and s_B[j] = max_k |B[k, j]|:

A_q[i, k] = rint(q * A[i, k] / s_A[i])          (Int8)
B_q[k, j] = rint(q * B[k, j] / s_B[j])          (Int8)
P         = A_q @ B_q                            (Int8 -> Int32 MatMul, exact)
Y[i, j]   = P[i, j] * (s_A[i] / q) * (s_B[j] / q)

The scales are computed at run time, so the result changes with every rounding of A and B: about 1% relative error for 8 bits. The Int8 matmul stays a library node for the target to map, e.g. onto integer matrix units.

Applies to a Float or Double MatMul, also one repeating over batch dimensions with scales per matrix, or a row-major GEMM (whose alpha and beta it applies to the result), with a constant K small enough for exact Int32 accumulation.

Constructor & Destructor Documentation

◆ QuantizeContraction()

sdfg::fp_math::QuantizeContraction::QuantizeContraction ( data_flow::LibraryNode & node,
int bits = 8,
Rescaling rescaling = Rescaling::Exponents )
explicit

Member Function Documentation

◆ apply()

virtual void sdfg::fp_math::QuantizeContraction::apply ( builder::StructuredSDFGBuilder & builder,
analysis::AnalysisManager & analysis_manager )
overridevirtual

Apply this transformation to the SDFG.

Parameters
builderThe SDFG builder
analysis_managerThe analysis manager (may be invalidated)

Implements sdfg::transformations::Transformation.

◆ bits()

int sdfg::fp_math::QuantizeContraction::bits ( ) const
inline

◆ can_be_applied()

virtual bool sdfg::fp_math::QuantizeContraction::can_be_applied ( builder::StructuredSDFGBuilder & builder,
analysis::AnalysisManager & analysis_manager )
overridevirtual

Check if this transformation can be safely applied.

Parameters
builderThe SDFG builder
analysis_managerThe analysis manager providing necessary analyses
Returns
true if all preconditions are met

Implements sdfg::transformations::Transformation.

◆ from_json()

QuantizeContraction sdfg::fp_math::QuantizeContraction::from_json ( builder::StructuredSDFGBuilder & builder,
const nlohmann::json & j )
static

◆ name()

virtual std::string sdfg::fp_math::QuantizeContraction::name ( ) const
overridevirtual

Get the name of this transformation.

Returns
The transformation name (e.g., "LoopInterchange")

Implements sdfg::transformations::Transformation.

◆ rescaling()

Rescaling sdfg::fp_math::QuantizeContraction::rescaling ( ) const
inline

◆ to_json()

virtual void sdfg::fp_math::QuantizeContraction::to_json ( nlohmann::json & j) const
overridevirtual

Serialize this transformation to JSON.

Parameters
jJSON object to populate with transformation description
Exceptions
std::logic_errorif not implemented

Implements sdfg::transformations::Transformation.


The documentation for this class was generated from the following file: