|
docc 0.8.3 (0d44999b)
C++ API 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>
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 |
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.
|
explicit |
|
overridevirtual |
Apply this transformation to the SDFG.
| builder | The SDFG builder |
| analysis_manager | The analysis manager (may be invalidated) |
Implements sdfg::transformations::Transformation.
|
inline |
|
overridevirtual |
Check if this transformation can be safely applied.
| builder | The SDFG builder |
| analysis_manager | The analysis manager providing necessary analyses |
Implements sdfg::transformations::Transformation.
|
static |
|
overridevirtual |
Get the name of this transformation.
Implements sdfg::transformations::Transformation.
|
inline |
|
overridevirtual |
Serialize this transformation to JSON.
| j | JSON object to populate with transformation description |
| std::logic_error | if not implemented |
Implements sdfg::transformations::Transformation.