Skip to content

Commit 335b7a0

Browse files
jzcKornevNikita
andauthored
[SYCL] Add device config file consistency test (#16369)
Co-authored-by: Kornev, Nikita <[email protected]>
1 parent b437083 commit 335b7a0

File tree

10 files changed

+180
-16
lines changed

10 files changed

+180
-16
lines changed

buildbot/configure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def do_configure(args, passthrough_args):
6666
xpti_enable_werror = "OFF"
6767
llvm_enable_zstd = "ON"
6868
spirv_enable_dis = "OFF"
69+
sycl_install_device_config_file = "OFF"
6970

7071
if sys.platform != "darwin":
7172
# For more info on the enablement of level_zero_v2 refer to this document:
@@ -160,6 +161,7 @@ def do_configure(args, passthrough_args):
160161
libclc_targets_to_build += libclc_nvidia_target_names
161162
libclc_gen_remangled_variants = "ON"
162163
spirv_enable_dis = "ON"
164+
sycl_install_device_config_file = "ON"
163165

164166
if args.enable_backends:
165167
sycl_enabled_backends += args.enable_backends
@@ -208,6 +210,7 @@ def do_configure(args, passthrough_args):
208210
"-DSYCL_ENABLE_EXTENSION_JIT={}".format(sycl_enable_jit),
209211
"-DSYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB={}".format(sycl_preview_lib),
210212
"-DBUG_REPORT_URL=https://github.com/intel/llvm/issues",
213+
"-DSYCL_INSTALL_DEVICE_CONFIG_FILE={}".format(sycl_install_device_config_file),
211214
]
212215

213216
if libclc_enabled:

llvm/include/llvm/SYCLLowerIR/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ set(LLVM_TABLEGEN_PROJECT LLVM)
66
set(LLVM_TARGET_DEFINITIONS DeviceConfigFile.td)
77
tablegen(LLVM DeviceConfigFile.inc -gen-dynamic-tables)
88
add_public_tablegen_target(DeviceConfigFile)
9+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/DeviceConfigFile.hpp"
10+
"${CMAKE_CURRENT_BINARY_DIR}/DeviceConfigFile.inc"
11+
DESTINATION include/llvm/SYCLLowerIR
12+
COMPONENT DeviceConfigFile)

llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#include <map>
1010
#include <string>
11+
#include <string_view>
1112
#include <vector>
1213

13-
namespace llvm {
14-
class StringRef;
15-
}
16-
1714
namespace DeviceConfigFile {
1815

1916
// This struct is used in DeviceConfigFile.td. Both the fields and the name of
@@ -22,7 +19,7 @@ namespace DeviceConfigFile {
2219
// DeviceConfigFile.td.
2320
struct TargetInfo {
2421
bool maySupportOtherAspects;
25-
std::vector<llvm::StringRef> aspects;
22+
std::vector<std::string_view> aspects;
2623
std::vector<unsigned> subGroupSizes;
2724
std::string aotToolchain;
2825
std::string aotToolchainOptions;

llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,18 @@ defvar IntelCpuAspects = [
177177
AspectExt_oneapi_srgb, AspectExt_oneapi_native_assert,
178178
AspectExt_intel_legacy_image, AspectExt_oneapi_ballot_group,
179179
AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group,
180-
AspectExt_oneapi_tangle_group, AspectExt_oneapi_private_alloca
180+
AspectExt_oneapi_tangle_group, AspectExt_oneapi_private_alloca,
181+
AspectOnline_compiler, AspectOnline_linker, AspectExt_intel_gpu_slices,
182+
AspectExt_intel_gpu_subslices_per_slice, AspectExt_intel_gpu_eu_count_per_subslice,
183+
AspectExt_intel_gpu_hw_threads_per_eu, AspectExt_intel_device_id,
184+
AspectExt_oneapi_virtual_functions
181185
] # AllUSMAspects;
182186

183187
def : TargetInfo<"spir64", [], [], "", "", 1>;
184188
def : TargetInfo<"spir64_gen", [], [], "", "", 1>;
185189
def : TargetInfo<"spir64_x86_64", IntelCpuAspects, [4, 8, 16, 32, 64], "", "", 1>;
186190
def : TargetInfo<"spir64_fpga", [], [], "", "", 1>;
187-
def : TargetInfo<"x86_64", [], [], "", "", 1>;
191+
def : TargetInfo<"x86_64", IntelCpuAspects, [4, 8, 16, 32, 64], "", "", 1>;
188192
// Examples of how to use a combination of explicitly specified values + predefined lists
189193
//defvar AspectList = [AspectCpu] # AllUSMAspects;
190194
//def : TargetInfo<"Test", AspectList, []>;
@@ -196,9 +200,11 @@ defvar Fp16Fp64Atomic64 = [AspectFp16, AspectFp64, AspectAtomic64];
196200
defvar Fp16Atomic64 = [AspectFp16, AspectAtomic64];
197201
defvar Sg8_16_32 = [8, 16, 32];
198202
defvar Sg16_32 = [16, 32];
199-
defvar IntelBaseAspects = [AspectExt_intel_esimd];
203+
defvar IntelGPUBaseAspects = [AspectExt_intel_esimd, AspectExt_oneapi_ballot_group,
204+
AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group,
205+
AspectExt_oneapi_tangle_group];
200206
class IntelTargetInfo<string Name, list<Aspect> Aspects, list<int> subGroupSizesList>
201-
: TargetInfo<Name, IntelBaseAspects # Aspects, subGroupSizesList>;
207+
: TargetInfo<Name, IntelGPUBaseAspects # Aspects, subGroupSizesList>;
202208
// Note: only the "canonical" target names are listed here - see
203209
// SYCL::gen::resolveGenDevice().
204210
//
@@ -268,7 +274,7 @@ defvar CudaMinUSMAspects = [AspectUsm_device_allocations, AspectUsm_host_allocat
268274
defvar CudaSM90USMAspects = [AspectUsm_system_allocations, AspectUsm_atomic_host_allocations, AspectUsm_atomic_shared_allocations];
269275

270276
defvar CudaMinAspects = !listconcat(CudaMinUSMAspects, [AspectGpu, AspectFp64, AspectOnline_compiler, AspectOnline_linker,
271-
AspectQueue_profiling, AspectExt_intel_pci_address, AspectExt_intel_max_mem_bandwidth, AspectExt_intel_memory_bus_width,
277+
AspectQueue_profiling, AspectExt_intel_pci_address, AspectExt_intel_memory_bus_width,
272278
AspectExt_intel_device_info_uuid, AspectExt_oneapi_native_assert, AspectExt_intel_free_memory, AspectExt_intel_device_id,
273279
AspectExt_intel_memory_clock_rate, AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group,
274280
AspectExt_oneapi_opportunistic_group, AspectExt_oneapi_graph, AspectExt_oneapi_limited_graph]);
@@ -325,9 +331,9 @@ defvar HipSubgroupSizesCDNA = [64]; // gfx908, gfx90a (encapsulates CDNA1..2
325331

326332
defvar HipMinAspects = [AspectGpu, AspectFp16, AspectFp64,
327333
AspectOnline_compiler, AspectOnline_linker, AspectQueue_profiling,
328-
AspectExt_intel_pci_address, AspectExt_intel_max_mem_bandwidth,
329-
AspectExt_intel_device_id, AspectExt_intel_memory_clock_rate,
330-
AspectExt_intel_memory_bus_width, AspectExt_intel_free_memory];
334+
AspectExt_intel_pci_address, AspectExt_intel_device_id,
335+
AspectExt_intel_memory_clock_rate, AspectExt_intel_memory_bus_width,
336+
AspectExt_intel_free_memory];
331337

332338
defvar HipUSMAspects = !listremove(AllUSMAspects, [AspectUsm_system_allocations]);
333339
defvar HipGraphAspects = [AspectExt_oneapi_graph, AspectExt_oneapi_limited_graph];

sycl/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,11 @@ if("hip" IN_LIST SYCL_ENABLE_BACKENDS)
547547
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS ur_adapter_hip)
548548
endif()
549549

550+
if(SYCL_INSTALL_DEVICE_CONFIG_FILE)
551+
add_dependencies(sycl-toolchain DeviceConfigFile)
552+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS DeviceConfigFile)
553+
endif()
554+
550555
# Use it as fake dependency in order to force another command(s) to execute.
551556
add_custom_command(OUTPUT __force_it
552557
COMMAND "${CMAKE_COMMAND}" -E echo
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// This test checks to see if every aspect and sub-group size declared in the
2+
// device config file is supported by the device. Note this does not mean
3+
// check that the device config file is exhaustive, only that the device
4+
// supports everything it declares. However, this test does print out any
5+
// aspects that are supported by the device but not declared in the device
6+
// config file.
7+
8+
// REQUIRES: device-config-file
9+
// RUN: %{build} -o %t.out %device_config_file_include_flag
10+
// RUN: %{run} %t.out
11+
#include <map>
12+
13+
#include <llvm/SYCLLowerIR/DeviceConfigFile.hpp>
14+
#include <sycl/detail/core.hpp>
15+
16+
#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE) \
17+
__SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE)
18+
19+
using namespace sycl;
20+
21+
const char *getArchName(const device &Device) {
22+
namespace syclex = sycl::ext::oneapi::experimental;
23+
auto Arch = Device.get_info<syclex::info::device::architecture>();
24+
switch (Arch) {
25+
#define __SYCL_ARCHITECTURE(ARCH, VAL) \
26+
case syclex::architecture::ARCH: \
27+
return #ARCH;
28+
#define __SYCL_ARCHITECTURE_ALIAS(ARCH, VAL)
29+
#include <sycl/ext/oneapi/experimental/device_architecture.def>
30+
#undef __SYCL_ARCHITECTURE
31+
#undef __SYCL_ARCHITECTURE_ALIAS
32+
}
33+
return "unknown";
34+
}
35+
36+
// Checks if a container contains a specific element.
37+
template <typename Container, typename T>
38+
bool contains(const Container &C, const T &Elem) {
39+
return std::find(C.begin(), C.end(), Elem) != C.end();
40+
}
41+
42+
std::string_view getAspectName(aspect Asp) {
43+
switch (Asp) {
44+
#define __SYCL_ASPECT(ASPECT, ID) \
45+
case aspect::ASPECT: \
46+
return #ASPECT;
47+
#include <sycl/info/aspects.def>
48+
#undef __SYCL_ASPECT
49+
}
50+
return "unknown";
51+
}
52+
53+
aspect getAspectByName(std::string_view Name) {
54+
#define __SYCL_ASPECT(ASPECT, ID) \
55+
if (Name == #ASPECT) \
56+
return aspect::ASPECT;
57+
#include <sycl/info/aspects.def>
58+
throw std::invalid_argument("Unknown aspect name");
59+
}
60+
61+
int main() {
62+
// Get the device arch.
63+
queue Q;
64+
auto Dev = Q.get_device();
65+
auto DeviceName = getArchName(Dev);
66+
67+
auto TargetInfo = DeviceConfigFile::TargetTable.find(DeviceName);
68+
if (TargetInfo == DeviceConfigFile::TargetTable.end()) {
69+
std::cout << "No aspects found for device " << DeviceName << "\n";
70+
return 1;
71+
}
72+
73+
// Check aspects consistency.
74+
int NAspectInconsistencies = 0;
75+
76+
auto SupportedAspects = Dev.get_info<info::device::aspects>();
77+
auto DeviceConfigAspectNames = TargetInfo->second.aspects;
78+
std::vector<aspect> DeviceConfigAspects;
79+
for (auto AspectName : DeviceConfigAspectNames) {
80+
DeviceConfigAspects.push_back(getAspectByName(AspectName));
81+
}
82+
83+
for (auto Asp : DeviceConfigAspects) {
84+
if (!contains(SupportedAspects, Asp)) {
85+
std::cout << "error: " << DeviceName << " does not support aspect "
86+
<< getAspectName(Asp)
87+
<< " but it is declared in the device config file\n";
88+
++NAspectInconsistencies;
89+
}
90+
}
91+
for (auto Asp : SupportedAspects) {
92+
if (!contains(DeviceConfigAspects, Asp)) {
93+
std::cout << "note: the device " << DeviceName << " supports aspect "
94+
<< getAspectName(Asp)
95+
<< " but it is not declared in the device config file\n";
96+
// Not necessarily an error, so we won't increment n_fail.
97+
}
98+
}
99+
100+
if (NAspectInconsistencies != 0) {
101+
std::cout << "Aspects are inconsistent\n";
102+
return 1;
103+
}
104+
105+
// Check sub-group sizes consistency.
106+
int NSubGroupSizeInconsistencies = 0;
107+
108+
auto SupportedSubGroupSizes = Dev.get_info<info::device::sub_group_sizes>();
109+
auto DeviceConfigSubGroupSizes = TargetInfo->second.subGroupSizes;
110+
111+
for (auto Size : DeviceConfigSubGroupSizes) {
112+
if (!contains(SupportedSubGroupSizes, Size)) {
113+
std::cout << "error: " << DeviceName
114+
<< " does not support sub-group size " << Size
115+
<< " but it is declared in the device config file\n";
116+
++NSubGroupSizeInconsistencies;
117+
}
118+
}
119+
for (auto Size : SupportedSubGroupSizes) {
120+
if (!contains(DeviceConfigSubGroupSizes, Size)) {
121+
std::cout << "note: the device " << DeviceName
122+
<< " supports sub-group size " << Size
123+
<< " but it is not declared in the device config file\n";
124+
// Not necessarily an error, so we won't increment n_fail.
125+
}
126+
}
127+
128+
if (NSubGroupSizeInconsistencies != 0) {
129+
std::cout << "Sub-group sizes are inconsistent\n";
130+
return 1;
131+
}
132+
133+
return 0;
134+
}
135+
136+
#undef __SYCL_ASPECT_DEPRECATED_ALIAS

sycl/test-e2e/E2EExpr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class E2EExpr(BooleanExpression):
4646
"false",
4747
"pdtracker",
4848
"ze_debug",
49+
"device-config-file",
4950
}
5051

5152
def __init__(self, string, variables, build_only_mode, final_unknown_value):

sycl/test-e2e/lit.cfg.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,18 @@ def get_sycl_ls_verbose(sycl_device, env):
932932

933933
for target in config.sycl_build_targets:
934934
config.available_features.add("any-target-is-" + target.replace("target-", ""))
935+
936+
if config.llvm_main_include_dir:
937+
lit_config.note("Using device config file built from LLVM")
938+
config.available_features.add("device-config-file")
939+
config.substitutions.append(
940+
("%device_config_file_include_flag", f"-I {config.llvm_main_include_dir}")
941+
)
942+
elif os.path.exists(f"{config.sycl_include}/llvm/SYCLLowerIR/DeviceConfigFile.hpp"):
943+
lit_config.note("Using installed device config file")
944+
config.available_features.add("device-config-file")
945+
config.substitutions.append(("%device_config_file_include_flag", ""))
946+
935947
# That has to be executed last so that all device-independent features have been
936948
# discovered already.
937949
config.sycl_dev_features = {}

sycl/test-e2e/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_dpcpp_tool_path(name):
1818
except subprocess.CalledProcessError:
1919
return os.path.join(config.dpcpp_bin_dir, name)
2020

21+
config.llvm_main_include_dir = "@LLVM_MAIN_INCLUDE_DIR@"
2122
config.llvm_tools_dir = os.path.dirname(get_dpcpp_tool_path("llvm-config"))
2223
config.lit_tools_dir = os.path.dirname("@TEST_SUITE_LIT@")
2324
config.dump_ir_supported = lit_config.params.get("dump_ir", ("@DUMP_IR_SUPPORTED@" if "@DUMP_IR_SUPPORTED@" else False))

sycl/test/basic_tests/device_config_file_aspects.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44
#include <map>
55

6-
#include <llvm/ADT/StringRef.h>
76
#include <llvm/SYCLLowerIR/DeviceConfigFile.hpp>
87
#include <sycl/sycl.hpp>
98

@@ -16,7 +15,7 @@ int main() {
1615
auto aspectsList = testAspects->second.aspects;
1716

1817
#define __SYCL_ASPECT(ASPECT, ASPECT_VAL) \
19-
llvm::StringRef s##ASPECT(#ASPECT); \
18+
std::string_view s##ASPECT(#ASPECT); \
2019
assert(std::find(aspectsList.begin(), aspectsList.end(), s##ASPECT) != \
2120
aspectsList.end());
2221

@@ -29,7 +28,7 @@ int main() {
2928
assert(testDeprecatedAspects != DeviceConfigFile::TargetTable.end());
3029
auto deprecatedAspectsList = testDeprecatedAspects->second.aspects;
3130
#define __SYCL_ASPECT_DEPRECATED(ASPECT, ASPECT_VAL, MSG) \
32-
llvm::StringRef s##ASPECT(#ASPECT); \
31+
std::string_view s##ASPECT(#ASPECT); \
3332
assert(std::find(deprecatedAspectsList.begin(), deprecatedAspectsList.end(), \
3433
s##ASPECT) != deprecatedAspectsList.end());
3534

0 commit comments

Comments
 (0)