1 //===- TestAllReduceLowering.cpp - Test gpu.all_reduce lowering -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains test passes for lowering the gpu.all_reduce op.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
14 #include "mlir/Dialect/Func/IR/FuncOps.h"
15 #include "mlir/Dialect/GPU/Transforms/Passes.h"
16 #include "mlir/Dialect/MemRef/IR/MemRef.h"
17 #include "mlir/Pass/Pass.h"
18 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
19 
20 using namespace mlir;
21 
22 namespace {
23 struct TestGpuRewritePass
24     : public PassWrapper<TestGpuRewritePass, OperationPass<ModuleOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID__anon2aa8a1760111::TestGpuRewritePass25   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestGpuRewritePass)
26 
27   void getDependentDialects(DialectRegistry &registry) const override {
28     registry.insert<arith::ArithmeticDialect, func::FuncDialect,
29                     memref::MemRefDialect>();
30   }
getArgument__anon2aa8a1760111::TestGpuRewritePass31   StringRef getArgument() const final { return "test-gpu-rewrite"; }
getDescription__anon2aa8a1760111::TestGpuRewritePass32   StringRef getDescription() const final {
33     return "Applies all rewrite patterns within the GPU dialect.";
34   }
runOnOperation__anon2aa8a1760111::TestGpuRewritePass35   void runOnOperation() override {
36     RewritePatternSet patterns(&getContext());
37     populateGpuRewritePatterns(patterns);
38     (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
39   }
40 };
41 } // namespace
42 
43 namespace mlir {
registerTestAllReduceLoweringPass()44 void registerTestAllReduceLoweringPass() {
45   PassRegistration<TestGpuRewritePass>();
46 }
47 } // namespace mlir
48