Skip to content

Commit 07fbf02

Browse files
vmustyaigcbot
authored andcommitted
Platform checker for VC internal intrinsics
VC should check the platform for internal intrinsics and emit an error during codegen, if the intrinsic is not supported by the platform. The new checker is implemented on top of the existing subtarget feature set.
1 parent c8a7ccf commit 07fbf02

File tree

9 files changed

+240
-18
lines changed

9 files changed

+240
-18
lines changed

IGC/VectorCompiler/include/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#=========================== begin_copyright_notice ============================
22
#
3-
# Copyright (C) 2020-2021 Intel Corporation
3+
# Copyright (C) 2020-2024 Intel Corporation
44
#
55
# SPDX-License-Identifier: MIT
66
#
@@ -17,7 +17,8 @@ target_include_directories(VCHeaders
1717
INTERFACE
1818
${CMAKE_CURRENT_SOURCE_DIR}
1919
${CMAKE_CURRENT_BINARY_DIR}
20-
)
20+
${CMAKE_CURRENT_BINARY_DIR}/vc/InternalIntrinsics
21+
)
2122

2223
add_dependencies(VCHeaders
2324
intrinsics_gen

IGC/VectorCompiler/include/vc/InternalIntrinsics/Intrinsic_definitions.py

Lines changed: 131 additions & 3 deletions
Large diffs are not rendered by default.

IGC/VectorCompiler/include/vc/InternalIntrinsics/Intrinsics.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# ========================== begin_copyright_notice ============================
44
#
5-
# Copyright (C) 2022-2023 Intel Corporation
5+
# Copyright (C) 2022-2024 Intel Corporation
66
#
77
# SPDX-License-Identifier: MIT
88
#
@@ -416,6 +416,72 @@ def createAttributeTable():
416416
"#endif // GET_INTRINSIC_ATTRIBUTES\n\n")
417417
f.close()
418418

419+
def createPlatformTable():
420+
key = 'target'
421+
422+
# Collect all the required target features
423+
targetFeatures = set()
424+
for desc in Intrinsics.values():
425+
feat = [x[1:] if x[0] == '!' else x for x in desc.get(key, [])]
426+
targetFeatures.update(feat)
427+
428+
# Create bit mask for each target feature
429+
targetFeatureMap = {feature: 1 << i for i, feature in enumerate(sorted(targetFeatures))}
430+
431+
# Generate the tables
432+
tableRequired = []
433+
tableForbidden = []
434+
for i in range(len(ID_array)):
435+
desc = Intrinsics[ID_array[i]]
436+
features = desc.get(key, [])
437+
438+
required = [feature for feature in features if not feature.startswith('!')]
439+
tableRequired.append(reduce(lambda acc, feature: acc | targetFeatureMap[feature], required, 0))
440+
441+
forbidden = [feature[1:] for feature in features if feature.startswith('!')]
442+
tableForbidden.append(reduce(lambda acc, feature: acc | targetFeatureMap[feature], forbidden, 0))
443+
444+
numFeatures = len(targetFeatureMap)
445+
assert numFeatures <= 64, "Too many target features"
446+
447+
storageType = 'uint64_t'
448+
if numFeatures <= 8:
449+
storageType = 'uint8_t'
450+
elif numFeatures <= 16:
451+
storageType = 'uint16_t'
452+
elif numFeatures <= 32:
453+
storageType = 'uint32_t'
454+
455+
# Write the table to the output file
456+
with open(outputFile, 'a') as f:
457+
f.write("// Platform table\n"
458+
"#ifdef GET_INTRINSIC_TARGET_FEATURE_TABLE\n"
459+
f"static const {storageType} RequiredTargetFeatures[] = " "{\n")
460+
461+
for i, mask in enumerate(tableRequired):
462+
f.write(" 0x{:x}, // llvm.vc.internal.{}\n".format(mask, ID_array[i].replace("_", ".")))
463+
464+
f.write("};\n"
465+
f"static const {storageType} ForbiddenTargetFeatures[] = " "{\n")
466+
467+
for i, mask in enumerate(tableForbidden):
468+
f.write(" 0x{:x}, // llvm.vc.internal.{}\n".format(mask, ID_array[i].replace("_", ".")))
469+
470+
f.write("};\n"
471+
"#endif // GET_INTRINSIC_TARGET_FEATURE_TABLE\n\n")
472+
473+
f.write("// Checker for platform features\n"
474+
"#ifdef GET_INTRINSIC_TARGET_FEATURE_CHECKER\n"
475+
"unsigned Index = ID - 1 - vc::InternalIntrinsic::not_internal_intrinsic;\n"
476+
"auto MaskRequired = RequiredTargetFeatures[Index];\n"
477+
"auto MaskForbidden = ForbiddenTargetFeatures[Index];\n")
478+
479+
for feature, mask in targetFeatureMap.items():
480+
f.write(f"if ((MaskRequired & {mask}) && !{feature}()) return false;\n"
481+
f"if ((MaskForbidden & {mask}) && {feature}()) return false;\n")
482+
f.write("#endif // GET_INTRINSIC_TARGET_FEATURE_CHECKER\n\n")
483+
484+
419485
def emitSuffix():
420486
f = open(outputFile,"a")
421487
f.write("#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
@@ -435,4 +501,5 @@ def emitSuffix():
435501
createOverloadRetTable()
436502
createTypeTable()
437503
createAttributeTable()
504+
createPlatformTable()
438505
emitSuffix()

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,12 +2685,11 @@ bool GenXKernelBuilder::buildMainInst(Instruction *Inst, BaleInfo BI,
26852685
Function *Callee = CI->getCalledFunction();
26862686
unsigned IntrinID = vc::getAnyIntrinsicID(Callee);
26872687

2688-
if (GenXIntrinsic::isGenXIntrinsic(IntrinID) &&
2689-
!GenXIntrinsic::isSupportedPlatform(Subtarget->getCPU().str(),
2690-
IntrinID)) {
2688+
if (vc::isAnyNonTrivialIntrinsic(IntrinID) &&
2689+
!Subtarget->isIntrinsicSupported(IntrinID)) {
26912690
vc::diagnose(getContext(), "GenXCisaBuilder",
2692-
"Intrinsic is not supported by <" + Subtarget->getCPU() +
2693-
"> platform",
2691+
"Intrinsic is not supported by the <" +
2692+
Subtarget->getCPU() + "> platform",
26942693
Inst);
26952694
}
26962695

IGC/VectorCompiler/lib/GenXCodeGen/GenXSubtarget.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2023 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -11,18 +11,21 @@ SPDX-License-Identifier: MIT
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "IGC/common/StringMacros.hpp"
15-
1614
#include "GenXSubtarget.h"
17-
#include "common/StringMacros.hpp"
15+
16+
#include "vc/Utils/GenX/IntrinsicsWrapper.h"
17+
1818
#include "llvm/CodeGen/MachineFunction.h"
1919
#include "llvm/IR/Attributes.h"
2020
#include "llvm/IR/Function.h"
2121
#include "llvm/IR/GlobalValue.h"
2222
#include "llvm/IR/InstrTypes.h"
2323
#include "llvm/Target/TargetMachine.h"
2424
#include "llvm/Target/TargetOptions.h"
25+
26+
#include "IGC/common/StringMacros.hpp"
2527
#include "Probe/Assertion.h"
28+
#include "common/StringMacros.hpp"
2629

2730
using namespace llvm;
2831

@@ -251,3 +254,23 @@ TARGET_PLATFORM GenXSubtarget::getVisaPlatform() const {
251254
return TARGET_PLATFORM::GENX_NONE;
252255
}
253256
}
257+
258+
bool GenXSubtarget::isIntrinsicSupported(unsigned ID) const {
259+
if (vc::InternalIntrinsic::isInternalIntrinsic(ID))
260+
return isInternalIntrinsicSupported(ID);
261+
if (GenXIntrinsic::isGenXIntrinsic(ID))
262+
return GenXIntrinsic::isSupportedPlatform(getCPU().str(), ID);
263+
return ID < Intrinsic::num_intrinsics;
264+
}
265+
266+
bool GenXSubtarget::isInternalIntrinsicSupported(unsigned ID) const {
267+
IGC_ASSERT(vc::InternalIntrinsic::isInternalIntrinsic(ID));
268+
269+
#define GET_INTRINSIC_TARGET_FEATURE_TABLE
270+
#define GET_INTRINSIC_TARGET_FEATURE_CHECKER
271+
#include "InternalIntrinsicDescription.gen"
272+
#undef GET_INTRINSIC_TARGET_FEATURE_TABLE
273+
#undef GET_INTRINSIC_TARGET_FEATURE_CHECKER
274+
275+
return true;
276+
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ class GenXSubtarget final : public GenXGenSubtargetInfo {
270270
// \brief Initialize the features for the GenX target.
271271
void initSubtargetFeatures(StringRef CPU, StringRef FS);
272272

273+
bool isInternalIntrinsicSupported(unsigned ID) const;
274+
273275
public:
274276
/// * translateMediaWalker - true if translate media walker APIs
275277
bool translateMediaWalker() const { return !HasMediaWalker; }
@@ -442,6 +444,8 @@ class GenXSubtarget final : public GenXGenSubtargetInfo {
442444

443445
/// * stackSurface - return a surface that should be used for stack.
444446
PreDefined_Surface stackSurface() const { return StackSurf; }
447+
448+
bool isIntrinsicSupported(unsigned ID) const;
445449
};
446450

447451
} // namespace llvm

IGC/VectorCompiler/test/CisaBuilder/dpas/dpas-nosrc0.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
; CHECK-XeHPCVG: GenXCisaBuilder failed for:
2222
; CHECK-XeHPCVG-SAME: %acc = call <16 x i32> @llvm.genx.dpas.nosrc0.v16i32.v128i32.v8i32(<128 x i32> %src1, <8 x i32> %src2, i32 17303560)
23-
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by <XeHPCVG> platform
23+
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by the <XeHPCVG> platform
2424

2525
; COM: ;;;;;;;;;; KERNEL ;;;;;;;;;;
2626

IGC/VectorCompiler/test/CisaBuilder/dpas/dpas.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
; CHECK-XeHPCVG: error: LLVM ERROR: GenXCisaBuilder failed for:
2222
; CHECK-XeHPCVG-SAME: %acc.1 = call <16 x i32> @llvm.genx.dpas.v16i32.v16i32.v128i32.v8i32(<16 x i32> %acc.0, <128 x i32> %src1, <8 x i32> %src2, i32 17303560)
23-
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by <XeHPCVG> platform
23+
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by the <XeHPCVG> platform
2424

2525

2626
; COM: ;;;;;;;;;; KERNEL ;;;;;;;;;;

IGC/VectorCompiler/test/CisaBuilder/dpas/dpas2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
; CHECK-XeHPCVG: error: LLVM ERROR: GenXCisaBuilder failed for:
2222
; CHECK-XeHPCVG-SAME: %acc.1 = call <16 x i32> @llvm.genx.dpas2.v16i32.v16i32.v128i32.v8i32(<16 x i32> %acc.0, <128 x i32> %src1, <8 x i32> %src2, i32 8, i32 8, i32 8, i32 1, i32 1, i32 1)
23-
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by <XeHPCVG> platform
23+
; CHECK-XeHPCVG-SAME: Intrinsic is not supported by the <XeHPCVG> platform
2424

2525

2626
; COM: ;;;;;;;;;; KERNEL ;;;;;;;;;;

0 commit comments

Comments
 (0)