Skip to content

Commit baa517d

Browse files
authored
[SYCL] Pass SPIR-V extensions explicitly to jit compiler (#17359)
Resolves #16597 This patch also adds few other missing options --------- Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
1 parent fc4f5ee commit baa517d

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10769,6 +10769,8 @@ static void getNonTripleBasedSPIRVTransOpts(Compilation &C,
1076910769
// to user supplied options.
1077010770
// NOTE: Any changes made here should be reflected in the similarly named
1077110771
// function in clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp.
10772+
// NOTE2: JIT related changes made here should be reflected in 'translatorOpts'
10773+
// from sycl-jit/jit-compiler/lib/translation/SPIRVLLVMTranslation.cpp.
1077210774
static void getTripleBasedSPIRVTransOpts(Compilation &C,
1077310775
const llvm::opt::ArgList &TCArgs,
1077410776
llvm::Triple Triple,

sycl-jit/jit-compiler/lib/translation/SPIRVLLVMTranslation.cpp

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,78 @@ using namespace jit_compiler::translation;
2323
using namespace llvm;
2424

2525
SPIRV::TranslatorOpts &SPIRVLLVMTranslator::translatorOpts() {
26-
static auto Opts = []() -> SPIRV::TranslatorOpts {
26+
// Keep this in sync with clang/lib/Driver/ToolChains/Clang.cpp
27+
// TODO: consider introducing a config file that both clang and jit-compiler
28+
// could use during options setting.
29+
std::vector<SPIRV::ExtensionID> AllowedExtensions{
30+
SPIRV::ExtensionID::SPV_EXT_shader_atomic_float_add,
31+
SPIRV::ExtensionID::SPV_EXT_shader_atomic_float_min_max,
32+
SPIRV::ExtensionID::SPV_KHR_no_integer_wrap_decoration,
33+
SPIRV::ExtensionID::SPV_KHR_float_controls,
34+
SPIRV::ExtensionID::SPV_KHR_expect_assume,
35+
SPIRV::ExtensionID::SPV_KHR_linkonce_odr,
36+
SPIRV::ExtensionID::SPV_INTEL_subgroups,
37+
SPIRV::ExtensionID::SPV_INTEL_media_block_io,
38+
SPIRV::ExtensionID::SPV_INTEL_device_side_avc_motion_estimation,
39+
SPIRV::ExtensionID::SPV_INTEL_fpga_loop_controls,
40+
SPIRV::ExtensionID::SPV_INTEL_unstructured_loop_controls,
41+
SPIRV::ExtensionID::SPV_INTEL_fpga_reg,
42+
SPIRV::ExtensionID::SPV_INTEL_blocking_pipes,
43+
SPIRV::ExtensionID::SPV_INTEL_function_pointers,
44+
SPIRV::ExtensionID::SPV_INTEL_kernel_attributes,
45+
SPIRV::ExtensionID::SPV_INTEL_io_pipes,
46+
SPIRV::ExtensionID::SPV_INTEL_inline_assembly,
47+
SPIRV::ExtensionID::SPV_INTEL_arbitrary_precision_integers,
48+
SPIRV::ExtensionID::SPV_INTEL_float_controls2,
49+
SPIRV::ExtensionID::SPV_INTEL_vector_compute,
50+
SPIRV::ExtensionID::SPV_INTEL_fast_composite,
51+
SPIRV::ExtensionID::SPV_INTEL_arbitrary_precision_fixed_point,
52+
SPIRV::ExtensionID::SPV_INTEL_arbitrary_precision_floating_point,
53+
SPIRV::ExtensionID::SPV_INTEL_variable_length_array,
54+
SPIRV::ExtensionID::SPV_INTEL_fp_fast_math_mode,
55+
SPIRV::ExtensionID::SPV_INTEL_long_composites,
56+
SPIRV::ExtensionID::SPV_INTEL_arithmetic_fence,
57+
SPIRV::ExtensionID::SPV_INTEL_global_variable_decorations,
58+
SPIRV::ExtensionID::SPV_INTEL_cache_controls,
59+
SPIRV::ExtensionID::SPV_INTEL_fpga_buffer_location,
60+
SPIRV::ExtensionID::SPV_INTEL_fpga_argument_interfaces,
61+
SPIRV::ExtensionID::SPV_INTEL_fpga_invocation_pipelining_attributes,
62+
SPIRV::ExtensionID::SPV_INTEL_fpga_latency_control,
63+
SPIRV::ExtensionID::SPV_KHR_shader_clock,
64+
SPIRV::ExtensionID::SPV_INTEL_bindless_images,
65+
SPIRV::ExtensionID::SPV_INTEL_task_sequence,
66+
SPIRV::ExtensionID::SPV_INTEL_bfloat16_conversion,
67+
SPIRV::ExtensionID::SPV_INTEL_joint_matrix,
68+
SPIRV::ExtensionID::SPV_INTEL_hw_thread_queries,
69+
SPIRV::ExtensionID::SPV_KHR_uniform_group_instructions,
70+
SPIRV::ExtensionID::SPV_INTEL_masked_gather_scatter,
71+
SPIRV::ExtensionID::SPV_INTEL_tensor_float32_conversion,
72+
SPIRV::ExtensionID::SPV_INTEL_optnone,
73+
SPIRV::ExtensionID::SPV_KHR_non_semantic_info,
74+
SPIRV::ExtensionID::SPV_KHR_cooperative_matrix,
75+
SPIRV::ExtensionID::SPV_EXT_shader_atomic_float16_add,
76+
SPIRV::ExtensionID::SPV_INTEL_fp_max_error};
77+
78+
static auto Opts = [&]() -> SPIRV::TranslatorOpts {
2779
// Options for translation between SPIR-V and LLVM IR.
28-
// Set SPIRV-V 1.4 as the maximum version number for now.
80+
// Set SPIRV-V 1.5 as the maximum version number for now.
2981
// Note that some parts of the code depend on the available builtins, e.g.,
3082
// passes/kernel-fusion/Builtins.cpp, so updating the SPIR-V version should
3183
// involve revisiting that code.
32-
SPIRV::TranslatorOpts TransOpt{SPIRV::VersionNumber::SPIRV_1_4};
84+
SPIRV::TranslatorOpts TransOpt{SPIRV::VersionNumber::SPIRV_1_5};
3385
// Enable attachment of kernel arg names as metadata.
3486
TransOpt.enableGenArgNameMD();
3587
// Enable mem2reg.
3688
TransOpt.setMemToRegEnabled(true);
37-
// Enable all extensions.
38-
// TODO: Specifically enable only the
39-
// extensions listed in the KernelInfo.
40-
// FIXME: Because there's no size provided,
41-
// there's currently no obvious way to iterate the
42-
// array of extensions in KernelInfo.
43-
TransOpt.enableAllExtensions();
44-
// TODO: Remove this workaround.
45-
TransOpt.setAllowedToUseExtension(
46-
SPIRV::ExtensionID::SPV_KHR_untyped_pointers, false);
89+
for (auto &Ext : AllowedExtensions)
90+
TransOpt.setAllowedToUseExtension(Ext, true);
4791
TransOpt.setDesiredBIsRepresentation(
4892
SPIRV::BIsRepresentation::SPIRVFriendlyIR);
93+
TransOpt.setDebugInfoEIS(
94+
SPIRV::DebugInfoEIS::NonSemantic_Shader_DebugInfo_200);
95+
const llvm::SmallVector<llvm::StringRef, 4> AllowedIntrinsics = {
96+
"llvm.genx."};
97+
TransOpt.setSPIRVAllowUnknownIntrinsics(AllowedIntrinsics);
4998
// TODO: We need to take care of specialization constants, either by
5099
// instantiating them by the user-supplied value from the SYCL runtime or by
51100
// making sure they are correctly represented in the output of the fusion

0 commit comments

Comments
 (0)