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/IR/Attributes.h" 21 #include "mlir/Pass/Pass.h" 22 23 using namespace mlir; 24 25 namespace { 26 /// Simple pass for testing the promotion to workgroup memory in GPU functions. 27 /// Promotes all arguments with "gpu.test_promote_workgroup" attribute. This 28 /// does not check whether the promotion is legal (e.g., amount of memory used) 29 /// or beneficial (e.g., makes previously uncoalesced loads coalesced). 30 class TestGpuMemoryPromotionPass 31 : public PassWrapper<TestGpuMemoryPromotionPass, 32 OperationPass<gpu::GPUFuncOp>> { 33 void getDependentDialects(DialectRegistry ®istry) const override { 34 registry.insert<AffineDialect, memref::MemRefDialect, scf::SCFDialect>(); 35 } 36 StringRef getArgument() const final { return "test-gpu-memory-promotion"; } 37 StringRef getDescription() const final { 38 return "Promotes the annotated arguments of gpu.func to workgroup memory."; 39 } 40 41 void runOnOperation() override { 42 gpu::GPUFuncOp op = getOperation(); 43 for (unsigned i = 0, e = op.getNumArguments(); i < e; ++i) { 44 if (op.getArgAttrOfType<UnitAttr>(i, "gpu.test_promote_workgroup")) 45 promoteToWorkgroupMemory(op, i); 46 } 47 } 48 }; 49 } // namespace 50 51 namespace mlir { 52 void registerTestGpuMemoryPromotionPass() { 53 PassRegistration<TestGpuMemoryPromotionPass>(); 54 } 55 } // namespace mlir 56