================
@@ -0,0 +1,216 @@
+// Sema — negative tests for diagnostic paths.
+//
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown \
+// RUN:   -cl-std=CL2.0 -cl-ext=+cl_khr_cooperative_matrix \
+// RUN:   -finclude-default-header -fsyntax-only -verify %s
+
+#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
+
+// ---------------------------------------------------------------------------
+// Use of cooperative matrix type without specifying pragma
+// ---------------------------------------------------------------------------
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatX_t; // 
expected-error {{cooperative matrix types require OpenCL extension 
'cl_khr_cooperative_matrix' to be enabled via pragma}}
+
+#pragma OPENCL EXTENSION cl_khr_cooperative_matrix : enable
+
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatA_t; // 
expected-note {{declared here}}
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_B))) MatB_t;
+typedef int   __attribute__((coop_mat(SCOPE, 16, 16, USE_C))) MatC_int_t;
+
+// ---------------------------------------------------------------------------
+// Invalid scope value (0 is not memory_scope_sub_group)
+// ---------------------------------------------------------------------------
+typedef float __attribute__((coop_mat(0, 16, 16, USE_A))) MatBadScope; // 
expected-error {{invalid 'scope' argument of cooperative matrix attribute}}
+
+// ---------------------------------------------------------------------------
+// Invalid use value (99 is not 0/1/2)
+// ---------------------------------------------------------------------------
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, 99))) MatBadUse;  // 
expected-error {{invalid 'use' argument of cooperative matrix attribute}}
+
+// ---------------------------------------------------------------------------
+// Mismatched element types in coop_mat_mulAdd
+//    a/b are float matrices, c is an int matrix — should fire element type
+//    mismatch diagnostic.
+// ---------------------------------------------------------------------------
+kernel void test_muladd_type_mismatch(__global float *fptr,
+                                      __global int   *iptr) {
+    MatA_t     a;
+    MatB_t     b;
+    MatC_int_t c;
+    a = coop_mat_load(fptr, ROW_MAJOR, 16);
+    b = coop_mat_load(fptr, ROW_MAJOR, 16);
+    c = coop_mat_load(iptr, ROW_MAJOR, 16);
+
+    MatC_int_t result;
+    result = coop_mat_mulAdd(a, b, c); // expected-error {{inconsistent 
cooperative matrix element types}}
+    (void)result;
----------------
svenvh wrote:

Could we also test the direct form:
```
MatC_int_t result2 = coop_mat_mulAdd(a, b, c); // expected-error {{inconsistent 
cooperative matrix element types}}
```

https://github.com/llvm/llvm-project/pull/221328
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to