Skip to content

Commit 2e21849

Browse files
ficoligcbot
authored andcommitted
Add support for out of bounds load/store
Handle ConstructChecked, LoadChecked and StoreChecked Joint Matrix instructions. Pass out of bounds arguments to 2d load/store builtins.
1 parent 301d372 commit 2e21849

File tree

7 files changed

+722
-98
lines changed

7 files changed

+722
-98
lines changed

IGC/BiFModule/Languages/OpenCL/PreRelease/IBiF_matrix.cl

Lines changed: 333 additions & 5 deletions
Large diffs are not rendered by default.

IGC/Compiler/Optimizer/OpenCLPasses/JointMatrixFuncsResolutionPass/JointMatrixFuncsResolutionPass.cpp

Lines changed: 255 additions & 90 deletions
Large diffs are not rendered by default.

IGC/Compiler/Optimizer/OpenCLPasses/JointMatrixFuncsResolutionPass/JointMatrixFuncsResolutionPass.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ namespace IGC
5353

5454
private:
5555
llvm::Instruction *ResolvePrefetch(llvm::CallInst *CI);
56-
template <bool IsJointMatrix>
56+
template <bool IsJointMatrix, bool isChecked>
5757
llvm::Instruction *ResolveLoad(llvm::CallInst *CI);
58-
template <bool IsJointMatrix>
58+
template <bool IsJointMatrix, bool IsChecked>
5959
llvm::Instruction *ResolveStore(llvm::CallInst *CI);
6060
llvm::Instruction *ResolveMad(llvm::CallInst *CI, unsigned OperationType);
6161
int getSliceSize(const JointMatrixTypeDescription *desc);
6262
llvm::Value *ResolveFill(llvm::CallInst *CI);
63+
llvm::Instruction *ResolveFillChecked(llvm::CallInst *CI);
6364
llvm::Value *ResolveWILength(llvm::CallInst *CI);
6465
llvm::Value *ResolveSliceInsert(llvm::CallInst *CI);
6566
llvm::Value *ResolveSliceExtract(llvm::CallInst *CI);
@@ -87,6 +88,8 @@ namespace IGC
8788
Prefetch,
8889
Load,
8990
Store,
91+
LoadChecked,
92+
StoreChecked,
9093
};
9194
std::string GetMatrixFuncName(GetMatrixFuncNameOperation operation,
9295
unsigned operationLayout,
@@ -97,6 +100,9 @@ namespace IGC
97100
bool ValidateLoadStore
98101
(bool isLoad, unsigned operationLayout, const JointMatrixTypeDescription *desc, llvm::Value *ctx);
99102

103+
void Validate2DBlockLoadStore
104+
(GetMatrixFuncNameOperation operation, unsigned operationLayout, unsigned address_space, const JointMatrixTypeDescription *desc, llvm::Value *ctx);
105+
100106
// SIMD Size helpers
101107
llvm::Function *getEntryFunction(llvm::Function *F);
102108
void ResolveSIMDSize(llvm::Function *F);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -igc-joint-matrix-resolution --platformpvc -S 2>&1 < %s | FileCheck %s
10+
; ------------------------------------------------
11+
; JointMatrixFuncsResolutionPass
12+
; ------------------------------------------------
13+
14+
%spirv.JointMatrixINTEL._int_8_16_0_3_1 = type opaque
15+
%spirv.JointMatrixINTEL._float_8_16_3_3_2 = type opaque
16+
%spirv.JointMatrixINTEL._int_8_16_2_3_1 = type opaque
17+
declare spir_func %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* @_Z46__spirv_CooperativeMatrixConstructCheckedINTELiiiif(i32, i32, i32, i32, float) #0
18+
declare spir_func %spirv.JointMatrixINTEL._int_8_16_0_3_1 addrspace(1)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__int_8_16_0_3_1PU3AS1ciiiiili(i8 addrspace(1)*, i32, i32, i32, i32, i32, i64, i32) #0
19+
declare spir_func %spirv.JointMatrixINTEL._int_8_16_2_3_1 addrspace(1)* @_Z94__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS143__spirv_JointMatrixINTEL__int_8_16_2_3_1PU3AS1ciiiiili(i8 addrspace(1)*, i32, i32, i32, i32, i32, i64, i32) #0
20+
declare spir_func void @_Z42__spirv_CooperativeMatrixStoreCheckedINTELPU3AS1fiiPU3AS142__spirv_JointMatrixINTEL__float_8_16_3_3_2iiili(float addrspace(1)*, i32, i32, %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)*, i32, i32, i32, i64, i32) #0
21+
22+
define spir_kernel void @matrix_load_checked(i8 addrspace(1)* %src, float addrspace(1)* %dst) {
23+
; CHECK-LABEL: define spir_kernel void @matrix_load_checked(
24+
%1 = call spir_func %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* @_Z46__spirv_CooperativeMatrixConstructCheckedINTELiiiif(i32 3, i32 4, i32 5, i32 6, float 1.000000e+00) #0
25+
%2 = call spir_func %spirv.JointMatrixINTEL._int_8_16_2_3_1 addrspace(1)* @_Z94__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS143__spirv_JointMatrixINTEL__int_8_16_2_3_1PU3AS1ciiiiili(i8 addrspace(1)* %src, i32 2, i32 3, i32 0, i32 13, i32 14, i64 14, i32 0) #0
26+
%3 = call spir_func %spirv.JointMatrixINTEL._int_8_16_0_3_1 addrspace(1)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__int_8_16_0_3_1PU3AS1ciiiiili(i8 addrspace(1)* %src, i32 3, i32 4, i32 0, i32 10, i32 11, i64 12, i32 0) #0
27+
call spir_func void @_Z42__spirv_CooperativeMatrixStoreCheckedINTELPU3AS1fiiPU3AS142__spirv_JointMatrixINTEL__float_8_16_3_3_2iiili(float addrspace(1)* %dst, i32 5, i32 6, %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* %1, i32 1, i32 12, i32 13, i64 13, i32 0) #0
28+
ret void
29+
; CHECK-NOT: error: Unsupported parameters for matrix checked load with SIMD size 32
30+
; CHECK: error: Matrix checked store is not supported for SIMD size 32
31+
; CHECK: error: Matrix checked store is not supported for ColumnMajor layout
32+
}
33+
34+
!igc.functions = !{!0}
35+
!0 = !{void (i8 addrspace(1)*, float addrspace(1)*)* @matrix_load_checked, !1}
36+
!1 = !{!2, !3}
37+
!2 = !{!"function_type", i32 0}
38+
!3 = !{!"sub_group_size", i32 32}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -igc-joint-matrix-resolution --platformpvc -S 2>&1 < %s | FileCheck %s
10+
; ------------------------------------------------
11+
; JointMatrixFuncsResolutionPass
12+
; ------------------------------------------------
13+
14+
%spirv.JointMatrixINTEL._short_7_66_0_3_0 = type opaque
15+
declare spir_func %spirv.JointMatrixINTEL._short_7_66_0_3_0 addrspace(3)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__short_7_66_0_3_0PU3AS1ciiiiili(i8 addrspace(3)*, i32, i32, i32, i32, i32, i64, i32)
16+
17+
define spir_kernel void @matrix_load_checked(i8 addrspace(3)* %src) {
18+
; CHECK-LABEL: define spir_kernel void @matrix_load_checked(
19+
%1 = call spir_func %spirv.JointMatrixINTEL._short_7_66_0_3_0 addrspace(3)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__short_7_66_0_3_0PU3AS1ciiiiili(i8 addrspace(3)* %src, i32 0, i32 0, i32 0, i32 16, i32 16, i64 16, i32 0) #0
20+
ret void
21+
; CHECK: error: Unsupported address space. Matrix checked load supports generic and global pointers.
22+
; CHECK: error: Unsupported row parameter for matrix checked load: 7. Supported values: 1, 2, 4, 8, 16, 32.
23+
; CHECK: error: Unsupported column parameter for matrix checked load: 66. Supported values: 8, 16, 32, 64.
24+
; CHECK: error: Matrix checked load size limit exceeded.
25+
; CHECK: Limit exceeded with values: 66 * 2B = 132B
26+
}
27+
28+
!igc.functions = !{!0}
29+
!0 = !{void (i8 addrspace(3)*)* @matrix_load_checked, !1}
30+
!1 = !{!2, !3}
31+
!2 = !{!"function_type", i32 0}
32+
!3 = !{!"sub_group_size", i32 16}

IGC/Compiler/tests/JointMatrixFuncsResolutionPass/ErrorsReporting/validate-prefetch-sg8.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define spir_kernel void @matrix_prefetch(float addrspace(1)* %src) {
1818
entry:
1919
call spir_func void @_Z38__spirv_CooperativeMatrixPrefetchINTELPU3AS4flllliil(float addrspace(1)* %src, i64 0, i64 0, i64 8, i64 16, i32 1, i32 0, i64 64)
2020
ret void
21-
; CHECK: error: Matrix prefetch requires SIMD size to be 16 or higher
21+
; CHECK: error: SYCL Joint Matrix prefetch API is not supported on targeted GPU device
2222
}
2323

2424
!igc.functions = !{!0}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt -platformpvc -igc-joint-matrix-resolution -S 2>&1 < %s | FileCheck %s
10+
; ------------------------------------------------
11+
; JointMatrixFuncsResolutionPass
12+
; ------------------------------------------------
13+
14+
%spirv.JointMatrixINTEL._float_8_16_3_3_2 = type opaque
15+
%spirv.JointMatrixINTEL._short_8_16_0_3_0 = type opaque
16+
%spirv.JointMatrixINTEL._short_16_16_2_3_1 = type opaque
17+
18+
; CHECK-LABEL: define spir_kernel void @test(
19+
; CHECK-SAME: i8 addrspace(1)* [[PTR1:%.*]], i8 addrspace(1)* [[PTR2:%.*]], float addrspace(1)* [[PTR3:%.*]]) {
20+
define spir_kernel void @test(i8 addrspace(1)* %ptr1, i8 addrspace(1)* %ptr2, float addrspace(1)* %ptr3) {
21+
; CHECK: [[TMP1:%.*]] = alloca <8 x float>
22+
; CHECK: [[TMP2:%.*]] = alloca <8 x i32>
23+
; CHECK: [[TMP3:%.*]] = alloca <8 x i16>
24+
; CHECK: [[TMP4:%.*]] = alloca <8 x float>
25+
; CHECK: [[TMP5:%.*]] = bitcast <8 x float>* [[TMP4]] to i8*
26+
; CHECK: call void @__builtin_spriv_OpJointMatrixFillCheckedINTEL_i32_8(i8* [[TMP5]], i32 3, i32 4, i32 5, i32 6, i32 1065353216)
27+
; CHECK: [[TMP6:%.*]] = load <8 x float>, <8 x float>* [[TMP4]]
28+
; CHECK: [[TMP7:%.*]] = bitcast <8 x i16>* [[TMP3]] to i8*
29+
; CHECK: call void @__builtin_spriv_OpJointMatrixLoadCheckedINTEL_PackedA_RowMajor_SG16_8x16_i16_8_v8i8_pi32_i32(i8* [[TMP7]], i8 addrspace(1)* %ptr1, i32 3, i32 4, i32 10, i32 11, i64 12, i32 0)
30+
; CHECK: load <8 x i16>, <8 x i16>* [[TMP3]]
31+
; CHECK: [[TMP9:%.*]] = bitcast <8 x i32>* [[TMP2]] to i8*
32+
; CHECK: call void @__builtin_spriv_OpJointMatrixLoadCheckedINTEL_PackedB_PackedB_SG16_16x16_i16_8_v8i8_pi32_i32(i8* [[TMP9]], i8 addrspace(1)* %ptr2, i32 2, i32 3, i32 13, i32 14, i64 14, i32 0)
33+
; CHECK: [[TMP10:%.*]] = load <8 x i32>, <8 x i32>* [[TMP2]]
34+
; CHECK: store <8 x float> [[TMP6]], <8 x float>* [[TMP1]]
35+
; CHECK: [[TMP11:%.*]] = bitcast <8 x float>* [[TMP1]] to i8*
36+
; CHECK: call void @__builtin_spriv_OpJointMatrixStoreCheckedINTEL_Accumulator_RowMajor_SG16_8x16_i32_8_pi64_v8i8(float addrspace(1)* %ptr3, i8* [[TMP11]], i32 5, i32 6, i32 12, i32 13, i64 13, i32 0)
37+
; CHECK: ret void
38+
%1 = call spir_func %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* @_Z46__spirv_CooperativeMatrixConstructCheckedINTELiiiif(i32 3, i32 4, i32 5, i32 6, float 1.000000e+00) #0
39+
%2 = call spir_func %spirv.JointMatrixINTEL._short_8_16_0_3_0 addrspace(1)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__short_8_16_0_3_0PU3AS1ciiiiili(i8 addrspace(1)* %ptr1, i32 3, i32 4, i32 0, i32 10, i32 11, i64 12, i32 0) #0
40+
%3 = call spir_func %spirv.JointMatrixINTEL._short_16_16_2_3_1 addrspace(1)* @_Z94__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS143__spirv_JointMatrixINTEL__short_16_16_2_3_1PU3AS1ciiiiili(i8 addrspace(1)* %ptr2, i32 2, i32 3, i32 2, i32 13, i32 14, i64 14, i32 0) #0
41+
call spir_func void @_Z42__spirv_CooperativeMatrixStoreCheckedINTELPU3AS1fiiPU3AS142__spirv_JointMatrixINTEL__float_8_16_3_3_2iiili(float addrspace(1)* %ptr3, i32 5, i32 6, %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* %1, i32 0, i32 12, i32 13, i64 13, i32 0) #0
42+
43+
ret void
44+
}
45+
46+
declare spir_func %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)* @_Z46__spirv_CooperativeMatrixConstructCheckedINTELiiiif(i32, i32, i32, i32, float) #0
47+
declare spir_func %spirv.JointMatrixINTEL._short_8_16_0_3_0 addrspace(1)* @_Z93__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS142__spirv_JointMatrixINTEL__short_8_16_0_3_0PU3AS1ciiiiili(i8 addrspace(1)*, i32, i32, i32, i32, i32, i64, i32) #0
48+
declare spir_func %spirv.JointMatrixINTEL._short_16_16_2_3_1 addrspace(1)* @_Z94__spirv_CooperativeMatrixLoadCheckedINTEL_RPU3AS143__spirv_JointMatrixINTEL__short_16_16_2_3_1PU3AS1ciiiiili(i8 addrspace(1)*, i32, i32, i32, i32, i32, i64, i32) #0
49+
declare spir_func void @_Z42__spirv_CooperativeMatrixStoreCheckedINTELPU3AS1fiiPU3AS142__spirv_JointMatrixINTEL__float_8_16_3_3_2iiili(float addrspace(1)*, i32, i32, %spirv.JointMatrixINTEL._float_8_16_3_3_2 addrspace(1)*, i32, i32, i32, i64, i32) #0
50+
51+
!igc.functions = !{!0}
52+
!0 = !{void (i8 addrspace(1)*, i8 addrspace(1)*, float addrspace(1)*)* @test, !1}
53+
!1 = !{!2, !3}
54+
!2 = !{!"function_type", i32 0}
55+
!3 = !{!"sub_group_size", i32 16}

0 commit comments

Comments
 (0)