Skip to content

Crash during GPU linking #21024

Closed
Closed

Description

@rsuderman

Attempting to do hip kernel injection fails due to a crash in the gpu linking

Using the following patch nod-ai/amd-shark-ai#1585

iree-compile artifacts/model.mlir -o artifacts/model.vmfb \
        --iree-hal-target-device=hip \
        --iree-hip-target=gfx1100 \
        --iree-opt-aggressively-propagate-transposes \
        --iree-opt-level=O3 \
        --iree-dispatch-creation-enable-aggressive-fusion=true \
        --iree-hal-executable-debug-level=3 \
        --iree-hal-indirect-command-buffers=true  \
        --iree-codegen-enable-default-tuning-specs=true \
        --iree-stream-resource-memory-model=discrete  \
        --iree-hal-memoization=true \
        --iree-preprocessing-transform-spec-filename=topk_spec.mlir

topk_f.zip

model.zip

Activity

  1. benvanik commented on Jun 5, 2025

    @benvanik
    Collaborator

    got a stack?

  2. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    Posting stack from internal chat

     #0 0x00007c7f978e3c52 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x20e3c52)
     #1 0x00007c7f978e10de SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
     #2 0x00007c7f95445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
     #3 0x00007c7f9aa9767c mlir::iree_compiler::mergeModuleInto(mlir::Operation*, mlir::Operation*, llvm::DenseMap<llvm::StringRef, mlir::Operation*, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, mlir::Operation*>>&, std::function<bool (mlir::Operation*)>) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x529767c)
     #4 0x00007c7f9980b3e6 std::_Function_handler<llvm::LogicalResult (mlir::ModuleOp, mlir::ModuleOp, llvm::DenseMap<llvm::StringRef, mlir::Operation*, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, mlir::Operation*>>&), mlir::iree_compiler::(anonymous namespace)::LLVMGPULinkExecutablesPass::runOnOperation()::'lambda'(mlir::ModuleOp, mlir::ModuleOp, llvm::DenseMap<llvm::StringRef, mlir::Operation*, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, mlir::Operation*>>&)>::_M_invoke(std::_Any_data const&, mlir::ModuleOp&&, mlir::ModuleOp&&, llvm::DenseMap<llvm::StringRef, mlir::Operation*, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, mlir::Operation*>>&) LLVMGPULinkExecutables.cpp:0:0
     #5 0x00007c7f9aa9b893 mlir::iree_compiler::linkExecutablesInto(mlir::ModuleOp, llvm::SmallVectorImpl<mlir::iree_compiler::IREE::HAL::ExecutableOp>&, mlir::iree_compiler::IREE::HAL::ExecutableOp, mlir::iree_compiler::IREE::HAL::ExecutableVariantOp, std::function<llvm::LogicalResult (mlir::ModuleOp, mlir::ModuleOp, llvm::DenseMap<llvm::StringRef, mlir::Operation*, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, mlir::Operation*>>&)>) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x529b893)
     #6 0x00007c7f9980c170 mlir::iree_compiler::(anonymous namespace)::LLVMGPULinkExecutablesPass::runOnOperation() LLVMGPULinkExecutables.cpp:0:0
     #7 0x00007c7f97bc9b6e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9b6e)
     #8 0x00007c7f97bc9f79 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9f79)
     #9 0x00007c7f97bcafac mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda'(mlir::OpPassManager&, mlir::Operation*)::operator()(mlir::OpPassManager&, mlir::Operation*) const Pass.cpp:0:0
    #10 0x00007c7f9984db34 mlir::iree_compiler::IREE::HAL::(anonymous namespace)::LinkTargetExecutablesPass::runOnOperation() LinkExecutables.cpp:0:0
    #11 0x00007c7f97bc9b6e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9b6e)
    #12 0x00007c7f97bc9f79 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9f79)
    #13 0x00007c7f97bcafac mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda'(mlir::OpPassManager&, mlir::Operation*)::operator()(mlir::OpPassManager&, mlir::Operation*) const Pass.cpp:0:0
    #14 0x00007c7f9984f23a mlir::iree_compiler::IREE::HAL::(anonymous namespace)::LinkAllExecutablesPass::runOnOperation() LinkExecutables.cpp:0:0
    #15 0x00007c7f97bc9b6e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9b6e)
    #16 0x00007c7f97bc9f79 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23c9f79)
    #17 0x00007c7f97bcadfb mlir::PassManager::run(mlir::Operation*) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x23cadfb)
    #18 0x00007c7f97834d8f mlir::iree_compiler::embed::(anonymous namespace)::Invocation::runPipeline(iree_compiler_pipeline_t) CompilerDriver.cpp:0:0
    #19 0x00007c7f97ac468a mlir::iree_compiler::runIreecMain(int, char**)::'lambda'(iree_compiler_source_t*)::operator()(iree_compiler_source_t*) const iree_compile_lib.cc:0:0
    #20 0x00007c7f97ac7d43 mlir::iree_compiler::runIreecMain(int, char**) (/home/rsuderman/repos/iree/build/lib/libIREECompiler.so+0x22c7d43)
    #21 0x00007c7f9542a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
    #22 0x00007c7f9542a28b call_init ./csu/../csu/libc-start.c:128:20
    #23 0x00007c7f9542a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
    #24 0x00005eea58fad095 _start (/home/rsuderman/repos/iree/build/tools/iree-compile+0x1095)
    Segmentation fault (core dumped)
    
  3. benvanik commented on Jun 5, 2025

    @benvanik
    Collaborator

    cool - an --mlir-print-ir-before=iree-llvmgpu-link-executables should be all that's needed to repro!

  4. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    IR before the pass

    https://gist.github.com/MaheshRavishankar/28b2983c85f6f154621fb01dbbc3cebb

    but

    iree-opt --iree-llvmgpu-link-executables pass_repro.mlir
    

    isnt reproducing the crash

  5. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    Ah

    iree-opt --pass-pipeline="builtin.module(iree-llvmgpu-link-executables{target=rocm})" pass_repro.mlir
    

    reproduces the issue.

  6. benvanik commented on Jun 5, 2025

    @benvanik
    Collaborator

    noticed:

    objects([#hal.executable.object<{path = "/home/rsuderman/repos/shark-ai/sharktank/hip_kernels/build/compiled_kernels/topk_fp16_ukernel.c.hsaco"}>]) {

    may have to change that file to test it all the way, but I think this failure happens before it's actually needed

  7. rsuderman commented on Jun 5, 2025

    @rsuderman
    CollaboratorAuthor

    It looks like mergeModuleInto is being invoked with a nullptr for the sourceModuleOp being invoked during LLVMGPULinkExecutablesPass

  8. benvanik commented on Jun 5, 2025

    @benvanik
    Collaborator

    that's it - it assumes there's some inner module - we don't want to link executables with no inner module at all.

    gatherExecutablesForTarget/gatherExecutablesForTargets should be changed to not return any executable without an inner module
    (that makes the naming a bit weird, may be better to filter, or change those to be gatherLinkableExecutable....)

  9. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator
    diff --git a/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp b/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    index bdcdd8a4b9..64669bf729 100644
    --- a/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    +++ b/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    @@ -22,6 +22,9 @@ gatherExecutableTargets(ArrayRef<IREE::HAL::ExecutableOp> executableOps) {
         auto variantOps =
             llvm::to_vector(executableOp.getOps<IREE::HAL::ExecutableVariantOp>());
         for (auto variantOp : variantOps) {
    +      if (!variantOp.getInnerModule()) {
    +        continue;
    +      }
           result.insert(variantOp.getTarget());
         }
       }
    

    Fixes the issue. But do we expect variants with no inner modules?

  10. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    I can land that change if that is the right fix, but I see the executable failing here as

    hal.executable.variant public @rocm_hsaco_fb target(<"rocm", "rocm-hsaco-fb", {target_arch = "gfx1100", ukernels = "none"}>) objects([#hal.executable.object<{path = "/home/rsuderman/repos/shark-ai/sharktank/hip_kernels/build/compiled_kernels/topk_fp16_ukernel.c.hsaco"}>]) {
      hal.executable.export public @topk_F16I32 ordinal(0) layout(#hal.pipeline.layout<constants = 1, bindings = [#hal.pipeline.binding<storage_buffer, ReadOnly>, #hal.pipeline.binding<storage_buffer>, #hal.pipeline.binding<storage_buffer>]>) attributes {workgroup_size = [64 : index, 1 : index, 1 : index]}
    }
    

    It has an export but doesnt have a module that exports this. Is that expected?

  11. benvanik commented on Jun 5, 2025

    @benvanik
    Collaborator

    in this particular case of a fully external executable (the hsaco, or if the user provided a .so on CPU, or something) yep! it'll always be better if we could be merging in .bc/.mlir instead (which we would want to link, and would likely need a dummy inner module).

  12. rsuderman commented on Jun 5, 2025

    @rsuderman
    CollaboratorAuthor
    diff --git a/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp b/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    index bdcdd8a4b9..64669bf729 100644
    --- a/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    +++ b/compiler/src/iree/compiler/Codegen/Utils/LinkingUtils.cpp
    @@ -22,6 +22,9 @@ gatherExecutableTargets(ArrayRef<IREE::HAL::ExecutableOp> executableOps) {
         auto variantOps =
             llvm::to_vector(executableOp.getOps<IREE::HAL::ExecutableVariantOp>());
         for (auto variantOp : variantOps) {
    +      if (!variantOp.getInnerModule()) {
    +        continue;
    +      }
           result.insert(variantOp.getTarget());
         }
       }
    

    Fixes the issue. But do we expect variants with no inner modules?

    This appears to get us through the compilation process.

  13. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    yeah, struggling a bit to write a test.
    But will send pr

  14. added a commit that references this issue on Jun 5, 2025
    d7a7acb
  15. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    Sent PR. That also fixes the issue but I am not sure that is right fix. Ill wait for Bens review.

  16. added a commit that references this issue on Jun 5, 2025
    21c44b2
  17. added a commit that references this issue on Jun 6, 2025
    b4cdec3
  18. added a commit that references this issue on Dec 1, 2025
    a4e39d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions