Handle VM BIND events - extract ISA allocation info

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe 2021-05-19 11:52:10 +00:00 committed by Compute-Runtime-Automation
parent b50a6bec82
commit 32729f6feb
7 changed files with 59 additions and 2 deletions

View File

@ -13,6 +13,7 @@
#include "shared/source/helpers/constants.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/memory_operations_handler.h"
#include "shared/source/os_interface/os_context.h"
#include <cstring>
@ -62,10 +63,15 @@ void DebuggerL0::initialize() {
DebugAreaHeader debugArea = {};
debugArea.size = sizeof(DebugAreaHeader);
debugArea.pgsize = 1;
debugArea.isShared = 0;
debugArea.isShared = moduleDebugArea->storageInfo.getNumBanks() == 1;
debugArea.scratchBegin = sizeof(DebugAreaHeader);
debugArea.scratchEnd = MemoryConstants::pageSize64k - sizeof(DebugAreaHeader);
NEO::MemoryOperationsHandler *memoryOperationsIface = device->getRootDeviceEnvironment().memoryOperationsInterface.get();
if (memoryOperationsIface) {
memoryOperationsIface->makeResident(device, ArrayRef<NEO::GraphicsAllocation *>(&moduleDebugArea, 1));
}
NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *moduleDebugArea),
*device, moduleDebugArea, 0, &debugArea,
sizeof(DebugAreaHeader));

View File

@ -16,6 +16,7 @@
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/kernel/kernel_descriptor.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/memory_operations_handler.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/utilities/arrayref.h"
@ -126,6 +127,13 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device
auto &hwInfo = neoDevice->getHardwareInfo();
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
if (device->getL0Debugger()) {
NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get();
if (memoryOperationsIface) {
memoryOperationsIface->makeResident(neoDevice, ArrayRef<NEO::GraphicsAllocation *>(&allocation, 1));
}
}
if (kernelInfo->heapInfo.pKernelHeap != nullptr && internalKernel == false) {
NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *allocation),
*neoDevice, allocation, 0, kernelInfo->heapInfo.pKernelHeap,

View File

@ -7,6 +7,7 @@
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
#include "opencl/test/unit_test/mocks/mock_compilers.h"
@ -24,6 +25,9 @@ struct L0DebuggerFixture {
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
memoryOperationsHandler = new NEO::MockMemoryOperations();
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(memoryOperationsHandler);
hwInfo = *NEO::defaultHwInfo.get();
hwInfo.featureTable.ftrLocalMemory = true;
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
@ -47,6 +51,7 @@ struct L0DebuggerFixture {
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
NEO::HardwareInfo hwInfo;
MockMemoryOperations *memoryOperationsHandler = nullptr;
};
struct L0DebuggerHwFixture : public L0DebuggerFixture {

View File

@ -731,9 +731,12 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate
VariableBackup<NEO::BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup(
&NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation);
memoryOperationsHandler->makeResidentCalledCount = 0;
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(neoDevice);
auto debugArea = debugger->getModuleDebugArea();
EXPECT_EQ(1, memoryOperationsHandler->makeResidentCalledCount);
auto allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{neoDevice->getRootDeviceIndex(), 4096, NEO::GraphicsAllocation::AllocationType::KERNEL_ISA, neoDevice->getDeviceBitfield()});
@ -741,7 +744,8 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate
DebugAreaHeader *header = reinterpret_cast<DebugAreaHeader *>(debugArea->getUnderlyingBuffer());
EXPECT_EQ(1u, header->pgsize);
EXPECT_EQ(0u, header->isShared);
uint64_t isShared = debugArea->storageInfo.getNumBanks() == 1 ? 1 : 0;
EXPECT_EQ(isShared, header->isShared);
EXPECT_STREQ("dbgarea", header->magic);
EXPECT_EQ(sizeof(DebugAreaHeader), header->size);

View File

@ -384,6 +384,19 @@ TEST_F(ModuleWithDebuggerL0Test, givenDebuggingEnabledWhenModuleIsCreatedThenDeb
EXPECT_FALSE(CompilerOptions::contains(cip->buildInternalOptions, L0::BuildOptions::debugKernelEnable));
EXPECT_FALSE(CompilerOptions::contains(cip->buildOptions, NEO::CompilerOptions::generateDebugInfo));
EXPECT_FALSE(CompilerOptions::contains(cip->buildOptions, L0::BuildOptions::optDisable));
}
TEST_F(ModuleWithDebuggerL0Test, givenDebuggingEnabledWhenKernelsAreInitializedThenAllocationsAreBound) {
uint32_t kernelHeap = 0;
KernelInfo kernelInfo;
kernelInfo.heapInfo.KernelHeapSize = 1;
kernelInfo.heapInfo.pKernelHeap = &kernelHeap;
KernelImmutableData kernelImmutableData(device);
memoryOperationsHandler->makeResidentCalledCount = 0;
kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false);
EXPECT_EQ(1, memoryOperationsHandler->makeResidentCalledCount);
};
} // namespace ult

View File

@ -28,6 +28,7 @@ DrmMemoryOperationsHandlerBind::~DrmMemoryOperationsHandlerBind() = default;
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
auto &engines = device->getEngines();
for (const auto &engine : engines) {
engine.osContext->ensureContextInitialized();
this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false);
}
return MemoryOperationsStatus::SUCCESS;

View File

@ -33,4 +33,24 @@ class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler {
(Device * device, GraphicsAllocation &gfxAllocation), (override));
};
class MockMemoryOperations : public MemoryOperationsHandler {
public:
MockMemoryOperations() {}
MemoryOperationsStatus makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) override {
makeResidentCalledCount++;
return MemoryOperationsStatus::SUCCESS;
}
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override {
evictCalledCount++;
return MemoryOperationsStatus::SUCCESS;
}
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override {
return MemoryOperationsStatus::SUCCESS;
}
int makeResidentCalledCount = 0;
int evictCalledCount = 0;
};
} // namespace NEO