forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][gpu][bufferization] Implement BufferDeallocationOpInterface fo…
…r gpu.terminator (llvm#66880) This is necessary to support deallocation of IR with gpu.launch operations because it does not implement the RegionBranchOpInterface. Implementing the interface would require it to support regions with unstructured control flow and produced arguments/results.
- Loading branch information
Showing
10 changed files
with
149 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
mlir/include/mlir/Dialect/GPU/Transforms/BufferDeallocationOpInterfaceImpl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- BufferDeallocationOpInterfaceImpl.h ----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_GPU_TRANSFORMS_BUFFERDEALLOCATIONOPINTERFACEIMPL_H | ||
#define MLIR_DIALECT_GPU_TRANSFORMS_BUFFERDEALLOCATIONOPINTERFACEIMPL_H | ||
|
||
namespace mlir { | ||
|
||
class DialectRegistry; | ||
|
||
namespace gpu { | ||
void registerBufferDeallocationOpInterfaceExternalModels( | ||
DialectRegistry ®istry); | ||
} // namespace gpu | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_GPU_TRANSFORMS_BUFFERDEALLOCATIONOPINTERFACEIMPL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
mlir/lib/Dialect/GPU/Transforms/BufferDeallocationOpInterfaceImpl.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===- BufferDeallocationOpInterfaceImpl.cpp ------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/GPU/Transforms/BufferDeallocationOpInterfaceImpl.h" | ||
#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h" | ||
#include "mlir/Dialect/Bufferization/IR/Bufferization.h" | ||
#include "mlir/Dialect/GPU/IR/GPUDialect.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::bufferization; | ||
|
||
namespace { | ||
/// | ||
struct GPUTerminatorOpInterface | ||
: public BufferDeallocationOpInterface::ExternalModel< | ||
GPUTerminatorOpInterface, gpu::TerminatorOp> { | ||
FailureOr<Operation *> process(Operation *op, DeallocationState &state, | ||
const DeallocationOptions &options) const { | ||
SmallVector<Value> updatedOperandOwnerships; | ||
return deallocation_impl::insertDeallocOpForReturnLike( | ||
state, op, {}, updatedOperandOwnerships); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
void mlir::gpu::registerBufferDeallocationOpInterfaceExternalModels( | ||
DialectRegistry ®istry) { | ||
registry.addExtension(+[](MLIRContext *ctx, GPUDialect *dialect) { | ||
gpu::TerminatorOp::attachInterface<GPUTerminatorOpInterface>(*ctx); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
mlir/test/Dialect/GPU/bufferization-buffer-deallocation.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// RUN: mlir-opt %s -buffer-deallocation-pipeline --allow-unregistered-dialect | FileCheck %s | ||
|
||
func.func @gpu_launch() { | ||
%c1 = arith.constant 1 : index | ||
gpu.launch blocks(%arg0, %arg1, %arg2) in (%arg6 = %c1, %arg7 = %c1, %arg8 = %c1) | ||
threads(%arg3, %arg4, %arg5) in (%arg9 = %c1, %arg10 = %c1, %arg11 = %c1) { | ||
%alloc = memref.alloc() : memref<2xf32> | ||
"test.memref_user"(%alloc) : (memref<2xf32>) -> () | ||
gpu.terminator | ||
} | ||
return | ||
} | ||
|
||
// CHECK-LABEL: func @gpu_launch | ||
// CHECK: gpu.launch | ||
// CHECK: [[ALLOC:%.+]] = memref.alloc( | ||
// CHECK: memref.dealloc [[ALLOC]] | ||
// CHECK: gpu.terminator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters