================
@@ -0,0 +1,159 @@
+// Tests for function-name mangling of SPIR-V friendly cooperative matrix 
intrinsics.
+//
+// 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 %t.ll %s
+// RUN: FileCheck --check-prefix=CHECK      %s < %t.ll
+// RUN: FileCheck --check-prefix=CHECK-DECL %s < %t.ll
+
+#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
+
+// --- float 16x16 (MulAdd group 1) ---
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatF_16x16_A;
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_B))) MatF_16x16_B;
+typedef float __attribute__((coop_mat(SCOPE, 16, 16, USE_C))) MatF_16x16_C;
+
+// --- float 8x32 / 32x8 / 8x8 (MulAdd group 2 -- same elem type, diff dims) 
---
+typedef float __attribute__((coop_mat(SCOPE,  8, 32, USE_A))) MatF_8x32_A;
+typedef float __attribute__((coop_mat(SCOPE, 32,  8, USE_B))) MatF_32x8_B;
+typedef float __attribute__((coop_mat(SCOPE,  8,  8, USE_C))) MatF_8x8_C;
+
+// --- int 16x16 (MulAdd group 3 -- different element type to group 1) ---
+typedef int __attribute__((coop_mat(SCOPE, 16, 16, USE_A))) MatI_16x16_A;
+typedef int __attribute__((coop_mat(SCOPE, 16, 16, USE_B))) MatI_16x16_B;
+typedef int __attribute__((coop_mat(SCOPE, 16, 16, USE_C))) MatI_16x16_C;
+
+// MulAdd: same element type (float), different matrix dimensions
+// 16x16 x 16x16 -> 16x16   vs   8x32 x 32x8 -> 8x8
+// Must produce TWO distinct __spirv_CooperativeMatrixMulAddKHR_* symbols.
+
+kernel void test_muladd_f32_16x16(__global float *ptr) {
+    MatF_16x16_A a;
+    MatF_16x16_B b;
+    MatF_16x16_C c, r;
+    a = coop_mat_load(ptr, ROW_MAJOR, 16);
+    b = coop_mat_load(ptr, ROW_MAJOR, 16);
+    c = coop_mat_load(ptr, ROW_MAJOR, 16);
+    r = coop_mat_mulAdd(a, b, c);
+    (void)r;
+}
+// CHECK-LABEL: @__clang_ocl_kern_imp_test_muladd_f32_16x16
+// CHECK: call {{.*}} @__spirv_CooperativeMatrixMulAddKHR
+// CHECK-SAME: _f32_sc{{[0-9]+}}_16x16_u{{[0-9]+}}
+// CHECK-SAME: _f32_sc{{[0-9]+}}_16x16_u{{[0-9]+}}
+// CHECK-SAME: _f32_sc{{[0-9]+}}_16x16_u{{[0-9]+}}
+
+kernel void test_muladd_f32_8x32(__global float *ptr) {
+    MatF_8x32_A  a;
+    MatF_32x8_B  b;
+    MatF_8x8_C   c, r;
+    a = coop_mat_load(ptr, ROW_MAJOR, 8);
+    b = coop_mat_load(ptr, ROW_MAJOR, 32);
+    c = coop_mat_load(ptr, ROW_MAJOR, 8);
+    r = coop_mat_mulAdd(a, b, c);
+    (void)r;
+}
+// CHECK-LABEL: @__clang_ocl_kern_imp_test_muladd_f32_8x32
+// CHECK: call {{.*}} @__spirv_CooperativeMatrixMulAddKHR
+// CHECK-SAME: _f32_sc{{[0-9]+}}_8x32_u{{[0-9]+}}
+// CHECK-SAME: _f32_sc{{[0-9]+}}_32x8_u{{[0-9]+}}
+// CHECK-SAME: _f32_sc{{[0-9]+}}_8x8_u{{[0-9]+}}
+
+// MulAdd: different element types -- float 16x16 vs int 16x16
+// Same dimensions, different elem type -> must produce two distinct symbols.
+
+kernel void test_muladd_i32_16x16(__global int *iptr) {
+    MatI_16x16_A a;
+    MatI_16x16_B b;
+    MatI_16x16_C c, r;
+    a = coop_mat_load(iptr, ROW_MAJOR, 16);
+    b = coop_mat_load(iptr, ROW_MAJOR, 16);
+    c = coop_mat_load(iptr, ROW_MAJOR, 16);
+    r = coop_mat_mulAdd(a, b, c);
+    (void)r;
+}
+// CHECK-LABEL: @__clang_ocl_kern_imp_test_muladd_i32_16x16
+// CHECK: call {{.*}} @__spirv_CooperativeMatrixMulAddKHR
+// CHECK-SAME: _i32_sc{{[0-9]+}}_16x16_u{{[0-9]+}}
----------------
svenvh wrote:

Missing the 2nd and 3rd operand?

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