8000 [NFC][SYCL] Move `platform::khr_get_default_context` impl to `platform_impl.cpp` by aelovikov-intel · Pull Request #19157 · intel/llvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[NFC][SYCL] Move platform::khr_get_default_context impl to platform_impl.cpp #19157

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
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
17 changes: 17 additions & 0 deletions sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ platform_impl::getPlatformFromUrDevice(ur_device_handle_t UrDevice,
return getOrMakePlatformImpl(Plt, Adapter);
}

context_impl &platform_impl::khr_get_default_context() {
GlobalHandler &GH = GlobalHandler::instance();
// Keeping the default context for platforms in the global cache to avoid
// shared_ptr based circular dependency between platform and context classes
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>>
&PlatformToDefaultContextCache = GH.getPlatformToDefaultContextCache();

std::lock_guard<std::mutex> Lock{GH.getPlatformToDefaultContextCacheMutex()};

auto It = PlatformToDefaultContextCache.find(this);
if (PlatformToDefaultContextCache.end() == It)
std::tie(It, std::ignore) = PlatformToDefaultContextCache.insert(
{this, detail::getSyclObjImpl(context{get_devices()})});

return *It->second;
}

static bool IsBannedPlatform(platform Platform) {
// The NVIDIA OpenCL platform is currently not compatible with DPC++
// since it is only 1.2 but gets selected by default in many systems
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/platform_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ class platform_impl : public std::enable_shared_from_this<platform_impl> {
static platform_impl &getPlatformFromUrDevice(ur_device_handle_t UrDevice,
const AdapterPtr &Adapter);

context_impl &khr_get_default_context();

// when getting sub-devices for ONEAPI_DEVICE_SELECTOR we may temporarily
// ensure every device is a root one.
bool MAlwaysRootDevice = false;
Expand Down
22 changes: 11 additions & 11 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
public:
// \return a default context for the platform if it includes the device
// passed and default contexts are enabled, a new context otherwise.
static ContextImplPtr getDefaultOrNew(device_impl &Device) {
if (!SYCLConfig<SYCL_ENABLE_DEFAULT_CONTEXTS>::get())
return detail::getSyclObjImpl(
context{createSyclObjFromImpl<device>(Device), {}, {}});

ContextImplPtr DefaultContext =
detail::getSyclObjImpl(Device.get_platform().khr_get_default_context());
if (DefaultContext->isDeviceValid(Device))
return DefaultContext;
return detail::getSyclObjImpl(
context{createSyclObjFromImpl<device>(Device), {}, {}});
static std::shared_ptr<context_impl> getDefaultOrNew(device_impl &Device) {
if (SYCLConfig<SYCL_ENABLE_DEFAULT_CONTEXTS>::get()) {
context_impl &CtxImpl =
Device.getPlatformImpl().khr_get_default_context();
if (CtxImpl.isDeviceValid(Device))
return CtxImpl.shared_from_this();
}

return context_impl::create(
std::vector<device>{createSyclObjFromImpl<device>(Device)},
async_handler{}, property_list{});
}
/// Constructs a SYCL queue from a device using an async_handler and
/// property_list provided.
Expand Down
19 changes: 3 additions & 16 deletions sycl/source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <detail/backend_impl.hpp>
#include <detail/config.hpp>
#include <detail/context_impl.hpp>
#include <detail/global_handler.hpp>
#include <detail/platform_impl.hpp>
#include <detail/ur.hpp>
Expand Down Expand Up @@ -89,22 +90,8 @@ platform::get_backend_info() const {
#undef __SYCL_PARAM_TRAITS_SPEC

context platform::khr_get_default_context() const {
// Keeping the default context for platforms in the global cache to avoid
// shared_ptr based circular dependency between platform and context classes
std::unordered_map<detail::platform_impl *, detail::ContextImplPtr>
&PlatformToDefaultContextCache =
detail::GlobalHandler::instance().getPlatformToDefaultContextCache();

std::lock_guard<std::mutex> Lock{
detail::GlobalHandler::instance()
.getPlatformToDefaultContextCacheMutex()};

auto It = PlatformToDefaultContextCache.find(impl.get());
if (PlatformToDefaultContextCache.end() == It)
std::tie(It, std::ignore) = PlatformToDefaultContextCache.insert(
{impl.get(), detail::getSyclObjImpl(context{get_devices()})});

return detail::createSyclObjFromImpl<context>(It->second);
return detail::createSyclObjFromImpl<context>(
impl->khr_get_default_context());
}

context platform::ext_oneapi_get_default_context() const {
Expand Down
0