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/GPU/Passes.h" 15 #include "mlir/Dialect/MemRef/IR/MemRef.h" 16 #include "mlir/Dialect/StandardOps/IR/Ops.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>> { 25 void getDependentDialects(DialectRegistry ®istry) const override { 26 registry.insert<arith::ArithmeticDialect, StandardOpsDialect, 27 memref::MemRefDialect>(); 28 } 29 StringRef getArgument() const final { return "test-gpu-rewrite"; } 30 StringRef getDescription() const final { 31 return "Applies all rewrite patterns within the GPU dialect."; 32 } 33 void runOnOperation() override { 34 RewritePatternSet patterns(&getContext()); 35 populateGpuRewritePatterns(patterns); 36 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); 37 } 38 }; 39 } // namespace 40 41 namespace mlir { 42 void registerTestAllReduceLoweringPass() { 43 PassRegistration<TestGpuRewritePass>(); 44 } 45 } // namespace mlir 46