Skip to content

Commit 2452093

Browse files
committed
[SYCL] address review comments
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 4a4a5e0 commit 2452093

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

sycl/CMakeLists.txt

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ add_custom_target( sycl-toolchain
232232
llvm-link
233233
llvm-objcopy
234234
sycl-post-link
235+
sycl-ls
235236
COMMENT "Building SYCL compiler toolchain..."
236237
)
237238

sycl/test/plugins/lspi_gpu_cuda.cpp

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIERS: gpu, cuda
1+
// REQUIRES: gpu, cuda
22

33
// RUN: lspi --verbose >%t.default.out
44
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-OPENCL,CHECK-CUSTOM-GPU-OPENCL --input-file %t.default.out

sycl/tools/CMakeLists.txt

100644100755
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ set(CMAKE_CXX_STANDARD 11)
22
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33
set(CMAKE_CXX_EXTENSIONS OFF)
44

5-
# TODO: move each tool in its own sub-directory
6-
7-
add_executable(lspi lspi.cpp)
8-
add_dependencies(lspi sycl)
9-
target_include_directories(lspi PRIVATE "${sycl_inc_dir}")
10-
target_link_libraries(lspi
11-
PRIVATE sycl
12-
PRIVATE OpenCL::Headers
13-
PRIVATE ${OpenCL_LIBRARIES})
5+
add_subdirectory(sycl-ls)
146

7+
# TODO: move each tool in its own sub-directory
158
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
169
add_dependencies(get_device_count_by_type ocl-headers ocl-icd)
1710

sycl/tools/sycl-ls/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(CMAKE_CXX_STANDARD 11)
2+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3+
set(CMAKE_CXX_EXTENSIONS OFF)
4+
5+
add_executable(sycl-ls sycl-ls.cpp)
6+
add_dependencies(sycl-ls sycl)
7+
target_include_directories(sycl-ls PRIVATE "${sycl_inc_dir}")
8+
target_link_libraries(sycl-ls
9+
PRIVATE
10+
sycl
11+
OpenCL::Headers
12+
${OpenCL_LIBRARIES}
13+
)

sycl/tools/lspi.cpp renamed to sycl/tools/sycl-ls/sycl-ls.cpp

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
//==----------- lspi.cpp ---------------------------------------------------==//
1+
//==----------- sycl-ls.cpp ------------------------------------------------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// The "lspi" utility lists all platforms/devices discovered by PI similar to
10-
// how lscl prints this for OpenCL devices. It can probably be eventually merged
11-
// with the more complex "check-sycl" utility.
9+
// The "sycl-ls" utility lists all platforms/devices discovered by PI similar to
10+
// how lscl prints this for OpenCL devices.
1211
//
1312
// There are two types of output:
1413
// concise (default) and
15-
// verbose (enabled with any argument).
14+
// verbose (enabled with --verbose).
1615
//
17-
// In verbose mode it also prints, which devices would be chose by various SYCL
16+
// In verbose mode it also prints, which devices would be chosen by various SYCL
1817
// device selectors.
1918
//
2019
#include <CL/sycl.hpp>
@@ -24,10 +23,9 @@
2423
#include <stdlib.h>
2524

2625
using namespace cl::sycl;
27-
using namespace std;
2826

2927
// Controls verbose output vs. concise.
30-
bool verbose = false;
28+
bool verbose;
3129

3230
// Trivial custom selector that selects a device of the given type.
3331
class custom_selector : public device_selector {
@@ -40,9 +38,9 @@ class custom_selector : public device_selector {
4038
}
4139
};
4240

43-
static void printDeviceInfo(const device &Device, const string &Prepend) {
41+
static void printDeviceInfo(const device &Device, const std::string &Prepend) {
4442
auto DeviceType = Device.get_info<info::device::device_type>();
45-
string DeviceTypeName;
43+
std::string DeviceTypeName;
4644
switch (DeviceType) {
4745
case info::device_type::cpu:
4846
DeviceTypeName = "CPU ";
@@ -57,7 +55,7 @@ static void printDeviceInfo(const device &Device, const string &Prepend) {
5755
DeviceTypeName = "ACC ";
5856
break;
5957
default:
60-
DeviceTypeName = "??? ";
58+
DeviceTypeName = "UNKNOWN";
6159
break;
6260
}
6361

@@ -67,14 +65,14 @@ static void printDeviceInfo(const device &Device, const string &Prepend) {
6765
auto DeviceDriverVersion = Device.get_info<info::device::driver_version>();
6866

6967
if (verbose) {
70-
cout << Prepend << "Type : " << DeviceTypeName << std::endl;
71-
cout << Prepend << "Version : " << DeviceVersion << std::endl;
72-
cout << Prepend << "Name : " << DeviceName << std::endl;
73-
cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
74-
cout << Prepend << "Driver : " << DeviceDriverVersion << std::endl;
68+
std::cout << Prepend << "Type : " << DeviceTypeName << std::endl;
69+
std::cout << Prepend << "Version : " << DeviceVersion << std::endl;
70+
std::cout << Prepend << "Name : " << DeviceName << std::endl;
71+
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
72+
std::cout << Prepend << "Driver : " << DeviceDriverVersion << std::endl;
7573
} else {
76-
cout << Prepend << DeviceTypeName << ": " << DeviceVersion << "[ "
77-
<< DeviceDriverVersion << " ]" << std::endl;
74+
std::cout << Prepend << DeviceTypeName << ": " << DeviceVersion << "[ "
75+
<< DeviceDriverVersion << " ]" << std::endl;
7876
}
7977
}
8078

@@ -89,33 +87,25 @@ static void printSelectorChoice(const device_selector &Selector,
8987
std::string What = Exception.what();
9088
if (What.length() > 50)
9189
What = What.substr(0, 50) + "...";
92-
93-
if (verbose) {
94-
cout << Prepend << "Type : " << What << std::endl;
95-
cout << Prepend << "Version : " << What << std::endl;
96-
cout << Prepend << "Name : " << What << std::endl;
97-
cout << Prepend << "Vendor : " << What << std::endl;
98-
cout << Prepend << "Driver : " << What << std::endl;
99-
} else {
100-
cout << Prepend << What << std::endl;
101-
}
90+
std::cout << Prepend << What << std::endl;
10291
}
10392
}
10493

10594
int main(int argc, char **argv) {
10695

107-
// Any options trigger verbose output.
108-
if (argc > 1) {
96+
// See if verbose output is requested
97+
if (argc == 1)
98+
verbose = false;
99+
else if (argc == 2 && std::string(argv[1]) == "--verbose")
109100
verbose = true;
110-
if (!std::getenv("SYCL_PI_TRACE")) {
111-
// Enable trace of PI discovery.
112-
// setenv("SYCL_PI_TRACE", "1", true);
113-
}
101+
else {
102+
std::cout << "Usage: sycl-ls [--verbose]" << std::endl;
103+
return -1;
114104
}
115105

116106
auto Platforms = platform::get_platforms();
117107
if (verbose)
118-
cout << "Platforms: " << Platforms.size() << std::endl;
108+
std::cout << "Platforms: " << Platforms.size() << std::endl;
119109

120110
uint32_t PlatformNum = 0;
121111
for (const auto &Platform : Platforms) {
@@ -124,19 +114,19 @@ int main(int argc, char **argv) {
124114
auto PlatformVersion = Platform.get_info<info::platform::version>();
125115
auto PlatformName = Platform.get_info<info::platform::name>();
126116
auto PlatformVendor = Platform.get_info<info::platform::vendor>();
127-
cout << "Platform [#" << PlatformNum << "]:" << std::endl;
128-
cout << " Version : " << PlatformVersion << std::endl;
129-
cout << " Name : " << PlatformName << std::endl;
130-
cout << " Vendor : " << PlatformVendor << std::endl;
117+
std::cout << "Platform [#" << PlatformNum << "]:" << std::endl;
118+
std::cout << " Version : " << PlatformVersion << std::endl;
119+
std::cout << " Name : " << PlatformName << std::endl;
120+
std::cout << " Vendor : " << PlatformVendor << std::endl;
131121
}
132122
auto Devices = Platform.get_devices();
133123
if (verbose)
134-
cout << " Devices : " << Devices.size() << std::endl;
124+
std::cout << " Devices : " << Devices.size() << std::endl;
135125
uint32_t DeviceNum = 0;
136126
for (const auto &Device : Devices) {
137127
++DeviceNum;
138128
if (verbose)
139-
cout << " Device [#" << DeviceNum << "]:" << std::endl;
129+
std::cout << " Device [#" << DeviceNum << "]:" << std::endl;
140130
printDeviceInfo(Device, verbose ? " " : "");
141131
}
142132
}

0 commit comments

Comments
 (0)