Add pageFault migration support for immediate cmdlist submission via flushTask.

Move logic for makeResident & pageFault migration to command place for re-use.

Signed-off-by: Vinod Tipparaju <vinod.tipparaju@intel.com>
This commit is contained in:
Vinod Tipparaju
2021-07-16 16:17:08 +05:30
committed by Compute-Runtime-Automation
parent 37670aeb91
commit a2012e04dc
6 changed files with 231 additions and 20 deletions

View File

@@ -7,10 +7,13 @@
#include "level_zero/core/source/cmdlist/cmdlist.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/command_stream/preemption.h"
#include "shared/source/device/device_info.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "level_zero/core/source/device/device_imp.h"
namespace L0 {
CommandList::~CommandList() {
@@ -124,4 +127,30 @@ NEO::PreemptionMode CommandList::obtainFunctionPreemptionMode(Kernel *kernel) {
return NEO::PreemptionHelper::taskPreemptionMode(device->getDevicePreemptionMode(), flags);
}
void CommandList::makeResidentAndMigrate(bool performMigration) {
for (auto alloc : commandContainer.getResidencyContainer()) {
if (csr->getResidencyAllocations().end() ==
std::find(csr->getResidencyAllocations().begin(), csr->getResidencyAllocations().end(), alloc)) {
csr->makeResident(*alloc);
if (performMigration &&
(alloc->getAllocationType() == NEO::GraphicsAllocation::AllocationType::SVM_GPU ||
alloc->getAllocationType() == NEO::GraphicsAllocation::AllocationType::SVM_CPU)) {
auto pageFaultManager = device->getDriverHandle()->getMemoryManager()->getPageFaultManager();
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(alloc->getGpuAddress()));
}
}
}
}
void CommandList::migrateSharedAllocations() {
auto deviceImp = static_cast<DeviceImp *>(device);
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(deviceImp->getDriverHandle());
std::lock_guard<std::mutex> lock(driverHandleImp->sharedMakeResidentAllocationsLock);
auto pageFaultManager = device->getDriverHandle()->getMemoryManager()->getPageFaultManager();
for (auto alloc : driverHandleImp->sharedMakeResidentAllocations) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(alloc.second->getGpuAddress()));
}
}
} // namespace L0

View File

@@ -248,6 +248,9 @@ struct CommandList : _ze_command_list_handle_t {
uint32_t threadArbitrationPolicy = NEO::ThreadArbitrationPolicy::RoundRobin;
bool isFlushTaskSubmissionEnabled = false;
void makeResidentAndMigrate(bool);
void migrateSharedAllocations();
protected:
std::map<const void *, NEO::GraphicsAllocation *> hostPtrMap;
NEO::EngineGroupType engineGroupType;

View File

@@ -65,6 +65,20 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::executeCommandListImm
this->csr->setRequiredScratchSizes(this->getCommandListPerThreadScratchSize(), this->getCommandListPerThreadScratchSize());
if (performMigration) {
auto deviceImp = static_cast<DeviceImp *>(this->device);
auto pageFaultManager = deviceImp->getDriverHandle()->getMemoryManager()->getPageFaultManager();
if (pageFaultManager == nullptr) {
performMigration = false;
}
}
this->makeResidentAndMigrate(performMigration);
if (performMigration) {
this->migrateSharedAllocations();
}
auto completionStamp = this->csr->flushTask(
*commandStream,
commandStreamStart,
@@ -319,9 +333,17 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendEventReset(ze_e
template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendPageFaultCopy(NEO::GraphicsAllocation *dstptr, NEO::GraphicsAllocation *srcptr, size_t size, bool flushHost) {
if (this->isFlushTaskSubmissionEnabled) {
checkAvailableSpace();
}
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendPageFaultCopy(dstptr, srcptr, size, flushHost);
if (ret == ZE_RESULT_SUCCESS) {
executeCommandListImmediate(false);
if (this->isFlushTaskSubmissionEnabled) {
executeCommandListImmediateWithFlushTask(false);
} else {
executeCommandListImmediate(false);
}
}
return ret;
}

View File

@@ -359,28 +359,13 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
commandList->getPrintfFunctionContainer().begin(),
commandList->getPrintfFunctionContainer().end());
for (auto alloc : commandList->commandContainer.getResidencyContainer()) {
if (csr->getResidencyAllocations().end() ==
std::find(csr->getResidencyAllocations().begin(), csr->getResidencyAllocations().end(), alloc)) {
csr->makeResident(*alloc);
if (performMigration) {
if (alloc &&
(alloc->getAllocationType() == NEO::GraphicsAllocation::AllocationType::SVM_GPU ||
alloc->getAllocationType() == NEO::GraphicsAllocation::AllocationType::SVM_CPU)) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(alloc->getGpuAddress()));
}
}
}
}
commandList->csr = csr;
commandList->makeResidentAndMigrate(performMigration);
}
if (performMigration) {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(device->getDriverHandle());
std::lock_guard<std::mutex> lock(driverHandleImp->sharedMakeResidentAllocationsLock);
for (auto alloc : driverHandleImp->sharedMakeResidentAllocations) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(alloc.second->getGpuAddress()));
}
auto commandList = CommandList::fromHandle(phCommandLists[0]);
commandList->migrateSharedAllocations();
}
if (stateSipRequired) {