PI context mapping to a CUDA context object. More...
#include <cuda/pi_cuda.hpp>
Classes | |
struct | deleter_data |
Public Types | |
enum | kind { kind::primary, kind::user_defined } |
using | native_type = CUcontext |
using | native_type = hipCtx_t |
PI context mapping to a CUDA context object.
PI context mapping to a HIP context object.
There is no direct mapping between a CUDA context and a PI context, main differences described below:
CUDA context vs PI context
One of the main differences between the PI API and the CUDA driver API is that the second modifies the state of the threads by assigning CUcontext
objects to threads. CUcontext
objects store data associated with a given device and control access to said device from the user side. PI API context are objects that are passed to functions, and not bound to threads. The _pi_context object doesn't implement this behavior, only holds the CUDA context data. The RAII object ScopedContext implements the active context behavior.
Primary vs User-defined context
CUDA has two different types of context, the Primary context, which is usable by all threads on a given process for a given device, and the aforementioned custom contexts. CUDA documentation, and performance analysis, indicates it is recommended to use Primary context whenever possible. Primary context is used as well by the CUDA Runtime API. For PI applications to interop with CUDA Runtime API, they have to use the primary context - and make that active in the thread. The _pi_context
object can be constructed with a kind
parameter that allows to construct a Primary or user-defined
context, so that the PI object interface is always the same.
Destructor callback
Required to implement CP023, SYCL Extended Context Destruction, the PI Context can store a number of callback functions that will be called upon destruction of the PI Context. See proposal for details.
There is no direct mapping between a HIP context and a PI context, main differences described below:
HIP context vs PI context
One of the main differences between the PI API and the HIP driver API is that the second modifies the state of the threads by assigning hipCtx_t
objects to threads. hipCtx_t
objects store data associated with a given device and control access to said device from the user side. PI API context are objects that are passed to functions, and not bound to threads. The _pi_context object doesn't implement this behavior, only holds the HIP context data. The RAII object ScopedContext implements the active context behavior.
Primary vs User-defined context
HIP has two different types of context, the Primary context, which is usable by all threads on a given process for a given device, and the aforementioned custom contexts. HIP documentation, and performance analysis, indicates it is recommended to use Primary context whenever possible. Primary context is used as well by the HIP Runtime API. For PI applications to interop with HIP Runtime API, they have to use the primary context - and make that active in the thread. The _pi_context
object can be constructed with a kind
parameter that allows to construct a Primary or user-defined
context, so that the PI object interface is always the same.
Destructor callback
Required to implement CP023, SYCL Extended Context Destruction, the PI Context can store a number of callback functions that will be called upon destruction of the PI Context. See proposal for details.
Definition at line 170 of file pi_cuda.hpp.
using _pi_context::native_type = hipCtx_t |
Definition at line 148 of file pi_hip.hpp.
using _pi_context::native_type = CUcontext |
Definition at line 179 of file pi_cuda.hpp.
|
strong |
Enumerator | |
---|---|
primary | |
user_defined |
Definition at line 150 of file pi_hip.hpp.
|
inline |
Definition at line 185 of file pi_cuda.hpp.
References _pi_device::get_context().
|
inline |
Definition at line 190 of file pi_cuda.hpp.
References cuda_piDeviceRelease(), and deviceId_.
|
inline |
Definition at line 95 of file pi_esimd_emulator.hpp.
|
inline |
Definition at line 155 of file pi_hip.hpp.
|
inline |
Definition at line 161 of file pi_hip.hpp.
References deviceId_, and hip_piDeviceRelease().
|
inline |
Definition at line 208 of file pi_level_zero.hpp.
References ZeContext.
void _pi_context::addEventToContextCache | ( | pi_event | Event | ) |
Definition at line 4657 of file pi_level_zero.cpp.
References _pi_event::isHostVisible(), and _pi_event::isProfilingEnabled().
Referenced by piEventReleaseInternal().
bool _pi_context::checkSurfaceArgument | ( | pi_mem_flags | Flags, |
void * | HostPtr | ||
) |
Definition at line 915 of file pi_esimd_emulator.cpp.
References PI_MEM_FLAGS_HOST_PTR_COPY, PI_MEM_FLAGS_HOST_PTR_USE, and PiTrace().
Referenced by piMemBufferCreate(), and piMemImageCreate().
|
inlinenoexcept |
Definition at line 184 of file pi_hip.hpp.
References refCount_.
|
inlinenoexcept |
Definition at line 211 of file pi_cuda.hpp.
References refCount_.
Referenced by cuda_piContextRelease(), and hip_piContextRelease().
Definition at line 282 of file pi_level_zero.cpp.
References sycl::_V1::detail::pi::die(), _pi_event::isHostVisible(), _pi_event::isProfilingEnabled(), and _pi_event::ZeEventPool.
Referenced by piEventReleaseInternal().
pi_result _pi_context::finalize | ( | ) |
Definition at line 601 of file pi_level_zero.cpp.
References ZE_CALL, ZeCommandListCacheMutex, ZeCommandListInit, ZeComputeCommandListCache, and ZeCopyCommandListCache.
Referenced by ContextReleaseHelper().
|
inlinenoexcept |
Definition at line 178 of file pi_hip.hpp.
References hipContext_.
|
inlinenoexcept |
Definition at line 207 of file pi_cuda.hpp.
References cuContext_.
Referenced by cuda_piextContextGetNativeHandle(), hip_piContextRelease(), and hip_piextContextGetNativeHandle().
|
inlinenoexcept |
Definition at line 176 of file pi_hip.hpp.
References deviceId_.
|
inlinenoexcept |
Definition at line 205 of file pi_cuda.hpp.
References deviceId_.
Referenced by cuda_piContextGetInfo(), cuda_piextGetDeviceFunctionPointer(), cuda_piextQueueCreateWithNativeHandle(), cuda_piextUSMEnqueueMemAdvise(), cuda_piextUSMEnqueuePrefetch(), cuda_piProgramCreateWithBinary(), cuda_piQueueCreate(), hip_piContextGetInfo(), hip_piContextRelease(), hip_piextGetDeviceFunctionPointer(), hip_piextUSMEnqueuePrefetch(), hip_piProgramCreateWithBinary(), and hip_piQueueCreate().
|
inlinenoexcept |
Definition at line 186 of file pi_hip.hpp.
References refCount_.
|
inlinenoexcept |
Definition at line 213 of file pi_cuda.hpp.
References refCount_.
Referenced by cuda_piContextGetInfo(), cuda_piContextRetain(), hip_piContextGetInfo(), and hip_piContextRetain().
pi_result _pi_context::getAvailableCommandList | ( | pi_queue | Queue, |
pi_command_list_ptr_t & | CommandList, | ||
bool | UseCopyEngine, | ||
bool | AllowBatching = false , |
||
ze_command_queue_handle_t * | ForcedCmdQueue = nullptr |
||
) |
Definition at line 1100 of file pi_level_zero.cpp.
References CleanupEventListFromResetCmdList(), _pi_queue::CommandListMap, _pi_queue::ComputeCommandBatch, _pi_queue::Context, _pi_queue::CopyCommandBatch, _pi_queue::createCommandList(), _pi_queue::Device, _pi_queue::executeOpenCommandList(), _pi_queue::pi_queue_group_t::getImmCmdList(), _pi_queue::getQueueGroup(), _pi_queue::pi_queue_group_t::getZeQueue(), _pi_queue::hasOpenCommandList(), ImmCmdListsEventCleanupThreshold, _pi_queue::insertActiveBarriers(), _pi_queue::insertStartBarrierIfDiscardEventsMode(), _pi_queue::command_batch::OpenCommandList, PI_CALL, _pi_queue::resetCommandList(), ZE_CALL, ZE_CALL_NOCHECK, ZeCommandListCacheMutex, ZeComputeCommandListCache, and ZeCopyCommandListCache.
Referenced by enqueueMemCopyHelper(), enqueueMemCopyRectHelper(), enqueueMemFillHelper(), enqueueMemImageCommandHelper(), piEnqueueEventsWait(), piEnqueueEventsWaitWithBarrier(), piEnqueueKernelLaunch(), piEnqueueMemBufferMap(), piEnqueueMemUnmap(), piextUSMEnqueueMemAdvise(), and piextUSMEnqueuePrefetch().
pi_event _pi_context::getEventFromContextCache | ( | bool | HostVisible, |
bool | WithProfiling | ||
) |
Definition at line 4642 of file pi_level_zero.cpp.
References _pi_event::reset().
Referenced by EventCreate().
pi_result _pi_context::getFreeSlotInExistingOrNewPool | ( | ze_event_pool_handle_t & | Pool, |
size_t & | Index, | ||
bool | HostVisible, | ||
bool | ProfilingEnabled | ||
) |
Definition at line 223 of file pi_level_zero.cpp.
References Devices, sycl::_V1::detail::for_each(), ZE_CALL, ZeContext, and zePrint().
Referenced by EventCreate().
pi_platform _pi_context::getPlatform | ( | ) | const |
Definition at line 211 of file pi_level_zero.cpp.
References Devices.
Referenced by ContextReleaseHelper(), _pi_buffer::free(), piContextRelease(), piextMemCreateWithNativeHandle(), piextUSMFree(), piextUSMGetMemAllocInfo(), piextUSMHostAlloc(), piMemBufferCreate(), piSamplerCreate(), USMFreeHelper(), ZeHostMemAllocHelper(), and ZeMemFreeHelper().
|
inlinenoexcept |
Definition at line 182 of file pi_hip.hpp.
References refCount_.
|
inlinenoexcept |
Definition at line 209 of file pi_cuda.hpp.
References refCount_.
Referenced by cuda_piContextRetain(), and hip_piContextRetain().
pi_result _pi_context::initialize | ( | ) |
Definition at line 512 of file pi_level_zero.cpp.
References usm_settings::USMAllocatorConfig::Configs, Device, DeviceMemAllocContexts, Devices, getRangeOfAllowedCopyEngines(), usm_settings::Host, HostMemAllocContext, sycl::_V1::detail::make_tuple(), usm_settings::Shared, SharedMemAllocContexts, usm_settings::SharedReadOnly, SharedReadOnlyMemAllocContexts, SingleRootDevice, ZE_CALL, ZeCommandListInit, and ZeContext.
|
inline |
Definition at line 163 of file pi_hip.hpp.
|
inline |
Definition at line 192 of file pi_cuda.hpp.
Referenced by cuda_piContextRelease(), and hip_piContextRelease().
|
inlinenoexcept |
Definition at line 180 of file pi_hip.hpp.
References kind_, and primary.
Referenced by hip_piContextRelease().
bool _pi_context::isValidDevice | ( | pi_device | Device | ) | const |
Definition at line 213 of file pi_level_zero.cpp.
References Device, and Devices.
Referenced by piextMemCreateWithNativeHandle(), piextQueueCreate(), piProgramBuild(), and piProgramLink().
|
inline |
Definition at line 170 of file pi_hip.hpp.
|
inline |
Definition at line 199 of file pi_cuda.hpp.
Referenced by cuda_piextContextSetExtendedDeleter(), and hip_piextContextSetExtendedDeleter().
std::unordered_map<void *, cm_support::CmBufferSVM *> _pi_context::Addr2CmBufferSVM |
Definition at line 102 of file pi_esimd_emulator.hpp.
Referenced by piContextRelease(), piextUSMFree(), and piextUSMSharedAlloc().
std::mutex _pi_context::Addr2CmBufferSVMLock |
Definition at line 104 of file pi_esimd_emulator.hpp.
Referenced by piContextRelease(), piextUSMFree(), and piextUSMSharedAlloc().
native_type _pi_context::cuContext_ |
Definition at line 181 of file pi_cuda.hpp.
Referenced by get().
pi_device _pi_context::Device |
Definition at line 98 of file pi_esimd_emulator.hpp.
Referenced by initialize(), isValidDevice(), piContextRelease(), piextUSMFree(), piextUSMSharedAlloc(), piMemBufferCreate(), piMemImageCreate(), and piQueueCreate().
_pi_device * _pi_context::deviceId_ |
Definition at line 182 of file pi_cuda.hpp.
Referenced by cuda_piProgramGetInfo(), get_device(), hip_piProgramGetInfo(), and ~_pi_context().
std::unordered_map<ze_device_handle_t, USMAllocContext> _pi_context::DeviceMemAllocContexts |
Definition at line 323 of file pi_level_zero.hpp.
Referenced by initialize(), piextUSMDeviceAlloc(), and USMFreeHelper().
const std::vector<pi_device> _pi_context::Devices |
Definition at line 239 of file pi_level_zero.hpp.
Referenced by getFreeSlotInExistingOrNewPool(), getPlatform(), _pi_buffer::getZeHandle(), initialize(), isValidDevice(), piContextGetInfo(), piEventGetProfilingInfo(), piMemBufferCreate(), piMemImageCreate(), piProgramGetInfo(), piSamplerCreate(), and USMAllocationMakeResident().
native_type _pi_context::hipContext_ |
Definition at line 151 of file pi_hip.hpp.
Referenced by get().
std::unique_ptr<USMAllocContext> _pi_context::HostMemAllocContext |
Definition at line 335 of file pi_level_zero.hpp.
Referenced by initialize(), piextUSMHostAlloc(), and USMFreeHelper().
pi_mutex _pi_context::ImmediateCommandListMutex |
Definition at line 264 of file pi_level_zero.hpp.
Referenced by _pi_buffer::getZeHandle(), piextMemCreateWithNativeHandle(), piMemBufferCreate(), and piMemImageCreate().
enum _pi_context::kind _pi_context::kind_ |
Referenced by is_primary().
std::unordered_map<void *, MemAllocRecord> _pi_context::MemAllocs |
Definition at line 342 of file pi_level_zero.hpp.
Referenced by piextMemCreateWithNativeHandle(), piextUSMDeviceAlloc(), piextUSMHostAlloc(), piextUSMSharedAlloc(), USMFreeHelper(), ZeDeviceMemAllocHelper(), ZeHostMemAllocHelper(), and ZeMemFreeHelper().
bool _pi_context::OwnZeContext |
Definition at line 234 of file pi_level_zero.hpp.
Referenced by ContextReleaseHelper().
std::atomic_uint32_t _pi_context::refCount_ |
Definition at line 183 of file pi_cuda.hpp.
Referenced by decrement_reference_count(), get_reference_count(), and increment_reference_count().
std::unordered_map<ze_device_handle_t, USMAllocContext> _pi_context::SharedMemAllocContexts |
Definition at line 325 of file pi_level_zero.hpp.
Referenced by initialize(), piextUSMSharedAlloc(), and USMFreeHelper().
std::unordered_set<void *> _pi_context::SharedReadOnlyAllocs |
Definition at line 332 of file pi_level_zero.hpp.
Referenced by piextUSMSharedAlloc(), and USMFreeHelper().
std::unordered_map<ze_device_handle_t, USMAllocContext> _pi_context::SharedReadOnlyMemAllocContexts |
Definition at line 327 of file pi_level_zero.hpp.
Referenced by initialize(), piextUSMSharedAlloc(), and USMFreeHelper().
const pi_device _pi_context::SingleRootDevice = nullptr |
Definition at line 249 of file pi_level_zero.hpp.
Referenced by _pi_buffer::getZeHandle(), initialize(), and piMemImageCreate().
pi_mutex _pi_context::ZeCommandListCacheMutex |
Definition at line 268 of file pi_level_zero.hpp.
Referenced by finalize(), getAvailableCommandList(), and _pi_queue::resetCommandList().
ze_command_list_handle_t _pi_context::ZeCommandListInit |
Definition at line 259 of file pi_level_zero.hpp.
Referenced by finalize(), _pi_buffer::getZeHandle(), initialize(), piextMemCreateWithNativeHandle(), piMemBufferCreate(), and piMemImageCreate().
std::unordered_map<ze_device_handle_t, std::list<ze_command_list_handle_t> > _pi_context::ZeComputeCommandListCache |
Definition at line 278 of file pi_level_zero.hpp.
Referenced by finalize(), getAvailableCommandList(), and _pi_queue::resetCommandList().
const ze_context_handle_t _pi_context::ZeContext |
Definition at line 230 of file pi_level_zero.hpp.
Referenced by _pi_context(), ContextReleaseHelper(), _pi_queue::createCommandList(), getFreeSlotInExistingOrNewPool(), initialize(), IsDevicePointer(), piextContextGetNativeHandle(), piextMemCreateWithNativeHandle(), piextUSMGetMemAllocInfo(), piMemBufferCreate(), piMemImageCreate(), piProgramBuild(), piProgramLink(), piSamplerCreate(), USMAllocationMakeResident(), USMDeviceAllocImpl(), USMFreeHelper(), USMFreeImpl(), USMHostAllocImpl(), USMSharedAllocImpl(), ZeDeviceMemAllocHelper(), ZeHostMemAllocHelper(), and ZeMemFreeHelper().
std::unordered_map<ze_device_handle_t, std::list<ze_command_list_handle_t> > _pi_context::ZeCopyCommandListCache |
Definition at line 280 of file pi_level_zero.hpp.
Referenced by finalize(), getAvailableCommandList(), and _pi_queue::resetCommandList().