[Mlir-commits] [clang] [flang] [mlir] [mlir][OpenACC] Decouple frontend support from GPU operations (PR #233103)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Oct 17 08:44:05 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Mehdi Amini (joker-eph)
<details>
<summary>Changes</summary>
Allow clients such as CIR to use OpenACC frontend IR without linking the full GPU operation implementation and its Math dependencies.
Provide MLIRGPUBase for GPU representations and expose OpenACC's GPU, LLVM and MemRef external interface models through separate extension libraries. Keep GPU type and attribute ownership and parsing in the GPU dialect, and retain all OpenACC operations in MLIROpenACCDialect.
Register the extensions through MLIR's default extension registration, OpenACC passes and Flang. Preserve the C API's automatic registration and CIR's pointer models, and explicitly load Arith for CIR's OpenACC lowering.
Save >4MB in clang+CIR build.
Assisted-by: Codex
---
Patch is 165.88 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/233103.diff
69 Files Affected:
- (modified) clang/lib/CIR/CMakeLists.txt (+1)
- (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+4-1)
- (modified) clang/lib/CIR/RegisterAllDialects.cpp (+5-3)
- (modified) flang/lib/Optimizer/OpenACC/Support/CMakeLists.txt (+2)
- (modified) flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp (+2)
- (modified) mlir/docs/Dialects/OpenACCDialect.md (+31)
- (added) mlir/include/mlir/Dialect/GPU/IR/GPUBase.h (+209)
- (modified) mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h (+1-179)
- (added) mlir/include/mlir/Dialect/OpenACC/Extensions/AllExtensions.h (+22)
- (added) mlir/include/mlir/Dialect/OpenACC/Extensions/GPUInterfaces.h (+20)
- (added) mlir/include/mlir/Dialect/OpenACC/Extensions/LLVMInterfaces.h (+21)
- (added) mlir/include/mlir/Dialect/OpenACC/Extensions/MemRefInterfaces.h (+21)
- (modified) mlir/include/mlir/Dialect/OpenACC/OpenACC.h (+1-3)
- (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCBase.td (-3)
- (modified) mlir/lib/CAPI/Dialect/CMakeLists.txt (+2)
- (modified) mlir/lib/CAPI/Dialect/OpenACC.cpp (+35-1)
- (modified) mlir/lib/Dialect/GPU/CMakeLists.txt (+24)
- (added) mlir/lib/Dialect/GPU/IR/GPUBase.cpp (+509)
- (modified) mlir/lib/Dialect/GPU/IR/GPUDialect.cpp (+18-482)
- (modified) mlir/lib/Dialect/OpenACC/CMakeLists.txt (+1)
- (added) mlir/lib/Dialect/OpenACC/Extensions/AllExtensions.cpp (+19)
- (added) mlir/lib/Dialect/OpenACC/Extensions/CMakeLists.txt (+41)
- (added) mlir/lib/Dialect/OpenACC/Extensions/GPUInterfaces.cpp (+32)
- (added) mlir/lib/Dialect/OpenACC/Extensions/LLVMInterfaces.cpp (+98)
- (added) mlir/lib/Dialect/OpenACC/Extensions/MemRefInterfaces.cpp (+328)
- (modified) mlir/lib/Dialect/OpenACC/IR/CMakeLists.txt (+1-3)
- (modified) mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (-394)
- (modified) mlir/lib/Dialect/OpenACC/IR/OpenACCCG.cpp (+2-5)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCBindRoutine.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCCGToGPU.cpp (+6-1)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCDeclareGPUModuleInsertion.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCEmitRemarksData.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCEmitRemarksLoop.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCEmitRemarksPrivate.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCIfClauseLowering.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitDeclare.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitRoutine.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCLegalizeSerial.cpp (+6-1)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCLoopTiling.cpp (+6-1)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCRecipeMaterialization.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCRoutineLowering.cpp (+6-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCRoutineToGPUFunc.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForDevice.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCSpecializeForHost.cpp (+7-1)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/CMakeLists.txt (+1)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/LegalizeDataValues.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/OffloadLiveInValueCanonicalization.cpp (+7-2)
- (modified) mlir/lib/Dialect/OpenACC/Transforms/OffloadTargetVerifier.cpp (+6-2)
- (modified) mlir/lib/RegisterAllExtensions.cpp (+2)
- (modified) mlir/test/CAPI/CMakeLists.txt (+8)
- (added) mlir/test/CAPI/openacc.c (+55)
- (modified) mlir/test/CMakeLists.txt (+1)
- (modified) mlir/unittests/Dialect/OpenACC/CMakeLists.txt (+5)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCCGOpsTest.cpp (+4)
- (added) mlir/unittests/Dialect/OpenACC/OpenACCExtensionsTest.cpp (+96)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCOpsInterfacesTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCOpsTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCTypeInterfacesTest.cpp (+4-2)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsLoopTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsReductionTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsTilingTest.cpp (+4)
- (modified) mlir/unittests/Dialect/OpenACC/OpenACCUtilsTypeTest.cpp (+4)
- (added) mlir/unittests/Dialect/OpenACC/Standalone/CMakeLists.txt (+7)
- (added) mlir/unittests/Dialect/OpenACC/Standalone/OpenACCStandaloneTest.cpp (+36)
``````````diff
diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt
index 6f9f4bb941aadb..c63c84afc8fa31 100644
--- a/clang/lib/CIR/CMakeLists.txt
+++ b/clang/lib/CIR/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(CIRRegisterAllDialects
MLIRCIR
CIROpenACCSupport
CIROpenMPSupport
+ MLIRArithDialect
MLIRDLTIDialect
MLIRLLVMDialect
)
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index bc0aed0b01ff03..d2f1b54e43325c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -12,6 +12,7 @@
#include "CIRGenModule.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
@@ -54,8 +55,10 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
mlirContext->loadDialect<mlir::DLTIDialect, mlir::LLVM::LLVMDialect,
cir::CIRDialect>();
const LangOptions &langOpts = astContext.getLangOpts();
+ // OpenACC lowering emits Arith constants for bounds and clause operands.
if (langOpts.OpenACC)
- mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
+ mlirContext
+ ->loadDialect<mlir::acc::OpenACCDialect, mlir::arith::ArithDialect>();
if (langOpts.OpenMP)
mlirContext->getOrLoadDialect<mlir::omp::OpenMPDialect>();
diff --git a/clang/lib/CIR/RegisterAllDialects.cpp b/clang/lib/CIR/RegisterAllDialects.cpp
index 73effa12b31921..706635049afbe4 100644
--- a/clang/lib/CIR/RegisterAllDialects.cpp
+++ b/clang/lib/CIR/RegisterAllDialects.cpp
@@ -8,6 +8,7 @@
#include "clang/CIR/InitAllDialects.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
@@ -24,9 +25,10 @@ namespace cir {
void registerAllDialects(mlir::DialectRegistry ®istry) {
// The LLVM dialect is needed to parse CIR: data layout specs use LLVM
// pointer types as keys.
- registry.insert<mlir::BuiltinDialect, cir::CIRDialect, mlir::DLTIDialect,
- mlir::LLVM::LLVMDialect, mlir::omp::OpenMPDialect,
- mlir::acc::OpenACCDialect>();
+ registry
+ .insert<mlir::BuiltinDialect, cir::CIRDialect, mlir::arith::ArithDialect,
+ mlir::DLTIDialect, mlir::LLVM::LLVMDialect,
+ mlir::omp::OpenMPDialect, mlir::acc::OpenACCDialect>();
// Register extensions to integrate CIR types with OpenACC and OpenMP.
cir::omp::registerOpenMPExtensions(registry);
cir::acc::registerOpenACCExtensions(registry);
diff --git a/flang/lib/Optimizer/OpenACC/Support/CMakeLists.txt b/flang/lib/Optimizer/OpenACC/Support/CMakeLists.txt
index 9ff46c70db3cc0..94f7fdf872a860 100644
--- a/flang/lib/Optimizer/OpenACC/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenACC/Support/CMakeLists.txt
@@ -27,10 +27,12 @@ add_flang_library(FIROpenACCSupport
HLFIRDialect
MLIR_DEPS
+ MLIROpenACCAllExtensions
MLIROpenACCDialect
MLIROpenACCUtils
MLIR_LIBS
+ MLIROpenACCAllExtensions
MLIROpenACCDialect
MLIROpenACCUtils
)
diff --git a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
index 0ffa43ac695858..262c39a72a5b1f 100644
--- a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
@@ -21,9 +21,11 @@
#include "flang/Optimizer/HLFIR/HLFIROps.h"
#include "flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h"
#include "flang/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.h"
+#include "mlir/Dialect/OpenACC/Extensions/AllExtensions.h"
namespace fir::acc {
void registerOpenACCExtensions(mlir::DialectRegistry ®istry) {
+ mlir::acc::registerAllExtensions(registry);
registry.addExtension(+[](mlir::MLIRContext *ctx,
fir::FIROpsDialect *dialect) {
fir::BoxType::attachInterface<OpenACCMappableModel<fir::BaseBoxType>>(*ctx);
diff --git a/mlir/docs/Dialects/OpenACCDialect.md b/mlir/docs/Dialects/OpenACCDialect.md
index 9e85d66ba340fd..f8864f28d508c9 100755
--- a/mlir/docs/Dialects/OpenACCDialect.md
+++ b/mlir/docs/Dialects/OpenACCDialect.md
@@ -19,6 +19,37 @@ operations, types, and attributes.
[TOC]
+## Registration and library dependencies
+
+`MLIROpenACCDialect` provides all OpenACC language and code-generation
+operations, types, and attributes.
+
+OpenACC interfaces for other dialects are provided by extension libraries:
+
+| Library | Registration API | Models |
+| --- | --- | --- |
+| `MLIROpenACCMemRefInterfaces` | `acc::registerMemRefInterfaces` | MemRef pointer and global interfaces |
+| `MLIROpenACCLLVMInterfaces` | `acc::registerLLVMInterfaces` | LLVM pointer and address-of interfaces |
+| `MLIROpenACCGPUInterfaces` | `acc::registerGPUInterfaces` | GPU launch offload-region interface |
+
+To use these models, link the corresponding libraries and register the
+extensions with a `DialectRegistry &`. Their headers are in
+`mlir/Dialect/OpenACC/Extensions`. `acc::registerAllExtensions`, declared in
+`Extensions/AllExtensions.h` and provided by `MLIROpenACCAllExtensions`,
+registers all three extensions.
+
+The MemRef and LLVM extensions load their target dialects and Arith when
+OpenACC is loaded to support IR generation. The MemRef extension attaches
+pointer models to builtin MemRef types. The GPU extension attaches the
+offload-region model to `gpu.launch` when both OpenACC and GPU are loaded,
+regardless of loading order. Extensions can also be registered by appending
+a registry to a context whose dialects are already loaded.
+
+`mlir::registerAllExtensions`, OpenACC passes, and Flang's OpenACC registration
+include these extensions. CIR registers its own pointer models.
+`MLIRCAPIOpenACC` provides a C API dialect handle that registers these
+extensions and loads GPU with OpenACC.
+
## Dialect Design Goals
* Needs to have complete representation of the OpenACC language.
diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUBase.h b/mlir/include/mlir/Dialect/GPU/IR/GPUBase.h
new file mode 100644
index 00000000000000..b8ae0c18b8f7d5
--- /dev/null
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUBase.h
@@ -0,0 +1,209 @@
+//===- GPUBase.h - GPU types, attributes, and enums -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares GPU types, attributes, and enums independently of GPU
+// operations.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_GPU_IR_GPUBASE_H
+#define MLIR_DIALECT_GPU_IR_GPUBASE_H
+
+// These representations can be inspected without linking GPU operations.
+// Constructing or parsing GPU types and attributes still requires loading
+// GPUDialect, which owns and registers them as before.
+// Attribute methods that build IR are provided by MLIRGPUDialect.
+#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
+#include "mlir/Dialect/GPU/IR/GPUDialectDecl.h"
+#include "mlir/Dialect/SCF/IR/DeviceMappingInterface.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/Interfaces/FunctionInterfaces.h"
+
+namespace mlir::gpu {
+namespace detail {
+/// Register storage whose definitions are private to MLIRGPUBase. Attribute
+/// metadata and interfaces are registered by GPUDialect::initialize().
+void registerAttributeStorage(MLIRContext *context);
+} // namespace detail
+
+class AsyncTokenType
+ : public Type::TypeBase<AsyncTokenType, Type, TypeStorage> {
+public:
+ // Used for generic hooks in TypeBase.
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.async_token";
+};
+
+class NamedBarrierType
+ : public Type::TypeBase<NamedBarrierType, Type, TypeStorage> {
+public:
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.named_barrier";
+};
+
+/// MMAMatrixType storage and uniquing. Array is uniqued based on its shape
+/// and type.
+struct MMAMatrixStorageType : public TypeStorage {
+ MMAMatrixStorageType(unsigned numDims, const int64_t *dimShapes,
+ Type elementType, StringRef operand)
+ : dimShapes(dimShapes), numDims(numDims), elementType(elementType),
+ operand(operand) {}
+
+ /// The hash key for uniquing.
+ using KeyTy = std::tuple<ArrayRef<int64_t>, Type, StringRef>;
+ bool operator==(const KeyTy &key) const {
+ return key == KeyTy(getShape(), elementType, operand);
+ }
+
+ /// Construction.
+ static MMAMatrixStorageType *construct(TypeStorageAllocator &allocator,
+ const KeyTy &key) {
+ ArrayRef<int64_t> shape = allocator.copyInto(std::get<0>(key));
+ StringRef operand = allocator.copyInto(std::get<2>(key));
+
+ return new (allocator.allocate<MMAMatrixStorageType>())
+ MMAMatrixStorageType(shape.size(), shape.data(), std::get<1>(key),
+ operand);
+ }
+
+ ArrayRef<int64_t> getShape() const {
+ return ArrayRef<int64_t>(dimShapes, numDims);
+ }
+
+ StringRef getOperand() const { return operand; }
+
+ /// Reference to the shape of the MMA matrix.
+ const int64_t *dimShapes;
+
+ /// Number of dimensions in the MMA matrix.
+ unsigned numDims;
+
+ /// Element type of elements held in the MMA matrix.
+ Type elementType;
+
+ /// MMA operand that this MMAMatrix holds. The general form of operation this
+ /// type supports is given by the equation C += A*B. This field specifies
+ /// which operand in the given equation is held by this type. The valid values
+ /// are "AOp", "BOp" and "COp".
+ StringRef operand;
+};
+
+/// MMAMatrix represents a matrix held by a subgroup for matrix-matrix multiply
+/// accumulate operations. MMAMatrices are taken as direct operands by these
+/// operations and are also produced as results. These matrices are meant to
+/// reside in the registers. A limited number of pointwise operations can be
+/// performed on these matrices, i.e., operations which operate uniformly on
+/// all the elements in the matrix and do not change the order of matrix
+/// elements. The above conditions exist because the layout of matrix elements
+/// inside the matrix is opaque i.e., the elements may be present in the
+/// matrix in any order. The general usage of this type is shown as follows:-
+///
+/// %0 = gpu.subgroup_mma_load_matrix %arg0[%c0, %c0] {leadDimension = 16 :
+/// index} : memref<16x16xf16> -> !gpu.mma_matrix<16x16xf16, "AOp">
+///
+/// The MMAMatrixType describes the shape of the matrix being loaded and the
+/// operand being loaded too. The operand needs to be specified to aid the
+/// lowering of this type to dialects such as NVVM where each workitem may
+/// hold different amount of elements depending on the elementType of the
+/// matrix. For e.g., Each workitem holds 4 vector<2xf16>s for f16 data type
+/// and 8 f32s for f32 data type of MMAMatrix. Some other instances of usage
+/// are:-
+///
+/// %3 = gpu.subgroup_mma_compute %0, %1, %2 :
+/// !gpu.mma_matrix<16x16xf16, "AOp">, !gpu.mma_matrix<16x16xf16, "BOp">
+/// -> !gpu.mma_matrix<16x16xf32, "COp">
+///
+///
+/// gpu.subgroup_mma_store_matrix %3, %arg22[%c0, %c0] {leadDimension = 16
+/// : index}: !gpu.mma_matrix<16x16xf32, "COp">, memref<16x16xf32>
+///
+/// MMA matrices may be memref elements on targets that support storing them,
+/// for example SPIRV can represent arrays of MMA matrices.
+// TODO: consider moving this to ODS.
+class MMAMatrixType
+ : public Type::TypeBase<MMAMatrixType, Type, MMAMatrixStorageType,
+ MemRefElementTypeInterface::Trait> {
+public:
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.mma_matrix";
+
+ /// Get MMAMatrixType and verify construction Invariants.
+ static MMAMatrixType get(ArrayRef<int64_t> shape, Type elementType,
+ StringRef operand);
+
+ /// Get MMAMatrixType at a particular location and verify construction
+ /// Invariants.
+ static MMAMatrixType getChecked(function_ref<InFlightDiagnostic()> emitError,
+ ArrayRef<int64_t> shape, Type elementType,
+ StringRef operand);
+
+ /// Check if a type is valid a MMAMatrixType elementType.
+ static bool isValidElementType(Type elementType);
+
+ /// Verify that shape and elementType are actually allowed for the
+ /// MMAMatrixType.
+ static LogicalResult
+ verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
+ ArrayRef<int64_t> shape, Type elementType,
+ StringRef operand);
+
+ /// Get number of dims.
+ unsigned getNumDims() const;
+
+ /// Get shape of the matrix.
+ ArrayRef<int64_t> getShape() const;
+
+ /// Get elementType of a single element.
+ Type getElementType() const;
+
+ /// The general form of operation this type supports is given by the equation
+ /// C += A*B. This function returns which operand in the given equation is
+ /// held by this type. String returned can be one of"AOp", "BOp" and "COp".
+ StringRef getOperand() const;
+};
+
+// Handle types for sparse.
+enum class SparseHandleKind { SpMat, DnTensor, SpGEMMOp };
+
+class SparseDnTensorHandleType
+ : public Type::TypeBase<SparseDnTensorHandleType, Type, TypeStorage> {
+public:
+ using Base =
+ Type::TypeBase<SparseDnTensorHandleType, Type, TypeStorage>::Base;
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.sparse.dntensor_handle";
+};
+
+class SparseSpMatHandleType
+ : public Type::TypeBase<SparseSpMatHandleType, Type, TypeStorage> {
+public:
+ using Base = Type::TypeBase<SparseSpMatHandleType, Type, TypeStorage>::Base;
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.sparse.spmat_handle";
+};
+
+class SparseSpGEMMOpHandleType
+ : public Type::TypeBase<SparseSpGEMMOpHandleType, Type, TypeStorage> {
+public:
+ using Base =
+ Type::TypeBase<SparseSpGEMMOpHandleType, Type, TypeStorage>::Base;
+ using Base::Base;
+
+ static constexpr StringLiteral name = "gpu.sparse.spgemmop_handle";
+};
+} // namespace mlir::gpu
+
+#define GET_ATTRDEF_CLASSES
+#include "mlir/Dialect/GPU/IR/GPUOpsAttributes.h.inc"
+
+#endif // MLIR_DIALECT_GPU_IR_GPUBASE_H
diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h b/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h
index 34ff868db7d446..18b9d1dffb4274 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h
@@ -17,7 +17,7 @@
#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/DLTI/Traits.h"
-#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
+#include "mlir/Dialect/GPU/IR/GPUBase.h"
#include "mlir/Dialect/GPU/IR/GPUDialectDecl.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
@@ -35,7 +35,6 @@
namespace mlir {
namespace gpu {
-
/// Utility class for the GPU dialect to represent triples of `Value`s
/// accessible through `.x`, `.y`, and `.z` similarly to CUDA notation.
struct KernelDim3 {
@@ -44,190 +43,13 @@ struct KernelDim3 {
Value z;
};
-class AsyncTokenType
- : public Type::TypeBase<AsyncTokenType, Type, TypeStorage> {
-public:
- // Used for generic hooks in TypeBase.
- using Base::Base;
-
- static constexpr StringLiteral name = "gpu.async_token";
-};
-
-class NamedBarrierType
- : public Type::TypeBase<NamedBarrierType, Type, TypeStorage> {
-public:
- using Base::Base;
-
- static constexpr StringLiteral name = "gpu.named_barrier";
-};
-
-/// MMAMatrixType storage and uniquing. Array is uniqued based on its shape
-/// and type.
-struct MMAMatrixStorageType : public TypeStorage {
- MMAMatrixStorageType(unsigned numDims, const int64_t *dimShapes,
- Type elementType, StringRef operand)
- : dimShapes(dimShapes), numDims(numDims), elementType(elementType),
- operand(operand) {}
-
- /// The hash key for uniquing.
- using KeyTy = std::tuple<ArrayRef<int64_t>, Type, StringRef>;
- bool operator==(const KeyTy &key) const {
- return key == KeyTy(getShape(), elementType, operand);
- }
-
- /// Construction.
- static MMAMatrixStorageType *construct(TypeStorageAllocator &allocator,
- const KeyTy &key) {
- ArrayRef<int64_t> shape = allocator.copyInto(std::get<0>(key));
- StringRef operand = allocator.copyInto(std::get<2>(key));
-
- return new (allocator.allocate<MMAMatrixStorageType>())
- MMAMatrixStorageType(shape.size(), shape.data(), std::get<1>(key),
- operand);
- }
-
- ArrayRef<int64_t> getShape() const {
- return ArrayRef<int64_t>(dimShapes, numDims);
- }
-
- StringRef getOperand() const { return operand; }
-
- /// Reference to the shape of the MMA matrix.
- const int64_t *dimShapes;
-
- /// Number of dimensions in the MMA matrix.
- unsigned numDims;
-
- /// Element type of elements held in the MMA matrix.
- Type elementType;
-
- /// MMA operand that this MMAMatrix holds. The general form of operation this
- /// type supports is given by the equation C += A*B. This field specifies
- /// which operand in the given equation is held by this type. The valid values
- /// are "AOp", "BOp" and "COp".
- StringRef operand;
-};
-
-/// MMAMatrix represents a matrix held by a subgroup for matrix-matrix multiply
-/// accumulate operations. MMAMatrices are taken as direct operands by these
-/// operations and are also produced as results. These matrices are meant to
-/// reside in the registers. A limited number of pointwise operations can be
-/// performed on these matrices, i.e., operations which operate uniformly on
-/// all the elements in the matrix and do not change the order of matrix
-/// elements. The above conditions exist because the layout of matrix elements
-/// inside the matrix is opaque i.e., the elements may be present in the
-/// matrix in any order. The general usage of this type is shown as follows:-
-///
-/// %0 = gpu.subgroup_mma_load_matrix %arg0[%c0, %c0] {leadDimension = 16 :
-/// index} : memref<16x16xf16> -> !gpu.mma_matrix<16x16xf16, "AOp">
-///
-/// The MMAMatrixType describes the shape of the matrix being loaded and the
-/// operand being loaded too. The operand needs to be specified to aid the
-/// lowering of this type to dialects such as NVVM where each workitem may
-/// hold different amount of elements depending on the elementType of the
-/// matrix. For e.g., Each workitem holds 4 vector<2xf16>s for f16 data type
-/// and 8 f32s for f32 data type of MMAMatrix. Some other instances of usage
-/// are:-
-///
-/// %3 = gpu.subgroup_mma_compute %0, %1, %2 :
-/// !gpu.mma_matrix<16x16xf16, "AOp">, !gpu.mma_matrix<16x16xf16, "BOp">
-/// -> !gpu.mma_matrix<16x16xf32, "COp">
-///
-///
-/// gpu.subgroup_mma_store_matrix %3, %arg22[%c0, %c0] {leadDimension = 16
-/// : index}: !gpu.mma_matrix<16x16xf32, "COp">, memref<16x16xf32>
-///
-/// MMA matrices may be memref elements on targets that support storing them,
-/// for example SPIRV can represent arrays of MMA matrices.
-// TODO: consider moving this to ODS.
-class MMAMatrixType
- : public Type::TypeBase<MMAMatrixType, Type, MMAMatrixStorageType,
- MemRefElementTypeInterface::Trait> {
-public:
- using Base::Base;
-
- static constexpr StringLiteral name = "gpu.mma_matrix";
-
- /// Get MMAMatrixType and verify construction Invariants.
- static MMAMatrixType get(ArrayRef<int64_t> shape, Type elementType,
- StringRef operand);
-
- /// Get MMAMatrixType at a particular location and verify construction
- /// Invariants.
- static MMAMatrixType getChecked(function_ref<InFlightDiagnostic()> emitError,
- ArrayRef<int64_t> shape, Type elementType,
- StringRef operand);
-
- /// Check if a type is valid a MMAMatrixType elementType.
- static bool isValidElementType(Type elementType);
-
- /// Verify that shape and elementType are actually allowed for the
- /// MMAMatrixType...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/233103
More information about the Mlir-commits
mailing list