1 //===- TestGPUMemoryPromotionPass.cpp - Test pass for GPU promotion -------===// 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 implements the pass testing the utilities for moving data across 10 // different levels of the GPU memory hierarchy. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "mlir/Dialect/Affine/IR/AffineOps.h" 15 #include "mlir/Dialect/GPU/GPUDialect.h" 16 #include "mlir/Dialect/GPU/MemoryPromotion.h" 17 #include "mlir/Dialect/MemRef/IR/MemRef.h" 18 #include "mlir/Dialect/SCF/SCF.h" 19 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h" 20 #include "mlir/Dialect/StandardOps/IR/Ops.h" 21 #include "mlir/IR/Attributes.h" 22 #include "mlir/Pass/Pass.h" 23 24 using namespace mlir; 25 26 namespace { 27 /// Simple pass for testing the promotion to workgroup memory in GPU functions. 28 /// Promotes all arguments with "gpu.test_promote_workgroup" attribute. This 29 /// does not check whether the promotion is legal (e.g., amount of memory used) 30 /// or beneficial (e.g., makes previously uncoalesced loads coalesced). 31 class TestGpuMemoryPromotionPass 32 : public PassWrapper<TestGpuMemoryPromotionPass, 33 OperationPass<gpu::GPUFuncOp>> { 34 void getDependentDialects(DialectRegistry ®istry) const override { 35 registry.insert<AffineDialect, memref::MemRefDialect, StandardOpsDialect, 36 scf::SCFDialect>(); 37 } 38 StringRef getArgument() const final { return "test-gpu-memory-promotion"; } 39 StringRef getDescription() const final { 40 return "Promotes the annotated arguments of gpu.func to workgroup memory."; 41 } 42 43 void runOnOperation() override { 44 gpu::GPUFuncOp op = getOperation(); 45 for (unsigned i = 0, e = op.getNumArguments(); i < e; ++i) { 46 if (op.getArgAttrOfType<UnitAttr>(i, "gpu.test_promote_workgroup")) 47 promoteToWorkgroupMemory(op, i); 48 } 49 } 50 }; 51 } // end namespace 52 53 namespace mlir { 54 void registerTestGpuMemoryPromotionPass() { 55 PassRegistration<TestGpuMemoryPromotionPass>(); 56 } 57 } // namespace mlir 58