-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AMDGPU][MLIR]Add shmem-optimization as an op using transform dialect (…
…#81550) This PR adds functionality to use shared memory optimization as an op using transform dialect.
- Loading branch information
1 parent
7180c23
commit 29d1aca
Showing
12 changed files
with
356 additions
and
19 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
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 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 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 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 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
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 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 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 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.