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

via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 17 10:42:31 PDT 2026


================
@@ -0,0 +1,106 @@
+// Cooperative matrix tests for SPIR-V friendly LLVM IR code generation from
+// clang frontend.
+//
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown \
+// RUN:   -cl-std=CL2.0 -cl-ext=+cl_khr_cooperative_matrix \
+// RUN:   -finclude-default-header -emit-llvm -O0 -o - %s \
+// RUN:   | FileCheck %s
+
+// expected-no-diagnostics
+
+#define SCOPE     memory_scope_sub_group
+#define USE_A     CLK_COOPERATIVE_MATRIX_A
+#define USE_B     CLK_COOPERATIVE_MATRIX_B
+#define USE_C     CLK_COOPERATIVE_MATRIX_ACCUMULATOR
+#define ROW_MAJOR CLK_COOPERATIVE_MATRIX_LAYOUT_ROW_MAJOR
+
+#pragma OPENCL EXTENSION cl_khr_cooperative_matrix : enable
+
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatA_t;
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_B))) MatB_t;
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_C))) MatC_t;
+
+// coop_mat_load -> __spirv_CooperativeMatrixLoadKHR
+//     Also verifies CooperativeMatrixType lowers to spirv.CooperativeMatrixKHR
+//     TargetExtType (visible in the call signature).
+kernel void test_load(__global float *ptr) {
+    MatA_t a_1;
+    a_1 = coop_mat_load(ptr, ROW_MAJOR, 16);
+    (void)a_1;
+    MatA_t a_2 = coop_mat_load(ptr, ROW_MAJOR, 16);
+    (void)a_2;
+    MatA_t a_3;
+    a_3 = (coop_mat_load(ptr, ROW_MAJOR, 16));
+    (void)a_3;
+    MatA_t a_4 = (coop_mat_load(ptr, ROW_MAJOR, 16));
+    (void)a_4;
+}
----------------
asudarsa-qti wrote:

Added to 1b54ae32a02b5b3ac8df823f995b0a3e6a5677d1

Thanks

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


More information about the cfe-commits mailing list