-
Notifications
You must be signed in to change notification settings - Fork 770
[SYCL] Add sycl-ls utility for listing devices discovered/selected by SYCL RT #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a4a5e0
[SYCL]: Add lspi utility for listing devices discovered/selected by S…
smaslov-intel 2452093
[SYCL] address review comments
smaslov-intel 9b6c8e2
[SYCL] address review comments #2
smaslov-intel 2e503e9
[SYCL] address review comments #3
smaslov-intel 9255a4d
[SYCL] address review comments #4
smaslov-intel 89ad5b0
[SYCL] address review comments #5
smaslov-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// REQUIRES: gpu, cuda | ||
|
||
// RUN: env SYCL_BE=PI_CUDA sycl-ls --verbose >%t.cuda.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-CUDA,CHECK-CUSTOM-GPU-CUDA --input-file %t.cuda.out | ||
|
||
// CHECK-BUILTIN-GPU-CUDA: gpu_selector(){{.*}}GPU :{{.*}}CUDA | ||
// CHECK-CUSTOM-GPU-CUDA: custom_selector(gpu){{.*}}GPU :{{.*}}CUDA | ||
|
||
//==---- sycl-ls-gpu-cuda.cpp - SYCL test for discovered/selected devices --==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// REQUIRES: gpu, opencl | ||
|
||
// RUN: sycl-ls --verbose >%t.default.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-GPU-BUILTIN,CHECK-GPU-CUSTOM --input-file %t.default.out | ||
|
||
// RUN: env SYCL_BE=PI_OPENCL sycl-ls --verbose >%t.opencl.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-GPU-BUILTIN,CHECK-GPU-CUSTOM --input-file %t.opencl.out | ||
|
||
// CHECK-GPU-BUILTIN: gpu_selector(){{.*}}GPU : OpenCL | ||
// CHECK-GPU-CUSTOM: custom_selector(gpu){{.*}}GPU : OpenCL | ||
|
||
//==-- sycl-ls-gpu-opencl.cpp - SYCL test for discovered/selected devices -===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// REQUIRES: gpu, cuda, opencl | ||
|
||
// RUN: sycl-ls --verbose >%t.default.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-OPENCL,CHECK-CUSTOM-GPU-OPENCL --input-file %t.default.out | ||
|
||
// RUN: env SYCL_BE=PI_OPENCL sycl-ls --verbose >%t.opencl.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-OPENCL,CHECK-CUSTOM-GPU-OPENCL --input-file %t.opencl.out | ||
|
||
// CHECK-BUILTIN-GPU-OPENCL: gpu_selector(){{.*}}GPU : OpenCL | ||
// CHECK-CUSTOM-GPU-OPENCL: custom_selector(gpu){{.*}}GPU : OpenCL | ||
|
||
// RUN: env SYCL_BE=PI_CUDA sycl-ls --verbose >%t.cuda.out | ||
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-CUDA,CHECK-CUSTOM-GPU-CUDA --input-file %t.cuda.out | ||
|
||
// CHECK-BUILTIN-GPU-CUDA: gpu_selector(){{.*}}GPU : CUDA | ||
// CHECK-CUSTOM-GPU-CUDA: custom_selector(gpu){{.*}}GPU : CUDA | ||
|
||
//==---- sycl-ls-gpu-sycl-be.cpp - SYCL test for discovered/selected devices --==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: sycl-ls --verbose | grep "Device \[" | wc -l >%t.verbose.out | ||
// RUN: sycl-ls | wc -l >%t.concise.out | ||
// RUN: diff %t.verbose.out %t.concise.out | ||
|
||
//==---- sycl-ls.cpp - SYCL test for consistency of sycl-ls output ---------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_executable(sycl-ls sycl-ls.cpp) | ||
add_dependencies(sycl-ls sycl) | ||
target_include_directories(sycl-ls PRIVATE "${sycl_inc_dir}") | ||
target_link_libraries(sycl-ls | ||
PRIVATE | ||
sycl | ||
OpenCL::Headers | ||
bader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
//==----------- sycl-ls.cpp ------------------------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The "sycl-ls" utility lists all platforms/devices discovered by SYCL similar | ||
// to how clinfo prints this for OpenCL devices. | ||
// | ||
// There are two types of output: | ||
// concise (default) and | ||
// verbose (enabled with --verbose). | ||
// | ||
// In verbose mode it also prints, which devices would be chosen by various SYCL | ||
// device selectors. | ||
// | ||
#include <CL/sycl.hpp> | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
using namespace cl::sycl; | ||
|
||
// Controls verbose output vs. concise. | ||
bool verbose; | ||
|
||
// Trivial custom selector that selects a device of the given type. | ||
class custom_selector : public device_selector { | ||
info::device_type MType; | ||
|
||
public: | ||
custom_selector(info::device_type Type) : MType(Type) {} | ||
int operator()(const device &Dev) const override { | ||
return Dev.get_info<info::device::device_type>() == MType ? 1 : -1; | ||
} | ||
}; | ||
|
||
static void printDeviceInfo(const device &Device, const std::string &Prepend) { | ||
auto DeviceType = Device.get_info<info::device::device_type>(); | ||
std::string DeviceTypeName; | ||
switch (DeviceType) { | ||
case info::device_type::cpu: | ||
DeviceTypeName = "CPU "; | ||
break; | ||
case info::device_type::gpu: | ||
DeviceTypeName = "GPU "; | ||
break; | ||
case info::device_type::host: | ||
DeviceTypeName = "HOST"; | ||
break; | ||
case info::device_type::accelerator: | ||
DeviceTypeName = "ACC "; | ||
break; | ||
default: | ||
DeviceTypeName = "UNKNOWN"; | ||
break; | ||
} | ||
|
||
auto DeviceVersion = Device.get_info<info::device::version>(); | ||
auto DeviceName = Device.get_info<info::device::name>(); | ||
auto DeviceVendor = Device.get_info<info::device::vendor>(); | ||
auto DeviceDriverVersion = Device.get_info<info::device::driver_version>(); | ||
|
||
if (verbose) { | ||
std::cout << Prepend << "Type : " << DeviceTypeName << std::endl; | ||
std::cout << Prepend << "Version : " << DeviceVersion << std::endl; | ||
std::cout << Prepend << "Name : " << DeviceName << std::endl; | ||
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl; | ||
std::cout << Prepend << "Driver : " << DeviceDriverVersion << std::endl; | ||
} else { | ||
std::cout << Prepend << DeviceTypeName << ": " << DeviceVersion << "[ " | ||
<< DeviceDriverVersion << " ]" << std::endl; | ||
} | ||
} | ||
|
||
static void printSelectorChoice(const device_selector &Selector, | ||
const std::string &Prepend) { | ||
try { | ||
const auto &Dev = device(Selector); | ||
printDeviceInfo(Dev, Prepend); | ||
|
||
} catch (const cl::sycl::runtime_error &Exception) { | ||
// Truncate long string so it can fit in one-line | ||
std::string What = Exception.what(); | ||
if (What.length() > 50) | ||
What = What.substr(0, 50) + "..."; | ||
std::cout << Prepend << What << std::endl; | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
|
||
// See if verbose output is requested | ||
if (argc == 1) | ||
verbose = false; | ||
else if (argc == 2 && std::string(argv[1]) == "--verbose") | ||
verbose = true; | ||
else { | ||
std::cout << "Usage: sycl-ls [--verbose]" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
auto Platforms = platform::get_platforms(); | ||
if (verbose) | ||
std::cout << "Platforms: " << Platforms.size() << std::endl; | ||
|
||
uint32_t PlatformNum = 0; | ||
for (const auto &Platform : Platforms) { | ||
++PlatformNum; | ||
if (verbose) { | ||
auto PlatformVersion = Platform.get_info<info::platform::version>(); | ||
auto PlatformName = Platform.get_info<info::platform::name>(); | ||
auto PlatformVendor = Platform.get_info<info::platform::vendor>(); | ||
std::cout << "Platform [#" << PlatformNum << "]:" << std::endl; | ||
std::cout << " Version : " << PlatformVersion << std::endl; | ||
std::cout << " Name : " << PlatformName << std::endl; | ||
std::cout << " Vendor : " << PlatformVendor << std::endl; | ||
} | ||
auto Devices = Platform.get_devices(); | ||
if (verbose) | ||
std::cout << " Devices : " << Devices.size() << std::endl; | ||
uint32_t DeviceNum = 0; | ||
for (const auto &Device : Devices) { | ||
++DeviceNum; | ||
if (verbose) | ||
std::cout << " Device [#" << DeviceNum << "]:" << std::endl; | ||
printDeviceInfo(Device, verbose ? " " : ""); | ||
} | ||
} | ||
|
||
if (!verbose) { | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
// Print the selectors choice in one-line always | ||
verbose = false; | ||
|
||
// Print built-in device selectors choice | ||
printSelectorChoice(default_selector(), "default_selector() : "); | ||
printSelectorChoice(host_selector(), "host_selector() : "); | ||
printSelectorChoice(accelerator_selector(), "accelerator_selector() : "); | ||
printSelectorChoice(cpu_selector(), "cpu_selector() : "); | ||
printSelectorChoice(gpu_selector(), "gpu_selector() : "); | ||
|
||
// Print trivial custom selectors choice | ||
printSelectorChoice(custom_selector(info::device_type::gpu), | ||
"custom_selector(gpu) : "); | ||
printSelectorChoice(custom_selector(info::device_type::cpu), | ||
"custom_selector(cpu) : "); | ||
printSelectorChoice(custom_selector(info::device_type::accelerator), | ||
"custom_selector(acc) : "); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.