From 1b7f6f674d565d23d283f8ca66315de2620c76bf Mon Sep 17 00:00:00 2001 From: Arvind Sudarsanam Date: Thu, 19 Jan 2023 18:36:14 -0800 Subject: [PATCH 1/2] [PI][OpenCL] Test support for exposing compute slices This test tries to identify devices at three levels - root, sub, and sub-sub. For a device at a given level, checks are provided to see if there is more than 1 device at its sub-level. This test is expected to run without crashing for all backends, though it is specifically added to test changes in OpenCL plugin. Signed-off-by: Arvind Sudarsanam --- SYCL/Basic/subsubdevice_cslice.cpp | 150 +++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100755 SYCL/Basic/subsubdevice_cslice.cpp diff --git a/SYCL/Basic/subsubdevice_cslice.cpp b/SYCL/Basic/subsubdevice_cslice.cpp new file mode 100755 index 0000000000..5f7e9a0ee4 --- /dev/null +++ b/SYCL/Basic/subsubdevice_cslice.cpp @@ -0,0 +1,150 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +//==----- subsubdevice_cslice.cpp - SYCL subsubdevice basic test -----------==// +// +// 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 test tries to identify devices at all levels of hierarchy. +//===----------------------------------------------------------------------===// + +#if 1 // __STANDALONE_TESTING__ +// unnamed namespace for standalone testing +#include +#include +namespace { + void readEnvStringWithDefault(const char* name, char* value, const char* def) + { + char* tmp = std::getenv(name); + if (!tmp) std::strcpy(value, def); + else std::strcpy(value, tmp); + } +} +#else +void readEnvStringWithDefault(const char*, char*, const char*); +#endif + +#if __clang_major__ > 15 +#include +#else +#include +inline namespace cl { + using namespace sycl; +} +namespace sycl = ::cl::sycl; +#endif + +#include +#include +#include +#include +#include + +static auto exception_handler = [](sycl::exception_list list) { + for (std::exception_ptr const& e : list) { + try { + std::rethrow_exception(e); + } + catch (std::exception const& e) { + std::cout << "Exception: " << e.what() << std::endl; std::fflush(stdout); + throw; + //std::terminate(); + } + } +}; + +int identify_devices() { + std::vector devices; + int verbose = 0; + try { + std::vector all_devices = sycl::device::get_devices(); + char variable_name[255]; + + readEnvStringWithDefault("XPU_USE_SUBDEVICES", variable_name, "1"); + auto use_subdevices = std::atoi(variable_name); + int split_streams = 0; + if (use_subdevices) { + readEnvStringWithDefault("XPU_SPLIT_STREAMS", variable_name, "1"); + split_streams = std::atoi(variable_name); + } + + readEnvStringWithDefault("XPU_VERBOSE", variable_name, "1"); + verbose = std::atoi(variable_name); + + readEnvStringWithDefault("XPU_DEVICE_NAME", variable_name, "Graphics"); + + if (verbose) { + std::cout << "XPU_DEVICE_NAME=" << variable_name << std::endl; + std::cout << "Devices found:" << std::endl; + } + std::cout << "Number of root devices = " << all_devices.size() << std::endl; + for (auto& device : all_devices) { + if (verbose) { + std::cout << "* Device: " + << device.get_info() + << ", Backend: " + << device.get_platform().get_backend() + << std::endl; + } + + if (device.get_info().find(variable_name) != std::string::npos) { + // Select devices with the same backend only + if (devices.empty() || (!devices.empty() && + devices[0].get_platform().get_backend() == device.get_platform().get_backend())) { + // Select subdevices if any + auto device_partition_properties = device.get_info(); + if (!use_subdevices || device_partition_properties.empty()) { + devices.push_back(device); + } else { + for (int i = 0; i < device_partition_properties.size(); i++) { + if (device_partition_properties[i] == sycl::info::partition_property::partition_by_affinity_domain) { + auto subdevices = device.create_sub_devices< + sycl::info::partition_property::partition_by_affinity_domain>( + sycl::info::partition_affinity_domain::numa); + std::cout << "Number of subdevices = " << subdevices.size() << "\n"; + for (int j = 0; j < subdevices.size(); j++) { + auto subdevice_partition_properties = + subdevices[j].get_info(); + if (!split_streams || subdevice_partition_properties.empty()) { + devices.push_back(subdevices[j]); + } else { + for (int i = 0; i < subdevice_partition_properties.size(); i++) { + if (subdevice_partition_properties[i] == sycl::info::partition_property::ext_intel_partition_by_cslice) { + auto streams = subdevices[j].create_sub_devices< + sycl::info::partition_property::ext_intel_partition_by_cslice>(); + std::cout << "Number of compute slices = " << streams.size() << "\n"; + for (int j = 0; j < streams.size(); j++) { + devices.push_back(streams[j]); + } + break; + } + } + } + } + break; + } else { + devices.push_back(device); + } + } + } + } + } + } + return 0; + } + catch (sycl::exception& e) { + std::cout << "Sync sycl exception in initialize_queues(): " << e.what() << std::endl; std::fflush(stdout); + return 1; + } +} + +int main() { + return identify_devices(); +} + + + From 5756215067732e0972981b3880b410d655c89008 Mon Sep 17 00:00:00 2001 From: Arvind Sudarsanam Date: Thu, 19 Jan 2023 21:19:59 -0800 Subject: [PATCH 2/2] fix formatting issues Signed-off-by: Arvind Sudarsanam --- SYCL/Basic/subsubdevice_cslice.cpp | 110 ++++++++++++++++------------- 1 file changed, 61 insertions(+), 49 deletions(-) mode change 100755 => 100644 SYCL/Basic/subsubdevice_cslice.cpp diff --git a/SYCL/Basic/subsubdevice_cslice.cpp b/SYCL/Basic/subsubdevice_cslice.cpp old mode 100755 new mode 100644 index 5f7e9a0ee4..3ff4a76f4a --- a/SYCL/Basic/subsubdevice_cslice.cpp +++ b/SYCL/Basic/subsubdevice_cslice.cpp @@ -17,15 +17,16 @@ #include #include namespace { - void readEnvStringWithDefault(const char* name, char* value, const char* def) - { - char* tmp = std::getenv(name); - if (!tmp) std::strcpy(value, def); - else std::strcpy(value, tmp); - } +void readEnvStringWithDefault(const char *name, char *value, const char *def) { + char *tmp = std::getenv(name); + if (!tmp) + std::strcpy(value, def); + else + std::strcpy(value, tmp); } +} // namespace #else -void readEnvStringWithDefault(const char*, char*, const char*); +void readEnvStringWithDefault(const char *, char *, const char *); #endif #if __clang_major__ > 15 @@ -33,26 +34,26 @@ void readEnvStringWithDefault(const char*, char*, const char*); #else #include inline namespace cl { - using namespace sycl; +using namespace sycl; } namespace sycl = ::cl::sycl; #endif -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static auto exception_handler = [](sycl::exception_list list) { - for (std::exception_ptr const& e : list) { + for (std::exception_ptr const &e : list) { try { std::rethrow_exception(e); - } - catch (std::exception const& e) { - std::cout << "Exception: " << e.what() << std::endl; std::fflush(stdout); + } catch (std::exception const &e) { + std::cout << "Exception: " << e.what() << std::endl; + std::fflush(stdout); throw; - //std::terminate(); + // std::terminate(); } } }; @@ -63,7 +64,7 @@ int identify_devices() { try { std::vector all_devices = sycl::device::get_devices(); char variable_name[255]; - + readEnvStringWithDefault("XPU_USE_SUBDEVICES", variable_name, "1"); auto use_subdevices = std::atoi(variable_name); int split_streams = 0; @@ -82,41 +83,56 @@ int identify_devices() { std::cout << "Devices found:" << std::endl; } std::cout << "Number of root devices = " << all_devices.size() << std::endl; - for (auto& device : all_devices) { + for (auto &device : all_devices) { if (verbose) { - std::cout << "* Device: " - << device.get_info() - << ", Backend: " - << device.get_platform().get_backend() + std::cout << "* Device: " << device.get_info() + << ", Backend: " << device.get_platform().get_backend() << std::endl; } - - if (device.get_info().find(variable_name) != std::string::npos) { + + if (device.get_info().find(variable_name) != + std::string::npos) { // Select devices with the same backend only - if (devices.empty() || (!devices.empty() && - devices[0].get_platform().get_backend() == device.get_platform().get_backend())) { + if (devices.empty() || + (!devices.empty() && devices[0].get_platform().get_backend() == + device.get_platform().get_backend())) { // Select subdevices if any - auto device_partition_properties = device.get_info(); + auto device_partition_properties = + device.get_info(); if (!use_subdevices || device_partition_properties.empty()) { devices.push_back(device); } else { for (int i = 0; i < device_partition_properties.size(); i++) { - if (device_partition_properties[i] == sycl::info::partition_property::partition_by_affinity_domain) { - auto subdevices = device.create_sub_devices< - sycl::info::partition_property::partition_by_affinity_domain>( + if (device_partition_properties[i] == + sycl::info::partition_property:: + partition_by_affinity_domain) { + auto subdevices = + device.create_sub_devices( sycl::info::partition_affinity_domain::numa); - std::cout << "Number of subdevices = " << subdevices.size() << "\n"; + std::cout << "Number of subdevices = " << subdevices.size() + << "\n"; for (int j = 0; j < subdevices.size(); j++) { auto subdevice_partition_properties = - subdevices[j].get_info(); - if (!split_streams || subdevice_partition_properties.empty()) { + subdevices[j] + .get_info(); + if (!split_streams || + subdevice_partition_properties.empty()) { devices.push_back(subdevices[j]); } else { - for (int i = 0; i < subdevice_partition_properties.size(); i++) { - if (subdevice_partition_properties[i] == sycl::info::partition_property::ext_intel_partition_by_cslice) { - auto streams = subdevices[j].create_sub_devices< - sycl::info::partition_property::ext_intel_partition_by_cslice>(); - std::cout << "Number of compute slices = " << streams.size() << "\n"; + for (int i = 0; i < subdevice_partition_properties.size(); + i++) { + if (subdevice_partition_properties[i] == + sycl::info::partition_property:: + ext_intel_partition_by_cslice) { + auto streams = + subdevices[j] + .create_sub_devices< + sycl::info::partition_property:: + ext_intel_partition_by_cslice>(); + std::cout + << "Number of compute slices = " << streams.size() + << "\n"; for (int j = 0; j < streams.size(); j++) { devices.push_back(streams[j]); } @@ -135,16 +151,12 @@ int identify_devices() { } } return 0; - } - catch (sycl::exception& e) { - std::cout << "Sync sycl exception in initialize_queues(): " << e.what() << std::endl; std::fflush(stdout); + } catch (sycl::exception &e) { + std::cout << "Sync sycl exception in initialize_queues(): " << e.what() + << std::endl; + std::fflush(stdout); return 1; } } -int main() { - return identify_devices(); -} - - - +int main() { return identify_devices(); }