Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions sycl/gdb/libsycl.so-gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ def range_common_array(self):
class SYCLDevice(SYCLValue):
"""Provides information about a sycl::device from a gdb.Value."""

IMPL_OFFSET_TO_DEVICE_TYPE = 0x8
IMPL_OFFSET_TO_PLATFORM = 0x18
IMPL_OFFSET_TO_DEVICE_TYPE = 0x18
IMPL_OFFSET_TO_PLATFORM = 0x28
PLATFORM_OFFSET_TO_BACKEND = 0x20

def __init__(self, gdb_value):
Expand Down
6 changes: 2 additions & 4 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ class HandlerAccess;
class HostTask;

using EventImplPtr = std::shared_ptr<event_impl>;
using DeviceImplPtr = std::shared_ptr<device_impl>;

template <typename RetType, typename Func, typename Arg>
static Arg member_ptr_helper(RetType (Func::*)(Arg) const);
Expand Down Expand Up @@ -251,7 +250,7 @@ template <typename Type> struct get_kernel_wrapper_name_t {
};

__SYCL_EXPORT device getDeviceFromHandler(handler &);
const DeviceImplPtr &getDeviceImplFromHandler(handler &);
device_impl &getDeviceImplFromHandler(handler &);

// Checks if a device_global has any registered kernel usage.
__SYCL_EXPORT bool isDeviceGlobalUsedInKernel(const void *DeviceGlobalPtr);
Expand Down Expand Up @@ -3303,8 +3302,7 @@ class __SYCL_EXPORT handler {
typename PropertyListT>
friend class accessor;
friend device detail::getDeviceFromHandler(handler &);
friend const detail::DeviceImplPtr &
detail::getDeviceImplFromHandler(handler &);
friend detail::device_impl &detail::getDeviceImplFromHandler(handler &);

template <typename DataT, int Dimensions, access::mode AccessMode,
access::target AccessTarget, access::placeholder IsPlaceholder>
Expand Down
7 changes: 3 additions & 4 deletions sycl/source/backend/opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ __SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice,
"has_extension can only be used with an OpenCL backend");
}

std::shared_ptr<sycl::detail::device_impl> DeviceImpl =
getSyclObjImpl(SyclDevice);
ur_device_handle_t AdapterDevice = DeviceImpl->getHandleRef();
const AdapterPtr &Adapter = DeviceImpl->getAdapter();
detail::device_impl &DeviceImpl = *getSyclObjImpl(SyclDevice);
ur_device_handle_t AdapterDevice = DeviceImpl.getHandleRef();
const AdapterPtr &Adapter = DeviceImpl.getAdapter();

// Manual invocation of UR API to avoid using deprecated
// info::device::extensions call.
Expand Down
10 changes: 4 additions & 6 deletions sycl/source/detail/allowlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,

int InsertIDx = 0;
for (ur_device_handle_t Device : UrDevices) {
auto DeviceImpl = PlatformImpl.getOrMakeDeviceImpl(Device);
device_impl &DeviceImpl = PlatformImpl.getOrMakeDeviceImpl(Device);
// get DeviceType value and put it to DeviceDesc
ur_device_type_t UrDevType = UR_DEVICE_TYPE_ALL;
Adapter->call<UrApiKind::urDeviceGetInfo>(
Expand Down Expand Up @@ -429,20 +429,18 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
}
// get DeviceVendorId value and put it to DeviceDesc
uint32_t DeviceVendorIdUInt =
sycl::detail::get_device_info<info::device::vendor_id>(
*DeviceImpl.get());
sycl::detail::get_device_info<info::device::vendor_id>(DeviceImpl);
std::stringstream DeviceVendorIdHexStringStream;
DeviceVendorIdHexStringStream << "0x" << std::hex << DeviceVendorIdUInt;
const auto &DeviceVendorIdValue = DeviceVendorIdHexStringStream.str();
DeviceDesc[DeviceVendorIdKeyName] = DeviceVendorIdValue;
// get DriverVersion value and put it to DeviceDesc
const std::string &DriverVersionValue =
sycl::detail::get_device_info<info::device::driver_version>(
*DeviceImpl.get());
sycl::detail::get_device_info<info::device::driver_version>(DeviceImpl);
DeviceDesc[DriverVersionKeyName] = DriverVersionValue;
// get DeviceName value and put it to DeviceDesc
const std::string &DeviceNameValue =
sycl::detail::get_device_info<info::device::name>(*DeviceImpl.get());
sycl::detail::get_device_info<info::device::name>(DeviceImpl);
DeviceDesc[DeviceNameKeyName] = DeviceNameValue;

// check if we can allow device with such device description DeviceDesc
Expand Down
26 changes: 12 additions & 14 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,18 @@ KernelProgramCache &context_impl::getKernelProgramCache() const {
return MKernelProgramCache;
}

bool context_impl::hasDevice(
std::shared_ptr<detail::device_impl> Device) const {
bool context_impl::hasDevice(const detail::device_impl &Device) const {
for (auto D : MDevices)
if (getSyclObjImpl(D) == Device)
if (getSyclObjImpl(D).get() == &Device)
return true;
return false;
}

DeviceImplPtr
device_impl *
context_impl::findMatchingDeviceImpl(ur_device_handle_t &DeviceUR) const {
for (device D : MDevices)
if (getSyclObjImpl(D)->getHandleRef() == DeviceUR)
return getSyclObjImpl(D);
return getSyclObjImpl(D).get();

return nullptr;
}
Expand Down Expand Up @@ -356,10 +355,10 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
return {};

const AdapterPtr &Adapter = getAdapter();
const DeviceImplPtr &DeviceImpl = QueueImpl->getDeviceImplPtr();
device_impl &DeviceImpl = QueueImpl->getDeviceImpl();
std::lock_guard<std::mutex> NativeProgramLock(MDeviceGlobalInitializersMutex);
auto ImgIt = MDeviceGlobalInitializers.find(
std::make_pair(NativePrg, DeviceImpl->getHandleRef()));
std::make_pair(NativePrg, DeviceImpl.getHandleRef()));
if (ImgIt == MDeviceGlobalInitializers.end() ||
ImgIt->second.MDeviceGlobalsFullyInitialized)
return {};
Expand Down Expand Up @@ -461,12 +460,12 @@ void context_impl::DeviceGlobalInitializer::ClearEvents(
}

void context_impl::memcpyToHostOnlyDeviceGlobal(
const std::shared_ptr<device_impl> &DeviceImpl, const void *DeviceGlobalPtr,
device_impl &DeviceImpl, const void *DeviceGlobalPtr,
const void *Src, size_t DeviceGlobalTSize, bool IsDeviceImageScoped,
size_t NumBytes, size_t Offset) {
std::optional<ur_device_handle_t> KeyDevice = std::nullopt;
if (IsDeviceImageScoped)
KeyDevice = DeviceImpl->getHandleRef();
KeyDevice = DeviceImpl.getHandleRef();
auto Key = std::make_pair(DeviceGlobalPtr, KeyDevice);

std::lock_guard<std::mutex> InitLock(MDeviceGlobalUnregisteredDataMutex);
Expand All @@ -483,13 +482,13 @@ void context_impl::memcpyToHostOnlyDeviceGlobal(
}

void context_impl::memcpyFromHostOnlyDeviceGlobal(
const std::shared_ptr<device_impl> &DeviceImpl, void *Dest,
device_impl &DeviceImpl, void *Dest,
const void *DeviceGlobalPtr, bool IsDeviceImageScoped, size_t NumBytes,
size_t Offset) {

std::optional<ur_device_handle_t> KeyDevice = std::nullopt;
if (IsDeviceImageScoped)
KeyDevice = DeviceImpl->getHandleRef();
KeyDevice = DeviceImpl.getHandleRef();
auto Key = std::make_pair(DeviceGlobalPtr, KeyDevice);

std::lock_guard<std::mutex> InitLock(MDeviceGlobalUnregisteredDataMutex);
Expand Down Expand Up @@ -580,9 +579,8 @@ context_impl::get_default_memory_pool(const context &Context,

assert(Kind == usm::alloc::device);

std::shared_ptr<sycl::detail::device_impl> DevImpl =
sycl::detail::getSyclObjImpl(Device);
ur_device_handle_t DeviceHandle = DevImpl->getHandleRef();
detail::device_impl &DevImpl = *detail::getSyclObjImpl(Device);
ur_device_handle_t DeviceHandle = DevImpl.getHandleRef();
const sycl::detail::AdapterPtr &Adapter = this->getAdapter();

// Check dev is already in our list of device pool pairs.
Expand Down
42 changes: 22 additions & 20 deletions sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,35 @@ class context_impl {
KernelProgramCache &getKernelProgramCache() const;

/// Returns true if and only if context contains the given device.
bool hasDevice(std::shared_ptr<detail::device_impl> Device) const;
bool hasDevice(const detail::device_impl &Device) const;

/// Returns true if and only if the device can be used within this context.
/// For OpenCL this is currently equivalent to hasDevice, for other backends
/// it returns true if the device is either a member of the context or a
/// descendant of a member.
bool isDeviceValid(DeviceImplPtr Device) {
while (!hasDevice(Device)) {
if (Device->isRootDevice()) {
if (Device->has(aspect::ext_oneapi_is_component)) {
bool isDeviceValid(detail::device_impl &Device) {
detail::device_impl *CurrDevice = &Device;
while (!hasDevice(*CurrDevice)) {
if (CurrDevice->isRootDevice()) {
if (CurrDevice->has(aspect::ext_oneapi_is_component)) {
// Component devices should be implicitly usable in context created
// for a composite device they belong to.
auto CompositeDevice = Device->get_info<
auto CompositeDevice = CurrDevice->get_info<
ext::oneapi::experimental::info::device::composite_device>();
return hasDevice(detail::getSyclObjImpl(CompositeDevice));
return hasDevice(*detail::getSyclObjImpl(CompositeDevice));
}

return false;
} else if (Device->getBackend() == backend::opencl) {
} else if (CurrDevice->getBackend() == backend::opencl) {
// OpenCL does not support using descendants of context members within
// that context yet. We make the exception in case it supports
// component/composite devices.
// TODO remove once this limitation is lifted
return false;
}
Device = detail::getSyclObjImpl(
Device->get_info<info::device::parent_device>());
CurrDevice = detail::getSyclObjImpl(
CurrDevice->get_info<info::device::parent_device>())
.get();
}

return true;
Expand All @@ -190,7 +192,7 @@ class context_impl {

/// Given a UR device, returns the matching shared_ptr<device_impl>
/// within this context. May return nullptr if no match discovered.
DeviceImplPtr findMatchingDeviceImpl(ur_device_handle_t &DeviceUR) const;
device_impl *findMatchingDeviceImpl(ur_device_handle_t &DeviceUR) const;

/// Gets the native handle of the SYCL context.
///
Expand All @@ -216,16 +218,16 @@ class context_impl {
initializeDeviceGlobals(ur_program_handle_t NativePrg,
const std::shared_ptr<queue_impl> &QueueImpl);

void memcpyToHostOnlyDeviceGlobal(
const std::shared_ptr<device_impl> &DeviceImpl,
const void *DeviceGlobalPtr, const void *Src, size_t DeviceGlobalTSize,
bool IsDeviceImageScoped, size_t NumBytes, size_t Offset);
void memcpyToHostOnlyDeviceGlobal(device_impl &DeviceImpl,
const void *DeviceGlobalPtr,
const void *Src, size_t DeviceGlobalTSize,
bool IsDeviceImageScoped, size_t NumBytes,
size_t Offset);

void
memcpyFromHostOnlyDeviceGlobal(const std::shared_ptr<device_impl> &DeviceImpl,
void *Dest, const void *DeviceGlobalPtr,
bool IsDeviceImageScoped, size_t NumBytes,
size_t Offset);
void memcpyFromHostOnlyDeviceGlobal(device_impl &DeviceImpl, void *Dest,
const void *DeviceGlobalPtr,
bool IsDeviceImageScoped, size_t NumBytes,
size_t Offset);

/// Gets a program associated with a device global from the cache.
std::optional<ur_program_handle_t>
Expand Down
9 changes: 4 additions & 5 deletions sycl/source/detail/device_global_map_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ DeviceGlobalUSMMem &DeviceGlobalMapEntry::getOrAllocateDeviceGlobalUSM(
"USM allocations should not be acquired for device_global with "
"device_image_scope property.");
const std::shared_ptr<context_impl> &CtxImpl = QueueImpl->getContextImplPtr();
const std::shared_ptr<device_impl> &DevImpl = QueueImpl->getDeviceImplPtr();
const device_impl &DevImpl = QueueImpl->getDeviceImpl();
std::lock_guard<std::mutex> Lock(MDeviceToUSMPtrMapMutex);

auto DGUSMPtr = MDeviceToUSMPtrMap.find({DevImpl.get(), CtxImpl.get()});
auto DGUSMPtr = MDeviceToUSMPtrMap.find({&DevImpl, CtxImpl.get()});
if (DGUSMPtr != MDeviceToUSMPtrMap.end())
return DGUSMPtr->second;

void *NewDGUSMPtr = detail::usm::alignedAllocInternal(
0, MDeviceGlobalTSize, CtxImpl.get(), DevImpl.get(),
0, MDeviceGlobalTSize, CtxImpl.get(), &DevImpl,
sycl::usm::alloc::device);

auto NewAllocIt = MDeviceToUSMPtrMap.emplace(
std::piecewise_construct,
std::forward_as_tuple(DevImpl.get(), CtxImpl.get()),
std::piecewise_construct, std::forward_as_tuple(&DevImpl, CtxImpl.get()),
std::forward_as_tuple(NewDGUSMPtr));
assert(NewAllocIt.second &&
"USM allocation for device and context already happened.");
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,12 @@ class device_image_impl {
getSyclObjImpl(MContext);

for (const auto &SyclDev : Devices) {
const DeviceImplPtr &DevImpl = getSyclObjImpl(SyclDev);
device_impl &DevImpl = *getSyclObjImpl(SyclDev);
if (!ContextImpl->hasDevice(DevImpl)) {
throw sycl::exception(make_error_code(errc::invalid),
"device not part of kernel_bundle context");
}
if (!DevImpl->extOneapiCanCompile(MRTCBinInfo->MLanguage)) {
if (!DevImpl.extOneapiCanCompile(MRTCBinInfo->MLanguage)) {
// This error cannot not be exercised in the current implementation, as
// compatibility with a source language depends on the backend's
// capabilities and all devices in one context share the same backend in
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace detail {
class platform_impl;

// TODO: Make code thread-safe
class device_impl {
class device_impl : public std::enable_shared_from_this<device_impl> {
struct private_tag {
explicit private_tag() = default;
};
Expand Down
10 changes: 5 additions & 5 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void event_impl::initContextIfNeeded() {

const device SyclDevice;
this->setContextImpl(
detail::queue_impl::getDefaultOrNew(detail::getSyclObjImpl(SyclDevice)));
detail::queue_impl::getDefaultOrNew(*detail::getSyclObjImpl(SyclDevice)));
}

event_impl::~event_impl() {
Expand Down Expand Up @@ -442,8 +442,8 @@ event_impl::get_backend_info<info::platform::version>() const {
"only be queried with an OpenCL backend");
}
if (QueueImplPtr Queue = MQueue.lock()) {
return Queue->getDeviceImplPtr()
->get_platform()
return Queue->getDeviceImpl()
.get_platform()
.get_info<info::platform::version>();
}
// If the queue has been released, no platform will be associated
Expand All @@ -465,7 +465,7 @@ event_impl::get_backend_info<info::device::version>() const {
"be queried with an OpenCL backend");
}
if (QueueImplPtr Queue = MQueue.lock()) {
return Queue->getDeviceImplPtr()->get_info<info::device::version>();
return Queue->getDeviceImpl().get_info<info::device::version>();
}
return ""; // If the queue has been released, no device will be associated so
// return empty string
Expand Down Expand Up @@ -590,7 +590,7 @@ void event_impl::setSubmissionTime() {
if (!MFallbackProfiling) {
if (QueueImplPtr Queue = MQueue.lock()) {
try {
MSubmitTime = Queue->getDeviceImplPtr()->getCurrentDeviceTime();
MSubmitTime = Queue->getDeviceImpl().getCurrentDeviceTime();
} catch (sycl::exception &e) {
if (e.code() == sycl::errc::feature_not_supported)
throw sycl::exception(
Expand Down
11 changes: 6 additions & 5 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ void exec_graph_impl::findRealDeps(

ur_exp_command_buffer_sync_point_t
exec_graph_impl::enqueueNodeDirect(sycl::context Ctx,
sycl::detail::DeviceImplPtr DeviceImpl,
sycl::detail::device_impl &DeviceImpl,
ur_exp_command_buffer_handle_t CommandBuffer,
std::shared_ptr<node_impl> Node) {
std::vector<ur_exp_command_buffer_sync_point_t> Deps;
Expand Down Expand Up @@ -861,10 +861,10 @@ void exec_graph_impl::createCommandBuffers(
Partition->MIsInOrderGraph && !MEnableProfiling, MEnableProfiling};
auto ContextImpl = sycl::detail::getSyclObjImpl(MContext);
const sycl::detail::AdapterPtr &Adapter = ContextImpl->getAdapter();
auto DeviceImpl = sycl::detail::getSyclObjImpl(Device);
sycl::detail::device_impl & DeviceImpl = *sycl::detail::getSyclObjImpl(Device);
ur_result_t Res =
Adapter->call_nocheck<sycl::detail::UrApiKind::urCommandBufferCreateExp>(
ContextImpl->getHandleRef(), DeviceImpl->getHandleRef(), &Desc,
ContextImpl->getHandleRef(), DeviceImpl.getHandleRef(), &Desc,
&OutCommandBuffer);
if (Res != UR_RESULT_SUCCESS) {
throw sycl::exception(errc::invalid, "Failed to create UR command-buffer");
Expand Down Expand Up @@ -1462,7 +1462,8 @@ void exec_graph_impl::populateURKernelUpdateStructs(
ur_exp_command_buffer_update_kernel_launch_desc_t &UpdateDesc) const {
auto ContextImpl = sycl::detail::getSyclObjImpl(MContext);
const sycl::detail::AdapterPtr &Adapter = ContextImpl->getAdapter();
auto DeviceImpl = sycl::detail::getSyclObjImpl(MGraphImpl->getDevice());
sycl::detail::device_impl &DeviceImpl =
*sycl::detail::getSyclObjImpl(MGraphImpl->getDevice());

// Gather arg information from Node
auto &ExecCG =
Expand Down Expand Up @@ -1515,7 +1516,7 @@ void exec_graph_impl::populateURKernelUpdateStructs(
LocalSize = &NDRDesc.LocalSize[0];
else {
Adapter->call<sycl::detail::UrApiKind::urKernelGetGroupInfo>(
UrKernel, DeviceImpl->getHandleRef(),
UrKernel, DeviceImpl.getHandleRef(),
UR_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE, sizeof(RequiredWGSize),
RequiredWGSize,
/* param_value_size_ret = */ nullptr);
Expand Down
6 changes: 2 additions & 4 deletions sycl/source/detail/graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,7 @@ class graph_impl : public std::enable_shared_from_this<graph_impl> {

/// Query for the device_impl tied to this graph.
/// @return device_impl shared ptr reference associated with graph.
const DeviceImplPtr &getDeviceImplPtr() const {
return getSyclObjImpl(MDevice);
}
device_impl &getDeviceImpl() const { return *getSyclObjImpl(MDevice); }

/// Query for the device tied to this graph.
/// @return Device associated with graph.
Expand Down Expand Up @@ -1421,7 +1419,7 @@ class exec_graph_impl {
/// @param Node The node being enqueued.
/// @return UR sync point created for this node in the command-buffer.
ur_exp_command_buffer_sync_point_t
enqueueNodeDirect(sycl::context Ctx, sycl::detail::DeviceImplPtr DeviceImpl,
enqueueNodeDirect(sycl::context Ctx, sycl::detail::device_impl &DeviceImpl,
ur_exp_command_buffer_handle_t CommandBuffer,
std::shared_ptr<node_impl> Node);

Expand Down
Loading
Loading