[Lldb-commits] [clang] [lldb] [llvm] [OpenCL][Clang] Add support for cooperative matrix extension (PR #221328)
Dmitry Sidorov via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 24 06:35:37 PDT 2026
================
@@ -4559,6 +4560,112 @@ 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)
+ : Type(Type::CooperativeMatrix, 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 true if \p NumElements is a valid cooperative matrix dimension.
+ static constexpr bool isDimensionValid(size_t NumElements) {
+ return NumElements > 0 && NumElements <= MaxElementsPerDimension;
+ }
+
+ /// Returns true if \p Scope is a valid cooperative matrix scope.
+ static constexpr bool isScopeValid(size_t Scope) {
+ return Scope == 3; // CLK_COOPERATIVE_MATRIX_SCOPE_SUBGROUP
----------------
MrSidims wrote:
I don't see CLK_COOPERATIVE_MATRIX_SCOPE_SUBGROUP defined in https://github.com/KhronosGroup/OpenCL-Docs/blob/ce02318cdbfad800e523a6843c019255b2623aaa/env/extensions.asciidoc , so the comment is confusing.
I hoped to find some enum defining scopes in clang, but apparently there are none (well, there are definitions in include/clang/Basic/SyncScope.h , but they don't match our needs). I would feel myself more comfortable if we have Scope and Use definitions somewhere in the headers, so there would be not magical literals, but meaningful contexpr variables, but I won't insist.
https://github.com/llvm/llvm-project/pull/221328
More information about the lldb-commits
mailing list