跳到主要内容

PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION

PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION

ASL 伪代码

下面直接显示完整的 ASL 所有者。

// PTO-UNIT: {"id":"PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION","surface":"arch","classification":["profile","reference-quantization"],"depends_on":["PTO-ARCH-PROFILE-REFERENCE-PROFILE","PTO-TILE-MODEL-NUMERIC-FORMATS"]}pure func ReferencePowerOfTwo(exponent: integer {-149..127}) => realbegin    var result: real = 1.0;    if exponent > 0 then        for step = 1 to exponent looplimit 127 do            result = result * 2.0;        end;    elsif exponent < 0 then        for step = 1 to -exponent looplimit 149 do            result = result / 2.0;        end;    end;    return result;end;
pure func ReferenceFP32FiniteValue(value: bits(32)) => realbegin    let exponent = UInt(value[30:23]);    let fraction = UInt(value[22:0]);    assert exponent != 255;    var magnitude: real = 0.0;    if exponent == 0 then        magnitude = Real(fraction) * ReferencePowerOfTwo(-149);    else        let significand = Real(0x800000 + fraction) / Real(0x800000);        magnitude = significand * ReferencePowerOfTwo(            (exponent - 127) as integer {-126..127});    end;    if value[31] == '1' then return -magnitude; end;    return magnitude;end;
pure func ReferenceIntegerValue(value: Word,                                data_type: TileDataType) => integerbegin    let normalized = NormalizeTileInteger(value, data_type);    if TileDataTypeIsSigned(data_type) then return SInt(normalized); end;    return UInt(normalized);end;
func ReferenceFP32FiniteEncoding(    value: real,    rounding_mode: NumericRoundingMode) => (Word, bits(5))begin    if value == 0.0 then return (Zeros{PTO_XLEN}, Zeros{5}); end;    let negative = value < 0.0;    var normalized = if negative then -value else value;    var exponent: integer {-149..128} = 0;    for step = 1 to 128 looplimit 128 do        if normalized >= 2.0 && exponent < 128 then            normalized = normalized / 2.0;            exponent = (exponent + 1) as integer {-149..128};        end;    end;    for step = 1 to 149 looplimit 149 do        if normalized < 1.0 && exponent > -149 then            normalized = normalized * 2.0;            exponent = (exponent - 1) as integer {-149..128};        end;    end;
    let sign = if negative then 0x80000000 else 0;    if exponent > 127 then        return (            Zeros{PTO_XLEN} + sign + 0x7f800000,            Zeros{5} + 0x14);    end;
    if exponent < -126 then        let scaled = value / ReferencePowerOfTwo(-149);        let rounded = FloatingToInteger(scaled, rounding_mode);        let magnitude = if rounded < 0 then -rounded else rounded;        if magnitude == 0 then            return (Zeros{PTO_XLEN} + sign, Zeros{5} + 0x18);        end;        return (            Zeros{PTO_XLEN} + sign + magnitude,            if Real(rounded) == scaled then Zeros{5}            else Zeros{5} + 0x18);    end;
    let scaled = if negative then        -(normalized * Real(0x800000))        else normalized * Real(0x800000);    let rounded = FloatingToInteger(scaled, rounding_mode);    var magnitude = if rounded < 0 then -rounded else rounded;    var encoded_exponent = exponent + 127;    if magnitude == 0x1000000 then        magnitude = 0x800000;        encoded_exponent =            (encoded_exponent + 1) as integer {-22..255};    end;    if encoded_exponent >= 255 then        return (            Zeros{PTO_XLEN} + sign + 0x7f800000,            Zeros{5} + 0x14);    end;    let fraction = magnitude - 0x800000;    return (        Zeros{PTO_XLEN} + sign + encoded_exponent * 0x800000 + fraction,        if Real(rounded) == scaled then Zeros{5} else Zeros{5} + 0x10);end;
implementation func TileProfileQuantize(value: Word, scale: Word,                                         zero_point: Word,                                         source_type: TileDataType,                                         destination_type: TileDataType,                                         control: NumericExecutionControl)                                         => (Word, bits(5))begin    assert source_type == TileDataType_FP32;    assert destination_type == TileDataType_S8 ||           destination_type == TileDataType_U8;    let source_class = TileNumericValueClass(source_type, value);    let scale_class = TileNumericValueClass(TileDataType_FP32, scale);    assert !NumericValueClassIsNaN(scale_class);    assert !NumericValueClassIsInfinity(scale_class);    assert !NumericValueClassIsZero(scale_class);    let minimum = ReferenceIntegerValue(        TileIntegerMinimum(destination_type), destination_type);    let maximum = ReferenceIntegerValue(        TileIntegerMaximum(destination_type), destination_type);    if NumericValueClassIsNaN(source_class) then        return (Zeros{PTO_XLEN}, Zeros{5} + 1);    elsif NumericValueClassIsInfinity(source_class) then        let saturated = if value[31] == '1' then minimum else maximum;        return (            NormalizeTileInteger(                Zeros{PTO_XLEN} + saturated,                destination_type),            Zeros{5} + 0x14);    end;    let affine = ReferenceFP32FiniteValue(value[31:0]) *        ReferenceFP32FiniteValue(scale[31:0]) +        Real(ReferenceIntegerValue(zero_point, destination_type));    let rounded = FloatingToInteger(affine, control.rounding_mode);    var selected = rounded;    let flags = if Real(rounded) == affine then Zeros{5}        else Zeros{5} + 0x10;    if control.saturating then        if selected < minimum then selected = minimum;        elsif selected > maximum then selected = maximum;        end;    end;    return (        NormalizeTileInteger(Zeros{PTO_XLEN} + selected, destination_type),        flags);end;
implementation func TileProfileDequantize(value: Word, scale: Word,                                           zero_point: Word,                                           source_type: TileDataType,                                           destination_type: TileDataType,                                           control: NumericExecutionControl)                                           => (Word, bits(5))begin    assert source_type == TileDataType_S8 ||           source_type == TileDataType_U8;    assert destination_type == TileDataType_FP32;    let scale_class = TileNumericValueClass(TileDataType_FP32, scale);    assert !NumericValueClassIsNaN(scale_class);    assert !NumericValueClassIsInfinity(scale_class);    assert !NumericValueClassIsZero(scale_class);    let source_value = ReferenceIntegerValue(value, source_type);    let zero_value = ReferenceIntegerValue(zero_point, source_type);    let dequantized = Real(source_value - zero_value) *        ReferenceFP32FiniteValue(scale[31:0]);    return ReferenceFP32FiniteEncoding(        dequantized,        control.rounding_mode);end;

架构行为

目的与范围

用途与范围

本单元为 FP32 有限值转换、仿射量化到 S8 或 U8,以及反量化回 FP32 提供确定性的 PTO v0 参考实现。

概念与架构状态

数值辅助函数

  • ReferencePowerOfTwo 构造指数 -149 到 127 对应的二次幂。
  • ReferenceFP32FiniteValue 把有限 FP32 的符号、指数和小数部分解码为实数值。
  • ReferenceIntegerValue 规范化 Tile 整数,并按源类型的有符号性解释该值。
  • ReferenceFP32FiniteEncoding 执行带状态的反向有限值编码。
规则与交互

量化与反量化

TileProfileQuantize 接受 FP32 输入以及 S8 或 U8 输出。它检查 FP32 缩放值有限且非零,计算 source * scale + zero_point,按所选模式舍入,并可选择把结果截取到目标范围。

TileProfileDequantize 接受 S8 或 U8 输入以及 FP32 输出。它计算 (source - zero_point) * scale,再返回参考 FP32 编码。

边界与未定义范围

异常与配置档边界

量化 NaN 会产生零并报告 NV;无穷值选择对应符号的整数端点,并报告上溢和不精确状态。缩放值不能是 NaN、无穷或零。这些是 PTO v0 的 implementation 函数,因此其他具名配置档需要各自经过审阅的定义。

使用示例

示例性仿射示例

本示例块只用于帮助阅读:先应用上文规则,再到规范 ASL 所有者中确认结果。它不会增加任何架构契约。

相关所有者

  • 参考配置档提供舍入选择等通用数值策略。
  • Tile 数值格式单元对编码分类;矩阵量化单元为更多格式复用这些参考辅助函数。

NDF 条款

正文来自 owning ASL。拖拽或按钮只临时改变当前页面显示顺序。

No NDF clause is attached to this unit.

Evidence index

10 matching entries

Executable evidence2
  • PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION compiles as an independent normative unit
    1. surfaceARCH
    2. ownerPTO-ARCH-PROFILE-REFERENCE-QUANTIZATION
    3. categorySTATIC-INVARIANT
    4. case001
    Show exact test source
    Sources and references
    Complete stable ID
    PTO-AVS-ARCH-PROFILE-REFERENCE-QUANTIZATION-STATIC-001
    Path
    tests/asl/arch/profile/reference-quantization/arch-static-reference-quantization-contract-001.asl
    Kind / role
    static-invariant
    Pass condition
    the complete model and this unit's static invariant compile
    SHA-256
    e5859faec80b723cccc8cd21c068ad1cd6ce6ba79c1ba1d9bf22e6365113487d
    Open exact source ↗ for PTO-AVS-ARCH-PROFILE-REFERENCE-QUANTIZATION-STATIC-001
  • The reference quantization profile converts representative FP32 and integer values without changing their encodings
    1. surfaceARCH
    2. ownerPTO-ARCH-PROFILE-REFERENCE-QUANTIZATION
    3. categoryEXECUTION
    4. case001
    Show exact test source
    Sources and references
    Complete stable ID
    PTO-AVS-ARCH-REFERENCE-QUANTIZATION-001
    Path
    tests/asl/arch/profile/reference-quantization/arch-exec-reference-quantization-001.asl
    Kind / role
    execution
    Pass condition
    FP32 one and two decode exactly, FP32 one re-encodes exactly with no flags, and signed integer normalization preserves minus one
    SHA-256
    77a1aeec8c6b63e08c22aca602ea197a22a51320e033721fa531bdfbb1046fea
    Open exact source ↗ for PTO-AVS-ARCH-REFERENCE-QUANTIZATION-001
Commit-scoped evidence5
  • spec/evidence/release-traceability-readiness.json · closedPTO-EVIDENCE-RELEASE-TRACEABILITY
    Sources and references
    Complete stable ID
    PTO-EVIDENCE-RELEASE-TRACEABILITY
    Path
    spec/evidence/release-traceability-readiness.json
    Kind / role
    ASL/NDF/documentation/AVS traceability
    SHA-256
    c7327021d39dc67ac5564bc55073b3870a397d79ac8d9648284d56e33bc14a3e
    Open exact source ↗ for PTO-EVIDENCE-RELEASE-TRACEABILITY
  • spec/evidence/instruction-contract-closure.json · closedPTO-EVIDENCE-INSTRUCTION-CONTRACT-CLOSURE
    Sources and references
    Complete stable ID
    PTO-EVIDENCE-INSTRUCTION-CONTRACT-CLOSURE
    Path
    spec/evidence/instruction-contract-closure.json
    Kind / role
    mnemonic and encoding contract closure
    SHA-256
    3ef2bb62421c79dff8fa77a1c7983923b523244b8090812883ef81286ca8106a
    Open exact source ↗ for PTO-EVIDENCE-INSTRUCTION-CONTRACT-CLOSURE
  • spec/evidence/architecture-readiness.json · openPTO-EVIDENCE-ARCHITECTURE-READINESS
    Sources and references
    Complete stable ID
    PTO-EVIDENCE-ARCHITECTURE-READINESS
    Path
    spec/evidence/architecture-readiness.json
    Kind / role
    architecture maturity and blockers
    SHA-256
    4b0b85199101251bea744e0f3591cc31906909dc80d5ab651c417a936036a004
    Open exact source ↗ for PTO-EVIDENCE-ARCHITECTURE-READINESS
  • spec/evidence/release-gate-readiness.json · ready-for-exact-head-verificationPTO-EVIDENCE-RELEASE-GATE-READINESS
    Sources and references
    Complete stable ID
    PTO-EVIDENCE-RELEASE-GATE-READINESS
    Path
    spec/evidence/release-gate-readiness.json
    Kind / role
    exact-head gate readiness
    SHA-256
    a0f4d2b6920c08981ea55fd8ef820708a40d4feb5402c5150e8e9ab532d84ce0
    Open exact source ↗ for PTO-EVIDENCE-RELEASE-GATE-READINESS
  • spec/release-manifest.json · draftPTO-EVIDENCE-RELEASE-MANIFEST
    Sources and references
    Complete stable ID
    PTO-EVIDENCE-RELEASE-MANIFEST
    Path
    spec/release-manifest.json
    Kind / role
    release content and encoding fingerprints
    SHA-256
    1a64c109ed7a90351c41e2a418b3c0ebaf8ad975838986d2101385186b85c0d8
    Open exact source ↗ for PTO-EVIDENCE-RELEASE-MANIFEST
Decision history3
  • PTO v0 concrete reference profile · accepted
    1. decision recordADR
    2. case0005

    Decision record

    Loading ADR-0005…

    Sources and references
    Complete stable ID
    ADR-0005
    Path
    docs/status/decisions/0005-pto-v0-concrete-reference-profile.md
    Affected units
    PTO-ARCH-PROFILE-APPLICABILITY, PTO-ARCH-PROFILE-E8M0-CONVERSION, PTO-ARCH-PROFILE-EXTENSION-FIRST-USE, PTO-ARCH-PROFILE-MATRIX-POSTPROCESS, PTO-ARCH-PROFILE-MATRIX-QUANTIZATION, PTO-ARCH-PROFILE-REFERENCE-PROFILE, PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION, PTO-ARCH-PROFILE-RESET, PTO-ARCH-PROFILE-TRAP-CONTEXT-RECOVERY
    Affected NDF
    PTO-ARCH-EXTENSION-FIRST-USE-PROFILE-001, PTO-MATRIX-POSTPROCESS-BITEXACT-001, PTO-MATRIX-QUANT-BITEXACT-001, PTO-TCVT-E8M0-PROFILE-001
    SHA-256
    a83528c2fc744cc120c2a0a32c82410059638ea88936fa65ac0eb36a0274d87c
    Open exact decision source ↗ for ADR-0005
  • Numeric profile identity and bounded variation framework · accepted
    1. decision recordADR
    2. case0037

    Decision record

    Loading ADR-0037…

    Sources and references
    Complete stable ID
    ADR-0037
    Path
    docs/status/decisions/0037-numeric-profile-identity-and-variation-framework.md
    Affected units
    PTO-ARCH-PROFILE-APPLICABILITY, PTO-ARCH-PROFILE-E8M0-CONVERSION, PTO-ARCH-PROFILE-MATRIX-POSTPROCESS, PTO-ARCH-PROFILE-MATRIX-QUANTIZATION, PTO-ARCH-PROFILE-REFERENCE-PROFILE, PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION
    Affected NDF
    PTO-MATRIX-POSTPROCESS-BITEXACT-001, PTO-MATRIX-QUANT-BITEXACT-001, PTO-TCVT-E8M0-PROFILE-001
    SHA-256
    b09efd36ccfc7258d1743c974f42b875ead42137c503f576a12f471f65b52e30
    Open exact decision source ↗ for ADR-0037
  • Numeric variation-point ownership · accepted
    1. decision recordADR
    2. case0042

    Decision record

    Loading ADR-0042…

    Sources and references
    Complete stable ID
    ADR-0042
    Path
    docs/status/decisions/0042-numeric-variation-point-ownership.md
    Affected units
    PTO-ARCH-PROFILE-APPLICABILITY, PTO-ARCH-PROFILE-E8M0-CONVERSION, PTO-ARCH-PROFILE-MATRIX-POSTPROCESS, PTO-ARCH-PROFILE-MATRIX-QUANTIZATION, PTO-ARCH-PROFILE-REFERENCE-PROFILE, PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION
    Affected NDF
    PTO-MATRIX-POSTPROCESS-BITEXACT-001, PTO-MATRIX-QUANT-BITEXACT-001, PTO-TCVT-E8M0-PROFILE-001
    SHA-256
    f25df23306837e4199f6b7c03f70de853a693fdc6435c65ead57b2a174076081
    Open exact decision source ↗ for ADR-0042

Unit metadata

Open 4 generated metadata fields
id
PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION
surface
arch
classification
[
  "profile",
  "reference-quantization"
]
depends_on
[
  "PTO-ARCH-PROFILE-REFERENCE-PROFILE",
  "PTO-TILE-MODEL-NUMERIC-FORMATS"
]
Open generated traceability record
{
  "classification": [
    "profile",
    "reference-quantization"
  ],
  "documentation": "docs/arch/profile/reference-quantization.md",
  "id": "PTO-ARCH-PROFILE-REFERENCE-QUANTIZATION",
  "mnemonic": null,
  "readiness_subjects": [
    "ADR-0005",
    "ADR-0037",
    "ADR-0042"
  ],
  "semantic_tests": [
    "PTO-AVS-ARCH-REFERENCE-QUANTIZATION-001"
  ],
  "source": "asl/arch/profile/reference-quantization.asl",
  "surface": "arch",
  "tests": [
    "PTO-AVS-ARCH-PROFILE-REFERENCE-QUANTIZATION-STATIC-001",
    "PTO-AVS-ARCH-REFERENCE-QUANTIZATION-001"
  ]
}

来源与发布信息

展开 commit、路径、hash、版本和规范所有者
发布
0.58.5 · 候选发布
Commit
7dc8b7e5b121d2b2499a2273bebff29e2cd86812
ASL SHA-256
e82820dc13f89142aa0448c4435f6cbd53d4eb0b85c05e63a887452c186d9aef
文档 SHA-256
5079808b9cb86d7eaa34576801b96182bdd5b47dfa6d74f4a37e7b1c21fa1efa

精确所有者