CANN PTO ISA反量化指令

发布时间:2026/7/16 19:49:25
CANN PTO ISA反量化指令 TDEQUANT【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isaIntroductionDequantize a low-precision quantized tile (S8/S16) into a high-precisionFP32tile. Each element undergoesaffine dequantization— the inverse ofTQUANTinteger quantization (INT8 symmetric / asymmetric):$$ \mathrm{dst}{i,j} (\mathrm{src}{i,j} - \mathrm{offset}{i}) \cdot \mathrm{scale}{i} $$scaleandoffsetareper-rowFP32 parameters (broadcast across the columns), so a single instruction performs the full subtract zero-point rescale dequantization.Math InterpretationConceptually, for each element(i, j)in the valid region:$$ \mathrm{dst}{i,j} \bigl(\mathrm{src}{i,j} - \mathrm{offset}{i}\bigr) \cdot \mathrm{scale}{i} $$src: the quantized integer code (S8orS16).scale,offset: per-row FP32 dequantization parameters;scalevalid-column count isparaCols max(1, scale.GetValidCol())with parameter column indexparaCol min(j, paraCols - 1)— i.e. parameters broadcast along the column axis.Inverse ofTQUANTinteger affine quantization:TQUANThas $q \mathrm{round}(x / \mathrm{scale}) \mathrm{offset}$, hence $x (q - \mathrm{offset}) \cdot \mathrm{scale}$.Unless otherwise specified, semantics are defined over the valid region and target-dependent behavior is marked as implementation-defined.scaleandoffsetare ISA-visible tile operands (not compiler scratch).C IntrinsicsDeclared ininclude/pto/common/pto_instr.hpp.template typename TileDataDst, typename TileDataSrc, typename TileDataPara, typename... WaitEvents PTO_INST RecordEvent TDEQUANT(TileDataDst dst, TileDataSrc src, TileDataPara scale, TileDataPara offset, WaitEvents ...events);ParameterDirectionMeaningdstoutputDequantized result tile,FP32, row-majorsrcinputQuantized source tile,S8orS16, row-major, same valid shape asdstscaleinputPer-row inverse scale,FP32, broadcast across columnsoffsetinputPer-row zero-point,FP32, broadcast across columnsevents...inputWait events (WaitEvents); an implicitTSYNCprecedes the opscaleandoffsetmust share a type (TileDataPara) whose dtype matchesdst(allFP32).Tile Sizes Data TypesFor a source/destination valid tile shape of $M \times N$:TiledtypeValid shapeLayoutNotesdstfloat32_t$M \times N$RowMajorDequantized resultsrcint8_torint16_t$M \times N$RowMajorQuantized integer code; dtype selects the unpack pathscalefloat32_t$M \times 1$ (per row)ColMajor / row broadcastBroadcast across columns (BRC_B32)offsetfloat32_t$M \times 1$ (per row)ColMajor / row broadcastBroadcast across columns (BRC_B32)scale/offsetvalid rows must equaldstvalid rows; columns are broadcast in 32-byte blocks, so the typical form is one scalar per row (shape $M \times 1$).Supported Input DtypesSource dtypeDestination dtypescale/offset dtypeNotesS8(int8_t)FP32FP32Unpacked viaUNPK4_B8, then cast to FP32S16(int16_t)FP32FP32Unpacked viaUNPK_B16, then cast to FP32dst,scale, andoffsetmust share a dtype and all beFP32;srcsupports onlyS8/S16. Other dtype combinations are illegal (rejected by an in-implementationstatic_assert).Implementation NotesTDEQUANT runs on the vector pipeline (PIPE_V) and needs notmpscratch tile (unlike the 5-stage cast chain ofTQUANTon A2/A3):Load and unpacksrc:S8viaUNPK4_B8,S16viaUNPK_B16, thenvcvtto FP32 (on kirinX90,S8uses theUS_B8 interleave path).Broadcast-load parameters:scaleandoffsetare loaded withvlds ... BRC_B32, broadcasting in 32-byte blocks across each row.Compute:vsub(dst, src, offset)followed byvmul(dst, dst, scale)— subtract zero-point, then rescale.EncodingTDEQUANT is a TEPL (Tile Elementwise Pipeline) complex-transform instruction:BSTART.TEPL TDEQUANT, DataType B.DATR(optional) B.DIM LB0 B.DIM (LB1/LB2 for 2D) B.IOTFieldValueMode3 (complex transform)Function11TileOp0x6BOperands (B.IOT)dst, src, scale, offsetConstraintsConstraintApplies toReasondstandsrcmust be row-majorall targetsper-row parameter broadcastdstandsrcshare the valid shape ($M \times N$)all targetsone-to-one element mappingscaleandoffsetvalid rows dstvalid rowsall targetsone parameter group per rowdst/scale/offsetdtypes must match and beFP32all targetsdequantization output precisionsrc∈ {S8,S16}all targetsquantized integer code widthExamples// src: int8/int16 quantized codes; scale/offset: per-row FP32 parameters TDEQUANT(dstTile, srcTile, scaleTile, offsetTile);Seetests/npu/a5/src/st/testcase/tdequant/(A5),tests/npu/a2a3/src/st/testcase/tdequant/(A2/A3), andtests/cpu/st/testcase/tdequant/(CPU reference) for complete ST examples.【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isa创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考