[all-commits] [llvm/llvm-project] 0ce625: [HIP][LLVM][Opt] Add LLVM support for `hipstdpar`

Alex Voicu via All-commits all-commits at lists.llvm.org
Thu Oct 12 03:27:08 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0ce6255a50584863c2f462390cac6a63ccb5f136
      https://github.com/llvm/llvm-project/commit/0ce6255a50584863c2f462390cac6a63ccb5f136
  Author: Alex Voicu <alexandru.voicu at amd.com>
  Date:   2023-10-12 (Thu, 12 Oct 2023)

  Changed paths:
    A llvm/include/llvm/Transforms/HipStdPar/HipStdPar.h
    M llvm/lib/Passes/CMakeLists.txt
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassBuilderPipelines.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
    M llvm/lib/Target/AMDGPU/CMakeLists.txt
    M llvm/lib/Transforms/CMakeLists.txt
    A llvm/lib/Transforms/HipStdPar/CMakeLists.txt
    A llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
    A llvm/test/Transforms/HipStdPar/accelerator-code-selection.ll
    A llvm/test/Transforms/HipStdPar/allocation-interposition.ll
    A llvm/test/Transforms/HipStdPar/allocation-no-interposition.ll
    A llvm/test/Transforms/HipStdPar/unsupported-asm.ll
    A llvm/test/Transforms/HipStdPar/unsupported-builtins.ll
    A llvm/test/Transforms/HipStdPar/unsupported-thread-local-direct-use.ll
    A llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll

  Log Message:
  -----------
  [HIP][LLVM][Opt] Add LLVM support for `hipstdpar`

This patch adds the LLVM changes needed for enabling HIP parallel algorithm offload on AMDGPU targets. What we do here is add two passes, one mandatory and one optional:

1. HipStdParAcceleratorCodeSelectionPass is mandatory, depends on CallGraphAnalysis, and implements the following transform:

    - Traverse the call-graph, and check for functions that are roots for accelerator execution (at the moment, these are GPU kernels exclusively, and would originate in the accelerator specific algorithm library the toolchain uses as an implementation detail);
    - Starting from a root, do a BFS to find all functions that are reachable (called directly or indirectly via a call- chain) and record them;
    - After having done the above for all roots in the Module, we have the computed the set of reachable functions, which is the union of roots and functions reachable from roots;
    - All functions that are not in the reachable set are removed; for the special case where the reachable set is empty we completely clear the module;

2. HipStdParAllocationInterpositionPass is optional, is meant as a fallback with restricted functionality for cases where on-demand paging is unavailable on a platform, and implements the following transform:
    - Iterate all functions in a Module;
    - If a function's name is in a predefined set of allocation / deallocation that the runtime implementation is allowed and expected to interpose, replace all its uses with the equivalent accelerator aware function, iff the latter is available;
        - If the accelerator aware equivalent is unavailable we warn, but compilation will go ahead, which means that it is possible to get issues around the accelerator trying to access inaccessible memory at run time;
    - We rely on direct name matching as opposed to using the new alloc-kind family of attributes and / or the LibCall analysis pass because some of the legacy functions that need replacing would not carry the former or be identified by the latter.

Reviewed by: JonChesterfield, yaxunl

Differential Revision: https://reviews.llvm.org/D155856




More information about the All-commits mailing list