MLIR  16.0.0git
Functions
KernelOutlining.cpp File Reference
#include "PassDetail.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/GPU/Transforms/Passes.h"
#include "mlir/Dialect/GPU/Transforms/Utils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/RegionUtils.h"
+ Include dependency graph for KernelOutlining.cpp:

Go to the source code of this file.

Functions

template<typename OpTy >
static void createForAllDimensions (OpBuilder &builder, Location loc, SmallVectorImpl< Value > &values)
 
static void injectGpuIndexOperations (Location loc, Region &launchFuncOpBody, Region &launchOpBody, BlockAndValueMapping &map)
 Adds operations generating block/thread ids and grid/block dimensions at the beginning of the launchFuncOpBody region. More...
 
static bool isLikelyAnIndexComputation (Operation *op)
 Identifies operations that are beneficial to sink into kernels. More...
 
static bool extractBeneficiaryOps (Operation *op, const SetVector< Value > &existingDependencies, SetVector< Operation *> &beneficiaryOps, llvm::SmallPtrSetImpl< Value > &availableValues, llvm::function_ref< bool(Operation *)> isSinkingBeneficiary)
 For a given operation op, computes whether it is beneficial to sink the operation into the kernel. More...
 
static gpu::GPUFuncOp outlineKernelFuncImpl (gpu::LaunchOp launchOp, StringRef kernelFnName, SetVector< Value > &operands)
 Outline the gpu.launch operation body into a kernel function. More...
 
static void convertToLaunchFuncOp (gpu::LaunchOp launchOp, gpu::GPUFuncOp kernelFunc, ValueRange operands)
 Replace gpu.launch operations with an gpu.launch_func operation launching kernelFunc. More...
 

Function Documentation

◆ convertToLaunchFuncOp()

static void convertToLaunchFuncOp ( gpu::LaunchOp  launchOp,
gpu::GPUFuncOp  kernelFunc,
ValueRange  operands 
)
static

◆ createForAllDimensions()

template<typename OpTy >
static void createForAllDimensions ( OpBuilder builder,
Location  loc,
SmallVectorImpl< Value > &  values 
)
static

Definition at line 33 of file KernelOutlining.cpp.

References mlir::OpBuilder::create(), and mlir::Builder::getIndexType().

◆ extractBeneficiaryOps()

static bool extractBeneficiaryOps ( Operation op,
const SetVector< Value > &  existingDependencies,
SetVector< Operation *> &  beneficiaryOps,
llvm::SmallPtrSetImpl< Value > &  availableValues,
llvm::function_ref< bool(Operation *)>  isSinkingBeneficiary 
)
static

For a given operation op, computes whether it is beneficial to sink the operation into the kernel.

An operation can be sunk if doing so does not introduce new kernel arguments. Whether a value is already available in the kernel (and hence does not introduce new arguments) is checked by querying existingDependencies and availableValues. If an operand is not yet available, we recursively check whether it can be made available by siking its defining op. Operations that are indentified for sinking are added to beneficiaryOps in the order they should appear in the kernel. Furthermore, availableValues is updated with results that will be available after sinking the identified ops.

Definition at line 79 of file KernelOutlining.cpp.

References mlir::Operation::getOperands(), and mlir::Operation::getResults().

Referenced by mlir::sinkOperationsIntoLaunchOp().

◆ injectGpuIndexOperations()

static void injectGpuIndexOperations ( Location  loc,
Region launchFuncOpBody,
Region launchOpBody,
BlockAndValueMapping map 
)
static

Adds operations generating block/thread ids and grid/block dimensions at the beginning of the launchFuncOpBody region.

Add mapping from argument in entry block of launchOpBody, to the corresponding result value of the added operations.

Definition at line 43 of file KernelOutlining.cpp.

References mlir::detail::enumerate(), mlir::Region::front(), mlir::Attribute::getContext(), and mlir::BlockAndValueMapping::map().

Referenced by outlineKernelFuncImpl().

◆ isLikelyAnIndexComputation()

static bool isLikelyAnIndexComputation ( Operation op)
static

Identifies operations that are beneficial to sink into kernels.

These operations may not have side-effects, as otherwise sinking (and hence duplicating them) is not legal.

Definition at line 63 of file KernelOutlining.cpp.

References mlir::m_Constant(), and mlir::matchPattern().

◆ outlineKernelFuncImpl()

static gpu::GPUFuncOp outlineKernelFuncImpl ( gpu::LaunchOp  launchOp,
StringRef  kernelFnName,
SetVector< Value > &  operands 
)
static