Skip to content

Commit 0040779

Browse files
Revert "changing from dialect converstion to gpu transform pass"
This reverts commit 9ddd155aee70d8380a22644b41c526acda198cc1. Signed-off-by: Muzammiluddin Syed <[email protected]>
1 parent 588cb13 commit 0040779

File tree

12 files changed

+701
-53
lines changed

12 files changed

+701
-53
lines changed

mlir/include/mlir/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
3535
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"
3636
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
37+
#include "mlir/Conversion/GPUToAMDGPU/GPUToAMDGPU.h"
3738
#include "mlir/Conversion/GPUToLLVMSPV/GPUToLLVMSPVPass.h"
3839
#include "mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h"
3940
#include "mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,22 @@ def ConvertGPUToSPIRV : Pass<"convert-gpu-to-spirv", "ModuleOp"> {
643643
];
644644
}
645645

646+
//===----------------------------------------------------------------------===//
647+
// GPUToAMDGPU
648+
//===----------------------------------------------------------------------===//
649+
650+
def ConvertGPUToAMDGPUPass : Pass<"convert-gpu-to-amdgpu"> {
651+
let summary = "Generate AMDGPU operations for gpu operations";
652+
let dependentDialects = [
653+
"LLVM::LLVMDialect",
654+
"::mlir::gpu::GPUDialect",
655+
"amdgpu::AMDGPUDialect",
656+
];
657+
let options = [Option<"subgroupSize", "subgroup-size", "unsigned",
658+
/*default=*/"64",
659+
"Size of subgroup">];
660+
}
661+
646662
//===----------------------------------------------------------------------===//
647663
// ConvertIndexToLLVMPass
648664
//===----------------------------------------------------------------------===//

mlir/include/mlir/Dialect/GPU/Transforms/Passes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ void populateGpuDecomposeMemrefsPatterns(RewritePatternSet &patterns);
9494
/// Erase barriers that do not enforce conflicting memory side effects.
9595
void populateGpuEliminateBarriersPatterns(RewritePatternSet &patterns);
9696

97-
void populateGpuDecomposeSubgroupReduceToDppPatterns(
98-
RewritePatternSet &patterns, unsigned subgroupSize);
99-
10097
/// Generate the code for registering passes.
10198
#define GEN_PASS_REGISTRATION
10299
#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"

mlir/include/mlir/Dialect/GPU/Transforms/Passes.td

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,28 +258,4 @@ def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
258258
];
259259
}
260260

261-
def GpuDecomposeSubgroupReduceToDppPass: Pass<"decompose-subgroup-reduce-to-dpp", ""> {
262-
let summary = "Decomposes reductions across subgroups to data parallel primitives.";
263-
let description = [{
264-
This pass decomposes gpu::subgroup_reduce ops to AMDGPU::DPP ops where
265-
applicable, while respecting cluster size and stride.
266-
267-
Example:
268-
```
269-
// File: in.mlir:
270-
[TO-DO]
271-
// mlir-opt --decompose-subgroup-reduce-to-dpp subgroup-size=64 in.mlir
272-
[TO-DO]
273-
```
274-
}];
275-
let dependentDialects = [
276-
"amdgpu::AMDGPUDialect",
277-
"LLVM::LLVMDialect",
278-
"ROCDL::ROCDLDialect",
279-
];
280-
let options = [Option<"subgroupSize", "subgroup-size", "unsigned",
281-
/*default=*/"64",
282-
"Size of subgroup">];
283-
}
284-
285261
#endif // MLIR_DIALECT_GPU_PASSES

mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ struct ConvertAMDGPUToROCDLPass
13331333
using Base::Base;
13341334

13351335
void runOnOperation() override {
1336+
llvm::errs() << " WHEN DOES AMDGPU TO ROCDL RUN\n";
13361337
MLIRContext *ctx = &getContext();
13371338
FailureOr<Chipset> maybeChipset = Chipset::parse(chipset);
13381339
if (failed(maybeChipset)) {

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_subdirectory(FuncToEmitC)
2424
add_subdirectory(FuncToLLVM)
2525
add_subdirectory(FuncToSPIRV)
2626
add_subdirectory(GPUCommon)
27+
add_subdirectory(GPUToAMDGPU)
2728
add_subdirectory(GPUToLLVMSPV)
2829
add_subdirectory(GPUToNVVM)
2930
add_subdirectory(GPUToROCDL)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_mlir_conversion_library(MLIRGPUToAMDGPU
2+
GPUToAMDGPU.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/GPUToAMDGPU
6+
7+
DEPENDS
8+
MLIRConversionPassIncGen
9+
10+
LINK_COMPONENTS
11+
Core
12+
13+
LINK_LIBS PUBLIC
14+
MLIRLLVMCommonConversion
15+
MLIRLLVMDialect
16+
MLIRGPUDialect
17+
MLIRAMDGPUDialect
18+
MLIRAMDGPUUtils
19+
MLIRROCDLDialect
20+
MLIRPass
21+
MLIRTransforms
22+
)

mlir/lib/Dialect/GPU/Transforms/DecomposeSubgroupReduceToDpp.cpp renamed to mlir/lib/Conversion/GPUToAMDGPU/GPUToAMDGPU.cpp

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
//===- DecomposeSubgroupReduceToDPP.cpp - Decompose subgroup reduce pass -===//
1+
//===- GPUToAMDGPU.cpp - GPU to AMDGPU dialect conversion -------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
//
9-
// This file implements decompose subgroup reduce to DPP pass.
10-
//
11-
//===----------------------------------------------------------------------===//
128

13-
#include "mlir/Dialect/GPU/Transforms/Passes.h"
9+
#include "mlir/Conversion/GPUToAMDGPU/GPUToAMDGPU.h"
1410

11+
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
12+
#include "mlir/Conversion/LLVMCommon/Pattern.h"
13+
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
1514
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
1615
#include "mlir/Dialect/AMDGPU/Utils/Chipset.h"
1716
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -23,14 +22,20 @@
2322
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
2423
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
2524
#include "mlir/Dialect/Vector/IR/VectorOps.h"
26-
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
27-
#include "mlir/Dialect/GPU/Transforms/Passes.h"
2825

2926
#include "llvm/Support/FormatVariadic.h"
27+
#include "llvm/Support/MathExtras.h"
28+
#include <cassert>
29+
#include <cstdint>
30+
31+
#include "../LLVMCommon/MemRefDescriptor.h"
32+
33+
#include "llvm/ADT/STLExtras.h"
34+
#include <optional>
3035

3136
namespace mlir {
32-
#define GEN_PASS_DEF_GPUDECOMPOSESUBGROUPREDUCETODPPPASS
33-
#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
37+
#define GEN_PASS_DEF_CONVERTGPUTOAMDGPUPASS
38+
#include "mlir/Conversion/Passes.h.inc"
3439
} // namespace mlir
3540

3641
using namespace mlir;
@@ -139,8 +144,8 @@ Value createSubgroupDPPReduction(OpBuilder &b, Location loc, Value input,
139144
struct ScalarSubgroupReduceToShuffles final
140145
: OpRewritePattern<gpu::SubgroupReduceOp> {
141146
ScalarSubgroupReduceToShuffles(MLIRContext *ctx, unsigned subgroupSize,
142-
bool matchClustered)
143-
: OpRewritePattern(ctx), subgroupSize(subgroupSize),
147+
bool matchClustered, PatternBenefit benefit)
148+
: OpRewritePattern(ctx, benefit), subgroupSize(subgroupSize),
144149
matchClustered(matchClustered) {}
145150

146151
LogicalResult matchAndRewrite(gpu::SubgroupReduceOp op,
@@ -169,24 +174,30 @@ struct ScalarSubgroupReduceToShuffles final
169174
bool matchClustered = false;
170175
};
171176

172-
struct GpuDecomposeSubgroupReduceToDppPass
173-
: public impl::GpuDecomposeSubgroupReduceToDppPassBase<
174-
GpuDecomposeSubgroupReduceToDppPass> {
177+
struct ConvertGPUToAMDGPUPass
178+
: public impl::ConvertGPUToAMDGPUPassBase<ConvertGPUToAMDGPUPass> {
175179
using Base::Base;
176180

177181
void runOnOperation() override {
178182
RewritePatternSet patterns(&getContext());
179-
// int subgroupSizeInt = static_cast<int>(subgroupSize);
180-
populateGpuDecomposeSubgroupReduceToDppPatterns(patterns, subgroupSize);
181-
if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
182-
return signalPassFailure();
183+
LLVMTypeConverter converter(&getContext());
184+
LLVMConversionTarget target(getContext());
185+
target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
186+
target.addLegalDialect<::mlir::amdgpu::AMDGPUDialect>();
187+
target.addLegalDialect<::mlir::ROCDL::ROCDLDialect>();
188+
189+
int subgroupSizeInt = static_cast<int>(subgroupSize);
190+
populateSubgroupReduceLoweringPatterns(converter, patterns, subgroupSizeInt,
191+
PatternBenefit(1));
192+
if (failed(applyPartialConversion(getOperation(), target,
193+
std::move(patterns))))
194+
signalPassFailure();
183195
}
184196
};
185-
186197
} // namespace
187198

188-
void mlir::populateGpuDecomposeSubgroupReduceToDppPatterns(
189-
RewritePatternSet &patterns, unsigned subgroupSize) {
199+
void mlir::populateSubgroupReduceLoweringPatterns(
200+
LLVMTypeConverter &converter, RewritePatternSet &patterns, unsigned subgroupSize, PatternBenefit benefit) {
190201
patterns.add<ScalarSubgroupReduceToShuffles>(
191-
patterns.getContext(), subgroupSize, /*matchClustered=*/true);
192-
}
202+
patterns.getContext(), subgroupSize, /*matchClustered=*/true, benefit);
203+
}

mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_mlir_conversion_library(MLIRGPUToROCDLTransforms
1515
MLIRMathToLLVM
1616
MLIRMathToROCDL
1717
MLIRAMDGPUToROCDL
18+
MLIRGPUToAMDGPU
1819
MLIRFuncToLLVM
1920
MLIRGPUDialect
2021
MLIRGPUToGPURuntimeTransforms

mlir/lib/Dialect/GPU/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ add_mlir_dialect_library(MLIRGPUTransforms
4141
Transforms/ShuffleRewriter.cpp
4242
Transforms/SPIRVAttachTarget.cpp
4343
Transforms/SubgroupReduceLowering.cpp
44-
Transforms/DecomposeSubgroupReduceToDpp.cpp
4544

4645
OBJECT
4746

0 commit comments

Comments
 (0)