diff --git a/sycl/test-e2e/AbiNeutral/catch-exception.cpp b/sycl/test-e2e/AbiNeutral/catch-exception.cpp new file mode 100644 index 0000000000000..865745ec39962 --- /dev/null +++ b/sycl/test-e2e/AbiNeutral/catch-exception.cpp @@ -0,0 +1,55 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +// RUN: %if preview-breaking-changes-supported %{ %{build} -fpreview-breaking-changes -D_GLIBCXX_USE_CXX11_ABI=0 -o %t2.out %} +// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} +// REQUIRES: level_zero && gpu + +// This test case tests if compiling works with or without +// _GLIBCXX_USE_CXX11_ABI=0. + +#include + +int main() { +#ifdef _GLIBCXX_USE_CXX11_ABI + std::cout << "is_cxx11_abi: " << (_GLIBCXX_USE_CXX11_ABI != 0) << std::endl; + ; +#else + std::cout << "is_cxx11_abi: 1" << std::endl; +#endif + std::vector root_devices; + auto platform_list = sycl::platform::get_platforms(); + // Enumerated GPU devices from GPU platform firstly. + for (const auto &platform : platform_list) { + if (platform.get_backend() != sycl::backend::ext_oneapi_level_zero) { + continue; + } + auto device_list = platform.get_devices(); + for (const auto &device : device_list) { + if (device.is_gpu()) { + root_devices.push_back(device); + } + } + } + assert(root_devices.size() > 0); + std::cout << "gpu number: " << root_devices.size() << std::endl; + constexpr sycl::info::partition_property partition_by_affinity = + sycl::info::partition_property::partition_by_affinity_domain; + constexpr sycl::info::partition_affinity_domain next_partitionable = + sycl::info::partition_affinity_domain::next_partitionable; + for (const auto &root_device : root_devices) { + try { + auto sub_devices = root_device.create_sub_devices( + next_partitionable); + std::cout << "tile partition is supported!" << std::endl; + } catch (sycl::exception &e) { + if (e.code() != sycl::errc::feature_not_supported && + e.code() != sycl::errc::invalid) { + throw std::runtime_error( + std::string("Failed to apply tile partition: ") + e.what()); + } else { + std::cout << "tile partition is UNSUPPORTED!" << std::endl; + } + } + } + std::cout << "pass!" << std::endl; +} diff --git a/sycl/test-e2e/AbiNeutral/device-info.cpp b/sycl/test-e2e/AbiNeutral/device-info.cpp new file mode 100644 index 0000000000000..ac4efd134a136 --- /dev/null +++ b/sycl/test-e2e/AbiNeutral/device-info.cpp @@ -0,0 +1,149 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +// RUN: %if preview-breaking-changes-supported %{ %{build} -fpreview-breaking-changes -D_GLIBCXX_USE_CXX11_ABI=0 -o %t2.out %} +// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} + +// This test case tests if compiling works with or without +// _GLIBCXX_USE_CXX11_ABI=0. + +#include +#include +#include +#include +#include + +template using dpcpp_info_t = typename T::return_type; + +struct DeviceProp { + dpcpp_info_t device_name; + dpcpp_info_t platform_name; + dpcpp_info_t vendor; + dpcpp_info_t driver_version; + dpcpp_info_t version; + dpcpp_info_t max_compute_units; +}; + +static std::once_flag init_device_flag; +static std::once_flag init_prop_flag; +static std::deque device_prop_flags; +static std::vector device_properties; + +struct DevicePool { + std::vector> devices; + std::vector> contexts; + std::mutex mutex; +} gDevPool; + +bool is_cxx11_abi() { +#ifdef _GLIBCXX_USE_CXX11_ABI + return (_GLIBCXX_USE_CXX11_ABI != 0); +#else + return true; +#endif +} + +static void enumDevices(std::vector> &devices) { + auto platform_list = sycl::platform::get_platforms(); + for (const auto &platform : platform_list) { + if (platform.get_backend() != sycl::backend::ext_oneapi_level_zero) { + continue; + } + auto device_list = platform.get_devices(); + for (const auto &device : device_list) { + if (device.is_gpu()) { + devices.push_back(std::make_unique(device)); + } + } + } +} + +static void initGlobalDevicePoolState() { + enumDevices(gDevPool.devices); + + auto device_count = gDevPool.devices.size(); + if (device_count <= 0) { + std::cout << "XPU device count is zero!" << std::endl; + return; + } + gDevPool.contexts.resize(1); + gDevPool.contexts[0] = std::make_unique( + gDevPool.devices[0]->get_platform().ext_oneapi_get_default_context()); +} + +static void initDevicePoolCallOnce() { + std::call_once(init_device_flag, initGlobalDevicePoolState); +} + +int dpcppGetDeviceCount() { + initDevicePoolCallOnce(); + std::lock_guard lock(gDevPool.mutex); + return static_cast(gDevPool.devices.size()); +} + +sycl::device &dpcppGetRawDevice(int device) { + initDevicePoolCallOnce(); + std::lock_guard lock(gDevPool.mutex); + if (device > static_cast(gDevPool.devices.size())) { + throw std::runtime_error(std::string("device is out of range")); + } + return *gDevPool.devices[device]; +} + +static void initDevicePropState() { + auto device_count = dpcppGetDeviceCount(); + device_prop_flags.resize(device_count); + device_properties.resize(device_count); +} + +static void initDeviceProperties(int device) { + DeviceProp device_prop; + auto &raw_device = dpcppGetRawDevice(device); + + device_prop.device_name = raw_device.get_info(); + device_prop.platform_name = + raw_device.get_platform().get_info(); + device_prop.vendor = raw_device.get_info(); + device_prop.driver_version = + raw_device.get_info(); + device_prop.version = raw_device.get_info(); + device_prop.max_compute_units = + raw_device.get_info(); + + device_properties[device] = device_prop; +} + +static void initDevicePropCallOnce(int device) { + std::call_once(init_prop_flag, initDevicePropState); + std::call_once(device_prop_flags[device], initDeviceProperties, device); +} + +DeviceProp &dpcppGetDeviceProperties(int device) { + initDevicePropCallOnce(device); + auto device_count = dpcppGetDeviceCount(); + if (device > device_count) { + throw std::runtime_error(std::string("device is out of range")); + } + return device_properties[device]; +} + +std::string &dpcppGetDeviceName(int device) { + return dpcppGetDeviceProperties(device).device_name; +} + +int main() { + std::cout << "device_count: " << dpcppGetDeviceCount() << std::endl; + std::cout << "hello world!" << std::endl; + std::cout << "is_cxx11_abi: " << is_cxx11_abi() << std::endl; + for (auto i = 0; i < dpcppGetDeviceCount(); i++) { + // std::cout << i << "th device name is " << dpcppGetDeviceName(i) << + // std::endl; + std::cout << i << "th device name is " + << dpcppGetDeviceProperties(i).device_name << std::endl; + std::cout << i << "th platform name is " + << dpcppGetDeviceProperties(i).platform_name << std::endl; + std::cout << dpcppGetDeviceProperties(i).version << std::endl; + std::cout << dpcppGetDeviceProperties(i).driver_version << std::endl; + std::cout << dpcppGetDeviceProperties(i).vendor << std::endl; + std::cout << dpcppGetDeviceProperties(i).max_compute_units << std::endl; + } +} diff --git a/sycl/test-e2e/AbiNeutral/submit-kernel.cpp b/sycl/test-e2e/AbiNeutral/submit-kernel.cpp new file mode 100644 index 0000000000000..20cee80288026 --- /dev/null +++ b/sycl/test-e2e/AbiNeutral/submit-kernel.cpp @@ -0,0 +1,31 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +// RUN: %if preview-breaking-changes-supported %{ %{build} -fpreview-breaking-changes -D_GLIBCXX_USE_CXX11_ABI=0 -o %t2.out %} +// RUN: %if preview-breaking-changes-supported %{ %{run} %t2.out %} + +// This test case tests if compiling works with or without +// _GLIBCXX_USE_CXX11_ABI=0. + +#include +#include + +int main() { + try { + auto cgf = [&](sycl::handler &cgh) { cgh.single_task([=]() {}); }; + sycl::queue queue; + for (auto i = 0; i < 25; i++) { + sycl::malloc_device(1024, queue); + } + auto event = queue.submit(cgf); + event.wait_and_throw(); + } catch (const sycl::exception &ep) { + const std::string_view err_msg(ep.what()); + if (err_msg.find("PI_ERROR_OUT_OF_RESOURCES") != std::string::npos) { + std::cout << "Allocation is out of device memory on the current platform." + << std::endl; + } else { + throw ep; + } + } + std::cout << "pass!" << std::endl; +}