[clang] [lldb] [llvm] [OpenCL][Clang] Add support for cooperative matrix extension (PR #221328)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 13:58:33 PDT 2026


================
@@ -4582,6 +4583,123 @@ class ConstantMatrixType final : public MatrixType {
   }
 };
 
+/// Represents an opaque OpenCL cooperative matrix type.
+///
+/// Unlike MatrixType, a cooperative matrix is not an ordinary matrix value.
+/// It is an opaque, distributed object whose shape and role are part of its
+/// type identity.
+class CooperativeMatrixType final : public Type, public llvm::FoldingSetNode {
+protected:
+  friend class ASTContext;
+
+  /// Element type of the cooperative matrix.
+  QualType ElementType;
+
+  /// Number of rows and columns.
+  unsigned NumRows;
+  unsigned NumColumns;
+
+  /// Cooperative matrix scope and use.
+  unsigned Scope;
+  unsigned Use;
+
+  static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
+
+  CooperativeMatrixType(QualType ElementType, unsigned Scope, unsigned NumRows,
+                        unsigned NumColumns, unsigned Use,
+                        QualType CanonicalType)
+      : CooperativeMatrixType(Type::CooperativeMatrix, ElementType, Scope,
+                              NumRows, NumColumns, Use, CanonicalType) {}
+
+  CooperativeMatrixType(TypeClass TypeClass, QualType ElementType,
+                        unsigned Scope, unsigned NumRows, unsigned NumColumns,
+                        unsigned Use, QualType CanonicalType)
+      : Type(TypeClass, CanonicalType, ElementType->getDependence()),
+        ElementType(ElementType), NumRows(NumRows), NumColumns(NumColumns),
+        Scope(Scope), Use(Use) {}
+
+public:
+  /// Returns the element type.
+  QualType getElementType() const { return ElementType; }
+
+  /// Returns the number of rows.
+  unsigned getNumRows() const { return NumRows; }
+
+  /// Returns the number of columns.
+  unsigned getNumColumns() const { return NumColumns; }
+
+  /// Returns the cooperative matrix scope.
+  unsigned getScope() const { return Scope; }
+
+  /// Returns the cooperative matrix use.
+  unsigned getUse() const { return Use; }
+
+  /// Returns the number of elements required to embed the matrix into
+  /// a vector representation.
+  unsigned getNumElementsFlattened() const {
----------------
asudarsa-qti wrote:

@MrSidims comment: I'm not sure it's useful for cooperative matrices if we use target extension type to represent them.

Reply: Good point. I do not use it anywhere. Removed it. Thanks

https://github.com/llvm/llvm-project/pull/221328


More information about the cfe-commits mailing list