mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 22:43:00 +08:00
Add mechanism to migrate multi root device memory
invalidate TLB cache if kernel requires migration Related-To: NEO-3691 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
714a1ebf53
commit
6f3c89decb
@@ -9,6 +9,8 @@ set(RUNTIME_SRCS_MEMORY_MANAGER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/compression_selector_ocl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cpu_page_fault_manager_memory_sync.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mem_obj_surface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/migration_controller.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/migration_controller.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resource_surface.h
|
||||
)
|
||||
|
||||
|
||||
97
opencl/source/memory_manager/migration_controller.cpp
Normal file
97
opencl/source/memory_manager/migration_controller.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "opencl/source/memory_manager/migration_controller.h"
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/memory_manager/migration_sync_data.h"
|
||||
|
||||
#include "opencl/source/command_queue/command_queue.h"
|
||||
#include "opencl/source/context/context.h"
|
||||
#include "opencl/source/mem_obj/image.h"
|
||||
#include "opencl/source/mem_obj/mem_obj.h"
|
||||
|
||||
namespace NEO {
|
||||
class MemoryManager;
|
||||
class CommandStreamReceiver;
|
||||
class MultiGraphicsAllocation;
|
||||
void MigrationController::handleMigration(Context &context, CommandStreamReceiver &targetCsr, MemObj *memObj) {
|
||||
auto memoryManager = targetCsr.getMemoryManager();
|
||||
auto targetRootDeviceIndex = targetCsr.getRootDeviceIndex();
|
||||
auto migrationSyncData = memObj->getMultiGraphicsAllocation().getMigrationSyncData();
|
||||
if (!migrationSyncData->isUsedByTheSameContext(targetCsr.getTagAddress())) {
|
||||
migrationSyncData->waitOnCpu();
|
||||
}
|
||||
if (migrationSyncData->getCurrentLocation() != targetRootDeviceIndex) {
|
||||
migrateMemory(context, *memoryManager, memObj, targetRootDeviceIndex);
|
||||
}
|
||||
migrationSyncData->signalUsage(targetCsr.getTagAddress(), targetCsr.peekTaskCount() + 1);
|
||||
}
|
||||
|
||||
void MigrationController::migrateMemory(Context &context, MemoryManager &memoryManager, MemObj *memObj, uint32_t targetRootDeviceIndex) {
|
||||
auto &multiGraphicsAllocation = memObj->getMultiGraphicsAllocation();
|
||||
auto migrationSyncData = multiGraphicsAllocation.getMigrationSyncData();
|
||||
|
||||
auto sourceRootDeviceIndex = migrationSyncData->getCurrentLocation();
|
||||
if (sourceRootDeviceIndex == std::numeric_limits<uint32_t>::max()) {
|
||||
migrationSyncData->setCurrentLocation(targetRootDeviceIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
migrationSyncData->startMigration();
|
||||
|
||||
auto srcMemory = multiGraphicsAllocation.getGraphicsAllocation(sourceRootDeviceIndex);
|
||||
auto dstMemory = multiGraphicsAllocation.getGraphicsAllocation(targetRootDeviceIndex);
|
||||
|
||||
auto size = srcMemory->getUnderlyingBufferSize();
|
||||
auto hostPtr = migrationSyncData->getHostPtr();
|
||||
|
||||
if (srcMemory->isAllocationLockable()) {
|
||||
auto srcLockPtr = memoryManager.lockResource(srcMemory);
|
||||
memcpy_s(hostPtr, size, srcLockPtr, size);
|
||||
memoryManager.unlockResource(srcMemory);
|
||||
} else {
|
||||
|
||||
auto srcCmdQ = context.getSpecialQueue(sourceRootDeviceIndex);
|
||||
if (srcMemory->getAllocationType() == GraphicsAllocation::AllocationType::IMAGE) {
|
||||
auto pImage = static_cast<Image *>(memObj);
|
||||
size_t origin[3] = {};
|
||||
size_t region[3] = {};
|
||||
pImage->fillImageRegion(region);
|
||||
|
||||
srcCmdQ->enqueueReadImage(pImage, CL_TRUE, origin, region, pImage->getHostPtrRowPitch(), pImage->getHostPtrSlicePitch(), hostPtr, nullptr, 0, nullptr, nullptr);
|
||||
} else {
|
||||
auto pBuffer = static_cast<Buffer *>(memObj);
|
||||
srcCmdQ->enqueueReadBuffer(pBuffer, CL_TRUE, 0u, pBuffer->getSize(), hostPtr, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
srcCmdQ->finish();
|
||||
}
|
||||
|
||||
if (dstMemory->isAllocationLockable()) {
|
||||
auto dstLockPtr = memoryManager.lockResource(dstMemory);
|
||||
memcpy_s(dstLockPtr, size, hostPtr, size);
|
||||
memoryManager.unlockResource(dstMemory);
|
||||
} else {
|
||||
|
||||
auto dstCmdQ = context.getSpecialQueue(targetRootDeviceIndex);
|
||||
if (dstMemory->getAllocationType() == GraphicsAllocation::AllocationType::IMAGE) {
|
||||
auto pImage = static_cast<Image *>(memObj);
|
||||
size_t origin[3] = {};
|
||||
size_t region[3] = {};
|
||||
pImage->fillImageRegion(region);
|
||||
|
||||
dstCmdQ->enqueueWriteImage(pImage, CL_TRUE, origin, region, pImage->getHostPtrRowPitch(), pImage->getHostPtrSlicePitch(), hostPtr, nullptr, 0, nullptr, nullptr);
|
||||
} else {
|
||||
auto pBuffer = static_cast<Buffer *>(memObj);
|
||||
dstCmdQ->enqueueWriteBuffer(pBuffer, CL_TRUE, 0u, pBuffer->getSize(), hostPtr, nullptr, 0, nullptr, nullptr);
|
||||
}
|
||||
dstCmdQ->finish();
|
||||
}
|
||||
migrationSyncData->setCurrentLocation(targetRootDeviceIndex);
|
||||
}
|
||||
} // namespace NEO
|
||||
22
opencl/source/memory_manager/migration_controller.h
Normal file
22
opencl/source/memory_manager/migration_controller.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
class MemoryManager;
|
||||
class CommandStreamReceiver;
|
||||
class Context;
|
||||
class MultiGraphicsAllocation;
|
||||
class MemObj;
|
||||
class MigrationController {
|
||||
public:
|
||||
static void handleMigration(Context &context, CommandStreamReceiver &targetCsr, MemObj *memObj);
|
||||
static void migrateMemory(Context &context, MemoryManager &memoryManager, MemObj *memObj, uint32_t targetRootDeviceIndex);
|
||||
};
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user