1
+ // RUN: %clangxx -fsycl %s -o %t.out
2
+ // RUN: env SYCL_DEVICE_FILTER=level_zero:gpu %t.out
3
+ // RUN: env SYCL_DEVICE_FILTER=opencl:gpu %t.out
4
+ //
5
+ // REQUIRES: gpu
6
+ // UNSUPPORTED: cuda
7
+ // UNSUPPORTED: hip
8
+ // Temporarily disable on L0 due to fails in CI
9
+ // UNSUPPORTED: level_zero
10
+
11
+ // ==--------- intel-ext-device.cpp - SYCL device test ------------==//
12
+ //
13
+ // Returns the low-level device details. These are Intel-specific extensions
14
+ // that are only supported on Level Zero.
15
+ //
16
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
17
+ // See https://llvm.org/LICENSE.txt for license information.
18
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
19
+ //
20
+ // ===----------------------------------------------------------------------===//
21
+
22
+ #include < sycl/sycl.hpp>
23
+
24
+ #include < cassert>
25
+ #include < iostream>
26
+
27
+ using namespace sycl ;
28
+
29
+ #ifdef _WIN32
30
+ #define setenv (name, value, overwrite ) _putenv_s(name, value)
31
+ #endif
32
+
33
+ int main (int argc, char **argv) {
34
+ // Must be enabled at the beginning of the application
35
+ // to obtain the PCI address
36
+ setenv (" SYCL_ENABLE_PCI" , " 1" , 0 );
37
+
38
+ int pltCount = 1 ;
39
+ for (const auto &plt : platform::get_platforms ()) {
40
+ if (!plt.has (aspect::host)) {
41
+ int devCount = 1 ;
42
+ int totalEUs = 0 ;
43
+ int numSlices = 0 ;
44
+ int numSubslices = 0 ;
45
+ int numEUsPerSubslice = 0 ;
46
+ int numHWThreadsPerEU = 0 ;
47
+ for (const auto &dev : plt.get_devices ()) {
48
+ std::cout << " Platform #" << pltCount++ << " :" << std::endl;
49
+ if (dev.has (aspect::gpu)) {
50
+ auto name = dev.get_info <info::device::name>();
51
+ std::cout << " Device #" << devCount++ << " : "
52
+ << dev.get_info <info::device::name>() << " :" << std::endl;
53
+
54
+ std::cout << " Backend: " ;
55
+ if (plt.get_backend () == backend::ext_oneapi_level_zero) {
56
+ std::cout << " Level Zero" << std::endl;
57
+ } else if (plt.get_backend () == backend::opencl) {
58
+ std::cout << " OpenCL" << std::endl;
59
+ } else if (plt.get_backend () == backend::ext_oneapi_cuda) {
60
+ std::cout << " CUDA" << std::endl;
61
+ } else {
62
+ std::cout << " Unknown" << std::endl;
63
+ }
64
+
65
+ // Use Feature Test macro to see if extensions are supported.
66
+ if (SYCL_EXT_INTEL_DEVICE_INFO >= 1 ) {
67
+
68
+ if (dev.has (aspect::ext_intel_pci_address)) {
69
+ std::cout << " PCI address = "
70
+ << dev.get_info <info::device::ext_intel_pci_address>()
71
+ << std::endl;
72
+ }
73
+ if (dev.has (aspect::ext_intel_gpu_eu_count)) {
74
+ totalEUs = dev.get_info <info::device::ext_intel_gpu_eu_count>();
75
+ std::cout << " Number of EUs = " << totalEUs << std::endl;
76
+ }
77
+ if (dev.has (aspect::ext_intel_gpu_eu_simd_width)) {
78
+ int w = dev.get_info <info::device::ext_intel_gpu_eu_simd_width>();
79
+ std::cout << " EU SIMD width = " << w << std::endl;
80
+ }
81
+ if (dev.has (aspect::ext_intel_gpu_slices)) {
82
+ numSlices = dev.get_info <info::device::ext_intel_gpu_slices>();
83
+ std::cout << " Number of slices = " << numSlices << std::endl;
84
+ }
85
+ if (dev.has (aspect::ext_intel_gpu_subslices_per_slice)) {
86
+ numSubslices = dev.get_info <
87
+ info::device::ext_intel_gpu_subslices_per_slice>();
88
+ std::cout << " Number of subslices per slice = " << numSubslices
89
+ << std::endl;
90
+ }
91
+ if (dev.has (aspect::ext_intel_gpu_eu_count_per_subslice)) {
92
+ numEUsPerSubslice = dev.get_info <
93
+ info::device::ext_intel_gpu_eu_count_per_subslice>();
94
+ std::cout << " Number of EUs per subslice = " << numEUsPerSubslice
95
+ << std::endl;
96
+ }
97
+ if (dev.has (aspect::ext_intel_gpu_hw_threads_per_eu)) {
98
+ numHWThreadsPerEU =
99
+ dev.get_info <info::device::ext_intel_gpu_hw_threads_per_eu>();
100
+ std::cout << " Number of HW threads per EU = " << numHWThreadsPerEU
101
+ << std::endl;
102
+ }
103
+ if (dev.has (aspect::ext_intel_max_mem_bandwidth)) {
104
+ // not supported yet
105
+ long m =
106
+ dev.get_info <info::device::ext_intel_max_mem_bandwidth>();
107
+ std::cout << " Maximum memory bandwidth = " << m << std::endl;
108
+ }
109
+ // This is the only data we can verify.
110
+ if (totalEUs != numSlices * numSubslices * numEUsPerSubslice) {
111
+ std::cout << " Error: EU Count is incorrect!" << std::endl;
112
+ std::cout << " Failed!" << std::endl;
113
+ return 1 ;
114
+ }
115
+ } // SYCL_EXT_INTEL_DEVICE_INFO
116
+ }
117
+ std::cout << std::endl;
118
+ }
119
+ }
120
+ }
121
+ std::cout << " Passed!" << std::endl;
122
+ return 0 ;
123
+ }
0 commit comments