performance: move host/device memUsmAllocPool init to platform/context init

Related-To: NEO-16059

Signed-off-by: Aleksander Czerwionka <aleksander.czerwionka@intel.com>
This commit is contained in:
Aleksander Czerwionka
2025-09-17 11:17:23 +00:00
committed by Compute-Runtime-Automation
parent 6ec9ebd7a6
commit f0f869ed42
18 changed files with 160 additions and 136 deletions

View File

@@ -3977,10 +3977,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
return nullptr;
}
auto platform = neoContext->getDevice(0u)->getPlatform();
platform->initializeHostUsmAllocationPool();
auto allocationFromPool = platform->getHostMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
auto allocationFromPool = neoContext->getDevice(0u)->getPlatform()->getHostMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (allocationFromPool) {
TRACING_EXIT(ClHostMemAllocINTEL, &allocationFromPool);
return allocationFromPool;
@@ -4042,8 +4039,6 @@ CL_API_ENTRY void *CL_API_CALL clDeviceMemAllocINTEL(
unifiedMemoryProperties.device = &neoDevice->getDevice();
neoContext->initializeDeviceUsmAllocationPool();
auto allocationFromPool = neoContext->getDeviceMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (allocationFromPool) {
TRACING_EXIT(ClDeviceMemAllocINTEL, &allocationFromPool);

View File

@@ -299,6 +299,7 @@ bool Context::createImpl(const cl_context_properties *properties,
setupContextType();
initializeManagers();
initializeDeviceUsmAllocationPool();
smallBufferPoolAllocator.setParams(SmallBuffersParams::getPreferredBufferPoolParams(device->getProductHelper()));
}
@@ -505,19 +506,11 @@ bool Context::isSingleDeviceContext() {
}
void Context::initializeDeviceUsmAllocationPool() {
if (this->usmPoolInitialized) {
return;
}
auto svmMemoryManager = getSVMAllocsManager();
if (!(svmMemoryManager && this->isSingleDeviceContext())) {
return;
}
TakeOwnershipWrapper<Context> lock(*this);
if (this->usmPoolInitialized) {
return;
}
auto &productHelper = getDevices()[0]->getProductHelper();
bool enabled = ApiSpecificConfig::isDeviceUsmPoolingEnabled() &&
productHelper.isDeviceUsmPoolAllocatorSupported() &&
@@ -537,7 +530,6 @@ void Context::initializeDeviceUsmAllocationPool() {
memoryProperties.device = &neoDevice;
usmDeviceMemAllocPool.initialize(svmMemoryManager, memoryProperties, usmDevicePoolParams.poolSize, usmDevicePoolParams.minServicedSize, usmDevicePoolParams.maxServicedSize);
}
this->usmPoolInitialized = true;
}
bool Context::BufferPoolAllocator::isAggregatedSmallBuffersEnabled(Context *context) const {

View File

@@ -304,7 +304,6 @@ class Context : public BaseObject<_cl_context> {
bool interopUserSync = false;
bool resolvesRequiredInKernels = false;
bool usmPoolInitialized = false;
bool platformManagersInitialized = false;
};

View File

@@ -169,6 +169,7 @@ bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
bool requiresWritableStaging = this->clDevices[0]->getDefaultEngine().commandStreamReceiver->getType() != CommandStreamReceiverType::hardware;
this->stagingBufferManager = new StagingBufferManager(this->svmAllocsManager, rootDeviceIndices, deviceBitfields, requiresWritableStaging);
this->initializeHostUsmAllocationPool(rootDeviceIndices, deviceBitfields);
DEBUG_BREAK_IF(this->platformInfo);
this->platformInfo.reset(new PlatformInfo);
@@ -309,17 +310,9 @@ void Platform::decActiveContextCount() {
}
}
void Platform::initializeHostUsmAllocationPool() {
if (this->usmPoolInitialized) {
return;
}
void Platform::initializeHostUsmAllocationPool(const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &deviceBitfields) {
auto svmMemoryManager = this->getSVMAllocsManager();
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->usmPoolInitialized) {
return;
}
auto usmHostAllocPoolingEnabled = ApiSpecificConfig::isHostUsmPoolingEnabled();
for (auto &device : this->clDevices) {
usmHostAllocPoolingEnabled &= device->getProductHelper().isHostUsmPoolAllocatorSupported() && DeviceFactory::isHwModeSelected();
@@ -331,27 +324,9 @@ void Platform::initializeHostUsmAllocationPool() {
usmHostPoolParams.poolSize = debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte;
}
if (usmHostAllocPoolingEnabled) {
RootDeviceIndicesContainer rootDeviceIndices;
std::map<uint32_t, DeviceBitfield> deviceBitfields;
for (auto &device : this->clDevices) {
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
}
for (auto &rootDeviceIndex : rootDeviceIndices) {
DeviceBitfield deviceBitfield{};
for (const auto &pDevice : this->clDevices) {
if (pDevice->getRootDeviceIndex() == rootDeviceIndex) {
deviceBitfield |= pDevice->getDeviceBitfield();
}
}
deviceBitfields.insert({rootDeviceIndex, deviceBitfield});
}
SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M,
rootDeviceIndices, deviceBitfields);
this->usmHostMemAllocPool.initialize(svmMemoryManager, memoryProperties, usmHostPoolParams.poolSize, usmHostPoolParams.minServicedSize, usmHostPoolParams.maxServicedSize);
}
this->usmPoolInitialized = true;
}
} // namespace NEO

View File

@@ -64,7 +64,6 @@ class Platform : public BaseObject<_cl_platform_id> {
SVMAllocsManager *getSVMAllocsManager() const;
StagingBufferManager *getStagingBufferManager() const;
UsmMemAllocPool &getHostMemAllocPool();
void initializeHostUsmAllocationPool();
void incActiveContextCount();
void decActiveContextCount();
@@ -79,6 +78,7 @@ class Platform : public BaseObject<_cl_platform_id> {
};
cl_uint state = StateNone;
void fillGlobalDispatchTable();
void initializeHostUsmAllocationPool(const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &deviceBitfields);
std::unique_ptr<PlatformInfo> platformInfo;
ClDeviceVector clDevices;
ExecutionEnvironment &executionEnvironment;
@@ -88,7 +88,6 @@ class Platform : public BaseObject<_cl_platform_id> {
StagingBufferManager *stagingBufferManager = nullptr;
int32_t activeContextCount = 0;
UsmMemAllocPool usmHostMemAllocPool;
bool usmPoolInitialized = false;
};
static_assert(NEO::NonCopyableAndNonMovable<BaseObject<_cl_platform_id>>);