Skip to content
Closed
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
2 changes: 2 additions & 0 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3545,7 +3545,9 @@ class __SYCL_EXPORT handler {
UserRange, KernelFunc};
}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
const std::shared_ptr<detail::context_impl> &getContextImplPtr() const;
#endif
detail::context_impl &getContextImpl() const;

// Checks if 2D memory operations are supported by the underlying platform.
Expand Down
6 changes: 6 additions & 0 deletions sycl/include/sycl/interop_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class interop_handle {
friend class detail::DispatchHostTask;
using ReqToMem = std::pair<detail::AccessorImplHost *, ur_mem_handle_t>;

#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
// Clean this up (no shared pointers). Not doing it right now because I expect
// there will be several iterations of simplifications possible and it would
// be hard to track which of them made their way into a minor public release
// and which didn't. Let's just clean it up once during ABI breaking window.
#endif
interop_handle(std::vector<ReqToMem> MemObjs,
const std::shared_ptr<detail::queue_impl> &Queue,
const std::shared_ptr<detail::device_impl> &Device,
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
ur_device_handle_t UrDevice =
Device ? getSyclObjImpl(*Device)->getHandleRef() : nullptr;
const auto &Adapter = getAdapter(Backend);
const auto &ContextImpl = getSyclObjImpl(Context);
context_impl &ContextImpl = *getSyclObjImpl(Context);

if (PropList.has_property<ext::intel::property::queue::compute_index>()) {
throw sycl::exception(
Expand Down Expand Up @@ -156,7 +156,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
ur_queue_handle_t UrQueue = nullptr;

Adapter->call<UrApiKind::urQueueCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), UrDevice, &NativeProperties,
NativeHandle, ContextImpl.getHandleRef(), UrDevice, &NativeProperties,
&UrQueue);
// Construct the SYCL queue from UR queue.
return detail::createSyclObjFromImpl<queue>(
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/async_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void *async_malloc(sycl::handler &h, sycl::usm::alloc kind, size_t size) {
sycl::make_error_code(sycl::errc::feature_not_supported),
"Only device backed asynchronous allocations are supported!");

auto &Adapter = h.getContextImplPtr()->getAdapter();
auto &Adapter = h.getContextImpl().getAdapter();

// Get CG event dependencies for this allocation.
const auto &DepEvents = h.impl->CGData.MEvents;
Expand Down Expand Up @@ -117,7 +117,7 @@ __SYCL_EXPORT void *async_malloc(const sycl::queue &q, sycl::usm::alloc kind,
__SYCL_EXPORT void *async_malloc_from_pool(sycl::handler &h, size_t size,
const memory_pool &pool) {

auto &Adapter = h.getContextImplPtr()->getAdapter();
auto &Adapter = h.getContextImpl().getAdapter();
auto &memPoolImpl = sycl::detail::getSyclObjImpl(pool);

// Get CG event dependencies for this allocation.
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/backend_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inline namespace _V1 {
namespace detail {

template <class T> backend getImplBackend(const T &Impl) {
return Impl->getContextImplPtr()->getBackend();
return Impl->getContextImpl().getBackend();
}

} // namespace detail
Expand Down
26 changes: 13 additions & 13 deletions sycl/source/detail/bindless_images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,9 @@ get_image_memory_support(const image_descriptor &imageDescriptor,
const sycl::context &syclContext) {
std::shared_ptr<sycl::detail::device_impl> DevImpl =
sycl::detail::getSyclObjImpl(syclDevice);
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
sycl::detail::context_impl &CtxImpl =
*sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();

ur_image_desc_t urDesc;
ur_image_format_t urFormat;
Expand All @@ -825,15 +825,15 @@ get_image_memory_support(const image_descriptor &imageDescriptor,
Adapter->call<sycl::errc::runtime,
sycl::detail::UrApiKind::
urBindlessImagesGetImageMemoryHandleTypeSupportExp>(
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
ur_exp_image_mem_type_t::UR_EXP_IMAGE_MEM_TYPE_USM_POINTER,
&supportsPointerAllocation);

ur_bool_t supportsOpaqueAllocation{0};
Adapter->call<sycl::errc::runtime,
sycl::detail::UrApiKind::
urBindlessImagesGetImageMemoryHandleTypeSupportExp>(
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
ur_exp_image_mem_type_t::UR_EXP_IMAGE_MEM_TYPE_OPAQUE_HANDLE,
&supportsOpaqueAllocation);

Expand Down Expand Up @@ -864,9 +864,9 @@ __SYCL_EXPORT bool is_image_handle_supported<unsampled_image_handle>(
const sycl::device &syclDevice, const sycl::context &syclContext) {
std::shared_ptr<sycl::detail::device_impl> DevImpl =
sycl::detail::getSyclObjImpl(syclDevice);
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
sycl::detail::context_impl &CtxImpl =
*sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();

ur_image_desc_t urDesc;
ur_image_format_t urFormat;
Expand All @@ -881,7 +881,7 @@ __SYCL_EXPORT bool is_image_handle_supported<unsampled_image_handle>(
Adapter->call<sycl::errc::runtime,
sycl::detail::UrApiKind::
urBindlessImagesGetImageUnsampledHandleSupportExp>(
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
memHandleType, &supportsUnsampledHandle);

return supportsUnsampledHandle;
Expand All @@ -904,9 +904,9 @@ __SYCL_EXPORT bool is_image_handle_supported<sampled_image_handle>(
const sycl::device &syclDevice, const sycl::context &syclContext) {
std::shared_ptr<sycl::detail::device_impl> DevImpl =
sycl::detail::getSyclObjImpl(syclDevice);
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
sycl::detail::context_impl &CtxImpl =
*sycl::detail::getSyclObjImpl(syclContext);
const sycl::detail::AdapterPtr &Adapter = CtxImpl.getAdapter();

ur_image_desc_t urDesc;
ur_image_format_t urFormat;
Expand All @@ -921,7 +921,7 @@ __SYCL_EXPORT bool is_image_handle_supported<sampled_image_handle>(
Adapter->call<
sycl::errc::runtime,
sycl::detail::UrApiKind::urBindlessImagesGetImageSampledHandleSupportExp>(
CtxImpl->getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
CtxImpl.getHandleRef(), DevImpl->getHandleRef(), &urDesc, &urFormat,
memHandleType, &supportsSampledHandle);

return supportsSampledHandle;
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,9 @@ class CGHostTask : public CG {
std::vector<ArgDesc> MArgs;

CGHostTask(std::shared_ptr<HostTask> HostTask, detail::queue_impl *Queue,
std::shared_ptr<detail::context_impl> Context,
std::vector<ArgDesc> Args, CG::StorageInitHelper CGData,
CGType Type, detail::code_location loc = {});
detail::context_impl *Context, std::vector<ArgDesc> Args,
CG::StorageInitHelper CGData, CGType Type,
detail::code_location loc = {});
};

} // namespace detail
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,13 @@ class device_image_impl {

ur_native_handle_t getNative() const {
assert(MProgram);
const auto &ContextImplPtr = detail::getSyclObjImpl(MContext);
const AdapterPtr &Adapter = ContextImplPtr->getAdapter();
context_impl &ContextImpl = *detail::getSyclObjImpl(MContext);
const AdapterPtr &Adapter = ContextImpl.getAdapter();

ur_native_handle_t NativeProgram = 0;
Adapter->call<UrApiKind::urProgramGetNativeHandle>(MProgram,
&NativeProgram);
if (ContextImplPtr->getBackend() == backend::opencl)
if (ContextImpl.getBackend() == backend::opencl)
__SYCL_OCL_CALL(clRetainProgram, ur::cast<cl_program>(NativeProgram));

return NativeProgram;
Expand Down
9 changes: 1 addition & 8 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class context;
namespace detail {
class Adapter;
class context_impl;
using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
class queue_impl;
class event_impl;
using EventImplPtr = std::shared_ptr<sycl::detail::event_impl>;
Expand Down Expand Up @@ -312,12 +311,6 @@ class event_impl {

bool isDefaultConstructed() const noexcept { return MIsDefaultConstructed; }

ContextImplPtr getContextImplPtr() {
if (MIsDefaultConstructed)
initContextIfNeeded();
return MContext;
}

// Sets a sync point which is used when this event represents an enqueue to a
// Command Buffer.
void setSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint) {
Expand Down Expand Up @@ -394,7 +387,7 @@ class event_impl {
std::atomic<ur_event_handle_t> MEvent = nullptr;
// Stores submission time of command associated with event
uint64_t MSubmitTime = 0;
ContextImplPtr MContext;
std::shared_ptr<context_impl> MContext;
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
void *MCommand = nullptr;
std::weak_ptr<queue_impl> MQueue;
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ ProgramManager &GlobalHandler::getProgramManager() {
return PM;
}

std::unordered_map<platform_impl *, ContextImplPtr> &
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
GlobalHandler::getPlatformToDefaultContextCache() {
// The optimization with static reference is not done because
// there are public methods of the GlobalHandler
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class XPTIRegistry;
class ThreadPool;
struct KernelNameBasedCacheT;

using ContextImplPtr = std::shared_ptr<context_impl>;
using AdapterPtr = std::shared_ptr<Adapter>;

/// Wrapper class for global data structures with non-trivial destructors.
Expand Down Expand Up @@ -65,7 +64,7 @@ class GlobalHandler {

void clearPlatforms();

std::unordered_map<platform_impl *, ContextImplPtr> &
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
getPlatformToDefaultContextCache();

std::mutex &getPlatformToDefaultContextCacheMutex();
Expand Down Expand Up @@ -121,7 +120,8 @@ class GlobalHandler {
InstWithLock<ProgramManager> MProgramManager;
InstWithLock<Sync> MSync;
InstWithLock<std::vector<std::shared_ptr<platform_impl>>> MPlatformCache;
InstWithLock<std::unordered_map<platform_impl *, ContextImplPtr>>
InstWithLock<
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>>>
MPlatformToDefaultContextCache;
InstWithLock<std::mutex> MPlatformToDefaultContextCacheMutex;
InstWithLock<std::mutex> MPlatformMapMutex;
Expand Down
12 changes: 6 additions & 6 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ exec_graph_impl::enqueueNode(ur_exp_command_buffer_handle_t CommandBuffer,

sycl::detail::EventImplPtr Event =
sycl::detail::Scheduler::getInstance().addCG(
Node->getCGCopy(), MQueueImpl,
Node->getCGCopy(), *MQueueImpl,
/*EventNeeded=*/true, CommandBuffer, Deps);

if (MIsUpdatable) {
Expand Down Expand Up @@ -996,7 +996,7 @@ exec_graph_impl::exec_graph_impl(sycl::context Context,
: MSchedule(), MGraphImpl(GraphImpl), MSyncPoints(),
MQueueImpl(sycl::detail::queue_impl::create(
*sycl::detail::getSyclObjImpl(GraphImpl->getDevice()),
sycl::detail::getSyclObjImpl(Context), sycl::async_handler{},
*sycl::detail::getSyclObjImpl(Context), sycl::async_handler{},
sycl::property_list{})),
MDevice(GraphImpl->getDevice()), MContext(Context), MRequirements(),
MSchedulerDependencies(),
Expand Down Expand Up @@ -1084,12 +1084,12 @@ EventImplPtr exec_graph_impl::enqueueHostTaskPartition(
// dependencies for the current execution.
std::unique_ptr<sycl::detail::CG> CommandGroup =
std::make_unique<sycl::detail::CGHostTask>(sycl::detail::CGHostTask(
NodeCommandGroup->MHostTask, &Queue, NodeCommandGroup->MContext,
NodeCommandGroup->MHostTask, &Queue, NodeCommandGroup->MContext.get(),
NodeCommandGroup->MArgs, std::move(CGData),
NodeCommandGroup->getType()));

EventImplPtr SchedulerEvent = sycl::detail::Scheduler::getInstance().addCG(
std::move(CommandGroup), Queue.shared_from_this(), EventNeeded);
std::move(CommandGroup), Queue, EventNeeded);

if (EventNeeded) {
return SchedulerEvent;
Expand Down Expand Up @@ -1117,7 +1117,7 @@ EventImplPtr exec_graph_impl::enqueuePartitionWithScheduler(
CommandBuffer, nullptr, std::move(CGData));

EventImplPtr SchedulerEvent = sycl::detail::Scheduler::getInstance().addCG(
std::move(CommandGroup), Queue.shared_from_this(), EventNeeded);
std::move(CommandGroup), Queue, EventNeeded);

if (EventNeeded) {
SchedulerEvent->setEventFromSubmittedExecCommandBuffer(true);
Expand Down Expand Up @@ -1592,7 +1592,7 @@ void exec_graph_impl::update(
// other scheduler commands
auto UpdateEvent =
sycl::detail::Scheduler::getInstance().addCommandGraphUpdate(
this, Nodes, MQueueImpl, std::move(UpdateRequirements),
this, Nodes, MQueueImpl.get(), std::move(UpdateRequirements),
MSchedulerDependencies);

MSchedulerDependencies.push_back(UpdateEvent);
Expand Down
9 changes: 7 additions & 2 deletions sycl/source/detail/graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
return std::make_unique<sycl::detail::CGHostTask>(
sycl::detail::CGHostTask(
std::move(HostTaskSPtr), CommandGroupPtr->MQueue.get(),
CommandGroupPtr->MContext, std::move(NewArgs), std::move(Data),
CommandGroupPtr->getType(), Loc));
CommandGroupPtr->MContext.get(), std::move(NewArgs),
std::move(Data), CommandGroupPtr->getType(), Loc));
}
case sycl::detail::CGType::Barrier:
case sycl::detail::CGType::BarrierWaitlist:
Expand Down Expand Up @@ -980,9 +980,14 @@ class graph_impl : public std::enable_shared_from_this<graph_impl> {

/// Query for the context impl tied to this graph.
/// @return shared_ptr ref for the context impl associated with graph.
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
const std::shared_ptr<sycl::detail::context_impl> &getContextImplPtr() const {
return sycl::detail::getSyclObjImpl(MContext);
}
#endif
sycl::detail::context_impl &getContextImpl() const {
return *sycl::detail::getSyclObjImpl(MContext);
}

/// Query for the device_impl tied to this graph.
/// @return device_impl shared ptr reference associated with graph.
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/handler_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class handler_impl {
template <typename Self = handler_impl> context_impl &get_context() {
Self *self = this;
if (auto *Queue = self->get_queue_or_null())
return *Queue->getContextImplPtr();
return Queue->getContextImpl();
else
return *self->get_graph().getContextImplPtr();
return self->get_graph().getContextImpl();
}

/// If we are submitting a graph using ext_oneapi_graph this will be the graph
Expand Down
11 changes: 5 additions & 6 deletions sycl/source/detail/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

namespace sycl {
inline namespace _V1 {
using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;
namespace detail {
void waitEvents(std::vector<sycl::event> DepEvents) {
for (auto SyclEvent : DepEvents) {
Expand Down Expand Up @@ -59,10 +58,10 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
if (DeviceImage == DeviceImages.end()) {
return {nullptr, nullptr};
}
auto ContextImpl = Queue.getContextImplPtr();
context_impl &ContextImpl = Queue.getContextImpl();
ur_program_handle_t Program =
detail::ProgramManager::getInstance().createURProgram(
**DeviceImage, *ContextImpl, {createSyclObjFromImpl<device>(Dev)});
**DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
return {*DeviceImage, Program};
}

Expand All @@ -79,11 +78,11 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
DeviceImage = SyclKernelImpl->getDeviceImage()->get_bin_image_ref();
Program = SyclKernelImpl->getDeviceImage()->get_ur_program_ref();
} else {
auto ContextImpl = Queue.getContextImplPtr();
context_impl &ContextImpl = Queue.getContextImpl();
DeviceImage = &detail::ProgramManager::getInstance().getDeviceImage(
KernelName, *ContextImpl, Dev);
KernelName, ContextImpl, Dev);
Program = detail::ProgramManager::getInstance().createURProgram(
*DeviceImage, *ContextImpl, {createSyclObjFromImpl<device>(Dev)});
*DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
}
return {DeviceImage, Program};
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/kernel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class kernel_impl {
bool isInterop() const { return MIsInterop; }

ur_program_handle_t getProgramRef() const { return MProgram; }
ContextImplPtr getContextImplPtr() const { return MContext; }
context_impl &getContextImpl() const { return *MContext; }

std::mutex &getNoncacheableEnqueueMutex() const {
return MNoncacheableEnqueueMutex;
Expand Down
2 changes: 0 additions & 2 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ namespace sycl {
inline namespace _V1 {
namespace detail {

using ContextImplPtr = std::shared_ptr<sycl::detail::context_impl>;

static constexpr int DbgProgMgr = 0;

static constexpr char UseSpvEnv[]("SYCL_USE_KERNEL_SPV");
Expand Down
1 change: 0 additions & 1 deletion sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ bool doesImageTargetMatchDevice(const RTDeviceBinaryImage &Img,
static constexpr uint32_t inline ITTSpecConstId = 0xFF747469;

class context_impl;
using ContextImplPtr = std::shared_ptr<context_impl>;
class device_impl;
class queue_impl;
class event_impl;
Expand Down
Loading