From 78ccd5dac05315eb0d2b89913a8806e2ec603b27 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Thu, 5 Dec 2024 17:30:13 +0100 Subject: [PATCH 1/6] [L0] Manage UMF pools through usm::pool_manager --- source/adapters/level_zero/context.cpp | 102 ------ source/adapters/level_zero/context.hpp | 26 +- source/adapters/level_zero/usm.cpp | 483 ++++++++++--------------- source/adapters/level_zero/usm.hpp | 26 +- source/common/ur_pool_manager.hpp | 6 + 5 files changed, 211 insertions(+), 432 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 67dcd513e5..ccb40f98ff 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -193,108 +193,6 @@ ur_result_t urContextSetExtendedDeleter( ur_result_t ur_context_handle_t_::initialize() { - // Helper lambda to create various USM allocators for a device. - // Note that the CCS devices and their respective subdevices share a - // common ze_device_handle and therefore, also share USM allocators. - auto createUSMAllocators = [this](ur_device_handle_t Device) { - auto MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - auto UmfDeviceParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Device]); - DeviceMemPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), - std::move(MemProvider), - UmfDeviceParamsHandle.get()) - .second)); - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - - auto UmfSharedParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Shared]); - SharedMemPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), - std::move(MemProvider), - UmfSharedParamsHandle.get()) - .second)); - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - - auto UmfSharedROParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance - .Configs[usm::DisjointPoolMemType::SharedReadOnly]); - SharedReadOnlyMemPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple(umf::poolMakeUniqueFromOps( - umfDisjointPoolOps(), std::move(MemProvider), - UmfSharedROParamsHandle.get()) - .second)); - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - DeviceMemProxyPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple( - umf::poolMakeUnique(std::move(MemProvider)).second)); - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - SharedMemProxyPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple( - umf::poolMakeUnique(std::move(MemProvider)).second)); - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), Device) - .second; - SharedReadOnlyMemProxyPools.emplace( - std::piecewise_construct, std::make_tuple(Device->ZeDevice), - std::make_tuple( - umf::poolMakeUnique(std::move(MemProvider)).second)); - }; - - // Recursive helper to call createUSMAllocators for all sub-devices - std::function createUSMAllocatorsRecursive; - createUSMAllocatorsRecursive = - [createUSMAllocators, - &createUSMAllocatorsRecursive](ur_device_handle_t Device) -> void { - createUSMAllocators(Device); - for (auto &SubDevice : Device->SubDevices) - createUSMAllocatorsRecursive(SubDevice); - }; - - // Create USM pool for each pair (device, context). - // - for (auto &Device : Devices) { - createUSMAllocatorsRecursive(Device); - } - // Create USM pool for host. Device and Shared USM allocations - // are device-specific. Host allocations are not device-dependent therefore - // we don't need a map with device as key. - auto MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), nullptr) - .second; - auto UmfHostParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host]); - HostMemPool = - umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider), - UmfHostParamsHandle.get()) - .second; - - MemProvider = umf::memoryProviderMakeUnique( - reinterpret_cast(this), nullptr) - .second; - HostMemProxyPool = - umf::poolMakeUnique(std::move(MemProvider)).second; - // We may allocate memory to this root device so create allocators. if (SingleRootDevice && DeviceMemPools.find(SingleRootDevice->ZeDevice) == DeviceMemPools.end()) { diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index 43608e8bfc..f0c7ad3e13 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -24,6 +24,7 @@ #include "common.hpp" #include "queue.hpp" +#include "usm.hpp" #include @@ -55,11 +56,14 @@ struct ur_context_handle_t_ : _ur_object { ur_context_handle_t_(ze_context_handle_t ZeContext, uint32_t NumDevices, const ur_device_handle_t *Devs, bool OwnZeContext) : ZeContext{ZeContext}, Devices{Devs, Devs + NumDevices}, - NumDevices{NumDevices} { + NumDevices{NumDevices}, DefaultPool{this, nullptr}, + ProxyPool{this, nullptr} { OwnNativeHandle = OwnZeContext; } - ur_context_handle_t_(ze_context_handle_t ZeContext) : ZeContext{ZeContext} {} + ur_context_handle_t_(ze_context_handle_t ZeContext) + : ZeContext{ZeContext}, DefaultPool{this, nullptr}, + ProxyPool{this, nullptr} {} // A L0 context handle is primarily used during creation and management of // resources that may be used by multiple devices. @@ -123,24 +127,10 @@ struct ur_context_handle_t_ : _ur_object { // Store USM pool for USM shared and device allocations. There is 1 memory // pool per each pair of (context, device) per each memory type. - std::unordered_map - DeviceMemPools; - std::unordered_map - SharedMemPools; - std::unordered_map - SharedReadOnlyMemPools; - - // Store the host memory pool. It does not depend on any device. - umf::pool_unique_handle_t HostMemPool; + ur_usm_pool_handle_t_ DefaultPool; // Allocation-tracking proxy pools for direct allocations. No pooling used. - std::unordered_map - DeviceMemProxyPools; - std::unordered_map - SharedMemProxyPools; - std::unordered_map - SharedReadOnlyMemProxyPools; - umf::pool_unique_handle_t HostMemProxyPool; + ur_usm_pool_handle_t_ ProxyPool; // Map associating pools created with urUsmPoolCreate and internal pools std::list UsmPoolHandles{}; diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 19480e83c5..0a383d55ea 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -332,66 +332,17 @@ ur_result_t urUSMHostAlloc( size_t Size, /// [out] pointer to USM host memory object void **RetMem) { - - uint32_t Align = USMDesc ? USMDesc->align : 0; - // L0 supports alignment up to 64KB and silently ignores higher values. - // We flag alignment > 64KB as an invalid value. - // L0 spec says that alignment values that are not powers of 2 are invalid. - // If alignment == 0, then we are allowing the L0 driver to choose the - // alignment so no need to check. - if (Align > 0) { - if (Align > 65536 || (Align & (Align - 1)) != 0) - return UR_RESULT_ERROR_INVALID_VALUE; - } - - ur_platform_handle_t Plt = Context->getPlatform(); - // If indirect access tracking is enabled then lock the mutex which is - // guarding contexts container in the platform. This prevents new kernels from - // being submitted in any context while we are in the process of allocating a - // memory, this is needed to properly capture allocations by kernels with - // indirect access. This lock also protects access to the context's data - // structures. If indirect access tracking is not enabled then lock context - // mutex to protect access to context's data structures. - std::shared_lock ContextLock(Context->Mutex, - std::defer_lock); - std::unique_lock IndirectAccessTrackingLock( - Plt->ContextsMutex, std::defer_lock); - if (IndirectAccessTrackingEnabled) { - IndirectAccessTrackingLock.lock(); - // We are going to defer memory release if there are kernels with indirect - // access, that is why explicitly retain context to be sure that it is - // released after all memory allocations in this context are released. - UR_CALL(ur::level_zero::urContextRetain(Context)); - } else { - ContextLock.lock(); - } - - // There is a single allocator for Host USM allocations, so we don't need to - // find the allocator depending on context as we do for Shared and Device - // allocations. - umf_memory_pool_handle_t hPoolInternal = nullptr; + ur_usm_pool_handle_t USMPool = nullptr; if (!UseUSMAllocator) { - hPoolInternal = Context->HostMemProxyPool.get(); + USMPool = &Context->ProxyPool; } else if (Pool) { - hPoolInternal = Pool->HostMemPool.get(); + USMPool = Pool; } else { - hPoolInternal = Context->HostMemPool.get(); + USMPool = &Context->DefaultPool; } - *RetMem = umfPoolAlignedMalloc(hPoolInternal, Size, Align); - if (*RetMem == nullptr) { - auto umfRet = umfPoolGetLastAllocationError(hPoolInternal); - return umf2urResult(umfRet); - } - - if (IndirectAccessTrackingEnabled) { - // Keep track of all memory allocations in the context - Context->MemAllocs.emplace(std::piecewise_construct, - std::forward_as_tuple(*RetMem), - std::forward_as_tuple(Context)); - } - - return UR_RESULT_SUCCESS; + return USMPool->allocate(Context, nullptr, USMDesc, UR_USM_TYPE_HOST, Size, + RetMem); } ur_result_t urUSMDeviceAlloc( @@ -408,72 +359,17 @@ ur_result_t urUSMDeviceAlloc( /// [out] pointer to USM device memory object void **RetMem) { - uint32_t Alignment = USMDesc ? USMDesc->align : 0; - - // L0 supports alignment up to 64KB and silently ignores higher values. - // We flag alignment > 64KB as an invalid value. - // L0 spec says that alignment values that are not powers of 2 are invalid. - // If alignment == 0, then we are allowing the L0 driver to choose the - // alignment so no need to check. - if (Alignment > 0) { - if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0) - return UR_RESULT_ERROR_INVALID_VALUE; - } - - ur_platform_handle_t Plt = Device->Platform; - - // If indirect access tracking is enabled then lock the mutex which is - // guarding contexts container in the platform. This prevents new kernels from - // being submitted in any context while we are in the process of allocating a - // memory, this is needed to properly capture allocations by kernels with - // indirect access. This lock also protects access to the context's data - // structures. If indirect access tracking is not enabled then lock context - // mutex to protect access to context's data structures. - std::shared_lock ContextLock(Context->Mutex, - std::defer_lock); - std::unique_lock IndirectAccessTrackingLock( - Plt->ContextsMutex, std::defer_lock); - if (IndirectAccessTrackingEnabled) { - IndirectAccessTrackingLock.lock(); - // We are going to defer memory release if there are kernels with indirect - // access, that is why explicitly retain context to be sure that it is - // released after all memory allocations in this context are released. - UR_CALL(ur::level_zero::urContextRetain(Context)); - } else { - ContextLock.lock(); - } - - umf_memory_pool_handle_t hPoolInternal = nullptr; + ur_usm_pool_handle_t USMPool = nullptr; if (!UseUSMAllocator) { - auto It = Context->DeviceMemProxyPools.find(Device->ZeDevice); - if (It == Context->DeviceMemProxyPools.end()) - return UR_RESULT_ERROR_INVALID_VALUE; - - hPoolInternal = It->second.get(); + USMPool = &Context->ProxyPool; } else if (Pool) { - hPoolInternal = Pool->DeviceMemPools[Device].get(); + USMPool = Pool; } else { - auto It = Context->DeviceMemPools.find(Device->ZeDevice); - if (It == Context->DeviceMemPools.end()) - return UR_RESULT_ERROR_INVALID_VALUE; - - hPoolInternal = It->second.get(); - } - - *RetMem = umfPoolAlignedMalloc(hPoolInternal, Size, Alignment); - if (*RetMem == nullptr) { - auto umfRet = umfPoolGetLastAllocationError(hPoolInternal); - return umf2urResult(umfRet); + USMPool = &Context->DefaultPool; } - if (IndirectAccessTrackingEnabled) { - // Keep track of all memory allocations in the context - Context->MemAllocs.emplace(std::piecewise_construct, - std::forward_as_tuple(*RetMem), - std::forward_as_tuple(Context)); - } - - return UR_RESULT_SUCCESS; + return USMPool->allocate(Context, Device, USMDesc, UR_USM_TYPE_DEVICE, Size, + RetMem); } ur_result_t urUSMSharedAlloc( @@ -489,100 +385,17 @@ ur_result_t urUSMSharedAlloc( size_t Size, /// [out] pointer to USM shared memory object void **RetMem) { - - uint32_t Alignment = USMDesc ? USMDesc->align : 0; - - ur_usm_host_mem_flags_t UsmHostFlags{}; - - // See if the memory is going to be read-only on the device. - bool DeviceReadOnly = false; - ur_usm_device_mem_flags_t UsmDeviceFlags{}; - - void *pNext = USMDesc ? const_cast(USMDesc->pNext) : nullptr; - while (pNext != nullptr) { - const ur_base_desc_t *BaseDesc = - reinterpret_cast(pNext); - if (BaseDesc->stype == UR_STRUCTURE_TYPE_USM_DEVICE_DESC) { - const ur_usm_device_desc_t *UsmDeviceDesc = - reinterpret_cast(pNext); - UsmDeviceFlags = UsmDeviceDesc->flags; - } - if (BaseDesc->stype == UR_STRUCTURE_TYPE_USM_HOST_DESC) { - const ur_usm_host_desc_t *UsmHostDesc = - reinterpret_cast(pNext); - UsmHostFlags = UsmHostDesc->flags; - std::ignore = UsmHostFlags; - } - pNext = const_cast(BaseDesc->pNext); - } - DeviceReadOnly = UsmDeviceFlags & UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY; - - // L0 supports alignment up to 64KB and silently ignores higher values. - // We flag alignment > 64KB as an invalid value. - // L0 spec says that alignment values that are not powers of 2 are invalid. - // If alignment == 0, then we are allowing the L0 driver to choose the - // alignment so no need to check. - if (Alignment > 0) { - if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0) - return UR_RESULT_ERROR_INVALID_VALUE; - } - - ur_platform_handle_t Plt = Device->Platform; - - // If indirect access tracking is enabled then lock the mutex which is - // guarding contexts container in the platform. This prevents new kernels from - // being submitted in any context while we are in the process of allocating a - // memory, this is needed to properly capture allocations by kernels with - // indirect access. This lock also protects access to the context's data - // structures. If indirect access tracking is not enabled then lock context - // mutex to protect access to context's data structures. - std::scoped_lock Lock( - IndirectAccessTrackingEnabled ? Plt->ContextsMutex : Context->Mutex); - - if (IndirectAccessTrackingEnabled) { - // We are going to defer memory release if there are kernels with indirect - // access, that is why explicitly retain context to be sure that it is - // released after all memory allocations in this context are released. - UR_CALL(ur::level_zero::urContextRetain(Context)); - } - - umf_memory_pool_handle_t hPoolInternal = nullptr; + ur_usm_pool_handle_t USMPool = nullptr; if (!UseUSMAllocator) { - auto &Allocator = (DeviceReadOnly ? Context->SharedReadOnlyMemProxyPools - : Context->SharedMemProxyPools); - auto It = Allocator.find(Device->ZeDevice); - if (It == Allocator.end()) - return UR_RESULT_ERROR_INVALID_VALUE; - - hPoolInternal = It->second.get(); + USMPool = &Context->ProxyPool; } else if (Pool) { - hPoolInternal = (DeviceReadOnly) - ? Pool->SharedReadOnlyMemPools[Device].get() - : Pool->SharedMemPools[Device].get(); + USMPool = Pool; } else { - auto &Allocator = (DeviceReadOnly ? Context->SharedReadOnlyMemPools - : Context->SharedMemPools); - auto It = Allocator.find(Device->ZeDevice); - if (It == Allocator.end()) - return UR_RESULT_ERROR_INVALID_VALUE; - - hPoolInternal = It->second.get(); + USMPool = &Context->DefaultPool; } - *RetMem = umfPoolAlignedMalloc(hPoolInternal, Size, Alignment); - if (*RetMem == nullptr) { - auto umfRet = umfPoolGetLastAllocationError(hPoolInternal); - return umf2urResult(umfRet); - } - - if (IndirectAccessTrackingEnabled) { - // Keep track of all memory allocations in the context - Context->MemAllocs.emplace(std::piecewise_construct, - std::forward_as_tuple(*RetMem), - std::forward_as_tuple(Context)); - } - - return UR_RESULT_SUCCESS; + return USMPool->allocate(Context, Device, USMDesc, UR_USM_TYPE_SHARED, Size, + RetMem); } ur_result_t @@ -667,26 +480,8 @@ ur_result_t urUSMGetMemAllocInfo( std::shared_lock ContextLock(Context->Mutex); - auto SearchMatchingPool = - [](std::unordered_map - &PoolMap, - umf_memory_pool_handle_t UMFPool) { - for (auto &PoolPair : PoolMap) { - if (PoolPair.second.get() == UMFPool) { - return true; - } - } - return false; - }; - for (auto &Pool : Context->UsmPoolHandles) { - if (SearchMatchingPool(Pool->DeviceMemPools, UMFPool)) { - return ReturnValue(Pool); - } - if (SearchMatchingPool(Pool->SharedMemPools, UMFPool)) { - return ReturnValue(Pool); - } - if (Pool->HostMemPool.get() == UMFPool) { + if (Pool->hasPool(UMFPool)) { return ReturnValue(Pool); } } @@ -1034,84 +829,176 @@ ur_result_t L0HostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size, return USMHostAllocImpl(ResultPtr, Context, /* flags */ 0, Size, Alignment); } -ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context, - ur_usm_pool_desc_t *PoolDesc) { - - this->Context = Context; - zeroInit = static_cast(PoolDesc->flags & - UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK); - - void *pNext = const_cast(PoolDesc->pNext); - while (pNext != nullptr) { - const ur_base_desc_t *BaseDesc = - reinterpret_cast(pNext); - switch (BaseDesc->stype) { - case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: { - const ur_usm_pool_limits_desc_t *Limits = - reinterpret_cast(BaseDesc); - for (auto &config : DisjointPoolConfigs.Configs) { - config.MaxPoolableSize = Limits->maxPoolableSize; - config.SlabMinSize = Limits->minDriverAllocSize; - } - break; +static usm::DisjointPoolMemType +DescToDisjointPoolMemType(const usm::pool_descriptor &desc) { + switch (desc.type) { + case UR_USM_TYPE_DEVICE: + return usm::DisjointPoolMemType::Device; + case UR_USM_TYPE_SHARED: + if (desc.deviceReadOnly) + return usm::DisjointPoolMemType::SharedReadOnly; + else + return usm::DisjointPoolMemType::Shared; + case UR_USM_TYPE_HOST: + return usm::DisjointPoolMemType::Host; + default: + throw UR_RESULT_ERROR_INVALID_ARGUMENT; + } +} + +static umf::pool_unique_handle_t +MakePool(usm::pool_descriptor PoolDesc, + usm::umf_disjoint_pool_config_t &PoolParams) { + umf_result_t Ret = UMF_RESULT_SUCCESS; + umf::provider_unique_handle_t Provider = nullptr; + + switch (PoolDesc.type) { + case UR_USM_TYPE_HOST: + std::tie(Ret, Provider) = + umf::memoryProviderMakeUnique(PoolDesc.hContext, + PoolDesc.hDevice); + break; + case UR_USM_TYPE_DEVICE: + std::tie(Ret, Provider) = + umf::memoryProviderMakeUnique(PoolDesc.hContext, + PoolDesc.hDevice); + break; + case UR_USM_TYPE_SHARED: + if (PoolDesc.deviceReadOnly) { + std::tie(Ret, Provider) = + umf::memoryProviderMakeUnique( + PoolDesc.hContext, PoolDesc.hDevice); + } else { + std::tie(Ret, Provider) = + umf::memoryProviderMakeUnique( + PoolDesc.hContext, PoolDesc.hDevice); } - default: { - logger::error("urUSMPoolCreate: unexpected chained stype"); - throw UsmAllocationException(UR_RESULT_ERROR_INVALID_ARGUMENT); + break; + default: + logger::error("urUSMPoolCreate: invalid USM type found in pool descriptor"); + Ret = UMF_RESULT_ERROR_INVALID_ARGUMENT; + } + + if (Ret != UMF_RESULT_SUCCESS) { + logger::error("urUSMPoolCreate: failed to create UMF provider"); + throw UsmAllocationException(umf::umf2urResult(Ret)); + } + + { + auto UmfParamsHandle = getUmfParamsHandle(PoolParams); + auto [Ret, Pool] = umf::poolMakeUniqueFromOps( + umfDisjointPoolOps(), std::move(Provider), UmfParamsHandle.get()); + if (Ret != UMF_RESULT_SUCCESS) { + logger::error("urUSMPoolCreate: failed to create UMF pool"); + throw UsmAllocationException(umf::umf2urResult(Ret)); } + + return std::move(Pool); + } +} + +ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context, + ur_usm_pool_desc_t *PoolDesc) + : Context(Context) { + // TODO: handle zero-init flag 'UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK' + auto DisjointPoolConfigs = InitializeDisjointPoolConfig(); + if (auto Limits = find_stype_node(PoolDesc)) { + for (auto &Config : DisjointPoolConfigs.Configs) { + Config.MaxPoolableSize = Limits->maxPoolableSize; + Config.SlabMinSize = Limits->minDriverAllocSize; } - pNext = const_cast(BaseDesc->pNext); - } - - auto MemProvider = - umf::memoryProviderMakeUnique(Context, nullptr) - .second; - - auto UmfHostParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host]); - HostMemPool = - umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), std::move(MemProvider), - UmfHostParamsHandle.get()) - .second; - - for (auto device : Context->Devices) { - MemProvider = - umf::memoryProviderMakeUnique(Context, device) - .second; - auto UmfDeviceParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Device]); - DeviceMemPools.emplace( - std::piecewise_construct, std::make_tuple(device), - std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), - std::move(MemProvider), - UmfDeviceParamsHandle.get()) - .second)); - - MemProvider = - umf::memoryProviderMakeUnique(Context, device) - .second; - auto UmfSharedParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Shared]); - SharedMemPools.emplace( - std::piecewise_construct, std::make_tuple(device), - std::make_tuple(umf::poolMakeUniqueFromOps(umfDisjointPoolOps(), - std::move(MemProvider), - UmfSharedParamsHandle.get()) - .second)); - - MemProvider = umf::memoryProviderMakeUnique( - Context, device) - .second; - auto UmfSharedROParamsHandle = getUmfParamsHandle( - DisjointPoolConfigInstance - .Configs[usm::DisjointPoolMemType::SharedReadOnly]); - SharedReadOnlyMemPools.emplace( - std::piecewise_construct, std::make_tuple(device), - std::make_tuple(umf::poolMakeUniqueFromOps( - umfDisjointPoolOps(), std::move(MemProvider), - UmfSharedROParamsHandle.get()) - .second)); } + + auto [Ret, Descriptors] = usm::pool_descriptor::create(this, Context); + if (Ret) { + logger::error("urUSMPoolCreate: failed to create pool descriptors"); + throw UsmAllocationException(Ret); + } + + for (auto &Desc : Descriptors) { + auto &PoolConfig = + DisjointPoolConfigs.Configs[DescToDisjointPoolMemType(Desc)]; + PoolManager.addPool(Desc, MakePool(Desc, PoolConfig)); + } +} + +umf_memory_pool_handle_t +ur_usm_pool_handle_t_::getPool(const usm::pool_descriptor &Desc) { + auto PoolOpt = PoolManager.getPool(Desc); + return PoolOpt.has_value() ? PoolOpt.value() : nullptr; +} + +bool ur_usm_pool_handle_t_::hasPool(umf_memory_pool_handle_t Pool) { + return PoolManager.hasPool(Pool); +} + +ur_result_t ur_usm_pool_handle_t_::allocate(ur_context_handle_t Context, + ur_device_handle_t Device, + const ur_usm_desc_t *USMDesc, + ur_usm_type_t Type, size_t Size, + void **RetMem) { + uint32_t Alignment = USMDesc ? USMDesc->align : 0; + // L0 supports alignment up to 64KB and silently ignores higher values. + // We flag alignment > 64KB as an invalid value. + // L0 spec says that alignment values that are not powers of 2 are invalid. + // If alignment == 0, then we are allowing the L0 driver to choose the + // alignment so no need to check. + if (Alignment > 0) { + if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0) + return UR_RESULT_ERROR_INVALID_VALUE; + } + + // Handle the extension structures for 'ur_usm_desc_t'. + if (auto UsmHostDesc = find_stype_node(USMDesc)) { + std::ignore = UsmHostDesc; // Unused + } + + bool DeviceReadOnly = false; + if (auto UsmDeviceDesc = find_stype_node(USMDesc)) { + DeviceReadOnly = + (Type == UR_USM_TYPE_SHARED) && + (UsmDeviceDesc->flags & UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY); + } + + ur_platform_handle_t Plt = + (Device) ? Device->Platform : Context->getPlatform(); + // If indirect access tracking is enabled then lock the mutex which is + // guarding contexts container in the platform. This prevents new kernels from + // being submitted in any context while we are in the process of allocating a + // memory, this is needed to properly capture allocations by kernels with + // indirect access. This lock also protects access to the context's data + // structures. If indirect access tracking is not enabled then lock context + // mutex to protect access to context's data structures. + std::scoped_lock Lock( + IndirectAccessTrackingEnabled ? Plt->ContextsMutex : Context->Mutex); + + if (IndirectAccessTrackingEnabled) { + // We are going to defer memory release if there are kernels with indirect + // access, that is why explicitly retain context to be sure that it is + // released after all memory allocations in this context are released. + UR_CALL(ur::level_zero::urContextRetain(Context)); + } + + auto umfPool = getPool( + usm::pool_descriptor{this, Context, Device, Type, DeviceReadOnly}); + if (!umfPool) { + return UR_RESULT_ERROR_INVALID_ARGUMENT; + } + + *RetMem = umfPoolAlignedMalloc(umfPool, Size, Alignment); + if (*RetMem == nullptr) { + auto umfRet = umfPoolGetLastAllocationError(umfPool); + return umf::umf2urResult(umfRet); + } + + if (IndirectAccessTrackingEnabled) { + // Keep track of all memory allocations in the context + Context->MemAllocs.emplace(std::piecewise_construct, + std::forward_as_tuple(*RetMem), + std::forward_as_tuple(Context)); + } + + return UR_RESULT_SUCCESS; } // If indirect access tracking is not enabled then this functions just performs diff --git a/source/adapters/level_zero/usm.hpp b/source/adapters/level_zero/usm.hpp index 2fe74a5ecf..2b3ce5f541 100644 --- a/source/adapters/level_zero/usm.hpp +++ b/source/adapters/level_zero/usm.hpp @@ -11,28 +11,26 @@ #include "common.hpp" +#include "ur_pool_manager.hpp" #include usm::DisjointPoolAllConfigs InitializeDisjointPoolConfig(); struct ur_usm_pool_handle_t_ : _ur_object { - bool zeroInit; - - usm::DisjointPoolAllConfigs DisjointPoolConfigs = - InitializeDisjointPoolConfig(); + ur_usm_pool_handle_t_(ur_context_handle_t Context, + ur_usm_pool_desc_t *PoolDesc); - std::unordered_map - DeviceMemPools; - std::unordered_map - SharedMemPools; - std::unordered_map - SharedReadOnlyMemPools; - umf::pool_unique_handle_t HostMemPool; + ur_result_t allocate(ur_context_handle_t Context, ur_device_handle_t Device, + const ur_usm_desc_t *USMDesc, ur_usm_type_t Type, + size_t Size, void **RetMem); + ur_result_t free(void *Ptr); + umf_memory_pool_handle_t getPool(const usm::pool_descriptor &Desc); + bool hasPool(umf_memory_pool_handle_t Pool); - ur_context_handle_t Context{}; + ur_context_handle_t Context; - ur_usm_pool_handle_t_(ur_context_handle_t Context, - ur_usm_pool_desc_t *PoolDesc); +private: + usm::pool_manager PoolManager; }; // Exception type to pass allocation errors diff --git a/source/common/ur_pool_manager.hpp b/source/common/ur_pool_manager.hpp index 2913c8e3af..b4a736d103 100644 --- a/source/common/ur_pool_manager.hpp +++ b/source/common/ur_pool_manager.hpp @@ -288,6 +288,12 @@ template struct pool_manager { return it->second.get(); } + + bool hasPool(umf_memory_pool_handle_t hPool) noexcept { + return std::any_of( + descToPoolMap.begin(), descToPoolMap.end(), + [&](const auto &Pair) { return Pair.second.get() == hPool; }); + } }; } // namespace usm From 3abc64c2af4ac705eec9c137193a4d6b0808e6f1 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 17 Dec 2024 13:23:05 +0100 Subject: [PATCH 2/6] [L0] Remove SingleRootDevice from context This variable is not initialized in any way and it is set to nullptr by default. --- source/adapters/level_zero/context.cpp | 9 +--- source/adapters/level_zero/context.hpp | 7 --- source/adapters/level_zero/memory.cpp | 66 ++++++-------------------- 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index ccb40f98ff..1fe7b4c273 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -192,13 +192,6 @@ ur_result_t urContextSetExtendedDeleter( } // namespace ur::level_zero ur_result_t ur_context_handle_t_::initialize() { - - // We may allocate memory to this root device so create allocators. - if (SingleRootDevice && - DeviceMemPools.find(SingleRootDevice->ZeDevice) == DeviceMemPools.end()) { - createUSMAllocators(SingleRootDevice); - } - // Create the immediate command list to be used for initializations. // Created as synchronous so level-zero performs implicit synchronization and // there is no need to query for completion in the plugin @@ -209,7 +202,7 @@ ur_result_t ur_context_handle_t_::initialize() { // D2D migartion, if no P2P, is broken since it should use // immediate command-list for the specfic devices, and this single one. // - ur_device_handle_t Device = SingleRootDevice ? SingleRootDevice : Devices[0]; + ur_device_handle_t Device = Devices[0]; // Prefer to use copy engine for initialization copies, // if available and allowed (main copy engine with index 0). diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index f0c7ad3e13..99435de859 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -98,13 +98,6 @@ struct ur_context_handle_t_ : _ur_object { // compute and copy command list caches. ur_mutex ZeCommandListCacheMutex; - // If context contains one device or sub-devices of the same device, we want - // to save this device. - // This field is only set at ur_context_handle_t creation time, and cannot - // change. Therefore it can be accessed without holding a lock on this - // ur_context_handle_t. - ur_device_handle_t SingleRootDevice = nullptr; - // Cache of all currently available/completed command/copy lists. // Note that command-list can only be re-used on the same device. // diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index e21470eee2..2b2af3b8cb 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -1592,9 +1592,7 @@ ur_result_t urMemImageCreate( // own the image. // TODO: Implement explicit copying for acessing the image from other devices // in the context. - ur_device_handle_t Device = Context->SingleRootDevice - ? Context->SingleRootDevice - : Context->Devices[0]; + ur_device_handle_t Device = Context->Devices[0]; ze_image_handle_t ZeImage; ZE2UR_CALL(zeImageCreate, (Context->ZeContext, Device->ZeDevice, &ZeImageDesc, &ZeImage)); @@ -2154,58 +2152,22 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode, LastDeviceWithValidAllocation = Device; return UR_RESULT_SUCCESS; } - // Reads user setting on how to deal with buffers in contexts where - // all devices have the same root-device. Returns "true" if the - // preference is to have allocate on each [sub-]device and migrate - // normally (copy) to other sub-devices as needed. Returns "false" - // if the preference is to have single root-device allocations - // serve the needs of all [sub-]devices, meaning potentially more - // cross-tile traffic. - // - static const bool SingleRootDeviceBufferMigration = [] { - const char *UrRet = - std::getenv("UR_L0_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION"); - const char *PiRet = - std::getenv("SYCL_PI_LEVEL_ZERO_SINGLE_ROOT_DEVICE_BUFFER_MIGRATION"); - const char *EnvStr = UrRet ? UrRet : (PiRet ? PiRet : nullptr); - if (EnvStr) - return (std::stoi(EnvStr) != 0); - // The default is to migrate normally, which may not always be the - // best option (depends on buffer access patterns), but is an - // overall win on the set of the available benchmarks. - return true; - }(); // Peform actual device allocation as needed. if (!Allocation.ZeHandle) { - if (!SingleRootDeviceBufferMigration && UrContext->SingleRootDevice && - UrContext->SingleRootDevice != Device) { - // If all devices in the context are sub-devices of the same device - // then we reuse root-device allocation by all sub-devices in the - // context. - // TODO: we can probably generalize this and share root-device - // allocations by its own sub-devices even if not all other - // devices in the context have the same root. - UR_CALL(getZeHandle(ZeHandle, AccessMode, UrContext->SingleRootDevice, - phWaitEvents, numWaitEvents)); - Allocation.ReleaseAction = allocation_t::keep; - Allocation.ZeHandle = ZeHandle; - Allocation.Valid = true; - return UR_RESULT_SUCCESS; - } else { // Create device allocation - if (DisjointPoolConfigInstance.EnableBuffers) { - Allocation.ReleaseAction = allocation_t::free; - ur_usm_desc_t USMDesc{}; - USMDesc.align = getAlignment(); - ur_usm_pool_handle_t Pool{}; - UR_CALL(ur::level_zero::urUSMDeviceAlloc( - UrContext, Device, &USMDesc, Pool, Size, - reinterpret_cast(&ZeHandle))); - } else { - Allocation.ReleaseAction = allocation_t::free_native; - UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast(&ZeHandle), - UrContext, Device, Size)); - } + // Create device allocation + if (DisjointPoolConfigInstance.EnableBuffers) { + Allocation.ReleaseAction = allocation_t::free; + ur_usm_desc_t USMDesc{}; + USMDesc.align = getAlignment(); + ur_usm_pool_handle_t Pool{}; + UR_CALL(ur::level_zero::urUSMDeviceAlloc( + UrContext, Device, &USMDesc, Pool, Size, + reinterpret_cast(&ZeHandle))); + } else { + Allocation.ReleaseAction = allocation_t::free_native; + UR_CALL(ZeDeviceMemAllocHelper(reinterpret_cast(&ZeHandle), + UrContext, Device, Size)); } Allocation.ZeHandle = ZeHandle; } else { From 7f2b5b2e5693958eb984e92cc5113594366e7e4c Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 7 Jan 2025 14:41:35 +0100 Subject: [PATCH 3/6] [L0] Fix provider native error reporting Level Zero provider internally stores native errors of ur_result_t type. --- source/adapters/level_zero/usm.cpp | 3 ++- source/adapters/level_zero/usm.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 0a383d55ea..49d392366b 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -27,7 +27,8 @@ namespace umf { ur_result_t getProviderNativeError(const char *providerName, int32_t nativeError) { if (strcmp(providerName, "Level Zero") == 0) { - return ze2urResult(static_cast(nativeError)); + // L0 provider stores native errors of ur_result_t type + return static_cast(nativeError); } return UR_RESULT_ERROR_UNKNOWN; diff --git a/source/adapters/level_zero/usm.hpp b/source/adapters/level_zero/usm.hpp index 2b3ce5f541..a7a1ee8777 100644 --- a/source/adapters/level_zero/usm.hpp +++ b/source/adapters/level_zero/usm.hpp @@ -123,7 +123,7 @@ class L0MemoryProvider : public USMMemoryProviderBase { umf_result_t free(void *Ptr, size_t Size) override; umf_result_t get_min_page_size(void *, size_t *) override; // TODO: Different name for each provider (Host/Shared/SharedRO/Device) - const char *get_name() override { return "L0"; }; + const char *get_name() override { return "Level Zero"; }; umf_result_t get_ipc_handle_size(size_t *) override; umf_result_t get_ipc_handle(const void *, size_t, void *) override; umf_result_t put_ipc_handle(void *) override; From bbf3d89d6e5bc9f63ba6504a9fae14ae547d2dcd Mon Sep 17 00:00:00 2001 From: Hugh Delaney Date: Mon, 30 Sep 2024 10:06:52 +0100 Subject: [PATCH 4/6] Add initial spec for async alloc entry points First basic work in progress spec. --- include/ur_api.h | 270 ++++++++++++- include/ur_api_funcs.def | 4 + include/ur_ddi.h | 31 ++ include/ur_print.h | 60 +++ include/ur_print.hpp | 381 ++++++++++++++++++ scripts/core/EXP-ASYNC-ALLOC.rst | 78 ++++ scripts/core/exp-async-alloc.yml | 216 ++++++++++ scripts/core/registry.yml | 12 + source/adapters/cuda/common.cpp | 9 +- source/adapters/cuda/usm.cpp | 120 ++++++ source/adapters/hip/common.cpp | 12 +- source/adapters/hip/usm.cpp | 120 ++++++ .../level_zero/ur_interface_loader.cpp | 4 + .../level_zero/ur_interface_loader.hpp | 20 + source/adapters/level_zero/usm.cpp | 120 ++++++ source/adapters/level_zero/v2/queue_api.cpp | 43 ++ source/adapters/level_zero/v2/queue_api.hpp | 18 + .../v2/queue_immediate_in_order.cpp | 56 +++ .../v2/queue_immediate_in_order.hpp | 19 + source/adapters/mock/ur_mockddi.cpp | 270 +++++++++++++ source/adapters/native_cpu/usm.cpp | 61 +++ source/adapters/opencl/usm.cpp | 45 +++ source/common/logger/ur_sinks.hpp | 4 +- source/common/stype_map_helpers.def | 2 + source/loader/layers/tracing/ur_trcddi.cpp | 240 +++++++++++ source/loader/layers/validation/ur_valddi.cpp | 277 ++++++++++++- source/loader/loader.def.in | 10 + source/loader/loader.map.in | 10 + source/loader/ur_ldrddi.cpp | 274 +++++++++++++ source/loader/ur_libapi.cpp | 199 ++++++++- source/loader/ur_print.cpp | 49 +++ source/ur_api.cpp | 168 +++++++- test/conformance/testing/include/uur/utils.h | 8 +- tools/urinfo/urinfo.cpp | 28 +- tools/urinfo/urinfo.hpp | 3 + 35 files changed, 3203 insertions(+), 38 deletions(-) create mode 100644 scripts/core/EXP-ASYNC-ALLOC.rst create mode 100644 scripts/core/exp-async-alloc.yml diff --git a/include/ur_api.h b/include/ur_api.h index 4b0be51f0c..bdfed5a757 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -429,6 +429,14 @@ typedef enum ur_function_t { UR_FUNCTION_ENQUEUE_EVENTS_WAIT_WITH_BARRIER_EXT = 246, /// Enumerator for ::urPhysicalMemGetInfo UR_FUNCTION_PHYSICAL_MEM_GET_INFO = 249, + /// Enumerator for ::urEnqueueUSMDeviceAllocExp + UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP = 250, + /// Enumerator for ::urEnqueueUSMSharedAllocExp + UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP = 251, + /// Enumerator for ::urEnqueueUSMHostAllocExp + UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP = 252, + /// Enumerator for ::urEnqueueUSMFreeExp + UR_FUNCTION_ENQUEUE_USM_FREE_EXP = 253, /// @cond UR_FUNCTION_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -536,6 +544,8 @@ typedef enum ur_structure_type_t { UR_STRUCTURE_TYPE_EXP_IMAGE_COPY_REGION = 0x2007, /// ::ur_exp_enqueue_native_command_properties_t UR_STRUCTURE_TYPE_EXP_ENQUEUE_NATIVE_COMMAND_PROPERTIES = 0x3000, + /// ::ur_exp_enqueue_usm_alloc_properties_t + UR_STRUCTURE_TYPE_EXP_ENQUEUE_USM_ALLOC_PROPERTIES = 0x3001, /// ::ur_exp_enqueue_ext_properties_t UR_STRUCTURE_TYPE_EXP_ENQUEUE_EXT_PROPERTIES = 0x4000, /// @cond @@ -2289,6 +2299,9 @@ typedef enum ur_device_info_t { /// [::ur_exp_device_2d_block_array_capability_flags_t] return a bit-field /// of Intel GPU 2D block array capabilities UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP = 0x2022, + /// [::ur_bool_t] returns true if the device supports USM allocation + /// enqueueing + UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP = 0x2023, /// @cond UR_DEVICE_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -2314,7 +2327,7 @@ typedef enum ur_device_info_t { /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hDevice` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP < propName` +/// + `::UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE @@ -7047,6 +7060,14 @@ typedef enum ur_command_t { UR_COMMAND_TIMESTAMP_RECORDING_EXP = 0x2002, /// Event created by ::urEnqueueNativeCommandExp UR_COMMAND_ENQUEUE_NATIVE_EXP = 0x2004, + /// Event created by ::urEnqueueUSMDeviceAllocExp + UR_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP = 0x2005, + /// Event created by ::urEnqueueUSMSharedAllocExp + UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP = 0x2006, + /// Event created by ::urEnqueueUSMHostAllocExp + UR_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP = 0x2007, + /// Event created by ::urEnqueueUSMFreeExp + UR_COMMAND_ENQUEUE_USM_FREE_EXP = 0x2008, /// @cond UR_COMMAND_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -8941,6 +8962,195 @@ typedef enum ur_exp_device_2d_block_array_capability_flag_t { /// ur_exp_device_2d_block_array_capability_flags_t #define UR_EXP_DEVICE_2D_BLOCK_ARRAY_CAPABILITY_FLAGS_MASK 0xfffffffc +#if !defined(__GNUC__) +#pragma endregion +#endif +// Intel 'oneAPI' Unified Runtime Experimental API for enqueuing asynchronous +// USM allocations +#if !defined(__GNUC__) +#pragma region async_alloc_(experimental) +#endif +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue USM allocation flags +typedef uint32_t ur_exp_enqueue_usm_alloc_flags_t; +typedef enum ur_exp_enqueue_usm_alloc_flag_t { + /// reserved for future use. + UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD = UR_BIT(0), + /// @cond + UR_EXP_ENQUEUE_USM_ALLOC_FLAG_FORCE_UINT32 = 0x7fffffff + /// @endcond + +} ur_exp_enqueue_usm_alloc_flag_t; +/// @brief Bit Mask for validating ur_exp_enqueue_usm_alloc_flags_t +#define UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK 0xfffffffe + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue USM allocation properties +typedef struct ur_exp_enqueue_usm_alloc_properties_t { + /// [in] type of this structure, must be + /// ::UR_STRUCTURE_TYPE_EXP_ENQUEUE_USM_ALLOC_PROPERTIES + ur_structure_type_t stype; + /// [in,out][optional] pointer to extension-specific structure + void *pNext; + /// [in] enqueue USM allocation flags + ur_exp_enqueue_usm_alloc_flags_t flags; + +} ur_exp_enqueue_usm_alloc_properties_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM device allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM shared allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM host allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM deallocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent); + #if !defined(__GNUC__) #pragma endregion #endif @@ -13486,6 +13696,64 @@ typedef struct ur_enqueue_events_wait_with_barrier_ext_params_t { ur_event_handle_t **pphEvent; } ur_enqueue_events_wait_with_barrier_ext_params_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urEnqueueUSMDeviceAllocExp +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_enqueue_usm_device_alloc_exp_params_t { + ur_queue_handle_t *phQueue; + ur_usm_pool_handle_t *ppPool; + const size_t *psize; + const ur_exp_enqueue_usm_alloc_properties_t **ppProperties; + uint32_t *pnumEventsInWaitList; + const ur_event_handle_t **pphEventWaitList; + void ***pppMem; + ur_event_handle_t **pphEvent; +} ur_enqueue_usm_device_alloc_exp_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urEnqueueUSMSharedAllocExp +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_enqueue_usm_shared_alloc_exp_params_t { + ur_queue_handle_t *phQueue; + ur_usm_pool_handle_t *ppPool; + const size_t *psize; + const ur_exp_enqueue_usm_alloc_properties_t **ppProperties; + uint32_t *pnumEventsInWaitList; + const ur_event_handle_t **pphEventWaitList; + void ***pppMem; + ur_event_handle_t **pphEvent; +} ur_enqueue_usm_shared_alloc_exp_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urEnqueueUSMHostAllocExp +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_enqueue_usm_host_alloc_exp_params_t { + ur_queue_handle_t *phQueue; + ur_usm_pool_handle_t *ppPool; + const size_t *psize; + const ur_exp_enqueue_usm_alloc_properties_t **ppProperties; + uint32_t *pnumEventsInWaitList; + const ur_event_handle_t **pphEventWaitList; + void ***pppMem; + ur_event_handle_t **pphEvent; +} ur_enqueue_usm_host_alloc_exp_params_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function parameters for urEnqueueUSMFreeExp +/// @details Each entry is a pointer to the parameter passed to the function; +/// allowing the callback the ability to modify the parameter's value +typedef struct ur_enqueue_usm_free_exp_params_t { + ur_queue_handle_t *phQueue; + ur_usm_pool_handle_t *ppPool; + void **ppMem; + uint32_t *pnumEventsInWaitList; + const ur_event_handle_t **pphEventWaitList; + ur_event_handle_t **pphEvent; +} ur_enqueue_usm_free_exp_params_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Function parameters for urEnqueueCooperativeKernelLaunchExp /// @details Each entry is a pointer to the parameter passed to the function; diff --git a/include/ur_api_funcs.def b/include/ur_api_funcs.def index 8c25dde67f..96234cc924 100644 --- a/include/ur_api_funcs.def +++ b/include/ur_api_funcs.def @@ -132,6 +132,10 @@ _UR_API(urEnqueueReadHostPipe) _UR_API(urEnqueueWriteHostPipe) _UR_API(urEnqueueEventsWaitWithBarrierExt) _UR_API(urEnqueueKernelLaunchCustomExp) +_UR_API(urEnqueueUSMDeviceAllocExp) +_UR_API(urEnqueueUSMSharedAllocExp) +_UR_API(urEnqueueUSMHostAllocExp) +_UR_API(urEnqueueUSMFreeExp) _UR_API(urEnqueueCooperativeKernelLaunchExp) _UR_API(urEnqueueTimestampRecordingExp) _UR_API(urEnqueueNativeCommandExp) diff --git a/include/ur_ddi.h b/include/ur_ddi.h index c64aaa8d46..8cacbdc091 100644 --- a/include/ur_ddi.h +++ b/include/ur_ddi.h @@ -1117,6 +1117,33 @@ typedef ur_result_t(UR_APICALL *ur_pfnEnqueueKernelLaunchCustomExp_t)( const size_t *, const size_t *, uint32_t, const ur_exp_launch_property_t *, uint32_t, const ur_event_handle_t *, ur_event_handle_t *); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urEnqueueUSMDeviceAllocExp +typedef ur_result_t(UR_APICALL *ur_pfnEnqueueUSMDeviceAllocExp_t)( + ur_queue_handle_t, ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, uint32_t, + const ur_event_handle_t *, void **, ur_event_handle_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urEnqueueUSMSharedAllocExp +typedef ur_result_t(UR_APICALL *ur_pfnEnqueueUSMSharedAllocExp_t)( + ur_queue_handle_t, ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, uint32_t, + const ur_event_handle_t *, void **, ur_event_handle_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urEnqueueUSMHostAllocExp +typedef ur_result_t(UR_APICALL *ur_pfnEnqueueUSMHostAllocExp_t)( + ur_queue_handle_t, ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, uint32_t, + const ur_event_handle_t *, void **, ur_event_handle_t *); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for urEnqueueUSMFreeExp +typedef ur_result_t(UR_APICALL *ur_pfnEnqueueUSMFreeExp_t)( + ur_queue_handle_t, ur_usm_pool_handle_t, void *, uint32_t, + const ur_event_handle_t *, ur_event_handle_t *); + /////////////////////////////////////////////////////////////////////////////// /// @brief Function-pointer for urEnqueueCooperativeKernelLaunchExp typedef ur_result_t(UR_APICALL *ur_pfnEnqueueCooperativeKernelLaunchExp_t)( @@ -1142,6 +1169,10 @@ typedef ur_result_t(UR_APICALL *ur_pfnEnqueueNativeCommandExp_t)( /// @brief Table of EnqueueExp functions pointers typedef struct ur_enqueue_exp_dditable_t { ur_pfnEnqueueKernelLaunchCustomExp_t pfnKernelLaunchCustomExp; + ur_pfnEnqueueUSMDeviceAllocExp_t pfnUSMDeviceAllocExp; + ur_pfnEnqueueUSMSharedAllocExp_t pfnUSMSharedAllocExp; + ur_pfnEnqueueUSMHostAllocExp_t pfnUSMHostAllocExp; + ur_pfnEnqueueUSMFreeExp_t pfnUSMFreeExp; ur_pfnEnqueueCooperativeKernelLaunchExp_t pfnCooperativeKernelLaunchExp; ur_pfnEnqueueTimestampRecordingExp_t pfnTimestampRecordingExp; ur_pfnEnqueueNativeCommandExp_t pfnNativeCommandExp; diff --git a/include/ur_print.h b/include/ur_print.h index f58133bb8a..52d25de412 100644 --- a/include/ur_print.h +++ b/include/ur_print.h @@ -1122,6 +1122,26 @@ urPrintExpDevice_2dBlockArrayCapabilityFlags( enum ur_exp_device_2d_block_array_capability_flag_t value, char *buffer, const size_t buff_size, size_t *out_size); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_exp_enqueue_usm_alloc_flag_t enum +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintExpEnqueueUsmAllocFlags( + enum ur_exp_enqueue_usm_alloc_flag_t value, char *buffer, + const size_t buff_size, size_t *out_size); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_exp_enqueue_usm_alloc_properties_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintExpEnqueueUsmAllocProperties( + const struct ur_exp_enqueue_usm_alloc_properties_t params, char *buffer, + const size_t buff_size, size_t *out_size); + /////////////////////////////////////////////////////////////////////////////// /// @brief Print ur_exp_image_copy_flag_t enum /// @returns @@ -2626,6 +2646,46 @@ urPrintEnqueueEventsWaitWithBarrierExtParams( const struct ur_enqueue_events_wait_with_barrier_ext_params_t *params, char *buffer, const size_t buff_size, size_t *out_size); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_enqueue_usm_device_alloc_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintEnqueueUsmDeviceAllocExpParams( + const struct ur_enqueue_usm_device_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_enqueue_usm_shared_alloc_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintEnqueueUsmSharedAllocExpParams( + const struct ur_enqueue_usm_shared_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_enqueue_usm_host_alloc_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintEnqueueUsmHostAllocExpParams( + const struct ur_enqueue_usm_host_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size); + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_enqueue_usm_free_exp_params_t struct +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// - `buff_size < out_size` +UR_APIEXPORT ur_result_t UR_APICALL urPrintEnqueueUsmFreeExpParams( + const struct ur_enqueue_usm_free_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size); + /////////////////////////////////////////////////////////////////////////////// /// @brief Print ur_enqueue_cooperative_kernel_launch_exp_params_t struct /// @returns diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 97bf14e61b..10de14a2e5 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -225,6 +225,10 @@ inline ur_result_t printFlag(std::ostream &os, uint32_t flag); +template <> +inline ur_result_t printFlag(std::ostream &os, + uint32_t flag); + template <> inline ur_result_t printFlag(std::ostream &os, uint32_t flag); @@ -502,6 +506,11 @@ inline std::ostream &operator<<(std::ostream &os, inline std::ostream & operator<<(std::ostream &os, enum ur_exp_device_2d_block_array_capability_flag_t value); +inline std::ostream &operator<<(std::ostream &os, + enum ur_exp_enqueue_usm_alloc_flag_t value); +inline std::ostream &operator<<( + std::ostream &os, + [[maybe_unused]] const struct ur_exp_enqueue_usm_alloc_properties_t params); inline std::ostream &operator<<(std::ostream &os, enum ur_exp_image_copy_flag_t value); inline std::ostream & @@ -1177,6 +1186,18 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_function_t value) { case UR_FUNCTION_PHYSICAL_MEM_GET_INFO: os << "UR_FUNCTION_PHYSICAL_MEM_GET_INFO"; break; + case UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP: + os << "UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP"; + break; + case UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP: + os << "UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP"; + break; + case UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP: + os << "UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP"; + break; + case UR_FUNCTION_ENQUEUE_USM_FREE_EXP: + os << "UR_FUNCTION_ENQUEUE_USM_FREE_EXP"; + break; default: os << "unknown enumerator"; break; @@ -1337,6 +1358,9 @@ inline std::ostream &operator<<(std::ostream &os, case UR_STRUCTURE_TYPE_EXP_ENQUEUE_NATIVE_COMMAND_PROPERTIES: os << "UR_STRUCTURE_TYPE_EXP_ENQUEUE_NATIVE_COMMAND_PROPERTIES"; break; + case UR_STRUCTURE_TYPE_EXP_ENQUEUE_USM_ALLOC_PROPERTIES: + os << "UR_STRUCTURE_TYPE_EXP_ENQUEUE_USM_ALLOC_PROPERTIES"; + break; case UR_STRUCTURE_TYPE_EXP_ENQUEUE_EXT_PROPERTIES: os << "UR_STRUCTURE_TYPE_EXP_ENQUEUE_EXT_PROPERTIES"; break; @@ -1639,6 +1663,12 @@ inline ur_result_t printStruct(std::ostream &os, const void *ptr) { printPtr(os, pstruct); } break; + case UR_STRUCTURE_TYPE_EXP_ENQUEUE_USM_ALLOC_PROPERTIES: { + const ur_exp_enqueue_usm_alloc_properties_t *pstruct = + (const ur_exp_enqueue_usm_alloc_properties_t *)ptr; + printPtr(os, pstruct); + } break; + case UR_STRUCTURE_TYPE_EXP_ENQUEUE_EXT_PROPERTIES: { const ur_exp_enqueue_ext_properties_t *pstruct = (const ur_exp_enqueue_ext_properties_t *)ptr; @@ -2975,6 +3005,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) { case UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP: os << "UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP"; break; + case UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP: + os << "UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP"; + break; default: os << "unknown enumerator"; break; @@ -4966,6 +4999,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, os << ")"; } break; + case UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP: { + const ur_bool_t *tptr = (const ur_bool_t *)ptr; + if (sizeof(ur_bool_t) > size) { + os << "invalid size (is: " << size + << ", expected: >=" << sizeof(ur_bool_t) << ")"; + return UR_RESULT_ERROR_INVALID_SIZE; + } + os << (const void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; default: os << "unknown enumerator"; return UR_RESULT_ERROR_INVALID_ENUMERATION; @@ -9897,6 +9943,18 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_command_t value) { case UR_COMMAND_ENQUEUE_NATIVE_EXP: os << "UR_COMMAND_ENQUEUE_NATIVE_EXP"; break; + case UR_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP: + os << "UR_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP"; + break; + case UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP: + os << "UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP"; + break; + case UR_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP: + os << "UR_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP"; + break; + case UR_COMMAND_ENQUEUE_USM_FREE_EXP: + os << "UR_COMMAND_ENQUEUE_USM_FREE_EXP"; + break; default: os << "unknown enumerator"; break; @@ -10390,6 +10448,80 @@ printFlag(std::ostream &os, } } // namespace ur::details /////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_exp_enqueue_usm_alloc_flag_t type +/// @returns +/// std::ostream & +inline std::ostream &operator<<(std::ostream &os, + enum ur_exp_enqueue_usm_alloc_flag_t value) { + switch (value) { + case UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD: + os << "UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD"; + break; + default: + os << "unknown enumerator"; + break; + } + return os; +} + +namespace ur::details { +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print ur_exp_enqueue_usm_alloc_flag_t flag +template <> +inline ur_result_t printFlag(std::ostream &os, + uint32_t flag) { + uint32_t val = flag; + bool first = true; + + if ((val & UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD) == + (uint32_t)UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD) { + val ^= (uint32_t)UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD; + if (!first) { + os << " | "; + } else { + first = false; + } + os << UR_EXP_ENQUEUE_USM_ALLOC_FLAG_TBD; + } + if (val != 0) { + std::bitset<32> bits(val); + if (!first) { + os << " | "; + } + os << "unknown bit flags " << bits; + } else if (first) { + os << "0"; + } + return UR_RESULT_SUCCESS; +} +} // namespace ur::details +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_exp_enqueue_usm_alloc_properties_t type +/// @returns +/// std::ostream & +inline std::ostream & +operator<<(std::ostream &os, + const struct ur_exp_enqueue_usm_alloc_properties_t params) { + os << "(struct ur_exp_enqueue_usm_alloc_properties_t){"; + + os << ".stype = "; + + os << (params.stype); + + os << ", "; + os << ".pNext = "; + + ur::details::printStruct(os, (params.pNext)); + + os << ", "; + os << ".flags = "; + + ur::details::printFlag(os, (params.flags)); + + os << "}"; + return os; +} +/////////////////////////////////////////////////////////////////////////////// /// @brief Print operator for the ur_exp_image_copy_flag_t type /// @returns /// std::ostream & @@ -16174,6 +16306,243 @@ operator<<(std::ostream &os, [[maybe_unused]] const struct return os; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_enqueue_usm_device_alloc_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream &operator<<( + std::ostream &os, + [[maybe_unused]] const struct ur_enqueue_usm_device_alloc_exp_params_t + *params) { + + os << ".hQueue = "; + + ur::details::printPtr(os, *(params->phQueue)); + + os << ", "; + os << ".pPool = "; + + ur::details::printPtr(os, *(params->ppPool)); + + os << ", "; + os << ".size = "; + + os << *(params->psize); + + os << ", "; + os << ".pProperties = "; + + ur::details::printPtr(os, *(params->ppProperties)); + + os << ", "; + os << ".numEventsInWaitList = "; + + os << *(params->pnumEventsInWaitList); + + os << ", "; + os << ".phEventWaitList = "; + ur::details::printPtr( + os, reinterpret_cast(*(params->pphEventWaitList))); + if (*(params->pphEventWaitList) != NULL) { + os << " {"; + for (size_t i = 0; i < *params->pnumEventsInWaitList; ++i) { + if (i != 0) { + os << ", "; + } + + ur::details::printPtr(os, (*(params->pphEventWaitList))[i]); + } + os << "}"; + } + + os << ", "; + os << ".ppMem = "; + + ur::details::printPtr(os, *(params->pppMem)); + + os << ", "; + os << ".phEvent = "; + + ur::details::printPtr(os, *(params->pphEvent)); + + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_enqueue_usm_shared_alloc_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream &operator<<( + std::ostream &os, + [[maybe_unused]] const struct ur_enqueue_usm_shared_alloc_exp_params_t + *params) { + + os << ".hQueue = "; + + ur::details::printPtr(os, *(params->phQueue)); + + os << ", "; + os << ".pPool = "; + + ur::details::printPtr(os, *(params->ppPool)); + + os << ", "; + os << ".size = "; + + os << *(params->psize); + + os << ", "; + os << ".pProperties = "; + + ur::details::printPtr(os, *(params->ppProperties)); + + os << ", "; + os << ".numEventsInWaitList = "; + + os << *(params->pnumEventsInWaitList); + + os << ", "; + os << ".phEventWaitList = "; + ur::details::printPtr( + os, reinterpret_cast(*(params->pphEventWaitList))); + if (*(params->pphEventWaitList) != NULL) { + os << " {"; + for (size_t i = 0; i < *params->pnumEventsInWaitList; ++i) { + if (i != 0) { + os << ", "; + } + + ur::details::printPtr(os, (*(params->pphEventWaitList))[i]); + } + os << "}"; + } + + os << ", "; + os << ".ppMem = "; + + ur::details::printPtr(os, *(params->pppMem)); + + os << ", "; + os << ".phEvent = "; + + ur::details::printPtr(os, *(params->pphEvent)); + + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_enqueue_usm_host_alloc_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream & +operator<<(std::ostream &os, + [[maybe_unused]] const struct ur_enqueue_usm_host_alloc_exp_params_t + *params) { + + os << ".hQueue = "; + + ur::details::printPtr(os, *(params->phQueue)); + + os << ", "; + os << ".pPool = "; + + ur::details::printPtr(os, *(params->ppPool)); + + os << ", "; + os << ".size = "; + + os << *(params->psize); + + os << ", "; + os << ".pProperties = "; + + ur::details::printPtr(os, *(params->ppProperties)); + + os << ", "; + os << ".numEventsInWaitList = "; + + os << *(params->pnumEventsInWaitList); + + os << ", "; + os << ".phEventWaitList = "; + ur::details::printPtr( + os, reinterpret_cast(*(params->pphEventWaitList))); + if (*(params->pphEventWaitList) != NULL) { + os << " {"; + for (size_t i = 0; i < *params->pnumEventsInWaitList; ++i) { + if (i != 0) { + os << ", "; + } + + ur::details::printPtr(os, (*(params->pphEventWaitList))[i]); + } + os << "}"; + } + + os << ", "; + os << ".ppMem = "; + + ur::details::printPtr(os, *(params->pppMem)); + + os << ", "; + os << ".phEvent = "; + + ur::details::printPtr(os, *(params->pphEvent)); + + return os; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Print operator for the ur_enqueue_usm_free_exp_params_t type +/// @returns +/// std::ostream & +inline std::ostream &operator<<( + std::ostream &os, + [[maybe_unused]] const struct ur_enqueue_usm_free_exp_params_t *params) { + + os << ".hQueue = "; + + ur::details::printPtr(os, *(params->phQueue)); + + os << ", "; + os << ".pPool = "; + + ur::details::printPtr(os, *(params->ppPool)); + + os << ", "; + os << ".pMem = "; + + ur::details::printPtr(os, *(params->ppMem)); + + os << ", "; + os << ".numEventsInWaitList = "; + + os << *(params->pnumEventsInWaitList); + + os << ", "; + os << ".phEventWaitList = "; + ur::details::printPtr( + os, reinterpret_cast(*(params->pphEventWaitList))); + if (*(params->pphEventWaitList) != NULL) { + os << " {"; + for (size_t i = 0; i < *params->pnumEventsInWaitList; ++i) { + if (i != 0) { + os << ", "; + } + + ur::details::printPtr(os, (*(params->pphEventWaitList))[i]); + } + os << "}"; + } + + os << ", "; + os << ".phEvent = "; + + ur::details::printPtr(os, *(params->pphEvent)); + + return os; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Print operator for the /// ur_enqueue_cooperative_kernel_launch_exp_params_t type @@ -19859,6 +20228,18 @@ inline ur_result_t UR_APICALL printFunctionParams(std::ostream &os, os << (const struct ur_enqueue_events_wait_with_barrier_ext_params_t *) params; } break; + case UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP: { + os << (const struct ur_enqueue_usm_device_alloc_exp_params_t *)params; + } break; + case UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP: { + os << (const struct ur_enqueue_usm_shared_alloc_exp_params_t *)params; + } break; + case UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP: { + os << (const struct ur_enqueue_usm_host_alloc_exp_params_t *)params; + } break; + case UR_FUNCTION_ENQUEUE_USM_FREE_EXP: { + os << (const struct ur_enqueue_usm_free_exp_params_t *)params; + } break; case UR_FUNCTION_ENQUEUE_COOPERATIVE_KERNEL_LAUNCH_EXP: { os << (const struct ur_enqueue_cooperative_kernel_launch_exp_params_t *) params; diff --git a/scripts/core/EXP-ASYNC-ALLOC.rst b/scripts/core/EXP-ASYNC-ALLOC.rst new file mode 100644 index 0000000000..8f337febcb --- /dev/null +++ b/scripts/core/EXP-ASYNC-ALLOC.rst @@ -0,0 +1,78 @@ +<% + OneApi=tags['$OneApi'] + x=tags['$x'] + X=x.upper() +%> + +.. _experimental-async-allocations: + +================================================================================ +Async Allocation Functions +================================================================================ + +.. warning:: + + Experimental features: + + * May be replaced, updated, or removed at any time. + * Do not require maintaining API/ABI stability of their own additions over + time. + * Do not require conformance testing of their own additions. + + +Motivation +-------------------------------------------------------------------------------- + +Asynchronous allocations can allow queues to allocate and free memory between +UR command enqueues without forcing synchronization points in the asynchronous +command DAG associated with a queue. This can allow applications to compose +memory allocation and command execution asynchronously, which can improve +performance. + +API +-------------------------------------------------------------------------------- + +Enums +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* ${x}_device_info_t + * ${X}_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP +* ${x}_command_t + * ${X}_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP + * ${X}_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP + * ${X}_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP + * ${X}_COMMAND_ENQUEUE_USM_FREE_EXP +* ${x}_exp_enqueue_usm_alloc_flags_t + +Types +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +${x}_exp_enqueue_usm_alloc_properties_t + +Functions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* ${x}EnqueueUSMDeviceAllocExp +* ${x}EnqueueUSMSharedAllocExp +* ${x}EnqueueUSMHostAllocExp +* ${x}EnqueueUSMFreeExp + +Changelog +-------------------------------------------------------------------------------- + ++-----------+---------------------------+ +| Revision | Changes | ++===========+===========================+ +| 1.0 | Initial Draft | ++-----------+---------------------------+ + +Support +-------------------------------------------------------------------------------- + +Adapters which support this experimental feature *must* return true for the new +``${X}_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP`` device info query. + + +Contributors +-------------------------------------------------------------------------------- + +* Hugh Delaney `hugh.delaney@codeplay.com `_ diff --git a/scripts/core/exp-async-alloc.yml b/scripts/core/exp-async-alloc.yml new file mode 100644 index 0000000000..92ff962df9 --- /dev/null +++ b/scripts/core/exp-async-alloc.yml @@ -0,0 +1,216 @@ +# +# Copyright (C) 2024 Intel Corporation +# +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +# See LICENSE.TXT +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +# See YaML.md for syntax definition +# +--- #-------------------------------------------------------------------------- +type: header +desc: "Intel $OneApi Unified Runtime Experimental API for enqueuing asynchronous USM allocations" +ordinal: "99" + +--- #-------------------------------------------------------------------------- +type: enum +extend: true +typed_etors: true +desc: "Extension enums to $x_device_info_t to support USM allocation enqueuing." +name: $x_device_info_t +etors: + - name: ENQUEUE_USM_ALLOCATIONS_EXP + value: "0x2023" + desc: "[$x_bool_t] returns true if the device supports USM allocation enqueueing" + +--- #-------------------------------------------------------------------------- +type: enum +extend: true +desc: "Command Type experimental enumerations." +name: $x_command_t +etors: + - name: ENQUEUE_USM_DEVICE_ALLOC_EXP + value: "0x2005" + desc: Event created by $xEnqueueUSMDeviceAllocExp + - name: ENQUEUE_USM_SHARED_ALLOC_EXP + value: "0x2006" + desc: Event created by $xEnqueueUSMSharedAllocExp + - name: ENQUEUE_USM_HOST_ALLOC_EXP + value: "0x2007" + desc: Event created by $xEnqueueUSMHostAllocExp + - name: ENQUEUE_USM_FREE_EXP + value: "0x2008" + desc: Event created by $xEnqueueUSMFreeExp + +--- #-------------------------------------------------------------------------- +type: enum +desc: "Enqueue USM allocation flags" +name: $x_exp_enqueue_usm_alloc_flags_t +etors: + - name: TBD + desc: "reserved for future use." + +--- #-------------------------------------------------------------------------- +type: struct +desc: "Enqueue USM allocation properties" +name: $x_exp_enqueue_usm_alloc_properties_t +base: $x_base_properties_t +members: + - type: $x_exp_enqueue_usm_alloc_flags_t + name: flags + desc: "[in] enqueue USM allocation flags" + +--- #-------------------------------------------------------------------------- +type: enum +extend: true +desc: "Structure type experimental enumerations" +name: $x_structure_type_t +etors: + - name: EXP_ENQUEUE_USM_ALLOC_PROPERTIES + desc: $x_exp_enqueue_usm_alloc_properties_t + value: "0x3001" + +--- #-------------------------------------------------------------------------- +type: function +desc: "Enqueue an asynchronous USM device allocation" +class: $xEnqueue +name: USMDeviceAllocExp +params: + - type: $x_queue_handle_t + name: hQueue + desc: "[in] handle of the queue object" + - type: $x_usm_pool_handle_t + desc: "[in][optional] handle of the USM memory pool" + name: pPool + - type: const size_t + desc: "[in] minimum size in bytes of the USM memory object to be allocated" + name: size + - type: const $x_exp_enqueue_usm_alloc_properties_t* + name: pProperties + desc: "[in][optional] pointer to the enqueue asynchronous USM allocation properties" + - type: uint32_t + name: numEventsInWaitList + desc: "[in] size of the event wait list" + - type: const $x_event_handle_t* + name: phEventWaitList + desc: | + [in][optional][range(0, numEventsInWaitList)] pointer to a list of events that must be complete before the kernel execution. + If nullptr, the numEventsInWaitList must be 0, indicating no wait events. + - type: void** + name: ppMem + desc: "[out] pointer to USM memory object" + - type: $x_event_handle_t* + name: phEvent + desc: "[out][optional] return an event object that identifies the asynchronous USM device allocation" +returns: + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_INVALID_NULL_HANDLE + - $X_RESULT_ERROR_INVALID_NULL_POINTER + - $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +--- #-------------------------------------------------------------------------- +type: function +desc: "Enqueue an asynchronous USM shared allocation" +class: $xEnqueue +name: USMSharedAllocExp +params: + - type: $x_queue_handle_t + name: hQueue + desc: "[in] handle of the queue object" + - type: $x_usm_pool_handle_t + desc: "[in][optional] handle of the USM memory pool" + name: pPool + - type: const size_t + desc: "[in] minimum size in bytes of the USM memory object to be allocated" + name: size + - type: const $x_exp_enqueue_usm_alloc_properties_t* + name: pProperties + desc: "[in][optional] pointer to the enqueue asynchronous USM allocation properties" + - type: uint32_t + name: numEventsInWaitList + desc: "[in] size of the event wait list" + - type: const $x_event_handle_t* + name: phEventWaitList + desc: | + [in][optional][range(0, numEventsInWaitList)] pointer to a list of events that must be complete before the kernel execution. + If nullptr, the numEventsInWaitList must be 0, indicating no wait events. + - type: void** + name: ppMem + desc: "[out] pointer to USM memory object" + - type: $x_event_handle_t* + name: phEvent + desc: "[out][optional] return an event object that identifies the asynchronous USM shared allocation" +returns: + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_INVALID_NULL_HANDLE + - $X_RESULT_ERROR_INVALID_NULL_POINTER + - $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +--- #-------------------------------------------------------------------------- +type: function +desc: "Enqueue an asynchronous USM host allocation" +class: $xEnqueue +name: USMHostAllocExp +params: + - type: $x_queue_handle_t + name: hQueue + desc: "[in] handle of the queue object" + - type: $x_usm_pool_handle_t + desc: "[in][optional] handle of the USM memory pool" + name: pPool + - type: const size_t + desc: "[in] minimum size in bytes of the USM memory object to be allocated" + name: size + - type: const $x_exp_enqueue_usm_alloc_properties_t* + name: pProperties + desc: "[in][optional] pointer to the enqueue asynchronous USM allocation properties" + - type: uint32_t + name: numEventsInWaitList + desc: "[in] size of the event wait list" + - type: const $x_event_handle_t* + name: phEventWaitList + desc: | + [in][optional][range(0, numEventsInWaitList)] pointer to a list of events that must be complete before the kernel execution. + If nullptr, the numEventsInWaitList must be 0, indicating no wait events. + - type: void** + name: ppMem + desc: "[out] pointer to USM memory object" + - type: $x_event_handle_t* + name: phEvent + desc: "[out][optional] return an event object that identifies the asynchronous USM host allocation" +returns: + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY + - $X_RESULT_ERROR_INVALID_NULL_HANDLE + - $X_RESULT_ERROR_INVALID_NULL_POINTER + - $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +--- #-------------------------------------------------------------------------- +type: function +desc: "Enqueue an asynchronous USM deallocation" +class: $xEnqueue +name: USMFreeExp +params: + - type: $x_queue_handle_t + name: hQueue + desc: "[in] handle of the queue object" + - type: $x_usm_pool_handle_t + desc: "[in][optional] handle of the USM memory pool" + name: pPool + - type: void* + name: pMem + desc: "[in] pointer to USM memory object" + - type: uint32_t + name: numEventsInWaitList + desc: "[in] size of the event wait list" + - type: const $x_event_handle_t* + name: phEventWaitList + desc: | + [in][optional][range(0, numEventsInWaitList)] pointer to a list of events that must be complete before the kernel execution. + If nullptr, the numEventsInWaitList must be 0, indicating no wait events. + - type: $x_event_handle_t* + name: phEvent + desc: "[out][optional] return an event object that identifies the asynchronous USM deallocation" +returns: + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY + - $X_RESULT_ERROR_INVALID_NULL_HANDLE + - $X_RESULT_ERROR_INVALID_NULL_POINTER + - $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST diff --git a/scripts/core/registry.yml b/scripts/core/registry.yml index c774642482..7894ebd4b5 100644 --- a/scripts/core/registry.yml +++ b/scripts/core/registry.yml @@ -601,6 +601,18 @@ etors: - name: PHYSICAL_MEM_GET_INFO desc: Enumerator for $xPhysicalMemGetInfo value: '249' +- name: ENQUEUE_USM_DEVICE_ALLOC_EXP + desc: Enumerator for $xEnqueueUSMDeviceAllocExp + value: '250' +- name: ENQUEUE_USM_SHARED_ALLOC_EXP + desc: Enumerator for $xEnqueueUSMSharedAllocExp + value: '251' +- name: ENQUEUE_USM_HOST_ALLOC_EXP + desc: Enumerator for $xEnqueueUSMHostAllocExp + value: '252' +- name: ENQUEUE_USM_FREE_EXP + desc: Enumerator for $xEnqueueUSMFreeExp + value: '253' --- type: enum desc: Defines structure types diff --git a/source/adapters/cuda/common.cpp b/source/adapters/cuda/common.cpp index 89500d1a1c..8a524a1cf6 100644 --- a/source/adapters/cuda/common.cpp +++ b/source/adapters/cuda/common.cpp @@ -47,8 +47,7 @@ void checkErrorUR(CUresult Result, const char *Function, int Line, cuGetErrorName(Result, &ErrorName); cuGetErrorString(Result, &ErrorString); std::stringstream SS; - SS << "\nUR CUDA ERROR:" - << "\n\tValue: " << Result + SS << "\nUR CUDA ERROR:" << "\n\tValue: " << Result << "\n\tName: " << ErrorName << "\n\tDescription: " << ErrorString << "\n\tFunction: " << Function << "\n\tSource Location: " << File @@ -70,9 +69,9 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line, } std::stringstream SS; - SS << "\nUR ERROR:" - << "\n\tValue: " << Result << "\n\tFunction: " << Function - << "\n\tSource Location: " << File << ":" << Line << "\n"; + SS << "\nUR ERROR:" << "\n\tValue: " << Result + << "\n\tFunction: " << Function << "\n\tSource Location: " << File + << ":" << Line << "\n"; logger::error("{}", SS.str()); if (std::getenv("PI_CUDA_ABORT") != nullptr) { diff --git a/source/adapters/cuda/usm.cpp b/source/adapters/cuda/usm.cpp index 7f48309ca3..0b76efd652 100644 --- a/source/adapters/cuda/usm.cpp +++ b/source/adapters/cuda/usm.cpp @@ -513,3 +513,123 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetInfo( } } } + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM device allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM shared allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM host allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFreeExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pooliptor + void *pMem, ///< [in] pointer to USM memory object + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + ur_event_handle_t *phEvent ///< [out][optional] return an event object that + ///< identifies the asynchronous USM deallocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = pMem; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/source/adapters/hip/common.cpp b/source/adapters/hip/common.cpp index 23ef1d3301..b77a1edcef 100644 --- a/source/adapters/hip/common.cpp +++ b/source/adapters/hip/common.cpp @@ -76,8 +76,7 @@ void checkErrorUR(amd_comgr_status_t Result, const char *Function, int Line, break; } std::stringstream SS; - SS << "\nUR HIP ERROR:" - << "\n\tValue: " << Result + SS << "\nUR HIP ERROR:" << "\n\tValue: " << Result << "\n\tName: " << ErrorName << "\n\tDescription: " << ErrorString << "\n\tFunction: " << Function << "\n\tSource Location: " << File @@ -103,8 +102,7 @@ void checkErrorUR(hipError_t Result, const char *Function, int Line, const char *ErrorName = hipGetErrorName(Result); std::stringstream SS; - SS << "\nUR HIP ERROR:" - << "\n\tValue: " << Result + SS << "\nUR HIP ERROR:" << "\n\tValue: " << Result << "\n\tName: " << ErrorName << "\n\tDescription: " << ErrorString << "\n\tFunction: " << Function << "\n\tSource Location: " << File @@ -126,9 +124,9 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line, } std::stringstream SS; - SS << "\nUR HIP ERROR:" - << "\n\tValue: " << Result << "\n\tFunction: " << Function - << "\n\tSource Location: " << File << ":" << Line << "\n"; + SS << "\nUR HIP ERROR:" << "\n\tValue: " << Result + << "\n\tFunction: " << Function << "\n\tSource Location: " << File + << ":" << Line << "\n"; logger::error("{}", SS.str()); if (std::getenv("PI_HIP_ABORT") != nullptr || diff --git a/source/adapters/hip/usm.cpp b/source/adapters/hip/usm.cpp index 922098e4a1..fb689d2353 100644 --- a/source/adapters/hip/usm.cpp +++ b/source/adapters/hip/usm.cpp @@ -478,3 +478,123 @@ ur_result_t umfPoolMallocHelper(ur_usm_pool_handle_t hPool, void **ppMem, } return UR_RESULT_SUCCESS; } + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM device allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM shared allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM host allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFreeExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pooliptor + void *pMem, ///< [in] pointer to USM memory object + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + ur_event_handle_t *phEvent ///< [out][optional] return an event object that + ///< identifies the asynchronous USM deallocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = pMem; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/source/adapters/level_zero/ur_interface_loader.cpp b/source/adapters/level_zero/ur_interface_loader.cpp index c237581016..0a830b7140 100644 --- a/source/adapters/level_zero/ur_interface_loader.cpp +++ b/source/adapters/level_zero/ur_interface_loader.cpp @@ -210,6 +210,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable( pDdiTable->pfnKernelLaunchCustomExp = ur::level_zero::urEnqueueKernelLaunchCustomExp; + pDdiTable->pfnUSMDeviceAllocExp = ur::level_zero::urEnqueueUSMDeviceAllocExp; + pDdiTable->pfnUSMSharedAllocExp = ur::level_zero::urEnqueueUSMSharedAllocExp; + pDdiTable->pfnUSMHostAllocExp = ur::level_zero::urEnqueueUSMHostAllocExp; + pDdiTable->pfnUSMFreeExp = ur::level_zero::urEnqueueUSMFreeExp; pDdiTable->pfnCooperativeKernelLaunchExp = ur::level_zero::urEnqueueCooperativeKernelLaunchExp; pDdiTable->pfnTimestampRecordingExp = diff --git a/source/adapters/level_zero/ur_interface_loader.hpp b/source/adapters/level_zero/ur_interface_loader.hpp index 8803b86b07..488e80f9db 100644 --- a/source/adapters/level_zero/ur_interface_loader.hpp +++ b/source/adapters/level_zero/ur_interface_loader.hpp @@ -466,6 +466,26 @@ ur_result_t urEnqueueWriteHostPipe(ur_queue_handle_t hQueue, uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent); +ur_result_t urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent); +ur_result_t urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent); +ur_result_t urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent); +ur_result_t urEnqueueUSMFreeExp(ur_queue_handle_t hQueue, + ur_usm_pool_handle_t pPool, void *pMem, + uint32_t numEventsInWaitList, + const ur_event_handle_t *phEventWaitList, + ur_event_handle_t *phEvent); ur_result_t urUSMPitchedAllocExp(ur_context_handle_t hContext, ur_device_handle_t hDevice, const ur_usm_desc_t *pUSMDesc, diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 49d392366b..99de496e7c 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -599,6 +599,126 @@ ur_result_t urUSMReleaseExp(ur_context_handle_t Context, void *HostPtr) { Context->getPlatform()->ZeDriverHandleExpTranslated, HostPtr); return UR_RESULT_SUCCESS; } + +ur_result_t urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM device allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM shared allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pool + const size_t size, ///< [in] minimum size in bytes of the USM memory object + ///< to be allocated + const ur_exp_enqueue_usm_alloc_properties_t + *pProperties, ///< [in][optional] pointer to the enqueue asynchronous + ///< USM allocation properties + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **ppMem, ///< [out] pointer to USM memory object + ur_event_handle_t + *phEvent ///< [out][optional] return an event object that identifies the + ///< asynchronous USM host allocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t urEnqueueUSMFreeExp( + ur_queue_handle_t hQueue, ///< [in] handle of the queue object + ur_usm_pool_handle_t + pPool, ///< [in][optional] handle of the USM memory pooliptor + void *pMem, ///< [in] pointer to USM memory object + uint32_t numEventsInWaitList, ///< [in] size of the event wait list + const ur_event_handle_t + *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + ur_event_handle_t *phEvent ///< [out][optional] return an event object that + ///< identifies the asynchronous USM deallocation +) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = pMem; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} } // namespace ur::level_zero static ur_result_t USMFreeImpl(ur_context_handle_t Context, void *Ptr) { diff --git a/source/adapters/level_zero/v2/queue_api.cpp b/source/adapters/level_zero/v2/queue_api.cpp index 28ff527413..3e9b5d0360 100644 --- a/source/adapters/level_zero/v2/queue_api.cpp +++ b/source/adapters/level_zero/v2/queue_api.cpp @@ -339,6 +339,49 @@ ur_result_t urEnqueueWriteHostPipe(ur_queue_handle_t hQueue, } catch (...) { return exceptionToResult(std::current_exception()); } +ur_result_t urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) try { + return hQueue->enqueueUSMDeviceAllocExp(pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, + ppMem, phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} +ur_result_t urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) try { + return hQueue->enqueueUSMSharedAllocExp(pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, + ppMem, phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} +ur_result_t urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) try { + return hQueue->enqueueUSMHostAllocExp(pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, + ppMem, phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} +ur_result_t urEnqueueUSMFreeExp(ur_queue_handle_t hQueue, + ur_usm_pool_handle_t pPool, void *pMem, + uint32_t numEventsInWaitList, + const ur_event_handle_t *phEventWaitList, + ur_event_handle_t *phEvent) try { + return hQueue->enqueueUSMFreeExp(pPool, pMem, numEventsInWaitList, + phEventWaitList, phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} ur_result_t urBindlessImagesImageCopyExp( ur_queue_handle_t hQueue, const void *pSrc, void *pDst, const ur_image_desc_t *pSrcImageDesc, const ur_image_desc_t *pDstImageDesc, diff --git a/source/adapters/level_zero/v2/queue_api.hpp b/source/adapters/level_zero/v2/queue_api.hpp index 88d812bbba..69de4bc87e 100644 --- a/source/adapters/level_zero/v2/queue_api.hpp +++ b/source/adapters/level_zero/v2/queue_api.hpp @@ -130,6 +130,24 @@ struct ur_queue_handle_t_ { bool, void *, size_t, uint32_t, const ur_event_handle_t *, ur_event_handle_t *) = 0; + virtual ur_result_t + enqueueUSMDeviceAllocExp(ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, + uint32_t, const ur_event_handle_t *, void **, + ur_event_handle_t *) = 0; + virtual ur_result_t + enqueueUSMSharedAllocExp(ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, + uint32_t, const ur_event_handle_t *, void **, + ur_event_handle_t *) = 0; + virtual ur_result_t + enqueueUSMHostAllocExp(ur_usm_pool_handle_t, const size_t, + const ur_exp_enqueue_usm_alloc_properties_t *, + uint32_t, const ur_event_handle_t *, void **, + ur_event_handle_t *) = 0; + virtual ur_result_t enqueueUSMFreeExp(ur_usm_pool_handle_t, void *, uint32_t, + const ur_event_handle_t *, + ur_event_handle_t *) = 0; virtual ur_result_t bindlessImagesImageCopyExp( const void *, void *, const ur_image_desc_t *, const ur_image_desc_t *, const ur_image_format_t *, const ur_image_format_t *, diff --git a/source/adapters/level_zero/v2/queue_immediate_in_order.cpp b/source/adapters/level_zero/v2/queue_immediate_in_order.cpp index 8da52fe6b6..6e5ee7cb65 100644 --- a/source/adapters/level_zero/v2/queue_immediate_in_order.cpp +++ b/source/adapters/level_zero/v2/queue_immediate_in_order.cpp @@ -918,6 +918,62 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueWriteHostPipe( return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } +ur_result_t ur_queue_immediate_in_order_t::enqueueUSMDeviceAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t ur_queue_immediate_in_order_t::enqueueUSMSharedAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t ur_queue_immediate_in_order_t::enqueueUSMHostAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ur_result_t ur_queue_immediate_in_order_t::enqueueUSMFreeExp( + ur_usm_pool_handle_t pPool, void *pMem, uint32_t numEventsInWaitList, + const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) { + std::ignore = pPool; + std::ignore = pMem; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = phEvent; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + ur_result_t ur_queue_immediate_in_order_t::bindlessImagesImageCopyExp( const void *pSrc, void *pDst, const ur_image_desc_t *pSrcImageDesc, const ur_image_desc_t *pDstImageDesc, diff --git a/source/adapters/level_zero/v2/queue_immediate_in_order.hpp b/source/adapters/level_zero/v2/queue_immediate_in_order.hpp index 6cf8b0c51c..babfffd3b8 100644 --- a/source/adapters/level_zero/v2/queue_immediate_in_order.hpp +++ b/source/adapters/level_zero/v2/queue_immediate_in_order.hpp @@ -231,6 +231,25 @@ struct ur_queue_immediate_in_order_t : _ur_object, public ur_queue_handle_t_ { uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) override; + ur_result_t enqueueUSMDeviceAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) override; + ur_result_t enqueueUSMSharedAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) override; + ur_result_t enqueueUSMHostAllocExp( + ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) override; + ur_result_t enqueueUSMFreeExp(ur_usm_pool_handle_t pPool, void *pMem, + uint32_t numEventsInWaitList, + const ur_event_handle_t *phEventWaitList, + ur_event_handle_t *phEvent) override; ur_result_t bindlessImagesImageCopyExp( const void *pSrc, void *pDst, const ur_image_desc_t *pSrcImageDesc, const ur_image_desc_t *pDstImageDesc, diff --git a/source/adapters/mock/ur_mockddi.cpp b/source/adapters/mock/ur_mockddi.cpp index c255dc0bcf..6feb722338 100644 --- a/source/adapters/mock/ur_mockddi.cpp +++ b/source/adapters/mock/ur_mockddi.cpp @@ -7279,6 +7279,268 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMDeviceAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_enqueue_usm_device_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback("urEnqueueUSMDeviceAllocExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback("urEnqueueUSMDeviceAllocExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + // optional output handle + if (phEvent) { + *phEvent = mock::createDummyHandle(); + } + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback("urEnqueueUSMDeviceAllocExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMSharedAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_enqueue_usm_shared_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback("urEnqueueUSMSharedAllocExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback("urEnqueueUSMSharedAllocExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + // optional output handle + if (phEvent) { + *phEvent = mock::createDummyHandle(); + } + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback("urEnqueueUSMSharedAllocExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMHostAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_enqueue_usm_host_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback("urEnqueueUSMHostAllocExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback("urEnqueueUSMHostAllocExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + // optional output handle + if (phEvent) { + *phEvent = mock::createDummyHandle(); + } + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback("urEnqueueUSMHostAllocExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMFreeExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) try { + ur_result_t result = UR_RESULT_SUCCESS; + + ur_enqueue_usm_free_exp_params_t params = { + &hQueue, &pPool, &pMem, &numEventsInWaitList, &phEventWaitList, &phEvent}; + + auto beforeCallback = reinterpret_cast( + mock::getCallbacks().get_before_callback("urEnqueueUSMFreeExp")); + if (beforeCallback) { + result = beforeCallback(¶ms); + if (result != UR_RESULT_SUCCESS) { + return result; + } + } + + auto replaceCallback = reinterpret_cast( + mock::getCallbacks().get_replace_callback("urEnqueueUSMFreeExp")); + if (replaceCallback) { + result = replaceCallback(¶ms); + } else { + + // optional output handle + if (phEvent) { + *phEvent = mock::createDummyHandle(); + } + result = UR_RESULT_SUCCESS; + } + + if (result != UR_RESULT_SUCCESS) { + return result; + } + + auto afterCallback = reinterpret_cast( + mock::getCallbacks().get_after_callback("urEnqueueUSMFreeExp")); + if (afterCallback) { + return afterCallback(¶ms); + } + + return result; +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urUSMPitchedAllocExp __urdlllocal ur_result_t UR_APICALL urUSMPitchedAllocExp( @@ -11209,6 +11471,14 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable( pDdiTable->pfnKernelLaunchCustomExp = driver::urEnqueueKernelLaunchCustomExp; + pDdiTable->pfnUSMDeviceAllocExp = driver::urEnqueueUSMDeviceAllocExp; + + pDdiTable->pfnUSMSharedAllocExp = driver::urEnqueueUSMSharedAllocExp; + + pDdiTable->pfnUSMHostAllocExp = driver::urEnqueueUSMHostAllocExp; + + pDdiTable->pfnUSMFreeExp = driver::urEnqueueUSMFreeExp; + pDdiTable->pfnCooperativeKernelLaunchExp = driver::urEnqueueCooperativeKernelLaunchExp; diff --git a/source/adapters/native_cpu/usm.cpp b/source/adapters/native_cpu/usm.cpp index 2fe0d551a8..2bea4c08a4 100644 --- a/source/adapters/native_cpu/usm.cpp +++ b/source/adapters/native_cpu/usm.cpp @@ -155,3 +155,64 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMReleaseExp(ur_context_handle_t Context, std::ignore = HostPtr; DIE_NO_IMPLEMENTATION; } + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + DIE_NO_IMPLEMENTATION; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + DIE_NO_IMPLEMENTATION; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, const size_t size, + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + void **ppMem, ur_event_handle_t *phEvent) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = size; + std::ignore = pProperties; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = ppMem; + std::ignore = phEvent; + DIE_NO_IMPLEMENTATION; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFreeExp( + ur_queue_handle_t hQueue, ur_usm_pool_handle_t pPool, void *pMem, + uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList, + ur_event_handle_t *phEvent) { + std::ignore = hQueue; + std::ignore = pPool; + std::ignore = pMem; + std::ignore = numEventsInWaitList; + std::ignore = phEventWaitList; + std::ignore = phEvent; + DIE_NO_IMPLEMENTATION; +} diff --git a/source/adapters/opencl/usm.cpp b/source/adapters/opencl/usm.cpp index 7961cb76ff..221b08a5d8 100644 --- a/source/adapters/opencl/usm.cpp +++ b/source/adapters/opencl/usm.cpp @@ -728,3 +728,48 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetInfo( [[maybe_unused]] size_t *pPropSizeRet) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + [[maybe_unused]] ur_queue_handle_t hQueue, + [[maybe_unused]] ur_usm_pool_handle_t pPool, + [[maybe_unused]] const size_t size, + [[maybe_unused]] const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + [[maybe_unused]] uint32_t numEventsInWaitList, + [[maybe_unused]] const ur_event_handle_t *phEventWaitList, + [[maybe_unused]] void **ppMem, + [[maybe_unused]] ur_event_handle_t *phEvent) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + [[maybe_unused]] ur_queue_handle_t hQueue, + [[maybe_unused]] ur_usm_pool_handle_t pPool, + [[maybe_unused]] const size_t size, + [[maybe_unused]] const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + [[maybe_unused]] uint32_t numEventsInWaitList, + [[maybe_unused]] const ur_event_handle_t *phEventWaitList, + [[maybe_unused]] void **ppMem, + [[maybe_unused]] ur_event_handle_t *phEvent) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + [[maybe_unused]] ur_queue_handle_t hQueue, + [[maybe_unused]] ur_usm_pool_handle_t pPool, + [[maybe_unused]] const size_t size, + [[maybe_unused]] const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + [[maybe_unused]] uint32_t numEventsInWaitList, + [[maybe_unused]] const ur_event_handle_t *phEventWaitList, + [[maybe_unused]] void **ppMem, + [[maybe_unused]] ur_event_handle_t *phEvent) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFreeExp( + [[maybe_unused]] ur_queue_handle_t hQueue, + [[maybe_unused]] ur_usm_pool_handle_t pPool, [[maybe_unused]] void *pMem, + [[maybe_unused]] uint32_t numEventsInWaitList, + [[maybe_unused]] const ur_event_handle_t *phEventWaitList, + [[maybe_unused]] ur_event_handle_t *phEvent) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; +} diff --git a/source/common/logger/ur_sinks.hpp b/source/common/logger/ur_sinks.hpp index 8f580bc04d..fe2af9dde0 100644 --- a/source/common/logger/ur_sinks.hpp +++ b/source/common/logger/ur_sinks.hpp @@ -28,8 +28,8 @@ class Sink { void log(logger::Level level, const char *fmt, Args &&...args) { std::ostringstream buffer; if (!skip_prefix && level != logger::Level::QUIET) { - buffer << "<" << logger_name << ">" - << "[" << level_to_str(level) << "]: "; + buffer << "<" << logger_name << ">" << "[" << level_to_str(level) + << "]: "; } format(buffer, fmt, std::forward(args)...); diff --git a/source/common/stype_map_helpers.def b/source/common/stype_map_helpers.def index ec2856e60d..3b3916a310 100644 --- a/source/common/stype_map_helpers.def +++ b/source/common/stype_map_helpers.def @@ -100,5 +100,7 @@ struct stype_map : stype_map_impl struct stype_map : stype_map_impl {}; template <> +struct stype_map : stype_map_impl {}; +template <> struct stype_map : stype_map_impl {}; diff --git a/source/loader/layers/tracing/ur_trcddi.cpp b/source/loader/layers/tracing/ur_trcddi.cpp index f53e7c1c4d..3024373d39 100644 --- a/source/loader/layers/tracing/ur_trcddi.cpp +++ b/source/loader/layers/tracing/ur_trcddi.cpp @@ -6000,6 +6000,232 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMDeviceAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) { + auto pfnUSMDeviceAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMDeviceAllocExp; + + if (nullptr == pfnUSMDeviceAllocExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_enqueue_usm_device_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + uint64_t instance = + getContext()->notify_begin(UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP, + "urEnqueueUSMDeviceAllocExp", ¶ms); + + auto &logger = getContext()->logger; + logger.info(" ---> urEnqueueUSMDeviceAllocExp\n"); + + ur_result_t result = pfnUSMDeviceAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + getContext()->notify_end(UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP, + "urEnqueueUSMDeviceAllocExp", ¶ms, &result, + instance); + + if (logger.getLevel() <= logger::Level::INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_ENQUEUE_USM_DEVICE_ALLOC_EXP, ¶ms); + logger.info(" <--- urEnqueueUSMDeviceAllocExp({}) -> {};\n", + args_str.str(), result); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMSharedAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) { + auto pfnUSMSharedAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMSharedAllocExp; + + if (nullptr == pfnUSMSharedAllocExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_enqueue_usm_shared_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + uint64_t instance = + getContext()->notify_begin(UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP, + "urEnqueueUSMSharedAllocExp", ¶ms); + + auto &logger = getContext()->logger; + logger.info(" ---> urEnqueueUSMSharedAllocExp\n"); + + ur_result_t result = pfnUSMSharedAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + getContext()->notify_end(UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP, + "urEnqueueUSMSharedAllocExp", ¶ms, &result, + instance); + + if (logger.getLevel() <= logger::Level::INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_ENQUEUE_USM_SHARED_ALLOC_EXP, ¶ms); + logger.info(" <--- urEnqueueUSMSharedAllocExp({}) -> {};\n", + args_str.str(), result); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMHostAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) { + auto pfnUSMHostAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMHostAllocExp; + + if (nullptr == pfnUSMHostAllocExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_enqueue_usm_host_alloc_exp_params_t params = { + &hQueue, &pPool, &size, &pProperties, &numEventsInWaitList, + &phEventWaitList, &ppMem, &phEvent}; + uint64_t instance = + getContext()->notify_begin(UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP, + "urEnqueueUSMHostAllocExp", ¶ms); + + auto &logger = getContext()->logger; + logger.info(" ---> urEnqueueUSMHostAllocExp\n"); + + ur_result_t result = + pfnUSMHostAllocExp(hQueue, pPool, size, pProperties, numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + getContext()->notify_end(UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP, + "urEnqueueUSMHostAllocExp", ¶ms, &result, + instance); + + if (logger.getLevel() <= logger::Level::INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams( + args_str, UR_FUNCTION_ENQUEUE_USM_HOST_ALLOC_EXP, ¶ms); + logger.info(" <--- urEnqueueUSMHostAllocExp({}) -> {};\n", args_str.str(), + result); + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMFreeExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) { + auto pfnUSMFreeExp = getContext()->urDdiTable.EnqueueExp.pfnUSMFreeExp; + + if (nullptr == pfnUSMFreeExp) + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + + ur_enqueue_usm_free_exp_params_t params = { + &hQueue, &pPool, &pMem, &numEventsInWaitList, &phEventWaitList, &phEvent}; + uint64_t instance = getContext()->notify_begin( + UR_FUNCTION_ENQUEUE_USM_FREE_EXP, "urEnqueueUSMFreeExp", ¶ms); + + auto &logger = getContext()->logger; + logger.info(" ---> urEnqueueUSMFreeExp\n"); + + ur_result_t result = pfnUSMFreeExp(hQueue, pPool, pMem, numEventsInWaitList, + phEventWaitList, phEvent); + + getContext()->notify_end(UR_FUNCTION_ENQUEUE_USM_FREE_EXP, + "urEnqueueUSMFreeExp", ¶ms, &result, instance); + + if (logger.getLevel() <= logger::Level::INFO) { + std::ostringstream args_str; + ur::extras::printFunctionParams(args_str, UR_FUNCTION_ENQUEUE_USM_FREE_EXP, + ¶ms); + logger.info(" <--- urEnqueueUSMFreeExp({}) -> {};\n", args_str.str(), + result); + } + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urUSMPitchedAllocExp __urdlllocal ur_result_t UR_APICALL urUSMPitchedAllocExp( @@ -9533,6 +9759,20 @@ __urdlllocal ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable( pDdiTable->pfnKernelLaunchCustomExp = ur_tracing_layer::urEnqueueKernelLaunchCustomExp; + dditable.pfnUSMDeviceAllocExp = pDdiTable->pfnUSMDeviceAllocExp; + pDdiTable->pfnUSMDeviceAllocExp = + ur_tracing_layer::urEnqueueUSMDeviceAllocExp; + + dditable.pfnUSMSharedAllocExp = pDdiTable->pfnUSMSharedAllocExp; + pDdiTable->pfnUSMSharedAllocExp = + ur_tracing_layer::urEnqueueUSMSharedAllocExp; + + dditable.pfnUSMHostAllocExp = pDdiTable->pfnUSMHostAllocExp; + pDdiTable->pfnUSMHostAllocExp = ur_tracing_layer::urEnqueueUSMHostAllocExp; + + dditable.pfnUSMFreeExp = pDdiTable->pfnUSMFreeExp; + pDdiTable->pfnUSMFreeExp = ur_tracing_layer::urEnqueueUSMFreeExp; + dditable.pfnCooperativeKernelLaunchExp = pDdiTable->pfnCooperativeKernelLaunchExp; pDdiTable->pfnCooperativeKernelLaunchExp = diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 1e79fa9d7a..75d8b55fae 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -495,7 +495,7 @@ __urdlllocal ur_result_t UR_APICALL urDeviceGetInfo( if (pPropValue == NULL && pPropSizeRet == NULL) return UR_RESULT_ERROR_INVALID_NULL_POINTER; - if (UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP < propName) + if (UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP < propName) return UR_RESULT_ERROR_INVALID_ENUMERATION; if (propSize == 0 && pPropValue != NULL) @@ -6566,6 +6566,267 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMDeviceAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) { + auto pfnUSMDeviceAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMDeviceAllocExp; + + if (nullptr == pfnUSMDeviceAllocExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == hQueue) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + + if (NULL == ppMem) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (NULL != pProperties && + UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & pProperties->flags) + return UR_RESULT_ERROR_INVALID_ENUMERATION; + + if (phEventWaitList != NULL && numEventsInWaitList > 0) { + for (uint32_t i = 0; i < numEventsInWaitList; ++i) { + if (phEventWaitList[i] == NULL) { + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + } + } + } + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hQueue)) { + getContext()->refCountContext->logInvalidReference(hQueue); + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(pPool)) { + getContext()->refCountContext->logInvalidReference(pPool); + } + + ur_result_t result = pfnUSMDeviceAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMSharedAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) { + auto pfnUSMSharedAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMSharedAllocExp; + + if (nullptr == pfnUSMSharedAllocExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == hQueue) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + + if (NULL == ppMem) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (NULL != pProperties && + UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & pProperties->flags) + return UR_RESULT_ERROR_INVALID_ENUMERATION; + + if (phEventWaitList != NULL && numEventsInWaitList > 0) { + for (uint32_t i = 0; i < numEventsInWaitList; ++i) { + if (phEventWaitList[i] == NULL) { + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + } + } + } + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hQueue)) { + getContext()->refCountContext->logInvalidReference(hQueue); + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(pPool)) { + getContext()->refCountContext->logInvalidReference(pPool); + } + + ur_result_t result = pfnUSMSharedAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMHostAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) { + auto pfnUSMHostAllocExp = + getContext()->urDdiTable.EnqueueExp.pfnUSMHostAllocExp; + + if (nullptr == pfnUSMHostAllocExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == hQueue) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + + if (NULL == ppMem) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (NULL != pProperties && + UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & pProperties->flags) + return UR_RESULT_ERROR_INVALID_ENUMERATION; + + if (phEventWaitList != NULL && numEventsInWaitList > 0) { + for (uint32_t i = 0; i < numEventsInWaitList; ++i) { + if (phEventWaitList[i] == NULL) { + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + } + } + } + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hQueue)) { + getContext()->refCountContext->logInvalidReference(hQueue); + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(pPool)) { + getContext()->refCountContext->logInvalidReference(pPool); + } + + ur_result_t result = + pfnUSMHostAllocExp(hQueue, pPool, size, pProperties, numEventsInWaitList, + phEventWaitList, ppMem, phEvent); + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMFreeExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) { + auto pfnUSMFreeExp = getContext()->urDdiTable.EnqueueExp.pfnUSMFreeExp; + + if (nullptr == pfnUSMFreeExp) { + return UR_RESULT_ERROR_UNINITIALIZED; + } + + if (getContext()->enableParameterValidation) { + if (NULL == hQueue) + return UR_RESULT_ERROR_INVALID_NULL_HANDLE; + + if (NULL == pMem) + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + + if (phEventWaitList != NULL && numEventsInWaitList > 0) { + for (uint32_t i = 0; i < numEventsInWaitList; ++i) { + if (phEventWaitList[i] == NULL) { + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + } + } + } + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(hQueue)) { + getContext()->refCountContext->logInvalidReference(hQueue); + } + + if (getContext()->enableLifetimeValidation && + !getContext()->refCountContext->isReferenceValid(pPool)) { + getContext()->refCountContext->logInvalidReference(pPool); + } + + ur_result_t result = pfnUSMFreeExp(hQueue, pPool, pMem, numEventsInWaitList, + phEventWaitList, phEvent); + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urUSMPitchedAllocExp __urdlllocal ur_result_t UR_APICALL urUSMPitchedAllocExp( @@ -10189,6 +10450,20 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable( pDdiTable->pfnKernelLaunchCustomExp = ur_validation_layer::urEnqueueKernelLaunchCustomExp; + dditable.pfnUSMDeviceAllocExp = pDdiTable->pfnUSMDeviceAllocExp; + pDdiTable->pfnUSMDeviceAllocExp = + ur_validation_layer::urEnqueueUSMDeviceAllocExp; + + dditable.pfnUSMSharedAllocExp = pDdiTable->pfnUSMSharedAllocExp; + pDdiTable->pfnUSMSharedAllocExp = + ur_validation_layer::urEnqueueUSMSharedAllocExp; + + dditable.pfnUSMHostAllocExp = pDdiTable->pfnUSMHostAllocExp; + pDdiTable->pfnUSMHostAllocExp = ur_validation_layer::urEnqueueUSMHostAllocExp; + + dditable.pfnUSMFreeExp = pDdiTable->pfnUSMFreeExp; + pDdiTable->pfnUSMFreeExp = ur_validation_layer::urEnqueueUSMFreeExp; + dditable.pfnCooperativeKernelLaunchExp = pDdiTable->pfnCooperativeKernelLaunchExp; pDdiTable->pfnCooperativeKernelLaunchExp = diff --git a/source/loader/loader.def.in b/source/loader/loader.def.in index 1425c602d6..8b3eea821f 100644 --- a/source/loader/loader.def.in +++ b/source/loader/loader.def.in @@ -85,11 +85,15 @@ EXPORTS urEnqueueReadHostPipe urEnqueueTimestampRecordingExp urEnqueueUSMAdvise + urEnqueueUSMDeviceAllocExp urEnqueueUSMFill urEnqueueUSMFill2D + urEnqueueUSMFreeExp + urEnqueueUSMHostAllocExp urEnqueueUSMMemcpy urEnqueueUSMMemcpy2D urEnqueueUSMPrefetch + urEnqueueUSMSharedAllocExp urEnqueueWriteHostPipe urEventCreateWithNativeHandle urEventGetInfo @@ -282,11 +286,15 @@ EXPORTS urPrintEnqueueReadHostPipeParams urPrintEnqueueTimestampRecordingExpParams urPrintEnqueueUsmAdviseParams + urPrintEnqueueUsmDeviceAllocExpParams urPrintEnqueueUsmFillParams urPrintEnqueueUsmFill_2dParams + urPrintEnqueueUsmFreeExpParams + urPrintEnqueueUsmHostAllocExpParams urPrintEnqueueUsmMemcpyParams urPrintEnqueueUsmMemcpy_2dParams urPrintEnqueueUsmPrefetchParams + urPrintEnqueueUsmSharedAllocExpParams urPrintEnqueueWriteHostPipeParams urPrintEventCreateWithNativeHandleParams urPrintEventGetInfoParams @@ -312,6 +320,8 @@ EXPORTS urPrintExpEnqueueExtProperties urPrintExpEnqueueNativeCommandFlags urPrintExpEnqueueNativeCommandProperties + urPrintExpEnqueueUsmAllocFlags + urPrintExpEnqueueUsmAllocProperties urPrintExpExternalMemDesc urPrintExpExternalMemType urPrintExpExternalSemaphoreDesc diff --git a/source/loader/loader.map.in b/source/loader/loader.map.in index ebb413c985..2ea3fea994 100644 --- a/source/loader/loader.map.in +++ b/source/loader/loader.map.in @@ -85,11 +85,15 @@ urEnqueueReadHostPipe; urEnqueueTimestampRecordingExp; urEnqueueUSMAdvise; + urEnqueueUSMDeviceAllocExp; urEnqueueUSMFill; urEnqueueUSMFill2D; + urEnqueueUSMFreeExp; + urEnqueueUSMHostAllocExp; urEnqueueUSMMemcpy; urEnqueueUSMMemcpy2D; urEnqueueUSMPrefetch; + urEnqueueUSMSharedAllocExp; urEnqueueWriteHostPipe; urEventCreateWithNativeHandle; urEventGetInfo; @@ -282,11 +286,15 @@ urPrintEnqueueReadHostPipeParams; urPrintEnqueueTimestampRecordingExpParams; urPrintEnqueueUsmAdviseParams; + urPrintEnqueueUsmDeviceAllocExpParams; urPrintEnqueueUsmFillParams; urPrintEnqueueUsmFill_2dParams; + urPrintEnqueueUsmFreeExpParams; + urPrintEnqueueUsmHostAllocExpParams; urPrintEnqueueUsmMemcpyParams; urPrintEnqueueUsmMemcpy_2dParams; urPrintEnqueueUsmPrefetchParams; + urPrintEnqueueUsmSharedAllocExpParams; urPrintEnqueueWriteHostPipeParams; urPrintEventCreateWithNativeHandleParams; urPrintEventGetInfoParams; @@ -312,6 +320,8 @@ urPrintExpEnqueueExtProperties; urPrintExpEnqueueNativeCommandFlags; urPrintExpEnqueueNativeCommandProperties; + urPrintExpEnqueueUsmAllocFlags; + urPrintExpEnqueueUsmAllocProperties; urPrintExpExternalMemDesc; urPrintExpExternalMemType; urPrintExpExternalSemaphoreDesc; diff --git a/source/loader/ur_ldrddi.cpp b/source/loader/ur_ldrddi.cpp index fc8585f9e4..d18ce1470a 100644 --- a/source/loader/ur_ldrddi.cpp +++ b/source/loader/ur_ldrddi.cpp @@ -6162,6 +6162,276 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMDeviceAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + + [[maybe_unused]] auto context = getContext(); + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hQueue)->dditable; + auto pfnUSMDeviceAllocExp = dditable->ur.EnqueueExp.pfnUSMDeviceAllocExp; + if (nullptr == pfnUSMDeviceAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // convert loader handle to platform handle + hQueue = reinterpret_cast(hQueue)->handle; + + // convert loader handle to platform handle + pPool = (pPool) ? reinterpret_cast(pPool)->handle + : nullptr; + + // convert loader handles to platform handles + auto phEventWaitListLocal = + std::vector(numEventsInWaitList); + for (size_t i = 0; i < numEventsInWaitList; ++i) + phEventWaitListLocal[i] = + reinterpret_cast(phEventWaitList[i])->handle; + + // forward to device-platform + result = pfnUSMDeviceAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitListLocal.data(), ppMem, phEvent); + + // In the event of ERROR_ADAPTER_SPECIFIC we should still attempt to wrap any + // output handles below. + if (UR_RESULT_SUCCESS != result && UR_RESULT_ERROR_ADAPTER_SPECIFIC != result) + return result; + try { + // convert platform handle to loader handle + if (nullptr != phEvent) + *phEvent = reinterpret_cast( + context->factories.ur_event_factory.getInstance(*phEvent, dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMSharedAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + + [[maybe_unused]] auto context = getContext(); + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hQueue)->dditable; + auto pfnUSMSharedAllocExp = dditable->ur.EnqueueExp.pfnUSMSharedAllocExp; + if (nullptr == pfnUSMSharedAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // convert loader handle to platform handle + hQueue = reinterpret_cast(hQueue)->handle; + + // convert loader handle to platform handle + pPool = (pPool) ? reinterpret_cast(pPool)->handle + : nullptr; + + // convert loader handles to platform handles + auto phEventWaitListLocal = + std::vector(numEventsInWaitList); + for (size_t i = 0; i < numEventsInWaitList; ++i) + phEventWaitListLocal[i] = + reinterpret_cast(phEventWaitList[i])->handle; + + // forward to device-platform + result = pfnUSMSharedAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, + phEventWaitListLocal.data(), ppMem, phEvent); + + // In the event of ERROR_ADAPTER_SPECIFIC we should still attempt to wrap any + // output handles below. + if (UR_RESULT_SUCCESS != result && UR_RESULT_ERROR_ADAPTER_SPECIFIC != result) + return result; + try { + // convert platform handle to loader handle + if (nullptr != phEvent) + *phEvent = reinterpret_cast( + context->factories.ur_event_factory.getInstance(*phEvent, dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMHostAllocExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + + [[maybe_unused]] auto context = getContext(); + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hQueue)->dditable; + auto pfnUSMHostAllocExp = dditable->ur.EnqueueExp.pfnUSMHostAllocExp; + if (nullptr == pfnUSMHostAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // convert loader handle to platform handle + hQueue = reinterpret_cast(hQueue)->handle; + + // convert loader handle to platform handle + pPool = (pPool) ? reinterpret_cast(pPool)->handle + : nullptr; + + // convert loader handles to platform handles + auto phEventWaitListLocal = + std::vector(numEventsInWaitList); + for (size_t i = 0; i < numEventsInWaitList; ++i) + phEventWaitListLocal[i] = + reinterpret_cast(phEventWaitList[i])->handle; + + // forward to device-platform + result = + pfnUSMHostAllocExp(hQueue, pPool, size, pProperties, numEventsInWaitList, + phEventWaitListLocal.data(), ppMem, phEvent); + + // In the event of ERROR_ADAPTER_SPECIFIC we should still attempt to wrap any + // output handles below. + if (UR_RESULT_SUCCESS != result && UR_RESULT_ERROR_ADAPTER_SPECIFIC != result) + return result; + try { + // convert platform handle to loader handle + if (nullptr != phEvent) + *phEvent = reinterpret_cast( + context->factories.ur_event_factory.getInstance(*phEvent, dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Intercept function for urEnqueueUSMFreeExp +__urdlllocal ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + + [[maybe_unused]] auto context = getContext(); + + // extract platform's function pointer table + auto dditable = reinterpret_cast(hQueue)->dditable; + auto pfnUSMFreeExp = dditable->ur.EnqueueExp.pfnUSMFreeExp; + if (nullptr == pfnUSMFreeExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + // convert loader handle to platform handle + hQueue = reinterpret_cast(hQueue)->handle; + + // convert loader handle to platform handle + pPool = (pPool) ? reinterpret_cast(pPool)->handle + : nullptr; + + // convert loader handles to platform handles + auto phEventWaitListLocal = + std::vector(numEventsInWaitList); + for (size_t i = 0; i < numEventsInWaitList; ++i) + phEventWaitListLocal[i] = + reinterpret_cast(phEventWaitList[i])->handle; + + // forward to device-platform + result = pfnUSMFreeExp(hQueue, pPool, pMem, numEventsInWaitList, + phEventWaitListLocal.data(), phEvent); + + // In the event of ERROR_ADAPTER_SPECIFIC we should still attempt to wrap any + // output handles below. + if (UR_RESULT_SUCCESS != result && UR_RESULT_ERROR_ADAPTER_SPECIFIC != result) + return result; + try { + // convert platform handle to loader handle + if (nullptr != phEvent) + *phEvent = reinterpret_cast( + context->factories.ur_event_factory.getInstance(*phEvent, dditable)); + } catch (std::bad_alloc &) { + result = UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief Intercept function for urUSMPitchedAllocExp __urdlllocal ur_result_t UR_APICALL urUSMPitchedAllocExp( @@ -9687,6 +9957,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable( // return pointers to loader's DDIs pDdiTable->pfnKernelLaunchCustomExp = ur_loader::urEnqueueKernelLaunchCustomExp; + pDdiTable->pfnUSMDeviceAllocExp = ur_loader::urEnqueueUSMDeviceAllocExp; + pDdiTable->pfnUSMSharedAllocExp = ur_loader::urEnqueueUSMSharedAllocExp; + pDdiTable->pfnUSMHostAllocExp = ur_loader::urEnqueueUSMHostAllocExp; + pDdiTable->pfnUSMFreeExp = ur_loader::urEnqueueUSMFreeExp; pDdiTable->pfnCooperativeKernelLaunchExp = ur_loader::urEnqueueCooperativeKernelLaunchExp; pDdiTable->pfnTimestampRecordingExp = diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index c5fe9bd7df..e22d015fc3 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -868,7 +868,7 @@ ur_result_t UR_APICALL urDeviceGetSelected( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hDevice` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP < propName` +/// + `::UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE @@ -6694,6 +6694,203 @@ ur_result_t UR_APICALL urEnqueueWriteHostPipe( return exceptionToResult(std::current_exception()); } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM device allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) try { + auto pfnUSMDeviceAllocExp = + ur_lib::getContext()->urDdiTable.EnqueueExp.pfnUSMDeviceAllocExp; + if (nullptr == pfnUSMDeviceAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnUSMDeviceAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, ppMem, + phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM shared allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) try { + auto pfnUSMSharedAllocExp = + ur_lib::getContext()->urDdiTable.EnqueueExp.pfnUSMSharedAllocExp; + if (nullptr == pfnUSMSharedAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnUSMSharedAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, ppMem, + phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM host allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) try { + auto pfnUSMHostAllocExp = + ur_lib::getContext()->urDdiTable.EnqueueExp.pfnUSMHostAllocExp; + if (nullptr == pfnUSMHostAllocExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnUSMHostAllocExp(hQueue, pPool, size, pProperties, + numEventsInWaitList, phEventWaitList, ppMem, + phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM deallocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) try { + auto pfnUSMFreeExp = + ur_lib::getContext()->urDdiTable.EnqueueExp.pfnUSMFreeExp; + if (nullptr == pfnUSMFreeExp) + return UR_RESULT_ERROR_UNINITIALIZED; + + return pfnUSMFreeExp(hQueue, pPool, pMem, numEventsInWaitList, + phEventWaitList, phEvent); +} catch (...) { + return exceptionToResult(std::current_exception()); +} + /////////////////////////////////////////////////////////////////////////////// /// @brief USM allocate pitched memory /// diff --git a/source/loader/ur_print.cpp b/source/loader/ur_print.cpp index d75272a1ae..905bf27725 100644 --- a/source/loader/ur_print.cpp +++ b/source/loader/ur_print.cpp @@ -897,6 +897,23 @@ ur_result_t urPrintExpDevice_2dBlockArrayCapabilityFlags( return str_copy(&ss, buffer, buff_size, out_size); } +ur_result_t +urPrintExpEnqueueUsmAllocFlags(enum ur_exp_enqueue_usm_alloc_flag_t value, + char *buffer, const size_t buff_size, + size_t *out_size) { + std::stringstream ss; + ss << value; + return str_copy(&ss, buffer, buff_size, out_size); +} + +ur_result_t urPrintExpEnqueueUsmAllocProperties( + const struct ur_exp_enqueue_usm_alloc_properties_t params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + ur_result_t urPrintExpImageCopyFlags(enum ur_exp_image_copy_flag_t value, char *buffer, const size_t buff_size, size_t *out_size) { @@ -1764,6 +1781,38 @@ ur_result_t urPrintEnqueueEventsWaitWithBarrierExtParams( return str_copy(&ss, buffer, buff_size, out_size); } +ur_result_t urPrintEnqueueUsmDeviceAllocExpParams( + const struct ur_enqueue_usm_device_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + +ur_result_t urPrintEnqueueUsmSharedAllocExpParams( + const struct ur_enqueue_usm_shared_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + +ur_result_t urPrintEnqueueUsmHostAllocExpParams( + const struct ur_enqueue_usm_host_alloc_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + +ur_result_t urPrintEnqueueUsmFreeExpParams( + const struct ur_enqueue_usm_free_exp_params_t *params, char *buffer, + const size_t buff_size, size_t *out_size) { + std::stringstream ss; + ss << params; + return str_copy(&ss, buffer, buff_size, out_size); +} + ur_result_t urPrintEnqueueCooperativeKernelLaunchExpParams( const struct ur_enqueue_cooperative_kernel_launch_exp_params_t *params, char *buffer, const size_t buff_size, size_t *out_size) { diff --git a/source/ur_api.cpp b/source/ur_api.cpp index a6f43ecda2..2a004eeeda 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -782,7 +782,7 @@ ur_result_t UR_APICALL urDeviceGetSelected( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hDevice` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP < propName` +/// + `::UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE @@ -5882,6 +5882,172 @@ ur_result_t UR_APICALL urEnqueueWriteHostPipe( return result; } +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM device allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMDeviceAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM device allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM shared allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMSharedAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM shared allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM host allocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION +/// + `NULL != pProperties && ::UR_EXP_ENQUEUE_USM_ALLOC_FLAGS_MASK & +/// pProperties->flags` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == ppMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMHostAllocExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] minimum size in bytes of the USM memory object to be allocated + const size_t size, + /// [in][optional] pointer to the enqueue asynchronous USM allocation + /// properties + const ur_exp_enqueue_usm_alloc_properties_t *pProperties, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out] pointer to USM memory object + void **ppMem, + /// [out][optional] return an event object that identifies the + /// asynchronous USM host allocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Enqueue an asynchronous USM deallocation +/// +/// @returns +/// - ::UR_RESULT_SUCCESS +/// - ::UR_RESULT_ERROR_UNINITIALIZED +/// - ::UR_RESULT_ERROR_DEVICE_LOST +/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC +/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `NULL == hQueue` +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `NULL == pMem` +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +ur_result_t UR_APICALL urEnqueueUSMFreeExp( + /// [in] handle of the queue object + ur_queue_handle_t hQueue, + /// [in][optional] handle of the USM memory pool + ur_usm_pool_handle_t pPool, + /// [in] pointer to USM memory object + void *pMem, + /// [in] size of the event wait list + uint32_t numEventsInWaitList, + /// [in][optional][range(0, numEventsInWaitList)] pointer to a list of + /// events that must be complete before the kernel execution. + /// If nullptr, the numEventsInWaitList must be 0, indicating no wait + /// events. + const ur_event_handle_t *phEventWaitList, + /// [out][optional] return an event object that identifies the + /// asynchronous USM deallocation + ur_event_handle_t *phEvent) { + ur_result_t result = UR_RESULT_SUCCESS; + return result; +} + /////////////////////////////////////////////////////////////////////////////// /// @brief USM allocate pitched memory /// diff --git a/test/conformance/testing/include/uur/utils.h b/test/conformance/testing/include/uur/utils.h index c94ff56dbd..ae60f2ed07 100644 --- a/test/conformance/testing/include/uur/utils.h +++ b/test/conformance/testing/include/uur/utils.h @@ -475,10 +475,10 @@ getDriverVersion(ur_device_handle_t hDevice) { if (major < minMajor || (major == minMajor && minor < minMinor) || \ (major == minMajor && minor == minMinor && patch < minPatch)) { \ GTEST_SKIP() << "Skipping test because driver version is too old for " \ - << adapterName << ". " \ - << "Driver version: " << major << "." << minor << "." \ - << patch << " Minimum required version: " << minMajor \ - << "." << minMinor << "." << minPatch; \ + << adapterName << ". " << "Driver version: " << major \ + << "." << minor << "." << patch \ + << " Minimum required version: " << minMajor << "." \ + << minMinor << "." << minPatch; \ } \ } \ } while (0) diff --git a/tools/urinfo/urinfo.cpp b/tools/urinfo/urinfo.cpp index c86d166034..293ff2bce0 100644 --- a/tools/urinfo/urinfo.cpp +++ b/tools/urinfo/urinfo.cpp @@ -145,15 +145,15 @@ devices which are currently visible in the local execution environment. << "]"; } else { std::cout << "[adapter(" << adapterIndex << "," << adapter_backend - << "):" - << "platform(" << platformIndex << "):" - << "device(" << deviceIndex << "," << device_type << ")]"; + << "):" << "platform(" << platformIndex + << "):" << "device(" << deviceIndex << "," << device_type + << ")]"; } std::cout << " " << urinfo::getPlatformName(platform) << ", " << urinfo::getDeviceName(device) << " " - << urinfo::getDeviceVersion(device) << " " - << "[" << urinfo::getDeviceDriverVersion(device) << "]\n"; + << urinfo::getDeviceVersion(device) << " " << "[" + << urinfo::getDeviceDriverVersion(device) << "]\n"; adapter_device_id++; } @@ -163,16 +163,14 @@ devices which are currently visible in the local execution environment. void printDetail() { std::cout << "\n" - << "[loader]:" - << "\n"; + << "[loader]:" << "\n"; urinfo::printLoaderConfigInfos(loaderConfig); for (size_t adapterIndex = 0; adapterIndex < adapters.size(); adapterIndex++) { auto adapter = adapters[adapterIndex]; std::cout << "\n" - << "[adapter(" << adapterIndex << ")]:" - << "\n"; + << "[adapter(" << adapterIndex << ")]:" << "\n"; urinfo::printAdapterInfos(adapter); size_t numPlatforms = adapterPlatformsMap[adapter].size(); @@ -180,19 +178,17 @@ devices which are currently visible in the local execution environment. platformIndex++) { auto platform = adapterPlatformsMap[adapter][platformIndex]; std::cout << "\n" - << "[adapter(" << adapterIndex << ")," - << "platform(" << platformIndex << ")]:" - << "\n"; + << "[adapter(" << adapterIndex << ")," << "platform(" + << platformIndex << ")]:" << "\n"; urinfo::printPlatformInfos(platform); size_t numDevices = platformDevicesMap[platform].size(); for (size_t deviceI = 0; deviceI < numDevices; deviceI++) { auto device = platformDevicesMap[platform][deviceI]; std::cout << "\n" - << "[adapter(" << adapterIndex << ")," - << "platform(" << platformIndex << ")," - << "device(" << deviceI << ")]:" - << "\n"; + << "[adapter(" << adapterIndex << ")," << "platform(" + << platformIndex << ")," << "device(" << deviceI + << ")]:" << "\n"; urinfo::printDeviceInfos(device); } } diff --git a/tools/urinfo/urinfo.hpp b/tools/urinfo/urinfo.hpp index d01245138f..d7e4e63021 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -420,5 +420,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice, std::cout << prefix; printDeviceInfo( hDevice, UR_DEVICE_INFO_2D_BLOCK_ARRAY_CAPABILITIES_EXP); + std::cout << prefix; + printDeviceInfo(hDevice, + UR_DEVICE_INFO_ENQUEUE_USM_ALLOCATIONS_EXP); } } // namespace urinfo From 3d9a3c2a2f22ab103b57b10a3999fc9a2561bb21 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 15 Oct 2024 09:51:45 +0000 Subject: [PATCH 5/6] [L0] Add initial USM alloc enqueue API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Staniewski --- source/adapters/level_zero/context.hpp | 7 +- source/adapters/level_zero/queue.cpp | 2 +- source/adapters/level_zero/usm.cpp | 276 ++++++++++++++------- test/adapters/level_zero/CMakeLists.txt | 11 + test/adapters/level_zero/enqueue_alloc.cpp | 137 ++++++++++ 5 files changed, 336 insertions(+), 97 deletions(-) create mode 100644 test/adapters/level_zero/enqueue_alloc.cpp diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index 99435de859..f090470daa 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -57,13 +57,13 @@ struct ur_context_handle_t_ : _ur_object { const ur_device_handle_t *Devs, bool OwnZeContext) : ZeContext{ZeContext}, Devices{Devs, Devs + NumDevices}, NumDevices{NumDevices}, DefaultPool{this, nullptr}, - ProxyPool{this, nullptr} { + ProxyPool{this, nullptr}, AsyncPool{this, nullptr} { OwnNativeHandle = OwnZeContext; } ur_context_handle_t_(ze_context_handle_t ZeContext) : ZeContext{ZeContext}, DefaultPool{this, nullptr}, - ProxyPool{this, nullptr} {} + ProxyPool{this, nullptr}, AsyncPool{this, nullptr} {} // A L0 context handle is primarily used during creation and management of // resources that may be used by multiple devices. @@ -125,6 +125,9 @@ struct ur_context_handle_t_ : _ur_object { // Allocation-tracking proxy pools for direct allocations. No pooling used. ur_usm_pool_handle_t_ ProxyPool; + // USM pools for async allocations. + ur_usm_pool_handle_t_ AsyncPool; + // Map associating pools created with urUsmPoolCreate and internal pools std::list UsmPoolHandles{}; diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index aed521b605..c4e96ff791 100644 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -1334,7 +1334,7 @@ ur_queue_handle_t_::executeCommandList(ur_command_list_ptr_t CommandList, Device->Platform->ContextsMutex, std::defer_lock); if (IndirectAccessTrackingEnabled) { - // We are going to submit kernels for execution. If indirect access flag is + // We are going to submit kernels for execution. If indirect access flag is // set for a kernel then we need to make a snapshot of existing memory // allocations in all contexts in the platform. We need to lock the mutex // guarding the list of contexts in the platform to prevent creation of new diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 99de496e7c..12b86fe080 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -600,124 +600,212 @@ ur_result_t urUSMReleaseExp(ur_context_handle_t Context, void *HostPtr) { return UR_RESULT_SUCCESS; } +static ur_result_t enqueueUSMAllocHelper( + ur_queue_handle_t Queue, ur_usm_pool_handle_t Pool, const size_t Size, + const ur_exp_enqueue_usm_alloc_properties_t *Properties, + uint32_t NumEventsInWaitList, const ur_event_handle_t *EventWaitList, + void **RetMem, ur_event_handle_t *OutEvent, ur_usm_type_t Type) { + std::ignore = Pool; + std::ignore = Properties; + + std::scoped_lock lock(Queue->Mutex); + + bool UseCopyEngine = false; + _ur_ze_event_list_t TmpWaitList; + UR_CALL(TmpWaitList.createAndRetainUrZeEventList( + NumEventsInWaitList, EventWaitList, Queue, UseCopyEngine)); + + bool OkToBatch = true; + // Get a new command list to be used on this call + ur_command_list_ptr_t CommandList{}; + UR_CALL(Queue->Context->getAvailableCommandList( + Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList, + OkToBatch, nullptr /*ForcedCmdQueue*/)); + + ze_event_handle_t ZeEvent = nullptr; + ur_event_handle_t InternalEvent{}; + bool IsInternal = OutEvent == nullptr; + ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent; + + ur_command_t CommandType = UR_COMMAND_FORCE_UINT32; + switch (Type) { + case UR_USM_TYPE_HOST: + CommandType = UR_COMMAND_ENQUEUE_USM_HOST_ALLOC_EXP; + break; + case UR_USM_TYPE_DEVICE: + CommandType = UR_COMMAND_ENQUEUE_USM_DEVICE_ALLOC_EXP; + break; + case UR_USM_TYPE_SHARED: + CommandType = UR_COMMAND_ENQUEUE_USM_SHARED_ALLOC_EXP; + break; + default: + logger::error("enqueueUSMAllocHelper: unsupported USM type"); + throw UR_RESULT_ERROR_UNKNOWN; + } + UR_CALL(createEventAndAssociateQueue(Queue, Event, CommandType, CommandList, + IsInternal, false)); + ZeEvent = (*Event)->ZeEvent; + (*Event)->WaitList = TmpWaitList; + + // Allocate USM memory + ur_usm_pool_handle_t USMPool = nullptr; + if (Pool) { + USMPool = Pool; + } else { + USMPool = &Queue->Context->AsyncPool; + } + + auto Device = (Type == UR_USM_TYPE_HOST) ? nullptr : Queue->Device; + auto Ret = + USMPool->allocate(Queue->Context, Device, nullptr, Type, Size, RetMem); + if (Ret) { + return Ret; + } + + // Signal that USM allocation event was finished + ZE2UR_CALL(zeCommandListAppendSignalEvent, (CommandList->first, ZeEvent)); + + UR_CALL(Queue->executeCommandList(CommandList, false, OkToBatch)); + + return UR_RESULT_SUCCESS; +} + ur_result_t urEnqueueUSMDeviceAllocExp( - ur_queue_handle_t hQueue, ///< [in] handle of the queue object - ur_usm_pool_handle_t - pPool, ///< [in][optional] handle of the USM memory pool - const size_t size, ///< [in] minimum size in bytes of the USM memory object + ur_queue_handle_t Queue, ///< [in] handle of the queue object + ur_usm_pool_handle_t Pool, ///< [in][optional] USM pool descriptor + const size_t Size, ///< [in] minimum size in bytes of the USM memory object ///< to be allocated const ur_exp_enqueue_usm_alloc_properties_t - *pProperties, ///< [in][optional] pointer to the enqueue asynchronous - ///< USM allocation properties - uint32_t numEventsInWaitList, ///< [in] size of the event wait list + *Properties, ///< [in][optional] pointer to the enqueue async alloc + ///< properties + uint32_t NumEventsInWaitList, ///< [in] size of the event wait list const ur_event_handle_t - *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] - ///< pointer to a list of events that must be complete - ///< before the kernel execution. If nullptr, the - ///< numEventsInWaitList must be 0, indicating no wait - ///< events. - void **ppMem, ///< [out] pointer to USM memory object - ur_event_handle_t - *phEvent ///< [out][optional] return an event object that identifies the - ///< asynchronous USM device allocation + *EventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **Mem, ///< [out] pointer to USM memory object + ur_event_handle_t *OutEvent ///< [out][optional] return an event object that + ///< identifies the async alloc ) { - std::ignore = hQueue; - std::ignore = pPool; - std::ignore = size; - std::ignore = pProperties; - std::ignore = numEventsInWaitList; - std::ignore = phEventWaitList; - std::ignore = ppMem; - std::ignore = phEvent; - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + return enqueueUSMAllocHelper(Queue, Pool, Size, Properties, + NumEventsInWaitList, EventWaitList, Mem, + OutEvent, UR_USM_TYPE_DEVICE); } ur_result_t urEnqueueUSMSharedAllocExp( - ur_queue_handle_t hQueue, ///< [in] handle of the queue object - ur_usm_pool_handle_t - pPool, ///< [in][optional] handle of the USM memory pool - const size_t size, ///< [in] minimum size in bytes of the USM memory object + ur_queue_handle_t Queue, ///< [in] handle of the queue object + ur_usm_pool_handle_t Pool, ///< [in][optional] USM pool descriptor + const size_t Size, ///< [in] minimum size in bytes of the USM memory object ///< to be allocated const ur_exp_enqueue_usm_alloc_properties_t - *pProperties, ///< [in][optional] pointer to the enqueue asynchronous - ///< USM allocation properties - uint32_t numEventsInWaitList, ///< [in] size of the event wait list + *Properties, ///< [in][optional] pointer to the enqueue async alloc + ///< properties + uint32_t NumEventsInWaitList, ///< [in] size of the event wait list const ur_event_handle_t - *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] - ///< pointer to a list of events that must be complete - ///< before the kernel execution. If nullptr, the - ///< numEventsInWaitList must be 0, indicating no wait - ///< events. - void **ppMem, ///< [out] pointer to USM memory object - ur_event_handle_t - *phEvent ///< [out][optional] return an event object that identifies the - ///< asynchronous USM shared allocation + *EventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **Mem, ///< [out] pointer to USM memory object + ur_event_handle_t *OutEvent ///< [out][optional] return an event object that + ///< identifies the async alloc ) { - std::ignore = hQueue; - std::ignore = pPool; - std::ignore = size; - std::ignore = pProperties; - std::ignore = numEventsInWaitList; - std::ignore = phEventWaitList; - std::ignore = ppMem; - std::ignore = phEvent; - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + return enqueueUSMAllocHelper(Queue, Pool, Size, Properties, + NumEventsInWaitList, EventWaitList, Mem, + OutEvent, UR_USM_TYPE_SHARED); } ur_result_t urEnqueueUSMHostAllocExp( - ur_queue_handle_t hQueue, ///< [in] handle of the queue object - ur_usm_pool_handle_t - pPool, ///< [in][optional] handle of the USM memory pool - const size_t size, ///< [in] minimum size in bytes of the USM memory object + ur_queue_handle_t Queue, ///< [in] handle of the queue object + ur_usm_pool_handle_t Pool, ///< [in][optional] USM pool descriptor + const size_t Size, ///< [in] minimum size in bytes of the USM memory object ///< to be allocated const ur_exp_enqueue_usm_alloc_properties_t - *pProperties, ///< [in][optional] pointer to the enqueue asynchronous - ///< USM allocation properties - uint32_t numEventsInWaitList, ///< [in] size of the event wait list + *Properties, ///< [in][optional] pointer to the enqueue async alloc + ///< properties + uint32_t NumEventsInWaitList, ///< [in] size of the event wait list const ur_event_handle_t - *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] - ///< pointer to a list of events that must be complete - ///< before the kernel execution. If nullptr, the - ///< numEventsInWaitList must be 0, indicating no wait - ///< events. - void **ppMem, ///< [out] pointer to USM memory object - ur_event_handle_t - *phEvent ///< [out][optional] return an event object that identifies the - ///< asynchronous USM host allocation + *EventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + void **Mem, ///< [out] pointer to USM memory object + ur_event_handle_t *OutEvent ///< [out][optional] return an event object that + ///< identifies the async alloc ) { - std::ignore = hQueue; - std::ignore = pPool; - std::ignore = size; - std::ignore = pProperties; - std::ignore = numEventsInWaitList; - std::ignore = phEventWaitList; - std::ignore = ppMem; - std::ignore = phEvent; - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + return enqueueUSMAllocHelper(Queue, Pool, Size, Properties, + NumEventsInWaitList, EventWaitList, Mem, + OutEvent, UR_USM_TYPE_HOST); } ur_result_t urEnqueueUSMFreeExp( - ur_queue_handle_t hQueue, ///< [in] handle of the queue object - ur_usm_pool_handle_t - pPool, ///< [in][optional] handle of the USM memory pooliptor - void *pMem, ///< [in] pointer to USM memory object - uint32_t numEventsInWaitList, ///< [in] size of the event wait list + ur_queue_handle_t Queue, ///< [in] handle of the queue object + ur_usm_pool_handle_t Pool, ///< [in][optional] USM pool descriptor + void *Mem, ///< [in] pointer to USM memory object + uint32_t NumEventsInWaitList, ///< [in] size of the event wait list const ur_event_handle_t - *phEventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] - ///< pointer to a list of events that must be complete - ///< before the kernel execution. If nullptr, the - ///< numEventsInWaitList must be 0, indicating no wait - ///< events. - ur_event_handle_t *phEvent ///< [out][optional] return an event object that - ///< identifies the asynchronous USM deallocation + *EventWaitList, ///< [in][optional][range(0, numEventsInWaitList)] + ///< pointer to a list of events that must be complete + ///< before the kernel execution. If nullptr, the + ///< numEventsInWaitList must be 0, indicating no wait + ///< events. + ur_event_handle_t *OutEvent ///< [out][optional] return an event object that + ///< identifies the async alloc ) { - std::ignore = hQueue; - std::ignore = pPool; - std::ignore = pMem; - std::ignore = numEventsInWaitList; - std::ignore = phEventWaitList; - std::ignore = phEvent; - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + std::ignore = Pool; + + std::scoped_lock lock(Queue->Mutex); + + bool UseCopyEngine = false; + _ur_ze_event_list_t TmpWaitList; + UR_CALL(TmpWaitList.createAndRetainUrZeEventList( + NumEventsInWaitList, EventWaitList, Queue, UseCopyEngine)); + + bool OkToBatch = false; + // Get a new command list to be used on this call + ur_command_list_ptr_t CommandList{}; + UR_CALL(Queue->Context->getAvailableCommandList( + Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList, + OkToBatch, nullptr /*ForcedCmdQueue*/)); + + ze_event_handle_t ZeEvent = nullptr; + ur_event_handle_t InternalEvent{}; + bool IsInternal = OutEvent == nullptr; + ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent; + + UR_CALL(createEventAndAssociateQueue(Queue, Event, + UR_COMMAND_ENQUEUE_USM_FREE_EXP, + CommandList, IsInternal, false)); + ZeEvent = (*Event)->ZeEvent; + (*Event)->WaitList = TmpWaitList; + + const auto &ZeCommandList = CommandList->first; + const auto &WaitList = (*Event)->WaitList; + if (WaitList.Length) { + ZE2UR_CALL(zeCommandListAppendWaitOnEvents, + (ZeCommandList, WaitList.Length, WaitList.ZeEventList)); + + // Wait for commands execution until USM can be freed + UR_CALL( + Queue->executeCommandList(CommandList, true, OkToBatch)); // Blocking + } + + // Free USM memory + auto Ret = USMFreeHelper(Queue->Context, Mem); + if (Ret) { + return Ret; + } + + // Signal that USM free event was finished + ZE2UR_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent)); + + UR_CALL(Queue->executeCommandList(CommandList, false, OkToBatch)); + + return UR_RESULT_SUCCESS; } } // namespace ur::level_zero diff --git a/test/adapters/level_zero/CMakeLists.txt b/test/adapters/level_zero/CMakeLists.txt index fd58154d56..090f698f7e 100644 --- a/test/adapters/level_zero/CMakeLists.txt +++ b/test/adapters/level_zero/CMakeLists.txt @@ -40,6 +40,17 @@ function(add_adapter_tests adapter) add_dependencies(test-adapter-${adapter} generate_device_binaries kernel_names_header) + + + if("${adapter}" STREQUAL "level_zero") + add_adapter_test(level_zero_enqueue_alloc + FIXTURE KERNELS + SOURCES + enqueue_alloc.cpp + ENVIRONMENT + "UR_ADAPTERS_FORCE_LOAD=\"$\"" + ) + endif() endif() if(NOT WIN32 AND NOT UR_STATIC_ADAPTER_L0) diff --git a/test/adapters/level_zero/enqueue_alloc.cpp b/test/adapters/level_zero/enqueue_alloc.cpp new file mode 100644 index 0000000000..c36038c859 --- /dev/null +++ b/test/adapters/level_zero/enqueue_alloc.cpp @@ -0,0 +1,137 @@ +// Copyright (C) 2025 Intel Corporation +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM +// Exceptions. See LICENSE.TXT +// +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +struct urL0EnqueueAllocTest : uur::urKernelExecutionTest { + void SetUp() { + program_name = "fill_usm"; + UUR_RETURN_ON_FATAL_FAILURE(urKernelExecutionTest::SetUp()); + } + + void ValidateEnqueueFree(void *ptr) { + ur_event_handle_t freeEvent = nullptr; + ASSERT_NE(ptr, nullptr); + ASSERT_SUCCESS( + urEnqueueUSMFreeExp(queue, nullptr, ptr, 0, nullptr, &freeEvent)); + ASSERT_NE(freeEvent, nullptr); + ASSERT_SUCCESS(urQueueFinish(queue)); + } + + static constexpr size_t ARRAY_SIZE = 16; + static constexpr uint32_t DATA = 0xC0FFEE; +}; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urL0EnqueueAllocTest); + +TEST_P(urL0EnqueueAllocTest, SuccessHost) { + ur_device_usm_access_capability_flags_t hostUSMSupport = 0; + ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport)); + if (!hostUSMSupport) { + GTEST_SKIP() << "Host USM is not supported."; + } + + void *ptr = nullptr; + ur_event_handle_t allocEvent = nullptr; + ASSERT_SUCCESS(urEnqueueUSMHostAllocExp(queue, nullptr, sizeof(uint32_t), + nullptr, 0, nullptr, &ptr, + &allocEvent)); + ASSERT_SUCCESS(urQueueFinish(queue)); + ASSERT_NE(ptr, nullptr); + ASSERT_NE(allocEvent, nullptr); + *(uint32_t *)ptr = DATA; + ValidateEnqueueFree(ptr); +} + +// Disable temporarily until user pool handling is implemented +// TEST_P(urL0EnqueueAllocTest, SuccessHostPoolAlloc) { +// ur_device_usm_access_capability_flags_t hostUSMSupport = 0; +// ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport)); +// if (!hostUSMSupport) { +// GTEST_SKIP() << "Host USM is not supported."; +// } + +// ur_usm_pool_handle_t pool = nullptr; +// ASSERT_SUCCESS(urUSMPoolCreate(context, nullptr, &pool)); + +// void *ptr = nullptr; +// ur_event_handle_t allocEvent = nullptr; +// ASSERT_SUCCESS(urEnqueueUSMHostAllocExp(queue, pool, sizeof(uint32_t), +// nullptr, +// 0, nullptr, &ptr, &allocEvent)); +// ASSERT_SUCCESS(urQueueFinish(queue)); +// ASSERT_NE(ptr, nullptr); +// ASSERT_NE(allocEvent, nullptr); +// *static_cast(ptr) = DATA; +// ValidateEnqueueFree(ptr, pool); +// } + +TEST_P(urL0EnqueueAllocTest, SuccessDevice) { + ur_device_usm_access_capability_flags_t deviceUSMSupport = 0; + ASSERT_SUCCESS(uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport)); + if (!(deviceUSMSupport & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) { + GTEST_SKIP() << "Device USM is not supported."; + } + + void *ptr = nullptr; + ur_event_handle_t allocEvent = nullptr; + ASSERT_SUCCESS( + urEnqueueUSMDeviceAllocExp(queue, nullptr, ARRAY_SIZE * sizeof(uint32_t), + nullptr, 0, nullptr, &ptr, &allocEvent)); + ASSERT_NE(ptr, nullptr); + ASSERT_NE(allocEvent, nullptr); + ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, ptr)); + ASSERT_SUCCESS(urKernelSetArgValue(kernel, 1, sizeof(DATA), nullptr, &DATA)); + Launch1DRange(ARRAY_SIZE); + ValidateEnqueueFree(ptr); +} + +TEST_P(urL0EnqueueAllocTest, SuccessDeviceRepeat) { + ur_device_usm_access_capability_flags_t deviceUSMSupport = 0; + ASSERT_SUCCESS(uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport)); + if (!(deviceUSMSupport & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) { + GTEST_SKIP() << "Device USM is not supported."; + } + + void *ptr = nullptr; + ASSERT_SUCCESS( + urEnqueueUSMDeviceAllocExp(queue, nullptr, ARRAY_SIZE * sizeof(uint32_t), + nullptr, 0, nullptr, &ptr, nullptr)); + ASSERT_NE(ptr, nullptr); + ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, ptr)); + ASSERT_SUCCESS(urKernelSetArgValue(kernel, 1, sizeof(DATA), nullptr, &DATA)); + Launch1DRange(ARRAY_SIZE); + ASSERT_SUCCESS(urEnqueueUSMFreeExp(queue, nullptr, ptr, 0, nullptr, nullptr)); + + void *ptr2 = nullptr; + ASSERT_SUCCESS( + urEnqueueUSMDeviceAllocExp(queue, nullptr, ARRAY_SIZE * sizeof(uint32_t), + nullptr, 0, nullptr, &ptr2, nullptr)); + ASSERT_NE(ptr, nullptr); + ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, ptr2)); + ASSERT_SUCCESS(urKernelSetArgValue(kernel, 1, sizeof(DATA), nullptr, &DATA)); + Launch1DRange(ARRAY_SIZE); + ValidateEnqueueFree(ptr2); +} + +TEST_P(urL0EnqueueAllocTest, SuccessShared) { + ur_device_usm_access_capability_flags_t sharedUSMSupport = 0; + ASSERT_SUCCESS( + uur::GetDeviceUSMSingleSharedSupport(device, sharedUSMSupport)); + if (!(sharedUSMSupport & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) { + GTEST_SKIP() << "Shared USM is not supported."; + } + + void *ptr = nullptr; + ur_event_handle_t allocEvent = nullptr; + ASSERT_SUCCESS( + urEnqueueUSMSharedAllocExp(queue, nullptr, ARRAY_SIZE * sizeof(uint32_t), + nullptr, 0, nullptr, &ptr, &allocEvent)); + ASSERT_NE(ptr, nullptr); + ASSERT_NE(allocEvent, nullptr); + ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, ptr)); + ASSERT_SUCCESS(urKernelSetArgValue(kernel, 1, sizeof(DATA), nullptr, &DATA)); + Launch1DRange(ARRAY_SIZE); + ValidateEnqueueFree(ptr); +} From 8016b17b87f6999a7b5fc464e7ed5e5ae3633214 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Thu, 16 Jan 2025 13:29:43 +0100 Subject: [PATCH 6/6] [L0] Add additional logs to enqueue alloc flow --- source/adapters/level_zero/usm.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 12b86fe080..c1da030abe 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -1188,15 +1188,27 @@ ur_result_t ur_usm_pool_handle_t_::allocate(ur_context_handle_t Context, UR_CALL(ur::level_zero::urContextRetain(Context)); } + const auto Desc = + usm::pool_descriptor{this, Context, Device, Type, DeviceReadOnly}; + logger::debug("enqueueUSMAllocHelper: retrieving an appropriate UMF pool for " + "pool descriptor {}", + Desc); auto umfPool = getPool( usm::pool_descriptor{this, Context, Device, Type, DeviceReadOnly}); if (!umfPool) { return UR_RESULT_ERROR_INVALID_ARGUMENT; } + logger::debug( + "enqueueUSMAllocHelper: preparing an allocation from the UMF pool {}", + umfPool); + *RetMem = umfPoolAlignedMalloc(umfPool, Size, Alignment); if (*RetMem == nullptr) { auto umfRet = umfPoolGetLastAllocationError(umfPool); + logger::error( + "enqueueUSMAllocHelper: allocation from the UMF pool {} failed", + umfPool); return umf::umf2urResult(umfRet); }