================
@@ -0,0 +1,172 @@
+// 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 -fdeclare-opencl-builtins -fsyntax-only \
+// RUN:   -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;
+typedef float   __attribute__((coop_mat(SCOPE, 16, 16, USE_C))) MatC_t;
+
+// Invalid 'scope'
+typedef float __attribute__((coop_mat(0, 16, 16, USE_A))) MatBadScope; // 
expected-error {{invalid 'scope' argument of cooperative matrix attribute}}
+
+// Invalid 'use'
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, 99))) MatBadUse;  // 
expected-error {{invalid 'use' argument of cooperative matrix attribute}}
+
+// Invalid element types.
+typedef bool __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatBadElement_t; 
// expected-error {{'bool' is invalid cooperative matrix element type}}
+typedef float * __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatPtrElem_t; 
// expected-error-re {{'{{.*}}float *' is invalid cooperative matrix element 
type}}
+typedef float Arr4_t[4];
+typedef Arr4_t __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatArrElem_t; 
// expected-error-re {{'Arr4_t'{{.*}} is invalid cooperative matrix element 
type}}
+struct ElemS { float x; };
+typedef struct ElemS __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) 
MatStructElem_t; // expected-error {{'struct ElemS' is invalid cooperative 
matrix element type}}
+typedef float4 __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatVecElem_t; 
// expected-error-re {{'float4'{{.*}} is invalid cooperative matrix element 
type}}
+
+// Assignment of coop_mat_load result to a plain scalar
+kernel void test_bad_assignment(__global float *ptr) {
+    float bad;
+       bad = coop_mat_load(ptr, ROW_MAJOR, 16); // expected-error {{builtin 
return value should be assigned to cooperative matrix type variable}}
+    (void)bad;
+}
+
+// Kernel parameter cannot be of cooperative matrix type.
+kernel void test_bad_kernel_param(MatA_t a) {} // expected-error {{cannot be 
used as the type of a kernel parameter}}
+
+// Invalid memory layout for cooperative matrix load.
+kernel void test_invalid_load_layout(__global float *ptr) {
+    MatA_t a;
+    a = coop_mat_load(ptr, 99, 16); // expected-error {{memory layout for 
cooperative matrix load/store should be CLK_COOPERATIVE_MATRIX_LAYOUT_ROW_MAJOR 
or CLK_COOPERATIVE_MATRIX_LAYOUT_COLUMN_MAJOR}}
+}
+
+// Invalid memory layout for cooperative matrix store.
+kernel void test_invalid_store_layout(__global float *ptr) {
+    MatA_t a;
+    coop_mat_store(ptr, a, 99, 16); // expected-error {{memory layout for 
cooperative matrix load/store should be CLK_COOPERATIVE_MATRIX_LAYOUT_ROW_MAJOR 
or CLK_COOPERATIVE_MATRIX_LAYOUT_COLUMN_MAJOR}}
+}
+
+// Invalid stride type for cooperative matrix load.
+kernel void test_invalid_load_stride(__global float *ptr) {
+    MatA_t a;
+    int stride = 16;
+    a = coop_mat_load(ptr, ROW_MAJOR, stride); // expected-error {{stride 
argument for load/store of cooperative matrix must have type 'size_t'}}
----------------
asudarsa-qti wrote:

Can we keep the code as is and then update it once the spec is resolved?

Thanks

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