[all-commits] [llvm/llvm-project] 5a1778: [mlir] use unpacked memref descriptors at function...

ftynse via All-commits all-commits at lists.llvm.org
Mon Feb 10 06:03:56 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 5a1778057f72b8e0444a7932144a3fa441b641bc
      https://github.com/llvm/llvm-project/commit/5a1778057f72b8e0444a7932144a3fa441b641bc
  Author: Alex Zinenko <zinenko at google.com>
  Date:   2020-02-10 (Mon, 10 Feb 2020)

  Changed paths:
    M mlir/docs/ConversionToLLVMDialect.md
    M mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
    M mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
    M mlir/include/mlir/IR/FunctionSupport.h
    M mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp
    M mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
    M mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
    M mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
    M mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
    M mlir/lib/Transforms/DialectConversion.cpp
    M mlir/test/Conversion/GPUToCUDA/lower-launch-func-to-cuda.mlir
    M mlir/test/Conversion/StandardToLLVM/convert-argattrs.mlir
    M mlir/test/Conversion/StandardToLLVM/convert-dynamic-memref-ops.mlir
    M mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir
    M mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
    M mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
    M mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir
    M mlir/test/Dialect/GPU/invalid.mlir
    M mlir/test/Dialect/Linalg/llvm.mlir
    M mlir/test/mlir-cpu-runner/cblas_interface.cpp
    M mlir/test/mlir-cpu-runner/include/cblas_interface.h
    M mlir/test/mlir-cpu-runner/include/mlir_runner_utils.h
    M mlir/test/mlir-cpu-runner/mlir_runner_utils.cpp
    M mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir
    M mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp

  Log Message:
  -----------
  [mlir] use unpacked memref descriptors at function boundaries

The existing (default) calling convention for memrefs in standard-to-LLVM
conversion was motivated by interfacing with LLVM IR produced from C sources.
In particular, it passes a pointer to the memref descriptor structure when
calling the function. Therefore, the descriptor is allocated on stack before
the call. This convention leads to several problems. PR44644 indicates a
problem with stack exhaustion when calling functions with memref-typed
arguments in a loop. Allocating outside of the loop may lead to concurrent
access problems in case the loop is parallel. When targeting GPUs, the contents
of the stack-allocated memory for the descriptor (passed by pointer) needs to
be explicitly copied to the device. Using an aggregate type makes it impossible
to attach pointer-specific argument attributes pertaining to alignment and
aliasing in the LLVM dialect.

Change the default calling convention for memrefs in standard-to-LLVM
conversion to transform a memref into a list of arguments, each of primitive
type, that are comprised in the memref descriptor. This avoids stack allocation
for ranked memrefs (and thus stack exhaustion and potential concurrent access
problems) and simplifies the device function invocation on GPUs.

Provide an option in the standard-to-LLVM conversion to generate auxiliary
wrapper function with the same interface as the previous calling convention,
compatible with LLVM IR porduced from C sources. These auxiliary functions
pack the individual values into a descriptor structure or unpack it. They also
handle descriptor stack allocation if necessary, serving as an allocation
scope: the memory reserved by `alloca` will be freed on exiting the auxiliary
function.

The effect of this change on MLIR-generated only LLVM IR is minimal. When
interfacing MLIR-generated LLVM IR with C-generated LLVM IR, the integration
only needs to require auxiliary functions and change the function name to call
the wrapper function instead of the original function.

This also opens the door to forwarding aliasing and alignment information from
memrefs to LLVM IR pointers in the standrd-to-LLVM conversion.




More information about the All-commits mailing list