Skip to content

Commit b717c7c

Browse files
pkwasnie-inteligcbot
authored andcommitted
fix test
igc_opt returns non-zero on failed assert
1 parent 46c11fc commit b717c7c

File tree

6 files changed

+1153
-126
lines changed

6 files changed

+1153
-126
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/DpasFuncs/DpasFuncsResolution.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class DpasFuncsResolution : public FunctionPass, public InstVisitor<DpasFuncsRes
107107
///
108108
static const StringRef SG_PREFIX_IDPAS16;
109109
static const StringRef SG_PREFIX_FDPAS16;
110+
static const StringRef SG_PREFIX_IDPAS32N16;
111+
static const StringRef SG_PREFIX_FDPAS32N16;
110112
// PVC+: pure hf/bf dpas builtins
111113
static const StringRef WI_PREFIX_HFDPAS;
112114
static const StringRef WI_PREFIX_BFDPAS;
@@ -200,6 +202,8 @@ const StringRef DpasFuncsResolution::WI_PREFIX_IDPAS = "__builtin_IB_idpas";
200202
const StringRef DpasFuncsResolution::WI_PREFIX_FDPAS = "__builtin_IB_fdpas";
201203
const StringRef DpasFuncsResolution::SG_PREFIX_IDPAS16 = "__builtin_IB_sub_group16_idpas";
202204
const StringRef DpasFuncsResolution::SG_PREFIX_FDPAS16 = "__builtin_IB_sub_group16_fdpas";
205+
const StringRef DpasFuncsResolution::SG_PREFIX_IDPAS32N16 = "__builtin_IB_sub_group32n16_idpas";
206+
const StringRef DpasFuncsResolution::SG_PREFIX_FDPAS32N16 = "__builtin_IB_sub_group32n16_fdpas";
203207
// PVC+: pure hf/bf dpas builtins
204208
const StringRef DpasFuncsResolution::WI_PREFIX_HFDPAS = "__builtin_IB_hfdpas";
205209
const StringRef DpasFuncsResolution::WI_PREFIX_BFDPAS = "__builtin_IB_bfdpas";
@@ -263,6 +267,11 @@ void DpasFuncsResolution::visitCallInst(CallInst &CI) {
263267

264268
bool IsDpasw = false;
265269
bool IsIDpas = false;
270+
// Dimension N is platform specific and is directly correlated to minimum subgroup-size for
271+
// given platform. If DPAS with the same M, N, K dimensions is executed within a subgroup
272+
// twice the size of minimum subgroup-size, each work item must contain half of the data
273+
// compared to the minimum subgroup-size.
274+
bool IsDoubleSubgroup = false;
266275
int DstTy, AccTy, PA, PB, SD, RC;
267276
GenISAIntrinsic::ID iid = GenISAIntrinsic::no_intrinsic;
268277
bool doVerify = false;
@@ -277,12 +286,26 @@ void DpasFuncsResolution::visitCallInst(CallInst &CI) {
277286
if (!demangleSuffix(funcName, SG_PREFIX_LEN, false, IsIDpas, DstTy, AccTy, PA, PB, SD, RC, nullptr))
278287
return;
279288
iid = GenISAIntrinsic::GenISA_sub_group_dpas;
289+
} else if (funcName.startswith(DpasFuncsResolution::SG_PREFIX_IDPAS32N16)) {
290+
const int SG_PREFIX_LEN = DpasFuncsResolution::SG_PREFIX_IDPAS32N16.size();
291+
IsIDpas = true;
292+
IsDoubleSubgroup = true;
293+
if (!demangleSuffix(funcName, SG_PREFIX_LEN, false, IsIDpas, DstTy, AccTy, PA, PB, SD, RC, nullptr))
294+
return;
295+
iid = GenISAIntrinsic::GenISA_sub_group_dpas;
280296
} else if (funcName.startswith(DpasFuncsResolution::SG_PREFIX_FDPAS16)) {
281297
const int SG_PREFIX_LEN = DpasFuncsResolution::SG_PREFIX_FDPAS16.size();
282298
IsIDpas = false;
283299
if (!demangleSuffix(funcName, SG_PREFIX_LEN, true, IsIDpas, DstTy, AccTy, PA, PB, SD, RC, nullptr))
284300
return;
285301
iid = GenISAIntrinsic::GenISA_sub_group_dpas;
302+
} else if (funcName.startswith(DpasFuncsResolution::SG_PREFIX_FDPAS32N16)) {
303+
const int SG_PREFIX_LEN = DpasFuncsResolution::SG_PREFIX_FDPAS32N16.size();
304+
IsIDpas = false;
305+
IsDoubleSubgroup = true;
306+
if (!demangleSuffix(funcName, SG_PREFIX_LEN, true, IsIDpas, DstTy, AccTy, PA, PB, SD, RC, nullptr))
307+
return;
308+
iid = GenISAIntrinsic::GenISA_sub_group_dpas;
286309
}
287310
else {
288311
return;
@@ -363,6 +386,14 @@ void DpasFuncsResolution::visitCallInst(CallInst &CI) {
363386
Type *A_BaseTy = ATy->getScalarType();
364387
Type *B_BaseTy = BTy->getScalarType();
365388

389+
if (IsDoubleSubgroup) {
390+
IGC_ASSERT_MESSAGE(RC >= 2, "ICE: repeat count of DPAS for double subgroup-size must be >= 2!");
391+
D_nelts *= 2;
392+
ACC_nelts *= 2;
393+
A_nelts *= 2;
394+
B_nelts *= 2;
395+
}
396+
366397
if (IsIDpas) {
367398
uint32_t Abits = getPrecisionInBits((PrecisionType)PA);
368399
uint32_t Bbits = getPrecisionInBits((PrecisionType)PB);

IGC/Compiler/Optimizer/OpenCLPasses/SpvSubgroupMMAResolution/SpvSubgroupMMAResolution.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ int SpvSubgroupMMAResolution::getElemCount(const Type *Ty) const {
272272
}
273273

274274
bool SpvSubgroupMMAResolution::validateElemCounts(int M, int AElemCount, int BElemCount, uint32_t Operands,
275-
const CallInst &CI) {
275+
CallInst &CI) {
276276
if (M != 1 && M != 2 && M != 4 && M != 8) {
277277
emitError(
278278
"__spirv_SubgroupMatrixMultiplyAccumulateINTEL: M dimension must be 1, 2, 4 or 8 for targeted HW. Actual: " +
@@ -295,16 +295,27 @@ bool SpvSubgroupMMAResolution::validateElemCounts(int M, int AElemCount, int BEl
295295
CI);
296296
return false;
297297
}
298-
if (BElemCount != 8) {
299-
emitError("__spirv_SubgroupMatrixMultiplyAccumulateINTEL: Matrix B argument must have 8 components for targeted "
300-
"HW. Actual: " +
301-
std::to_string(BElemCount),
298+
const int expectedBCount = isDoubleSubgroup(CI) ? 4 : 8;
299+
if (BElemCount != expectedBCount) {
300+
emitError("__spirv_SubgroupMatrixMultiplyAccumulateINTEL: Matrix B argument must have " +
301+
std::to_string(expectedBCount) +
302+
" components for targeted HW. Actual: " + std::to_string(BElemCount),
302303
CI);
303304
return false;
304305
}
305306
return true;
306307
}
307308

309+
// Dimension N is platform specific and is directly correlated to minimum subgroup-size for
310+
// given platform. If DPAS with the same M, N, K dimensions is executed within a subgroup
311+
// twice the size of minimum subgroup-size, each work item must contain half of the data
312+
// compared to the minimum subgroup-size.
313+
bool SpvSubgroupMMAResolution::isDoubleSubgroup(CallInst &CI) {
314+
if (!m_Ctx->platform.hasExecSize16DPAS())
315+
return false;
316+
return IGC::getSIMDSize(getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils(), CI.getParent()->getParent()) == 32;
317+
}
318+
308319
SpvSubgroupMMAResolution::SupportedTable *SpvSubgroupMMAResolution::getSupportedTable() {
309320
if (m_Ctx->platform.hasExecSize16DPAS()) {
310321
if (m_Simd16Table.empty())
@@ -480,9 +491,16 @@ void SpvSubgroupMMAResolution::visitCallInst(CallInst &CI) {
480491
SmallVector<Type *, 3> argTypes({c->getType(), a->getType(), b->getType()});
481492
FunctionType *FT = FunctionType::get(CI.getType(), argTypes, false);
482493

494+
std::string subgroupSize;
495+
if (isDoubleSubgroup(CI)) {
496+
subgroupSize = "32n16";
497+
M *= 2;
498+
} else {
499+
subgroupSize = m_Ctx->platform.hasExecSize16DPAS() ? "16" : "";
500+
}
501+
483502
std::stringstream newFuncName;
484-
newFuncName << "__builtin_IB_sub_group";
485-
newFuncName << (m_Ctx->platform.hasExecSize16DPAS() ? "16" : "");
503+
newFuncName << "__builtin_IB_sub_group" << subgroupSize;
486504
newFuncName << "_" << (ResultElemTy == I32 ? "i" : "f");
487505
newFuncName << "dpas_" << OperandsIt->second.str() << "8_" << M;
488506

IGC/Compiler/Optimizer/OpenCLPasses/SpvSubgroupMMAResolution/SpvSubgroupMMAResolution.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SpvSubgroupMMAResolution final : public llvm::ModulePass, public llvm::Ins
7272
bool validateI32Constant(const llvm::Value *V, const llvm::Twine &ParamName, const llvm::CallInst &CI);
7373
bool validateCType(const llvm::Type *ResultTy, const llvm::Type *CType, const llvm::CallInst &CI);
7474
bool validateElementType(const ElType ElemTy, llvm::StringRef ParamName, const llvm::CallInst &CI);
75-
bool validateElemCounts(int M, int AElemCount, int BElemCount, uint32_t Operands, const llvm::CallInst &CI);
75+
bool validateElemCounts(int M, int AElemCount, int BElemCount, uint32_t Operands, llvm::CallInst &CI);
7676

7777
template <typename T>
7878
bool validateKDimInTable(const T KIt, int K, const SupportedTable *table, const llvm::CallInst &CI);
@@ -89,6 +89,8 @@ class SpvSubgroupMMAResolution final : public llvm::ModulePass, public llvm::Ins
8989
bool validateOperands(const T OpIt, int K, ElType ResultElemTy, ElType AElemTy, ElType BElemTy, uint32_t Operands,
9090
const OperandsTable &operandMap, const llvm::CallInst &CI);
9191

92+
bool isDoubleSubgroup(llvm::CallInst &CI);
93+
9294
llvm::DenseSet<llvm::Function *> m_BuiltinsToRemove;
9395
bool m_Changed = false;
9496
IGC::CodeGenContext *m_Ctx = nullptr;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
; UNSUPPORTED: system-windows
9+
; REQUIRES: debug, llvm-14-plus
10+
; RUN: not igc_opt --opaque-pointers -platformpvc --igc-arith-funcs-translation -S < %s 2>&1 | FileCheck %s
11+
; ------------------------------------------------
12+
; DpasFuncsResolution
13+
; ------------------------------------------------
14+
15+
; Check assertion unique to DPAS in double-subgroup size.
16+
17+
; CHECK: RC >= 2, ICE: repeat count of DPAS for double subgroup-size must be >= 2!
18+
19+
define spir_kernel void @test_dpas(<4 x i32> %src, i32 %src2, ptr %dst) {
20+
%1 = load i16, ptr %dst, align 4
21+
%2 = call i32 @__builtin_IB_sub_group32n16_idpas_s8_s8_8_1(i32 %src2, i16 %1, <4 x i32> %src)
22+
store i32 %2, ptr %dst, align 4
23+
ret void
24+
}
25+
26+
declare i32 @__builtin_IB_sub_group32n16_idpas_s8_s8_8_1(i32, i16, <4 x i32>)

0 commit comments

Comments
 (0)