-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU][MLIR]Add shmem-optimization as an op using transform dialect #81550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harsh-nod
merged 5 commits into
llvm:main
from
erman-gurses:eg_shmem_opt_transform_dialect
Feb 14, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e54be9
Add shmem-opimization as an op using transform dialect
erman-gurses 60e42a5
Fix the format
erman-gurses 82045ca
Remove redundant namespaces
erman-gurses 1e6a448
Address the last comments
erman-gurses 889f1a1
Fix the format
erman-gurses File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(TransformOps) | ||
add_subdirectory(Transforms) |
48 changes: 48 additions & 0 deletions
48
mlir/include/mlir/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.h
This file contains hidden or 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,48 @@ | ||
//===- AMDGPUTransformOps.h - AMDGPU transform ops ---------------*- 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_AMDGPU_TRANSFORMOPS_AMDGPUTRANSFORMOPS_H | ||
#define MLIR_DIALECT_AMDGPU_TRANSFORMOPS_AMDGPUTRANSFORMOPS_H | ||
|
||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/Dialect/Transform/IR/TransformAttrs.h" | ||
#include "mlir/Dialect/Transform/IR/TransformDialect.h" | ||
#include "mlir/Dialect/Transform/IR/TransformInterfaces.h" | ||
#include "mlir/IR/OpImplementation.h" | ||
#include "mlir/IR/RegionKindInterface.h" | ||
|
||
namespace mlir { | ||
namespace transform { | ||
class TransformHandleTypeInterface; | ||
} // namespace transform | ||
} // namespace mlir | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
|
||
namespace linalg { | ||
class LinalgOp; | ||
} // namespace linalg | ||
|
||
namespace scf { | ||
class ForOp; | ||
} // namespace scf | ||
|
||
namespace amdgpu { | ||
void registerTransformDialectExtension(DialectRegistry ®istry); | ||
} // namespace amdgpu | ||
} // namespace mlir | ||
|
||
//===----------------------------------------------------------------------===// | ||
// AMDGPU Transform Operations | ||
//===----------------------------------------------------------------------===// | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.h.inc" | ||
|
||
#endif // MLIR_DIALECT_AMDGPU_TRANSFORMOPS_AMDGPUTRANSFORMOPS_H |
45 changes: 45 additions & 0 deletions
45
mlir/include/mlir/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.td
This file contains hidden or 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,45 @@ | ||
//===- AMDGPUTransformOps.td - AMDGPU transform ops --------*- tablegen -*-===// | ||
// | ||
// 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 AMDGPU_TRANSFORM_OPS | ||
#define AMDGPU_TRANSFORM_OPS | ||
|
||
include "mlir/Dialect/Transform/IR/TransformAttrs.td" | ||
include "mlir/Dialect/Transform/IR/TransformDialect.td" | ||
include "mlir/Dialect/Transform/IR/TransformInterfaces.td" | ||
include "mlir/Dialect/Transform/IR/TransformTypes.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ApplyOptimizeSharedMemoryReadsAndWritesOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
def ApplyOptimizeSharedMemoryReadsAndWritesOp : | ||
Op<Transform_Dialect, "amdgpu.optimize_shared_memory_reads_and_writes", | ||
[DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, | ||
TransformOpInterface, TransformEachOpTrait]> { | ||
let summary = "Reduce shared memory bank conflicts"; | ||
let description = [{ This op attempts to optimize GPU Shared memory | ||
reads/writes with the goal of avoiding bank conflicts. | ||
}]; | ||
|
||
let arguments = (ins TransformHandleTypeInterface:$target); | ||
let results = (outs); | ||
|
||
let assemblyFormat = "$target attr-dict `:` functional-type(operands, results)"; | ||
|
||
let extraClassDeclaration = [{ | ||
::mlir::DiagnosedSilenceableFailure applyToOne( | ||
::mlir::transform::TransformRewriter &rewriter, | ||
::mlir::func::FuncOp funcOp, | ||
::mlir::transform::ApplyToEachResultList &results, | ||
::mlir::transform::TransformState &state); | ||
}]; | ||
} | ||
|
||
#endif // AMDGPU_TRANSFORM_OPS |
This file contains hidden or 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,4 @@ | ||
set(LLVM_TARGET_DEFINITIONS AMDGPUTransformOps.td) | ||
mlir_tablegen(AMDGPUTransformOps.h.inc -gen-op-decls) | ||
mlir_tablegen(AMDGPUTransformOps.cpp.inc -gen-op-defs) | ||
add_public_tablegen_target(MLIRAMDGPUTransformOpsIncGen) |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) | ||
add_subdirectory(Utils) | ||
add_subdirectory(TransformOps) | ||
add_subdirectory(Transforms) | ||
66 changes: 66 additions & 0 deletions
66
mlir/lib/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.cpp
This file contains hidden or 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,66 @@ | ||
//===- AMDGPUTransformOps.cpp - Implementation of AMDGPU transform ops-----===// | ||
// | ||
// 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/AMDGPU/TransformOps/AMDGPUTransformOps.h" | ||
|
||
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h" | ||
#include "mlir/Dialect/AMDGPU/Transforms/Transforms.h" | ||
#include "mlir/Dialect/Affine/IR/AffineOps.h" | ||
#include "mlir/Dialect/Vector/IR/VectorOps.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::amdgpu; | ||
using namespace mlir::transform; | ||
using namespace mlir::func; | ||
|
||
#define DEBUG_TYPE "amdgpu-transforms" | ||
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ") | ||
#define DBGSNL() (llvm::dbgs() << "\n") | ||
#define LDBG(X) LLVM_DEBUG(DBGS() << (X) << "\n") | ||
|
||
DiagnosedSilenceableFailure | ||
ApplyOptimizeSharedMemoryReadsAndWritesOp::applyToOne( | ||
TransformRewriter &rewriter, FuncOp funcOp, ApplyToEachResultList &results, | ||
TransformState &state) { | ||
optimizeSharedMemoryReadsAndWritesOp(funcOp); | ||
return DiagnosedSilenceableFailure::success(); | ||
} | ||
|
||
void ApplyOptimizeSharedMemoryReadsAndWritesOp::getEffects( | ||
SmallVectorImpl<MemoryEffects::EffectInstance> &effects) { | ||
onlyReadsHandle(getTarget(), effects); | ||
modifiesPayload(effects); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Transform op registration | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace { | ||
class AMDGPUTransformDialectExtension | ||
: public TransformDialectExtension<AMDGPUTransformDialectExtension> { | ||
public: | ||
AMDGPUTransformDialectExtension() { | ||
declareGeneratedDialect<arith::ArithDialect>(); | ||
declareGeneratedDialect<affine::AffineDialect>(); | ||
declareGeneratedDialect<amdgpu::AMDGPUDialect>(); | ||
declareGeneratedDialect<vector::VectorDialect>(); | ||
registerTransformOps< | ||
#define GET_OP_LIST | ||
#include "mlir/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.cpp.inc" | ||
>(); | ||
} | ||
}; | ||
} // namespace | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/AMDGPU/TransformOps/AMDGPUTransformOps.cpp.inc" | ||
|
||
void amdgpu::registerTransformDialectExtension(DialectRegistry ®istry) { | ||
registry.addExtensions<AMDGPUTransformDialectExtension>(); | ||
} |
This file contains hidden or 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,25 @@ | ||
add_mlir_dialect_library(MLIRAMDGPUTransformOps | ||
AMDGPUTransformOps.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/AMDGPU/TransformOps | ||
|
||
DEPENDS | ||
MLIRAMDGPUTransformOpsIncGen | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRAffineDialect | ||
MLIRArithDialect | ||
MLIRIR | ||
MLIRLinalgDialect | ||
MLIRAMDGPUDialect | ||
MLIRAMDGPUTransforms | ||
MLIRParser | ||
MLIRSideEffectInterfaces | ||
MLIRSCFDialect | ||
MLIRSCFTransforms | ||
MLIRTransformDialect | ||
MLIRTransformDialectUtils | ||
MLIRVectorTransforms | ||
|
||
) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.