Skip to content

Commit 02372e4

Browse files
authored
[SYCL][SPIRV] Enable only required extensions for SPIRV Backend. (#20584)
SPIR-V backend recently started to support extensions not supported by drivers (e.g. SPV_KHR_float_controls2). At the same time, SPIR-V backend doesn't support the syntax for disabling specific extensions (i.e. --spirv-ext=-<extension>). We need to come up with a list of SPIR-V extensions that are supported by the backend, but also by the driver. This patch introduces the first approach for such a list.
1 parent e502f46 commit 02372e4

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10446,12 +10446,48 @@ static void getSPIRVBackendOpts(const llvm::opt::ArgList &TCArgs,
1044610446
TCArgs.MakeArgString("--avoid-spirv-capabilities=Shader"));
1044710447
BackendArgs.push_back(
1044810448
TCArgs.MakeArgString("--translator-compatibility-mode"));
10449-
// TODO: A list of SPIR-V extensions that are supported by the SPIR-V backend
10450-
// is growing. Let's postpone the decision on which extensions to enable until
10451-
// - the list is stable, and
10452-
// - we decide on a mapping of user requested extensions into backend's ones.
10453-
// Meanwhile we enable all the SPIR-V backend extensions.
10454-
BackendArgs.push_back(TCArgs.MakeArgString("--spirv-ext=all"));
10449+
10450+
// SPIR-V backend recently started to support extensions not supported by
10451+
// drivers (e.g. SPV_KHR_float_controls2). At the same time, SPIR-V backend
10452+
// doesn't support the syntax for disabling specific extensions (i.e.
10453+
// --spirv-ext=-<extension>). We need to come up with a list of SPIR-V
10454+
// extensions that are supported by the backend, but also by the driver. Below
10455+
// is the first approach for such a list.
10456+
// FIXME: A priori, we wouldn't expect
10457+
// SPV_EXT_relaxed_printf_string_address_space to be required, but without
10458+
// it, some SYCL E2E tests fail. Let's keep it until we figure out what's
10459+
// the problem.
10460+
std::string ExtArg("-spirv-ext=");
10461+
std::string DefaultExtArg = "+SPV_EXT_relaxed_printf_string_address_space"
10462+
",+SPV_EXT_shader_atomic_float16_add"
10463+
",+SPV_EXT_shader_atomic_float_add"
10464+
",+SPV_EXT_shader_atomic_float_min_max";
10465+
std::string IntelExtArg = ",+SPV_INTEL_2d_block_io"
10466+
",+SPV_INTEL_arbitrary_precision_integers"
10467+
",+SPV_INTEL_bfloat16_conversion"
10468+
",+SPV_INTEL_bindless_images"
10469+
",+SPV_INTEL_cache_controls"
10470+
",+SPV_INTEL_float_controls2"
10471+
",+SPV_INTEL_fp_max_error"
10472+
",+SPV_INTEL_function_pointers"
10473+
",+SPV_INTEL_inline_assembly"
10474+
",+SPV_INTEL_joint_matrix"
10475+
",+SPV_INTEL_long_composites"
10476+
",+SPV_INTEL_subgroups"
10477+
",+SPV_INTEL_tensor_float32_conversion"
10478+
",+SPV_INTEL_variable_length_array";
10479+
std::string KHRExtArg = ",+SPV_KHR_16bit_storage"
10480+
",+SPV_KHR_cooperative_matrix"
10481+
",+SPV_KHR_expect_assume"
10482+
",+SPV_KHR_float_controls"
10483+
",+SPV_KHR_linkonce_odr"
10484+
",+SPV_KHR_no_integer_wrap_decoration"
10485+
",+SPV_KHR_non_semantic_info"
10486+
",+SPV_KHR_shader_clock"
10487+
",+SPV_KHR_uniform_group_instructions";
10488+
ExtArg = ExtArg + DefaultExtArg + IntelExtArg + KHRExtArg;
10489+
BackendArgs.push_back(TCArgs.MakeArgString(ExtArg));
10490+
1045510491
// TODO:
1045610492
// - handle -Xspirv-translator option to avoid "argument unused during
1045710493
// compilation" error

clang/test/Driver/sycl-spirv-backend.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,31 @@
33
///
44
// RUN: %clangxx -fsycl -fsycl-use-spirv-backend-for-spirv-gen -### %s 2>&1 | FileCheck %s
55

6-
// CHECK: llc{{.*}} "-filetype=obj" "-mtriple=spirv64{{[^-]*}}-unknown-unknown" "--avoid-spirv-capabilities=Shader" "--translator-compatibility-mode" "--spirv-ext=
6+
// CHECK: llc{{.*}} "-filetype=obj" "-mtriple=spirv64{{[^-]*}}-unknown-unknown" "--avoid-spirv-capabilities=Shader" "--translator-compatibility-mode" "-spirv-ext=
7+
// CHECK-SAME: +SPV_EXT_relaxed_printf_string_address_space
8+
// CHECK-SAME:,+SPV_EXT_shader_atomic_float16_add
9+
// CHECK-SAME:,+SPV_EXT_shader_atomic_float_add
10+
// CHECK-SAME:,+SPV_EXT_shader_atomic_float_min_max
11+
// CHECK-SAME:,+SPV_INTEL_2d_block_io
12+
// CHECK-SAME:,+SPV_INTEL_arbitrary_precision_integers
13+
// CHECK-SAME:,+SPV_INTEL_bfloat16_conversion
14+
// CHECK-SAME:,+SPV_INTEL_bindless_images
15+
// CHECK-SAME:,+SPV_INTEL_cache_controls
16+
// CHECK-SAME:,+SPV_INTEL_float_controls2
17+
// CHECK-SAME:,+SPV_INTEL_fp_max_error
18+
// CHECK-SAME:,+SPV_INTEL_function_pointers
19+
// CHECK-SAME:,+SPV_INTEL_inline_assembly
20+
// CHECK-SAME:,+SPV_INTEL_joint_matrix
21+
// CHECK-SAME:,+SPV_INTEL_long_composites
22+
// CHECK-SAME:,+SPV_INTEL_subgroups
23+
// CHECK-SAME:,+SPV_INTEL_tensor_float32_conversion
24+
// CHECK-SAME:,+SPV_INTEL_variable_length_array
25+
// CHECK-SAME:,+SPV_KHR_16bit_storage
26+
// CHECK-SAME:,+SPV_KHR_cooperative_matrix
27+
// CHECK-SAME:,+SPV_KHR_expect_assume
28+
// CHECK-SAME:,+SPV_KHR_float_controls
29+
// CHECK-SAME:,+SPV_KHR_linkonce_odr
30+
// CHECK-SAME:,+SPV_KHR_no_integer_wrap_decoration
31+
// CHECK-SAME:,+SPV_KHR_non_semantic_info
32+
// CHECK-SAME:,+SPV_KHR_shader_clock
33+
// CHECK-SAME:,+SPV_KHR_uniform_group_instructions"

0 commit comments

Comments
 (0)