DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl::_V1::detail::context_impl Class Reference

#include <detail/context_impl.hpp>

Public Types

enum  PropertySupport { NotSupported = 0 , Supported = 1 , NotChecked = 2 }
 
using CachedLibProgramsT = std::map< std::pair< DeviceLibExt, sycl::detail::pi::PiDevice >, sycl::detail::pi::PiProgram >
 

Public Member Functions

 context_impl (const device &Device, async_handler AsyncHandler, const property_list &PropList)
 Constructs a context_impl using a single SYCL devices. More...
 
 context_impl (const std::vector< sycl::device > DeviceList, async_handler AsyncHandler, const property_list &PropList)
 Constructs a context_impl using a list of SYCL devices. More...
 
 context_impl (sycl::detail::pi::PiContext PiContext, async_handler AsyncHandler, const PluginPtr &Plugin, const std::vector< sycl::device > &DeviceList={}, bool OwnedByRuntime=true)
 Construct a context_impl using plug-in interoperability handle. More...
 
 ~context_impl ()
 
template<typename propertyT >
bool has_property () const noexcept
 Checks if this context_impl has a property of type propertyT. More...
 
template<typename propertyT >
propertyT get_property () const
 Gets the specified property of this context_impl. More...
 
cl_context get () const
 Gets OpenCL interoperability context handle. More...
 
bool is_host () const
 Checks if this context is a host context. More...
 
const async_handlerget_async_handler () const
 Gets asynchronous exception handler. More...
 
const PluginPtrgetPlugin () const
 
PlatformImplPtr getPlatformImpl () const
 
template<typename Param >
Param::return_type get_info () const
 Queries this context for information. More...
 
template<typename Param >
Param::return_type get_backend_info () const
 Queries SYCL queue for SYCL backend-specific information. More...
 
sycl::detail::pi::PiContextgetHandleRef ()
 Gets the underlying context object (if any) without reference count modification. More...
 
const sycl::detail::pi::PiContextgetHandleRef () const
 Gets the underlying context object (if any) without reference count modification. More...
 
const std::vector< device > & getDevices () const
 Unlike ‘get_info<info::context::devices>’, this function returns a reference. More...
 
Locked< CachedLibProgramsTacquireCachedLibPrograms ()
 In contrast to user programs, which are compiled from user code, library programs come from the SYCL runtime. More...
 
KernelProgramCachegetKernelProgramCache () const
 
bool hasDevice (std::shared_ptr< detail::device_impl > Device) const
 Returns true if and only if context contains the given device. More...
 
bool isDeviceValid (DeviceImplPtr Device)
 Returns true if and only if the device can be used within this context. More...
 
backend getBackend () const
 
DeviceImplPtr findMatchingDeviceImpl (sycl::detail::pi::PiDevice &DevicePI) const
 Given a PiDevice, returns the matching shared_ptr<device_impl> within this context. More...
 
pi_native_handle getNative () const
 Gets the native handle of the SYCL context. More...
 
bool isBufferLocationSupported () const
 
void addAssociatedDeviceGlobal (const void *DeviceGlobalPtr)
 Adds an associated device global to the tracked associates. More...
 
void addDeviceGlobalInitializer (sycl::detail::pi::PiProgram Program, const std::vector< device > &Devs, const RTDeviceBinaryImage *BinImage)
 Adds a device global initializer. More...
 
std::vector< sycl::detail::pi::PiEventinitializeDeviceGlobals (pi::PiProgram NativePrg, const std::shared_ptr< queue_impl > &QueueImpl)
 Initializes device globals for a program on the associated queue. More...
 
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 memcpyFromHostOnlyDeviceGlobal (const std::shared_ptr< device_impl > &DeviceImpl, void *Dest, const void *DeviceGlobalPtr, bool IsDeviceImageScoped, size_t NumBytes, size_t Offset)
 
std::optional< sycl::detail::pi::PiProgramgetProgramForDeviceGlobal (const device &Device, DeviceGlobalMapEntry *DeviceGlobalEntry)
 Gets a program associated with a device global from the cache. More...
 
std::optional< sycl::detail::pi::PiProgramgetProgramForHostPipe (const device &Device, HostPipeMapEntry *HostPipeEntry)
 Gets a program associated with a HostPipe Entry from the cache. More...
 
std::optional< sycl::detail::pi::PiProgramgetProgramForDevImgs (const device &Device, const std::set< std::uintptr_t > &ImgIdentifiers, const std::string &ObjectTypeName)
 Gets a program associated with Dev / Images pairs. More...
 
bool isOwnedByRuntime ()
 

Detailed Description

Definition at line 32 of file context_impl.hpp.

Member Typedef Documentation

◆ CachedLibProgramsT

Member Enumeration Documentation

◆ PropertySupport

Enumerator
NotSupported 
Supported 
NotChecked 

Definition at line 266 of file context_impl.hpp.

Constructor & Destructor Documentation

◆ context_impl() [1/3]

sycl::_V1::detail::context_impl::context_impl ( const device Device,
async_handler  AsyncHandler,
const property_list PropList 
)

Constructs a context_impl using a single SYCL devices.

The constructed context_impl will use the AsyncHandler parameter to handle exceptions. PropList carries the properties of the constructed context_impl.

Parameters
Deviceis an instance of SYCL device.
AsyncHandleris an instance of async_handler.
PropListis an instance of property_list.

Definition at line 31 of file context_impl.cpp.

References sycl::_V1::detail::KernelProgramCache::setContextPtr().

◆ context_impl() [2/3]

sycl::_V1::detail::context_impl::context_impl ( const std::vector< sycl::device DeviceList,
async_handler  AsyncHandler,
const property_list PropList 
)

Constructs a context_impl using a list of SYCL devices.

Newly created instance will save each SYCL device in the list. This requres that all devices in the list are associated with the same SYCL platform. The constructed context_impl will use the AsyncHandler parameter to handle exceptions. PropList carries the properties of the constructed context_impl.

Parameters
DeviceListis a list of SYCL device instances.
AsyncHandleris an instance of async_handler.
PropListis an instance of property_list.

Definition at line 42 of file context_impl.cpp.

References __SYCL_PI_CONTEXT_PROPERTIES_CUDA_PRIMARY, sycl::_V1::ext_oneapi_cuda, getBackend(), getPlugin(), sycl::_V1::detail::getSyclObjImpl(), sycl::_V1::property_list::has_property(), piContextCreate(), and sycl::_V1::detail::KernelProgramCache::setContextPtr().

◆ context_impl() [3/3]

sycl::_V1::detail::context_impl::context_impl ( sycl::detail::pi::PiContext  PiContext,
async_handler  AsyncHandler,
const PluginPtr Plugin,
const std::vector< sycl::device > &  DeviceList = {},
bool  OwnedByRuntime = true 
)

Construct a context_impl using plug-in interoperability handle.

The constructed context_impl will use the AsyncHandler parameter to handle exceptions.

Parameters
PiContextis an instance of a valid plug-in context handle.
AsyncHandleris an instance of async_handler.
Pluginis the reference to the underlying Plugin that this
OwnedByRuntimeis the flag if ownership is kept by user or transferred to runtime

Definition at line 85 of file context_impl.cpp.

References getBackend(), sycl::_V1::detail::platform_impl::getPlatformFromPiDevice(), getPlugin(), sycl::_V1::detail::getSyclObjImpl(), PI_CONTEXT_INFO_DEVICES, PI_CONTEXT_INFO_NUM_DEVICES, piContextGetInfo(), piContextRetain(), and sycl::_V1::detail::KernelProgramCache::setContextPtr().

◆ ~context_impl()

Member Function Documentation

◆ acquireCachedLibPrograms()

Locked<CachedLibProgramsT> sycl::_V1::detail::context_impl::acquireCachedLibPrograms ( )
inline

In contrast to user programs, which are compiled from user code, library programs come from the SYCL runtime.

They are identified by the corresponding extension:

cl_intel_devicelib_assert -> #<pi_program with assert functions> cl_intel_devicelib_complex -> #<pi_program with complex functions> etc.

See ‘doc/design/DeviceLibExtensions.rst’ for more details.

Returns
an instance of sycl::detail::Locked which wraps a map with device library programs and the corresponding lock for synchronized access.

Definition at line 168 of file context_impl.hpp.

◆ addAssociatedDeviceGlobal()

void sycl::_V1::detail::context_impl::addAssociatedDeviceGlobal ( const void *  DeviceGlobalPtr)

Adds an associated device global to the tracked associates.

Definition at line 351 of file context_impl.cpp.

◆ addDeviceGlobalInitializer()

void sycl::_V1::detail::context_impl::addDeviceGlobalInitializer ( sycl::detail::pi::PiProgram  Program,
const std::vector< device > &  Devs,
const RTDeviceBinaryImage BinImage 
)

Adds a device global initializer.

Definition at line 356 of file context_impl.cpp.

References getHandleRef(), and sycl::_V1::detail::getSyclObjImpl().

◆ findMatchingDeviceImpl()

DeviceImplPtr sycl::_V1::detail::context_impl::findMatchingDeviceImpl ( sycl::detail::pi::PiDevice DevicePI) const

Given a PiDevice, returns the matching shared_ptr<device_impl> within this context.

May return nullptr if no match discovered.

Definition at line 319 of file context_impl.cpp.

References getHandleRef(), and sycl::_V1::detail::getSyclObjImpl().

◆ get()

cl_context sycl::_V1::detail::context_impl::get ( ) const

Gets OpenCL interoperability context handle.

Returns
an instance of OpenCL cl_context.

Definition at line 134 of file context_impl.cpp.

References getPlugin(), and piContextRetain().

◆ get_async_handler()

const async_handler & sycl::_V1::detail::context_impl::get_async_handler ( ) const

Gets asynchronous exception handler.

Returns
an instance of SYCL async_handler.

Definition at line 168 of file context_impl.cpp.

◆ get_backend_info()

template<typename Param >
Param::return_type sycl::_V1::detail::context_impl::get_backend_info ( ) const

Queries SYCL queue for SYCL backend-specific information.

The return type depends on information being queried.

◆ get_info()

template<typename Param >
Param::return_type sycl::_V1::detail::context_impl::get_info ( ) const

Queries this context for information.

The return type depends on information being queried.

◆ get_property()

template<typename propertyT >
propertyT sycl::_V1::detail::context_impl::get_property ( ) const
inline

Gets the specified property of this context_impl.

Throws invalid_object_error if this context_impl does not have a property of type propertyT.

Returns
a copy of the property of type propertyT.

Definition at line 91 of file context_impl.hpp.

References sycl::_V1::property_list::get_property().

◆ getBackend()

backend sycl::_V1::detail::context_impl::getBackend ( ) const
inline

Definition at line 208 of file context_impl.hpp.

Referenced by context_impl(), and getNative().

◆ getDevices()

const std::vector<device>& sycl::_V1::detail::context_impl::getDevices ( ) const
inline

Unlike ‘get_info<info::context::devices>’, this function returns a reference.

Definition at line 149 of file context_impl.hpp.

Referenced by sycl::_V1::detail::DeviceGlobalMapEntry::removeAssociatedResources().

◆ getHandleRef() [1/2]

sycl::detail::pi::PiContext & sycl::_V1::detail::context_impl::getHandleRef ( )

Gets the underlying context object (if any) without reference count modification.

Caller must ensure the returned object lives on stack only. It can also be safely passed to the underlying native runtime API. Warning. Returned reference will be invalid if context_impl was destroyed.

Returns
an instance of raw plug-in context handle.

Definition at line 302 of file context_impl.cpp.

Referenced by addDeviceGlobalInitializer(), sycl::_V1::detail::usm::alignedAllocInternal(), findMatchingDeviceImpl(), sycl::_V1::detail::usm::freeInternal(), and getNative().

◆ getHandleRef() [2/2]

const sycl::detail::pi::PiContext & sycl::_V1::detail::context_impl::getHandleRef ( ) const

Gets the underlying context object (if any) without reference count modification.

Caller must ensure the returned object lives on stack only. It can also be safely passed to the underlying native runtime API. Warning. Returned reference will be invalid if context_impl was destroyed.

Returns
an instance of raw plug-in context handle.

Definition at line 303 of file context_impl.cpp.

◆ getKernelProgramCache()

KernelProgramCache & sycl::_V1::detail::context_impl::getKernelProgramCache ( ) const

Definition at line 307 of file context_impl.cpp.

◆ getNative()

pi_native_handle sycl::_V1::detail::context_impl::getNative ( ) const

Gets the native handle of the SYCL context.

Returns
a native handle.

Definition at line 328 of file context_impl.cpp.

References getBackend(), getHandleRef(), getPlugin(), sycl::_V1::opencl, piContextRetain(), and piextContextGetNativeHandle().

◆ getPlatformImpl()

PlatformImplPtr sycl::_V1::detail::context_impl::getPlatformImpl ( ) const
inline
Returns
the PlatformImpl associated with this context.

Definition at line 114 of file context_impl.hpp.

◆ getPlugin()

const PluginPtr& sycl::_V1::detail::context_impl::getPlugin ( ) const
inline

◆ getProgramForDeviceGlobal()

std::optional< sycl::detail::pi::PiProgram > sycl::_V1::detail::context_impl::getProgramForDeviceGlobal ( const device Device,
DeviceGlobalMapEntry DeviceGlobalEntry 
)

Gets a program associated with a device global from the cache.

Definition at line 556 of file context_impl.cpp.

References getProgramForDevImgs(), and sycl::_V1::detail::DeviceGlobalMapEntry::MImageIdentifiers.

◆ getProgramForDevImgs()

std::optional< sycl::detail::pi::PiProgram > sycl::_V1::detail::context_impl::getProgramForDevImgs ( const device Device,
const std::set< std::uintptr_t > &  ImgIdentifiers,
const std::string &  ObjectTypeName 
)

◆ getProgramForHostPipe()

std::optional< sycl::detail::pi::PiProgram > sycl::_V1::detail::context_impl::getProgramForHostPipe ( const device Device,
HostPipeMapEntry HostPipeEntry 
)

Gets a program associated with a HostPipe Entry from the cache.

Definition at line 563 of file context_impl.cpp.

References sycl::_V1::detail::HostPipeMapEntry::getDevBinImage(), sycl::_V1::detail::RTDeviceBinaryImage::getImageID(), and getProgramForDevImgs().

◆ has_property()

template<typename propertyT >
bool sycl::_V1::detail::context_impl::has_property ( ) const
inlinenoexcept

Checks if this context_impl has a property of type propertyT.

Returns
true if this context_impl has a property of type propertyT.

Definition at line 81 of file context_impl.hpp.

References sycl::_V1::property_list::has_property().

◆ hasDevice()

bool sycl::_V1::detail::context_impl::hasDevice ( std::shared_ptr< detail::device_impl Device) const

Returns true if and only if context contains the given device.

Definition at line 311 of file context_impl.cpp.

References sycl::_V1::detail::getSyclObjImpl().

Referenced by isDeviceValid().

◆ initializeDeviceGlobals()

std::vector< sycl::detail::pi::PiEvent > sycl::_V1::detail::context_impl::initializeDeviceGlobals ( pi::PiProgram  NativePrg,
const std::shared_ptr< queue_impl > &  QueueImpl 
)

◆ is_host()

bool sycl::_V1::detail::context_impl::is_host ( ) const

Checks if this context is a host context.

Returns
true if this context is a host context.

Definition at line 145 of file context_impl.cpp.

Referenced by sycl::_V1::detail::usm::alignedAllocInternal(), sycl::_V1::detail::usm::freeInternal(), and isDeviceValid().

◆ isBufferLocationSupported()

bool sycl::_V1::detail::context_impl::isBufferLocationSupported ( ) const

Definition at line 337 of file context_impl.cpp.

References NotChecked, NotSupported, and Supported.

◆ isDeviceValid()

bool sycl::_V1::detail::context_impl::isDeviceValid ( DeviceImplPtr  Device)
inline

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.

Definition at line 181 of file context_impl.hpp.

References sycl::_V1::detail::getSyclObjImpl(), hasDevice(), is_host(), and sycl::_V1::opencl.

◆ isOwnedByRuntime()

bool sycl::_V1::detail::context_impl::isOwnedByRuntime ( )
inline

Definition at line 264 of file context_impl.hpp.

◆ memcpyFromHostOnlyDeviceGlobal()

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

Definition at line 489 of file context_impl.cpp.

References sycl::_V1::ext::oneapi::experimental::fill().

◆ memcpyToHostOnlyDeviceGlobal()

void sycl::_V1::detail::context_impl::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 
)

Definition at line 467 of file context_impl.cpp.


The documentation for this class was generated from the following files: