LowerToAsc passes
-asclower-arith
Lower arith dialect constant, bitcast, and negf operations to ascendc equivalents
Converts selected arithmetic operations on tensor types to Ascend C equivalents:
Splat constants: Creates
LocalTensorAutoOp+DuplicateL2Opto broadcast scalar to all elementsDense non-splat constants: Creates tensor + series of
LocalTensorSetValueOpfor each elementBitcast: Converts to
LocalTensorReinterpretCastOpfor type reinterpretationNegf: Converts to
MulsL2Opwith -1.0 scalar to negate floating-point tiles
asctile::LocalTensorType is converted to ascendc::LocalTensorType via unrealized conversion casts.
-asclower-arith-binary
Lower binary arith dialect operations on tiles to ascendc L2 vector operations
Converts binary arithmetic operations on tensor types to Ascend C L2-level vector operations. Supports floating-point and integer arithmetic (add, sub, mul, div, max, min variants). For bitwise operations (andi, ori), performs reinterpret casting to i8 elements if needed since the hardware processes bitwise ops on 8-bit granularity.
Each operation creates a destination tensor allocation and the corresponding L2 compute op with calCount.
-asclower-asctile
Lower core asctile dialect operations to ascendc compute and neural network operations
Converts AscTile tensor operations to Ascend C equivalents:
TensorOp: Creates
GlobalTensorOpwith buffer pointer setupSplatOp: Creates
DuplicateL2Opto broadcast scalarReluOp, CastOp: Creates corresponding L2 unary ops
MatmulOp: Creates
MmadOpwith M/N/K params derived from tensor shapesReshapeOp: Creates
LocalTensorReinterpretCastOpBroadcastOp: Creates
DuplicateL2Opfor 1-element tiles orBroadcastOpfor larger tilesSoftmaxOp/RmsNormOp: Creates library ops with tiling/shape info params
ReduceAs1dOp/ReduceOp: Creates reduction ops with pattern-based shape decomposition
Scalar-tensor ops (adds, subs, muls, divs, mins, maxs, shls, shrs): Creates L2 scalar variants
AccumulatorOp/MatmulAccOp: Sets up L0C accumulator for matrix multiplication accumulation
-asclower-asctile-data-transfer
Lower asctile data transfer operations (load, store, copy) to ascendc memory operations
Converts AscTile memory transfer operations to Ascend C equivalents:
LoadOp (UB destination): Creates
DataCopyPadExtL0Opfrom GM to UB with optional paddingLoadOp (L1 destination): Creates
DataCopyL2Opwith Nd2Nz params for cube matrix formatStoreOp (from UB): Creates
DataCopyPadExtL2Opto GMStoreFixpipeOp (from L0C): Creates
FixpipeOpwith optional relu/quantize flagsCopyFixpipeOp (L0C to L1): Creates
FixpipeOpwith NZ layout for L0C-to-L1 transferCopyOp (L1 to L0A/L0B): Creates
LoadDataG2LOporLoadDataWithTransposeOpwith fractal layoutGetValueOp/SetValueOp: Creates global tensor scalar get/set operations
Handles both static and dynamic tensor shapes, computing linear offsets from multi-dimensional indices. Quantization modes (F322F16, DEQF16, QF322B8_PRE, REQ8) are inferred from source/destination type pairs.
-asclower-asctile-i1
Lower asctile comparison and select operations with i1 tiles to ascendc L0 operations
Converts i1 (boolean) tensor operations to Ascend C L0-level operations with packed i8 representation:
CmpOp: Creates
CompareL0Opwith packed i8 destination (8 boolean values per i8 byte)For integer comparisons on non-C310 targets, casts operands to float first
CmpSOp: Creates
CompareScalarL0Opfor tensor-scalar comparisonsSelectOp: Creates
SelectL0Opwith VSEL_TENSOR_TENSOR mode
Boolean tiles (i1 elements) are represented as packed i8 tensors (8 bits per byte), enabling hardware support for 8-way parallel boolean operations. The destination shape is ceil(numElements/8).
-asclower-atomic
Lower atomic read-modify-write operations to ascendc atomic store sequences
Converts asctile.atomic_rmw operations to atomic store sequences:
Sets atomic mode via
SetAtomicAddOp,SetAtomicMaxOp, orSetAtomicMinOpConverts
atomic_rmwtoasctile.store(which is later lowered byLowerAscTileDataTransfer)Resets atomic mode via
SetAtomicNoneOp
Supported atomic kinds: Add (accumulator), Max (maximum), Min (minimum). The atomic mode affects how subsequent stores modify existing memory values.
-asclower-displace-concat
Transform concat operations by rewriting related tensor allocations to eliminate actual data copies
Rewrites asctile.concat operations to avoid unnecessary data copies by adjusting tensor allocations:
Optimization phase: If all concat operands are from
LocalTensorAutoOpwith same position, creates a single combined tensor at function entry and rewrites each operand’s allocation as a sub-index view into this combined tensor. The concat itself becomes a no-op (just an unrealized conversion cast).Fallback phase: If operands cannot be optimized, creates a destination tensor and inserts
DataCopyL2Opoperations to copy each operand into its corresponding sub-index region.
This pass eliminates redundant UB allocations and copies when concatenating temporaries, reducing memory usage.
-asclower-expand-mask
Expand mask regions by moving nested operations outside and updating mask parameters
Transforms asctile.count_mask and asctile.bitwise_mask regions by:
Moving all operations from inside the mask region to outside (before the mask op)
Lowering L2 operations inside the mask to L0 variants via
populateLowerToL0PatternsUpdating each L0 operation’s mask parameter to use the mask region’s count or bitwise mask
If the mask has
othervalue, insertingDuplicateL2Opto fill the destination with that value
After expansion, the mask region op is erased and all operations execute with explicit mask parameters.
-asclower-expand-math
Expand math operations that lack direct hardware support into equivalent sequences
Applies MLIR’s standard math expansion patterns to decompose operations without direct Ascend C support:
rsqrt(x)→1.0 / sqrt(x)exp2(x)→exp(x * ln(2))
These expanded forms use math operations that have direct Ascend C library support.
-asclower-math
Lower math dialect unary operations on tiles to ascendc library and L2 operations
Converts math dialect unary operations on tensor types to Ascend C equivalents. Library operations (log, erf, trigonometric functions, ceil, floor, round) use Ascend C’s high-precision library calls with optional shared temporary buffer. Direct L2 operations (abs, exp, sqrt, rsqrt) map to hardware-accelerated vector instructions.
Each operation creates a destination tensor allocation and the corresponding compute op with calCount.
-asclower-realize-conversion-cast
Convert unrealized conversion casts between tensor types into ascendc reinterpret cast operations
Simplifies and materializes UnrealizedConversionCastOp chains between tensor types:
FoldCastChain: Eliminates redundant cast chains where source and destination types match (e.g., cast(cast(x → y) → x) → x, or three-level chains)
RewriteReinterpretCast: Converts nested casts between compatible tensor types to
LocalTensorReinterpretCastOpwhen memory size is identical
Compatible tensors have same total memory size (numElements × bitWidth), enabling type reinterpretation without data movement. This pass cleans up conversion artifacts from the dialect conversion process.
-asclower-redress-i1-tensor
Convert i1 tensor types to packed i8 representation and adjust constants accordingly
Rewrites i1 (boolean) tensor types to use packed i8 representation before lowering:
LocalTensorType conversion:
tensor<Nxi1>→tensor<ceil(N/8)xi8>(8 boolean values packed per byte)Splat constants:
dense<true>→dense<-1>(all bits set),dense<false>→dense<0>Dense constants: Bit-packed representation where bit index corresponds to original element index
This preprocessing enables hardware support for boolean operations, which operate on 8-bit granularity. After redressing, LowerAscTileI1 can convert comparison/select operations to packed L0 variants.
-asclower-scf
Convert tensor type operands and results in scf control flow operations to local tensor types
Uses MLIR’s populateSCFStructuralTypeConversionsAndLegality to convert scf operations with tensor types:
scf.if: Result types converted from
asctile::LocalTensorTypetoascendc::LocalTensorTypescf.for: Iter argument types converted, loop body operations wrapped with conversion casts
scf.while: Before/after region argument types converted
This enables scf control flow to work with converted tensor types after AscTile lowering.
Uses TensorTypeConverter to map asctile::LocalTensorType → ascendc::LocalTensorType.