Skip to content
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

[SYCL] Support sycl_khr_default_context #15645

Draft
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {

std::vector<device> 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;

Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class queue_impl {
context{createSyclObjFromImpl<device>(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(
Expand Down
1 change: 1 addition & 0 deletions sycl/source/feature_test.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion sycl/source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<detail::SYCL_ENABLE_DEFAULT_CONTEXTS>::get())
throw std::runtime_error("SYCL default contexts are not enabled");

Expand All @@ -108,6 +108,10 @@ context platform::ext_oneapi_get_default_context() const {
return detail::createSyclObjFromImpl<context>(It->second);
}

context platform::ext_oneapi_get_default_context() const {
return khr_get_default_context();
}

std::vector<device> platform::ext_oneapi_get_composite_devices() const {
// Only GPU architectures can be composite devices.
auto GPUDevices = get_devices(info::device_type::gpu);
Expand Down
25 changes: 25 additions & 0 deletions sycl/test-e2e/Basic/khr_get_default_context.cpp
Original file line number Diff line number Diff line change
@@ -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 <sycl/detail/core.hpp>
#include <algorithm>

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;
}
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sycl/unittests/Extensions/DefaultContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
Loading