Annotate outlined kernel functions with the attribute `gpu.kernel`.

--

PiperOrigin-RevId: 247589560
This commit is contained in:
Thomas Joerg 2019-05-10 04:26:58 -07:00 committed by Mehdi Amini
parent 29712d7ffa
commit df0296742b
3 changed files with 8 additions and 0 deletions

View File

@ -38,6 +38,9 @@ public:
/// Get the canonical string name of the dialect.
static StringRef getDialectName();
/// Get the name of the attribute used to annotate outlined kernel functions.
static StringRef getKernelFuncAttrName() { return "gpu.kernel"; }
};
/// Utility class for the GPU dialect to represent triples of `Value`s

View File

@ -71,6 +71,10 @@ Function *outlineKernelFunc(Module &module, gpu::LaunchOp &launchOp) {
mlir::BlockAndValueMapping mapper;
Function *outlinedFunc = new mlir::Function(loc, kernelFuncName, type);
outlinedFunc->getBody().takeBody(launchOp.getBody());
Builder builder(&module);
outlinedFunc->getAttrList().set(
builder.getIdentifier(gpu::GPUDialect::getKernelFuncAttrName()),
builder.getUnitAttr());
injectGpuIndexOperations(module, loc, outlinedFunc);
module.getFunctions().push_back(outlinedFunc);
return outlinedFunc;

View File

@ -26,6 +26,7 @@ func @launch() {
}
// CHECK: func @launch_kernel(%arg0: f32, %arg1: memref<?xf32, 1>)
// CHECK-NEXT: attributes {gpu.kernel}
// CHECK-NEXT: %0 = "gpu.block_id"() {dimension: "x"} : () -> index
// CHECK-NEXT: %1 = "gpu.block_id"() {dimension: "y"} : () -> index
// CHECK-NEXT: %2 = "gpu.block_id"() {dimension: "z"} : () -> index