iree: topk: Failed to bufferize op
What happened?
Trying to compile the attached mlir file fails in two different ways.
Without --iree-opt-level=O3: err_no03.txt
iree-compile: iree/compiler/src/iree/compiler/Codegen/Dialect/GPU/TargetUtils/ConfigUtils.cpp:147: std::optional<GPUMMASchedule> mlir::iree_compiler::IREE::GPU::getMmaScheduleFromProblemAndTarget(IREE::GPU::TargetAttr, mlir::iree_compiler::GPUMatmulShapeType, bool, bool, bool, bool): Assertion `problem.aType == problem.bType && "expected the same aType and bType."' failed.
With --iree-opt-level=O3: err.txt
topk.txt:73:25: error: failed to bufferize op
%values, %indices = torch.aten.topk %24, %int2_8, %int-1_9, %true, %true_10 : !torch.vtensor<[?,2,2],f32>, !torch.int, !torch.int, !torch.bool, !torch.bool -> !torch.vtensor<[?,2,2],f32>, !torch.vtensor<[?,2,2],si64>
^
topk.txt:73:25: note: see current operation: %24 = "bufferization.alloc_tensor"(%23) <{operandSegmentSizes = array<i32: 0, 1, 0>}> : (tensor<1x1x2xi64>) -> tensor<1x1x2xi64>
Steps to reproduce your issue
Compiled with
iree-compile topk.txt \
--iree-hal-target-device=hip[0] \
--iree-hal-executable-debug-level=3 \
-o=output.vmfb --iree-hip-target=gfx942 --iree-opt-level=O3
What component(s) does this issue relate to?
No response
Version information
Built from source using iree-3.4.0rc20250423.
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (25 by maintainers)
Commits related to this issue
- [LinalgExt] Add a canonicalization pattern to drop unused results from sort op (#20827) Issue: https://github.com/iree-org/iree/issues/20699 Fixes bufferization failures caused by unused results of ... — committed to iree-org/iree by Muzammiluddin-Syed-ECE 2 years ago
- [Codegen][GPU] Add support for allocating private memory for unused DPS results (#20793) Fixes https://github.com/iree-org/iree/issues/20699 Fixes bufferization failures caused by unused results of ... — committed to iree-org/iree by Muzammiluddin-Syed-ECE 2 years ago
Problems
indicesresult is unusedvaluesresult is unusedAfter some discussion with @MaheshRavishankar @Max191 @qedawkins there was consensus that Case 1 can be fixed easily by removing the unused result. For Case 2, the fix is more involved; the root cause of this problem has to do with teaching flow to tie operands during dispatch formation. But to quickly resolve the deepseek issue, we are also adding a band-aid solution at the Codegen level.
This is probably the right fix for this problem, but I think @krzysz00 is right that we need to tread safely.
That is also a fix. Actually in this case we should probably just do that. Its a good point and I missed that.
After chatting with @Max191
gpuRequireMemSpaceAllocationFnAfter chatting with @MaheshRavishankar the work is to make two changes:
createGPUInferMemorySpacePassto make the default memory space of unused results to private memory spaceOk, I looked further. I think it would be very hacky to fix that earlier. You will have to create a dummy buffer that is not used anywhere and just makes things fragile. The issue is probably back to codegen. We need to distribute this op to threads and have each thread use a private local memory that hopefully gets promoted to registers in LLVM.
Lets forget about the case of lacking O3 optimizations. Fixing with O3 is higher priority
Let me take an initial look at this today.