From a093f05460e2b3d67de523042bc9ae3755ec2387 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Tue, 8 Oct 2024 07:35:35 -0700 Subject: [PATCH 1/2] [SYCL] Support sycl_khr_default_context Spec: https://github.com/KhronosGroup/SYCL-Docs/pull/624 sycl-cts: https://github.com/KhronosGroup/SYCL-CTS/pull/960 This patch is intended to be merged only when there are sycl-cts tests and the ratified khr extension. --- sycl/include/sycl/platform.hpp | 5 ++++ sycl/source/detail/queue_impl.hpp | 2 +- sycl/source/feature_test.hpp.in | 1 + sycl/source/platform.cpp | 6 ++++- .../Basic/khr_get_default_context.cpp | 25 +++++++++++++++++++ sycl/test/abi/sycl_symbols_linux.dump | 1 + sycl/unittests/Extensions/DefaultContext.cpp | 13 ++++++++++ 7 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 sycl/test-e2e/Basic/khr_get_default_context.cpp diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index 0d10080e00142..f12877c28e0ba 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -230,6 +230,11 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { std::vector ext_oneapi_get_composite_devices() const; + /// Returns a copy of the default context object for this platform. + /// + /// \return the default context + context khr_get_default_context() const; + private: ur_native_handle_t getNative() const; diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 4b68aebab9013..70a5615e57165 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -77,7 +77,7 @@ class queue_impl { context{createSyclObjFromImpl(Device), {}, {}}); ContextImplPtr DefaultContext = detail::getSyclObjImpl( - Device->get_platform().ext_oneapi_get_default_context()); + Device->get_platform().khr_get_default_context()); if (DefaultContext->isDeviceValid(Device)) return DefaultContext; return detail::getSyclObjImpl( diff --git a/sycl/source/feature_test.hpp.in b/sycl/source/feature_test.hpp.in index a61e504eb5e4c..1d7ab87eab162 100644 --- a/sycl/source/feature_test.hpp.in +++ b/sycl/source/feature_test.hpp.in @@ -110,6 +110,7 @@ inline namespace _V1 { #define SYCL_EXT_ONEAPI_ENQUEUE_NATIVE_COMMAND 1 // In progress yet #define SYCL_EXT_ONEAPI_ATOMIC16 0 +#define SYCL_KHR_DEFAULT_CONTEXT 1 #ifndef __has_include #define __has_include(x) 0 diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 17de8c1700a89..45a32dfd1d5db 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -86,7 +86,7 @@ platform::get_backend_info() const { #undef __SYCL_PARAM_TRAITS_SPEC -context platform::ext_oneapi_get_default_context() const { +context platform::khr_get_default_context() const { if (!detail::SYCLConfig::get()) throw std::runtime_error("SYCL default contexts are not enabled"); @@ -108,6 +108,10 @@ context platform::ext_oneapi_get_default_context() const { return detail::createSyclObjFromImpl(It->second); } +context platform::ext_oneapi_get_default_context() const { + return khr_get_default_context(); +} + std::vector platform::ext_oneapi_get_composite_devices() const { // Only GPU architectures can be composite devices. auto GPUDevices = get_devices(info::device_type::gpu); diff --git a/sycl/test-e2e/Basic/khr_get_default_context.cpp b/sycl/test-e2e/Basic/khr_get_default_context.cpp new file mode 100644 index 0000000000000..42990366cd1ad --- /dev/null +++ b/sycl/test-e2e/Basic/khr_get_default_context.cpp @@ -0,0 +1,25 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +// Test checks that the default context contains all of the root devices that +// are associated with this platform. + +#include +#include + +using namespace sycl; + +int main() { + auto platforms = platform::get_platforms(); + + for (const auto &plt : platforms) { + auto def_ctx_devs = plt.khr_get_default_context().get_devices(); + auto root_devs = plt.get_devices(); + + for (const auto &dev : root_devs) + if (std::find(def_ctx_devs.begin(), def_ctx_devs.end(), dev) == def_ctx_devs.end()) + return 1; + } + + return 0; +} diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 26622cd2909de..b8ee86285c372 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3986,6 +3986,7 @@ _ZNK4sycl3_V18platform13has_extensionENS0_6detail11string_viewE _ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V18platform16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V18platform23khr_get_default_contextEv _ZNK4sycl3_V18platform30ext_oneapi_get_default_contextEv _ZNK4sycl3_V18platform32ext_oneapi_get_composite_devicesEv _ZNK4sycl3_V18platform3getEv diff --git a/sycl/unittests/Extensions/DefaultContext.cpp b/sycl/unittests/Extensions/DefaultContext.cpp index e0b85ce1a4e85..797ff947dcf5c 100644 --- a/sycl/unittests/Extensions/DefaultContext.cpp +++ b/sycl/unittests/Extensions/DefaultContext.cpp @@ -36,6 +36,9 @@ void test_default_context_enabled() { ASSERT_EQ(Dev1.get_platform().ext_oneapi_get_default_context(), Dev2.get_platform().ext_oneapi_get_default_context()); + + ASSERT_EQ(Dev1.get_platform().khr_get_default_context(), + Dev2.get_platform().khr_get_default_context()); } void test_default_context_disabled() { @@ -51,6 +54,16 @@ void test_default_context_disabled() { ASSERT_TRUE(catchException) << "ext_oneapi_get_default_context did not throw an exception"; + + catchException = false; + try { + (void)Plt.khr_get_default_context(); + } catch (const std::exception &) { + catchException = true; + } + + ASSERT_TRUE(catchException) + << "khr_get_default_context did not throw an exception"; } TEST(DefaultContextTest, DefaultContextTest) { From bd5917bf5aedf35794ce628530ade8cb6599294c Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Thu, 10 Oct 2024 02:46:07 -0700 Subject: [PATCH 2/2] fix windows.dump test --- sycl/test/abi/sycl_symbols_windows.dump | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index ee50c1e8e471a..d5a6532004f93 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -3808,6 +3808,7 @@ ?ext_oneapi_fill2d_impl@handler@_V1@sycl@@AEAAXPEAX_KPEBX111@Z ?ext_oneapi_get_composite_devices@platform@_V1@sycl@@QEBA?AV?$vector@Vdevice@_V1@sycl@@V?$allocator@Vdevice@_V1@sycl@@@std@@@std@@XZ ?ext_oneapi_get_default_context@platform@_V1@sycl@@QEBA?AVcontext@23@XZ +?khr_get_default_context@platform@_V1@sycl@@QEBA?AVcontext@23@XZ ?ext_oneapi_get_graph@queue@_V1@sycl@@QEBA?AV?$command_graph@$0A@@experimental@oneapi@ext@23@XZ ?ext_oneapi_get_kernel@kernel_bundle_plain@detail@_V1@sycl@@AEAA?AVkernel@34@Vstring_view@234@@Z ?ext_oneapi_get_kernel@kernel_bundle_plain@detail@_V1@sycl@@QEAA?AVkernel@34@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z