Repository navigation
Conversation
Unnecessary branching
|
this branching is the coding style |
Collaborator
|
Sorry, but purely stylistic changes like this are difficult to integrate. |
benvanik
added a commit
that referenced
this pull request
Jun 1, 2020
# This is the 1st commit message: Switching VM calling convention and making the stack growable. Reduces the default stack to be small enough to fit on the host stack and dynamically growable if needed. This dramatically reduces our memory footprint and speeds up almost everything VM-related (invocation from C to bytecode, bytecode to C, and bytecode to bytecode). It also has the effect of properly guarding register array accesses via valid bit masks that expensive logic in the actual bytecode op implementations. Latest VM bytecode benchmark numbers for desktop: ----------------------------------------------------------------------- Benchmark Time CPU Iterations ----------------------------------------------------------------------- BM_ModuleCreate 176 ns 176 ns 3733333 BM_ModuleCreateState 72.4 ns 71.5 ns 8960000 BM_FullModuleInit 236 ns 235 ns 2986667 BM_EmptyFuncReference 2.57 ns 2.55 ns 263529412 BM_EmptyFuncBytecode 76.4 ns 76.7 ns 11200000 BM_CallInternalFuncReference 2.27 ns 2.29 ns 320000000 BM_CallInternalFuncBytecode 22.4 ns 22.5 ns 29866680 BM_CallImportedFuncBytecode 20.7 ns 20.5 ns 32000000 BM_LoopSumReference/100000 1.17 ns 1.17 ns 640000000 BM_LoopSumBytecode/1000000 7.73 ns 7.64 ns 90000000 # The commit message #2 will be skipped: # x
Merged
Merged
dcaballe
added a commit
to dcaballe/iree
that referenced
this pull request
Feb 22, 2023
qcolombet
added a commit
to qcolombet/iree
that referenced
this pull request
Mar 15, 2023
Add a pass to extract address computation from memref.load and nvgpu.ldmatrix. Plumb the affine.apply decomposition through a new pass: decompose-affine-ops. Rework the lowering pipeline to connect all the piece together: 1. extract-address-computation turns address computation into subviews 2. expand-strided-metadata turns subviews into affine.apply 3. licm hoists the code introduced by iree-org#2 in the right scf.for loop 4. decompose-affine-ops breaks down the `affine.apply`s so that the resulting subexpressions can be hoisted in the right loops. 5. licm hoists the code introduced by iree-org#4 6. lower-affine materializes the decomposed `affine.apply`s. We do that early to avoid the canonicalization to undo this work. Phase 3-5 needs to run on `scf.for`, so the whole process has to run before scf to cf. Missing bits: - More comments - Add tests - Fix the subviews sizes for non-unary loads (although it doesn't break anything this is technically incorrect.) - LLVM reassociate undo some of the thing we improve here. Need to file a bug for that, investigate and fix. Note: extract-address-computation could be moved to LLVM open source, but we need to figure out where it could live since it has both a dependency on memref and nvgpu. We probably want to come up with an interface like `isAddressComputationExtractable` to push it upstream.
qcolombet
added a commit
to qcolombet/iree
that referenced
this pull request
Mar 17, 2023
Add a pass to extract address computation from memref.load and nvgpu.ldmatrix. Plumb the affine.apply decomposition through a new pass: decompose-affine-ops. Rework the lowering pipeline to connect all the piece together: 1. extract-address-computation turns address computation into subviews 2. expand-strided-metadata turns subviews into affine.apply 3. licm hoists the code introduced by iree-org#2 in the right scf.for loop 4. decompose-affine-ops breaks down the `affine.apply`s so that the resulting subexpressions can be hoisted in the right loops. 5. licm hoists the code introduced by iree-org#4 6. lower-affine materializes the decomposed `affine.apply`s. We do that early to avoid the canonicalization to undo this work. Phase 3-5 needs to run on `scf.for`, so the whole process has to run before scf to cf. Missing bits: - More comments - Add tests - Fix the subviews sizes for non-unary loads (although it doesn't break anything this is technically incorrect.) - LLVM reassociate undo some of the thing we improve here. Need to file a bug for that, investigate and fix. Note: extract-address-computation could be moved to LLVM open source, but we need to figure out where it could live since it has both a dependency on memref and nvgpu. We probably want to come up with an interface like `isAddressComputationExtractable` to push it upstream.
qcolombet
added a commit
to qcolombet/iree
that referenced
this pull request
Mar 21, 2023
Add a pass to extract address computation from memref.load and nvgpu.ldmatrix. Plumb the affine.apply decomposition through a new pass: decompose-affine-ops. Rework the lowering pipeline to connect all the piece together: 1. extract-address-computation turns address computation into subviews 2. expand-strided-metadata turns subviews into affine.apply 3. licm hoists the code introduced by iree-org#2 in the right scf.for loop 4. decompose-affine-ops breaks down the `affine.apply`s so that the resulting subexpressions can be hoisted in the right loops. 5. licm hoists the code introduced by iree-org#4 6. lower-affine materializes the decomposed `affine.apply`s. We do that early to avoid the canonicalization to undo this work. Phase 3-5 needs to run on `scf.for`, so the whole process has to run before scf to cf. TODO: - Add support for memref.store, vector.transfer_xxx Note: extract-address-computation could be moved to LLVM open source, but we need to figure out where it could live since it has both a dependency on memref and nvgpu. We probably want to come up with an interface like `isAddressComputationExtractable` to push it upstream.
ScottTodd
added a commit
that referenced
this pull request
Aug 20, 2024
Reverts #17751. A few of the new tests are failing on various platforms: * Timeouts (after 60 seconds) in `iree/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_large_llvm-cpu_local-task` on GitHub-hosted Windows and macOS runners * https://github.com/iree-org/iree/actions/runs/10468974350/job/28990992473#step:8:2477 * https://github.com/iree-org/iree/actions/runs/10468947894/job/28990909629#step:9:3076 ``` 1529/1568 Test #969: iree/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_large_llvm-cpu_local-task .............................***Timeout 60.07 sec --- TEST[attention_2_2048_256_512_128_dtype_f16_f16_f16_f16_2_2048_256_512_128_256_1.0_0] --- Attention shape (BATCHxMxK1xK2xN): 2x2048x256x512x256x128 ``` * Compilation error on arm64: https://github.com/iree-org/iree/actions/runs/10468944505/job/28990909321#step:4:9815: ``` [415/1150] Generating /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.vmfb from e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir FAILED: tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.vmfb /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.vmfb cd /work/build-arm64/tests/e2e/attention && /work/build-arm64/tools/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir -o /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.vmfb --iree-hal-executable-object-search-path=\"/work/build-arm64\" --iree-llvmcpu-embedded-linker-path=\"/work/build-arm64/llvm-project/bin/lld\" --iree-llvmcpu-wasm-linker-path=\"/work/build-arm64/llvm-project/bin/lld\" /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir:4:14: error: Yield operand #2 is not equivalent to the corresponding iter bbArg %result1 = iree_linalg_ext.attention { ^ /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir:1:1: note: called from func.func @attention_2_1024_128_256_64_dtype_f16_f16_f16_f16(%query: tensor<2x1024x128xf16>, %key: tensor<2x256x128xf16>, %value: tensor<2x256x64xf16>, %scale: f32) -> tensor<2x1024x64xf16> { ^ /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir:4:14: error: failed to run translation of source executable to target executable for backend #hal.executable.target<"llvm-cpu", "embedded-elf-arm_64", {cpu = "generic", cpu_features = "+reserve-x18", data_layout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", native_vector_size = 16 : i64, target_triple = "aarch64-unknown-unknown-eabi-elf"}> %result1 = iree_linalg_ext.attention { ^ /work/build-arm64/tests/e2e/attention/e2e_attention_cpu_f16_f16_f16_medium_llvm-cpu_local-task_attention.mlir:1:1: note: called from func.func @attention_2_1024_128_256_64_dtype_f16_f16_f16_f16(%query: tensor<2x1024x128xf16>, %key: tensor<2x256x128xf16>, %value: tensor<2x256x64xf16>, %scale: f32) -> tensor<2x1024x64xf16> { ^ failed to translate executables ```
This was referenced Apr 1, 2025
This was referenced Apr 9, 2025
amd-justchen
added a commit
that referenced
this pull request
May 21, 2025
Trying `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded` per #20763 (comment)
amd-justchen
added a commit
that referenced
this pull request
May 22, 2025
Trying `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded` per #20763 (comment) Signed-off-by: Justin Chen <[email protected]>
4 tasks
egebeysel
pushed a commit
to egebeysel/iree
that referenced
this pull request
Jul 1, 2025
feat(Broadcom): add SPIRV GPU Config fix(GPUUtils): add videocore to the target list fix: pre-commit failures (iree-org#7)
lialan
added a commit
that referenced
this pull request
May 8, 2026
GPUPushDownDMABoundsToConsumers fired on every DMA whose innermost dim is statically dynamic, including the common "shape-dynamic but runtime-DWORD-aligned" cases. For 4000x4000xf16 with N_tile=128 the RHS DMA's tensor<32x?xf16> source got both an unnecessary iree_gpu.buffer_resource_cast validBytes wrap and an unnecessary consumer-side extract_slice + tensor.pad chain after the outer forall, even though N=4000 is naturally DWORD-aligned and the LDS tile is fully filled for interior workgroups. The pad chain in particular lowers via vectorizeAsTensorPadOp to a per-thread masked write into a tensor.empty, which bufferization commits to a private alloca round-trip per K-iteration (~8 KB scratch traffic per thread), making the e2e ~450-850x slower than main on 4000/6789/12345 square F16 matmuls on MI355X. Two skip predicates added: - padSourceBufferDescriptorToDWORD: also skip when the *root* tensor's innermost row is statically DWORD-aligned (root_innermost * elemBytes divisible by 4). The wrap exists only to guard the partial-DWORD straddle at the buffer end, which cannot occur when the buffer end is naturally DWORD-aligned. Catches the 4000-class case and preserves the wrap for 64x43, 131x131 (odd inner row, partial DWORD at end is real). - rewriteOneDMA: also skip the post-forall extract_slice + tensor.pad chain when the source's innermost extent has a static upper bound equal to innerTileSize. The UB is read from a static dim, an arith.constant size, or the constant operand of an affine.min on the defining tensor.extract_slice. Safety relies on AMDGPULowerCoalescedDMAToGatherLDS::applyOOBClamping forcing OOB lanes past the root buffer's end and writing 0 to the original (possibly swizzled) LDS destination through the same swizzle the matmul reads through; the matmul then sees zeros in OOB columns identical to what the consumer pad would have written. K-reduction contributions are zero (no pollution); N-OOB outputs are discarded by the downstream output extract_slice. The pad is therefore pure perf-dressing, and removing it avoids the vectorizeAsTensorPadOp / tensor.empty alloca round-trip. Helper getInnermostStaticUpperBound walks tensor.extract_slice -> arith.constant / affine.min to extract a constant UB. Adds three lit test cases: - skip_validbytes_when_root_innermost_aligned (Skip #1 standalone) - skip_consumer_pad_when_inner_ub_matches_tile (both skips fire) - consumer_pad_skipped_even_when_root_misaligned (Skip #2 alone, wrap remains for buffer-end correctness) Also registers gpu_pushdown_dma_bounds_to_consumers.mlir in BUILD.bazel and CMakeLists.txt (it was orphaned on this branch). Verification: - Existing pushdown lit (Tests 1-6): pass. - New pushdown lit (Tests 7-9): pass. - pipeline_dma_unaligned ctest: pass (matmul_64x43x64 still gets validBytes wrap because root 43 is odd). - All swizzle ctests (5/5): pass. - 131x131x131 e2e canary: pass; correct 131.0 in every cell. Boundary workgroup garbage is zeroed by applyOOBClamping; matmul output is correct on both K-boundary (LHS) and N-boundary (RHS). - coalesced_dma|swizzle|pushdown ctest set: 22/22 ran pass. - iree/tests/e2e/matmul label: 12/12 ran pass. Boo perf vs main baseline (mean us, 100 dispatches, gfx950): size main branch (correctness only) branch + Part A vs main 4000 172.82 147403.43 173.22 1.00x 6789 1999.27 909933.93 1101.76 0.55x 12345 10344.51 4843764.74 6965.16 0.67x The 4000 perf regression is fully closed; 6789 and 12345 land ~1.5-1.8x faster than main since the alloca round-trip is now gone on a path main was also taking suboptimally. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
lialan
added a commit
that referenced
this pull request
May 9, 2026
GPUPushDownDMABoundsToConsumers fired on every DMA whose innermost dim is statically dynamic, including the common "shape-dynamic but runtime-DWORD-aligned" cases. For 4000x4000xf16 with N_tile=128 the RHS DMA's tensor<32x?xf16> source got both an unnecessary iree_gpu.buffer_resource_cast validBytes wrap and an unnecessary consumer-side extract_slice + tensor.pad chain after the outer forall, even though N=4000 is naturally DWORD-aligned and the LDS tile is fully filled for interior workgroups. The pad chain in particular lowers via vectorizeAsTensorPadOp to a per-thread masked write into a tensor.empty, which bufferization commits to a private alloca round-trip per K-iteration (~8 KB scratch traffic per thread), making the e2e ~450-850x slower than main on 4000/6789/12345 square F16 matmuls on MI355X. Two skip predicates added: - padSourceBufferDescriptorToDWORD: also skip when the *root* tensor's innermost row is statically DWORD-aligned (root_innermost * elemBytes divisible by 4). The wrap exists only to guard the partial-DWORD straddle at the buffer end, which cannot occur when the buffer end is naturally DWORD-aligned. Catches the 4000-class case and preserves the wrap for 64x43, 131x131 (odd inner row, partial DWORD at end is real). - rewriteOneDMA: also skip the post-forall extract_slice + tensor.pad chain when the source's innermost extent has a static upper bound equal to innerTileSize. The UB is read from a static dim, an arith.constant size, or the constant operand of an affine.min on the defining tensor.extract_slice. Safety relies on AMDGPULowerCoalescedDMAToGatherLDS::applyOOBClamping forcing OOB lanes past the root buffer's end and writing 0 to the original (possibly swizzled) LDS destination through the same swizzle the matmul reads through; the matmul then sees zeros in OOB columns identical to what the consumer pad would have written. K-reduction contributions are zero (no pollution); N-OOB outputs are discarded by the downstream output extract_slice. The pad is therefore pure perf-dressing, and removing it avoids the vectorizeAsTensorPadOp / tensor.empty alloca round-trip. Helper getInnermostStaticUpperBound walks tensor.extract_slice -> arith.constant / affine.min to extract a constant UB. Adds three lit test cases: - skip_validbytes_when_root_innermost_aligned (Skip #1 standalone) - skip_consumer_pad_when_inner_ub_matches_tile (both skips fire) - consumer_pad_skipped_even_when_root_misaligned (Skip #2 alone, wrap remains for buffer-end correctness) Also registers gpu_pushdown_dma_bounds_to_consumers.mlir in BUILD.bazel and CMakeLists.txt (it was orphaned on this branch). Verification: - Existing pushdown lit (Tests 1-6): pass. - New pushdown lit (Tests 7-9): pass. - pipeline_dma_unaligned ctest: pass (matmul_64x43x64 still gets validBytes wrap because root 43 is odd). - All swizzle ctests (5/5): pass. - 131x131x131 e2e canary: pass; correct 131.0 in every cell. Boundary workgroup garbage is zeroed by applyOOBClamping; matmul output is correct on both K-boundary (LHS) and N-boundary (RHS). - coalesced_dma|swizzle|pushdown ctest set: 22/22 ran pass. - iree/tests/e2e/matmul label: 12/12 ran pass. Boo perf vs main baseline (mean us, 100 dispatches, gfx950): size main branch (correctness only) branch + Part A vs main 4000 172.82 147403.43 173.22 1.00x 6789 1999.27 909933.93 1101.76 0.55x 12345 10344.51 4843764.74 6965.16 0.67x The 4000 perf regression is fully closed; 6789 and 12345 land ~1.5-1.8x faster than main since the alloca round-trip is now gone on a path main was also taking suboptimally. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
lialan
added a commit
that referenced
this pull request
May 9, 2026
* tests/e2e/rocm_specific/matmul_unaligned_innermost_dma.mlir: replace the informational stub with two check.expect_almost_eq_const cases: matmul_f16_padded_64x43x64 (K=43, 86 B/row, validBytes wrap + consumer pad both fire) and matmul_f16_dynamic_80x80x80 (all dims 80, 160 B/row DWORD-aligned, non-tile-divisible -> Part A skips fire). * tests/e2e/rocm_specific/CMakeLists.txt: register the new e2e under gfx94|gfx95 with --iree-llvmgpu-use-direct-load. * compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/ pipeline_dma_unaligned.mlir: add a matmul_80x80x80 block asserting no validBytes operand on fat_raw_buffer_cast and gather_to_lds reaching both bindings (skip #1 + skip #2 verified). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
lialan
added a commit
that referenced
this pull request
May 9, 2026
…ion. GPUPushDownDMABoundsToConsumers's Skip #2 predicate elides the consumer extract_slice + tensor.pad chain when the DMA source's innermost extent has a static upper bound equal to the LDS inner tile size. The original helper hand-walked the SSA chain one level: it required the immediate defining op to be a tensor.extract_slice and read the size operand directly from arith.constant or affine.min. That fired on the canonical shape `tensor.extract_slice ... [..., affine.min(..., tile)]` but gave up on any other producer chain (tensor.cast, multi-level slicing, affine.apply, scf.if, etc.). Switch the body to ValueBoundsConstraintSet::computeConstantBound on the source's innermost dim with closedUB=true. This delegates traversal to ValueBoundsOpInterface implementations registered for tensor, affine, arith, scf, etc., reaching constant upper bounds across full producer chains rather than just the immediate defining op. iree_gpu.buffer_resource_cast does not implement ValueBoundsOpInterface (it is a Pure, AllTypesMatch op that preserves shape). Peel any chain of these casts before delegating, otherwise Skip #2 would silently fail to fire whenever Skip #1's wrap had already been inserted on the source above the DMA. Adds Test 10 (`inner_ub_through_tensor_cast`): tensor.cast between an extract_slice with static inner size and the DMA source. The old helper bailed out on tensor.cast as the immediate defining op; the new helper traces the bound through it and Skip #2 still elides the pad. Root is intentionally DWORD-misaligned so Skip #1 is out of the picture and the test exclusively exercises the generalized UB extraction. All existing pushdown / coalesced-DMA / swizzle ctests pass (10/10). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
lialan
added a commit
that referenced
this pull request
May 9, 2026
…ided. GPUPushDownDMABoundsToConsumers's Skip #2 elides the post-forall extract_slice + tensor.pad chain on the assumption that downstream lowering preserves the OOB-zero invariant: any lane whose source index falls past the buffer end must write zero to the LDS destination. That invariant only holds when the source eventually lowers to a fat_raw_buffer memref so the AMD HW partial-OOB clamp returns zero and AMDGPULowerCoalescedDMA's applyOOBClamping forces the linearized offset past the root buffer's end. Today applyOOBClamping silently no-ops on non-fat_raw_buffer sources (the early `hasAMDGPUFatRawBufferAddressSpace` check at the top of the helper). If a future change routes a Skip #2'd DMA through a non-fat-raw lowering path, the consumer that we just relieved of its pad would observe garbage in the OOB columns with no diagnostic. Make the contract explicit: - GPUPushDownDMABoundsToConsumers: when Skip #2 fires, set the discardable `iree_gpu.oob_zero_fill_required` UnitAttr on the DMA before returning failure. The op definition is unchanged; this is a plain discardable attr that survives in attr-dict. - AMDGPULowerCoalescedDMAToGatherLDS: add a pre-pattern walk in runOnOperation that calls the new verifyOOBZeroFillContract helper on every CoalescedGatherDMAOp. If the op carries the attr but its source is not a fat_raw_buffer memref, emit a hard op error and signalPassFailure. The check runs before the rewrite patterns so the diagnostic fires exactly once, regardless of which (or how many) patterns later try to match. Adds a new lit case in amdgpu_lower_coalesced_dma_to_gather_lds.mlir (`oob_zero_fill_required_on_non_fat_raw`) that constructs a DMA with `in_bounds [false, true] {iree_gpu.oob_zero_fill_required}` on a plain `memref<2x128xf32>` (no fat_raw_buffer space) and asserts via `expected-error` that the new diagnostic fires. All existing pushdown / coalesced-DMA / swizzle ctests pass (10/10). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
lialan
added a commit
that referenced
this pull request
May 9, 2026
Two issues caught by CI on pipeline_dma_unaligned.mlir. 1. rewriteOneDMA used `tileTy` (the DMA's per-thread/per-warp init shape) for both the extract_slice sizes and the tensor.pad result type, but inserted those ops *outside* the outermost forall. When the outer forall is a warp/thread loop that produces a workgroup- level tile (e.g. matmul lowered with warp tiling: DMA init = tensor<16x64xf16>, outer forall result = tensor<64x64xf16>), the pad result type ended up at the warp shape and replaced uses of the workgroup-shaped result with it. The downstream linalg.pack then crashed the verifier with `expected 'tensor<1x2x16x32xf16>' for the packed domain value, got 'tensor<4x2x16x32xf16>'`: the pack op's tensor.empty was sized for the workgroup tile, but its source was a warp-shaped pad. Fix: take the slice + pad shape from `outerResult.getType()`. The outer dims now use the outer forall result's static sizes; the innermost still takes the dynamic source extent. Pad target type is now `outerTy`. Skip #2's UB comparison is against `outerInnerSize` (the size we'd actually pad to) for the same reason. 2. After (1), pushdown could still emit a tensor.dim outside the outer forall on a source defined inside it, producing a dominance violation on tile-and-fuse'd K-block patterns like `extract_slice %root[%off, ...] [..., affine.minsi(...)]` whose dynamic extent depends on a warp/lane induction variable. Fix: bail when `dma.getSource()` does not properly dominate `outerForall`. The DMA still routes through HW OOB clamping at lowering time, so the worst case is a missed optimization, not incorrect IR. To keep Skip #2 firing on the canonical K-block pattern (where the affine.minsi *result* IS bounded by a constant tile size), extend `getInnermostStaticUpperBound` with a shallow fallback that reads the constant operand of an `arith.minsi`/`arith.minui` directly when ValueBounds fails (upstream Arith does not yet provide a ValueBoundsOpInterface impl for these min ops). Updates pipeline_dma_unaligned.mlir's gather_to_lds checks to `CHECK-COUNT-2: ... #amdgpu.address_space<fat_raw_buffer>>`: with warp-level tile-and-fuse, the gather_to_lds source is a memref subview into the fat_raw_buffer space rather than the cast result itself. The fat_raw_buffer descriptor + validBytes assertions are unchanged. All pushdown / coalesced-DMA / swizzle / pipeline-dma-unaligned ctests pass (11/11).
lialan
added a commit
that referenced
this pull request
May 12, 2026
GPUPushDownDMABoundsToConsumers fired on every DMA whose innermost dim is statically dynamic, including the common "shape-dynamic but runtime-DWORD-aligned" cases. For 4000x4000xf16 with N_tile=128 the RHS DMA's tensor<32x?xf16> source got both an unnecessary iree_gpu.buffer_resource_cast validBytes wrap and an unnecessary consumer-side extract_slice + tensor.pad chain after the outer forall, even though N=4000 is naturally DWORD-aligned and the LDS tile is fully filled for interior workgroups. The pad chain in particular lowers via vectorizeAsTensorPadOp to a per-thread masked write into a tensor.empty, which bufferization commits to a private alloca round-trip per K-iteration (~8 KB scratch traffic per thread), making the e2e ~450-850x slower than main on 4000/6789/12345 square F16 matmuls on MI355X. Two skip predicates added: - padSourceBufferDescriptorToDWORD: also skip when the *root* tensor's innermost row is statically DWORD-aligned (root_innermost * elemBytes divisible by 4). The wrap exists only to guard the partial-DWORD straddle at the buffer end, which cannot occur when the buffer end is naturally DWORD-aligned. Catches the 4000-class case and preserves the wrap for 64x43, 131x131 (odd inner row, partial DWORD at end is real). - rewriteOneDMA: also skip the post-forall extract_slice + tensor.pad chain when the source's innermost extent has a static upper bound equal to innerTileSize. The UB is read from a static dim, an arith.constant size, or the constant operand of an affine.min on the defining tensor.extract_slice. Safety relies on AMDGPULowerCoalescedDMAToGatherLDS::applyOOBClamping forcing OOB lanes past the root buffer's end and writing 0 to the original (possibly swizzled) LDS destination through the same swizzle the matmul reads through; the matmul then sees zeros in OOB columns identical to what the consumer pad would have written. K-reduction contributions are zero (no pollution); N-OOB outputs are discarded by the downstream output extract_slice. The pad is therefore pure perf-dressing, and removing it avoids the vectorizeAsTensorPadOp / tensor.empty alloca round-trip. Helper getInnermostStaticUpperBound walks tensor.extract_slice -> arith.constant / affine.min to extract a constant UB. Adds three lit test cases: - skip_validbytes_when_root_innermost_aligned (Skip #1 standalone) - skip_consumer_pad_when_inner_ub_matches_tile (both skips fire) - consumer_pad_skipped_even_when_root_misaligned (Skip #2 alone, wrap remains for buffer-end correctness) Also registers gpu_pushdown_dma_bounds_to_consumers.mlir in BUILD.bazel and CMakeLists.txt (it was orphaned on this branch). Verification: - Existing pushdown lit (Tests 1-6): pass. - New pushdown lit (Tests 7-9): pass. - pipeline_dma_unaligned ctest: pass (matmul_64x43x64 still gets validBytes wrap because root 43 is odd). - All swizzle ctests (5/5): pass. - 131x131x131 e2e canary: pass; correct 131.0 in every cell. Boundary workgroup garbage is zeroed by applyOOBClamping; matmul output is correct on both K-boundary (LHS) and N-boundary (RHS). - coalesced_dma|swizzle|pushdown ctest set: 22/22 ran pass. - iree/tests/e2e/matmul label: 12/12 ran pass. Boo perf vs main baseline (mean us, 100 dispatches, gfx950): size main branch (correctness only) branch + Part A vs main 4000 172.82 147403.43 173.22 1.00x 6789 1999.27 909933.93 1101.76 0.55x 12345 10344.51 4843764.74 6965.16 0.67x The 4000 perf regression is fully closed; 6789 and 12345 land ~1.5-1.8x faster than main since the alloca round-trip is now gone on a path main was also taking suboptimally. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
AGindinson
pushed a commit
that referenced
this pull request
Jul 6, 2026
See issue #24673. Details are repeated here. `iree-reduce` crashes in `reduceLinalgOnTensorsDelta` when it tries to replace a `linalg` op that produces a **complex**-typed tensor. The strategy builds a zero constant via `Builder::getZeroAttr(elementType)`, which returns a **null** attribute for `complex` (it only supports int/index/float). Creating an `arith.constant` from the null attribute aborts the process. The proposed fix simply does an early-out if the type is not int, float, or index instead of crashing. Repro: `interesting.sh` ```bash #!/bin/bash # Interestingness oracle for iree-reduce. # # A reduced candidate is "interesting" (exit 0) only while it still contains the # complex-typed linalg.generic (identified by the complex.create in its body). # This keeps the reducer from deleting the op via an earlier strategy, so it # reaches reduceLinalgOnTensorsDelta with the complex op still present. grep -q "complex.create" "$1" ``` `complex_repro.mlir` ``` // Minimal reproducer for the iree-reduce crash in reduceLinalgOnTensorsDelta. // // The linalg.generic writes a complex<f32> tensor. When the reducer decides to // replace this op with a linalg.fill of a zero constant, it calls // Builder::getZeroAttr(complex<f32>), which returns a null attribute. Building // an arith.constant from that null attribute crashes ("Failed to infer result // type(s)"). // // The op survives the earlier reduction strategies because the interestingness // check (interesting.sh) requires "complex.create" to remain present, so the // reducer reaches reduceLinalgOnTensorsDelta with the complex op still in place. func.func @main(%arg0: tensor<4xf32>) -> tensor<4xcomplex<f32>> { %empty = tensor.empty() : tensor<4xcomplex<f32>> %0 = linalg.generic { indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"] } ins(%arg0 : tensor<4xf32>) outs(%empty : tensor<4xcomplex<f32>>) { ^bb0(%in: f32, %out: complex<f32>): %c = complex.create %in, %in : complex<f32> linalg.yield %c : complex<f32> } -> tensor<4xcomplex<f32>> return %0 : tensor<4xcomplex<f32>> } ``` Run using: ```bash chmod +x interesting.sh iree-reduce ./interesting.sh ./complex_repro.mlir -o reduced.mlir ``` Crashes with: ``` LLVM ERROR: Failed to infer result type(s): "arith.constant"(...) {} : () -> ( ??? ) Please report issues to https://github.com/iree-org/iree/issues and include the crash backtrace. Stack dump: 0. Program arguments: ../../fix-undef-global-hoist/iree-compiler/tools/iree-reduce ./interesting.sh ./complex_repro.mlir -o reduced.mlir #0 0x00007aa82ee7cf5b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) fix-undef-global-hoist/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:881:13 #1 0x00007aa82ee7ab83 llvm::sys::RunSignalHandlers() fix-undef-global-hoist/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:109:18 #2 0x00007aa82ee7de71 SignalHandler(int, siginfo_t*, void*) fix-undef-global-hoist/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38 #3 0x00007aa828e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330) #4 0x00007aa828e9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #5 0x00007aa828e9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #6 0x00007aa828e9eb2c pthread_kill ./nptl/pthread_kill.c:89:10 #7 0x00007aa828e4527e raise ./signal/../sysdeps/posix/raise.c:27:6 #8 0x00007aa828e288ff abort ./stdlib/abort.c:81:7 #9 0x00007aa82ee0850b llvm::report_fatal_error(llvm::Twine const&, bool) fix-undef-global-hoist/iree/third_party/llvm-project/llvm/lib/Support/ErrorHandling.cpp:137:5 #10 0x00007aa82ee0858e (fix-undef-global-hoist/iree-compiler/lib/libIREECompiler.so+0x580858e) #11 0x00007aa837dabc21 (fix-undef-global-hoist/iree-compiler/lib/libIREECompiler.so+0xe7abc21) #12 0x00007aa834c50cc1 llvm::SmallVectorTemplateCommon<mlir::Type, void>::begin() fix-undef-global-hoist/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallVector.h:276:45 #13 0x00007aa834c50cc1 llvm::SmallVectorTemplateCommon<mlir::Type, void>::end() fix-undef-global-hoist/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallVector.h:278:27 #14 0x00007aa834c50cc1 llvm::SmallVector<mlir::Type, 2u>::~SmallVector() fix-undef-global-hoist/iree/third_party/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1242:46 #15 0x00007aa834c50cc1 mlir::arith::ConstantOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::TypedAttr) fix-undef-global-hoist/iree-compiler/llvm-project/tools/mlir/include/mlir/Dialect/Arith/IR/ArithOps.cpp.inc:4379:1 #16 0x00007aa834c131be mlir::arith::ConstantOp::create(mlir::OpBuilder&, mlir::Location, mlir::TypedAttr) fix-undef-global-hoist/iree-compiler/llvm-project/tools/mlir/include/mlir/Dialect/Arith/IR/ArithOps.cpp.inc:4384:55 #17 0x00007aa8337db6af mlir::Operation::getInlineOpResult(unsigned int) fix-undef-global-hoist/iree/third_party/llvm-project/mlir/include/mlir/IR/Operation.h:1035:61 #18 0x00007aa8337db6af mlir::Operation::getOpResultImpl(unsigned int) fix-undef-global-hoist/iree/third_party/llvm-project/mlir/include/mlir/IR/Operation.h:1045:14 #19 0x00007aa8337db6af mlir::Operation::getResult(unsigned int) fix-undef-global-hoist/iree/third_party/llvm-project/mlir/include/mlir/IR/Operation.h:432:54 #20 0x00007aa8337db6af mlir::OpTrait::OneTypedResult<mlir::Type>::Impl<mlir::arith::ConstantOp>::getResult() fix-undef-global-hoist/iree/third_party/llvm-project/mlir/include/mlir/IR/OpDefinition.h:708:33 #21 0x00007aa8337db6af mlir::OpTrait::OneTypedResult<mlir::Type>::Impl<mlir::arith::ConstantOp>::operator mlir::Value() fix-undef-global-hoist/iree/third_party/llvm-project/mlir/include/mlir/IR/OpDefinition.h:713:54 #22 0x00007aa8337db6af mlir::iree_compiler::Reducer::reduceLinalgOnTensorsDelta(mlir::iree_compiler::Reducer::ChunkManager&, mlir::iree_compiler::Reducer::WorkItem&) fix-undef-global-hoist/iree/compiler/src/iree/compiler/Reducer/Strategies/ReduceLinalgOnTensorsDelta.cpp:114:18 #23 0x00007aa834d464dd mlir::iree_compiler::Reducer::Delta::checkChunk(mlir::iree_compiler::Reducer::Chunk, llvm::function_ref<void (mlir::iree_compiler::Reducer::ChunkManager&, mlir::iree_compiler::Reducer::WorkItem&)>, llvm::ArrayRef<mlir::iree_compiler::Reducer::Chunk>, llvm::DenseSet<mlir::iree_compiler::Reducer::Chunk, llvm::DenseMapInfo<mlir::iree_compiler::Reducer::Chunk, void>>&) fix-undef-global-hoist/iree/compiler/src/iree/compiler/Reducer/Framework/Delta.cpp:39:8 #24 0x00007aa834d46aa7 llvm::LogicalResult::failed() const fix-undef-global-hoist/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43 #25 0x00007aa834d46aa7 llvm::failed(llvm::LogicalResult) fix-undef-global-hoist/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:71:58 #26 0x00007aa834d46aa7 mlir::iree_compiler::Reducer::Delta::runDeltaPass(llvm::function_ref<void (mlir::iree_compiler::Reducer::ChunkManager&, mlir::iree_compiler::Reducer::WorkItem&)>, llvm::StringRef) fix-undef-global-hoist/iree/compiler/src/iree/compiler/Reducer/Framework/Delta.cpp:105:11 #27 0x00007aa82f5d68ea mlir::iree_compiler::Reducer::ireeRunReducingStrategies(mlir::OwningOpRef<mlir::Operation*>, mlir::iree_compiler::Reducer::ReducerConfig&) fix-undef-global-hoist/iree/compiler/src/iree/compiler/Reducer/iree_reduce_lib.cc:39:9 #28 0x00007aa82edba149 ireeReduceMainFromCL(int, char**, mlir::MLIRContext&) fix-undef-global-hoist/iree/compiler/src/iree/compiler/API/Internal/IREEReduceToolEntryPoint.cpp:102:26 #29 0x00007aa82edba149 ireeReduceRunMain fix-undef-global-hoist/iree/compiler/src/iree/compiler/API/Internal/IREEReduceToolEntryPoint.cpp:134:7 #30 0x00007aa828e2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3 #31 0x00007aa828e2a28b call_init ./csu/../csu/libc-start.c:128:20 #32 0x00007aa828e2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5 #33 0x00005a84cb2e26e5 _start (../../fix-undef-global-hoist/iree-compiler/tools/iree-reduce+0x16e5) ``` Signed-off-by: Paul Stark <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
adityasingh2400
added a commit
to adityasingh2400/iree
that referenced
this pull request
Aug 5, 2026
…nnels-last transposeConvLikeLinalgOp reads the image, filter and output as operands 0, 1 and 2, and the builders it hands off to rebuild the op with exactly two inputs and one init. A quantized convolution such as linalg.conv_2d_nchw_fchw_q has ins(image, filter, input_zp, filter_zp) and outs(output), so operand 2 is an i32 zero point rather than the output tensor. Its indexing map has no results, the pack of the output is a no-op, and the rebuilt linalg.generic is created with an i32 init, which fails verification with 'linalg.generic' op operand iree-org#2 must be variadic of shaped of any non-token type values, but got 'i32' Bail out when the op does not have the two inputs and one init the rewrite knows how to reconstruct. ConvertGenericFilterToFhwc in ConvertConvFilterToChannelsLast.cpp rebuilds the op the same way and looks to need the same guard. That is left out here to keep this change to the reproducer in the issue. Fixes iree-org#24774 Assisted-by: Claude Code Signed-off-by: Aditya Singh <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unnecessary branching