[PATCH] D74211: [mlir] use unpacked memref descriptors at function boundaries

Alex Zinenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 03:41:09 PST 2020


ftynse created this revision.
ftynse added reviewers: nicolasvasilache, dcaballe.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, aartbik, herhut, lucyrfox, mgester, arpith-jacob, csigg, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini, jholewinski.
Herald added a reviewer: mravishankar.
Herald added a reviewer: rriddle.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74211

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74211.243126.patch
Type: text/x-patch
Size: 117897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200207/7e712c23/attachment-0001.bin>


More information about the llvm-commits mailing list