| 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/IR/GPUDialect.h" |
| 16 | #include "mlir/Dialect/GPU/Transforms/MemoryPromotion.h" |
| 17 | #include "mlir/Dialect/MemRef/IR/MemRef.h" |
| 18 | #include "mlir/Dialect/SCF/IR/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 | struct TestGpuMemoryPromotionPass |
| 31 | : public PassWrapper<TestGpuMemoryPromotionPass, |
| 32 | OperationPass<gpu::GPUFuncOp>> { |
| 33 | MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestGpuMemoryPromotionPass) |
| 34 | |
| 35 | void getDependentDialects(DialectRegistry ®istry) const override { |
| 36 | registry.insert<affine::AffineDialect, memref::MemRefDialect, |
| 37 | scf::SCFDialect>(); |
| 38 | } |
| 39 | StringRef getArgument() const final { return "test-gpu-memory-promotion"; } |
| 40 | StringRef getDescription() const final { |
| 41 | return "Promotes the annotated arguments of gpu.func to workgroup memory."; |
| 42 | } |
| 43 | |
| 44 | void runOnOperation() override { |
| 45 | gpu::GPUFuncOp op = getOperation(); |
| 46 | for (unsigned i = 0, e = op.getNumArguments(); i < e; ++i) { |
| 47 | if (op.getArgAttrOfType<UnitAttr>(i, "gpu.test_promote_workgroup")) |
| 48 | promoteToWorkgroupMemory(op, i); |
| 49 | } |
| 50 | } |
| 51 | }; |
| 52 | } // namespace |
| 53 | |
| 54 | namespace mlir { |
| 55 | void registerTestGpuMemoryPromotionPass() { |
| 56 | PassRegistration<TestGpuMemoryPromotionPass>(); |
| 57 | } |
| 58 | } // namespace mlir |
| 59 |
