Use correct INTERNAL heap base address for ISA in system memory

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-05-24 18:57:32 +00:00
committed by Compute-Runtime-Automation
parent bc92cbf9e7
commit 0f32231fc8
7 changed files with 87 additions and 10 deletions

View File

@ -41,9 +41,6 @@ void CommandQueueHw<gfxCoreFamily>::programStateBaseAddress(uint64_t gsba, bool
NEO::MemorySynchronizationCommands<GfxFamily>::addPipeControl(commandStream, pcArgs); NEO::MemorySynchronizationCommands<GfxFamily>::addPipeControl(commandStream, pcArgs);
NEO::Device *neoDevice = device->getNEODevice(); NEO::Device *neoDevice = device->getNEODevice();
auto &hwInfo = neoDevice->getHardwareInfo();
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
NEO::EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(*neoDevice, commandStream, true); NEO::EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(*neoDevice, commandStream, true);
auto pSbaCmd = static_cast<STATE_BASE_ADDRESS *>(commandStream.getSpace(sizeof(STATE_BASE_ADDRESS))); auto pSbaCmd = static_cast<STATE_BASE_ADDRESS *>(commandStream.getSpace(sizeof(STATE_BASE_ADDRESS)));
@ -63,7 +60,7 @@ void CommandQueueHw<gfxCoreFamily>::programStateBaseAddress(uint64_t gsba, bool
true, true,
(device->getMOCS(true, false) >> 1), (device->getMOCS(true, false) >> 1),
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap), neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap),
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), !hwHelper.useSystemMemoryPlacementForISA(hwInfo)), neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), neoDevice->getMemoryManager()->isLocalMemoryUsedForIsa(neoDevice->getRootDeviceIndex())),
globalHeapsBase, globalHeapsBase,
true, true,
useGlobalSshAndDsh, useGlobalSshAndDsh,

View File

@ -1270,6 +1270,49 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryAndDebugModuleAreaTypeWhenCreating
memoryManager.freeGraphicsMemory(moduleDebugArea); memoryManager.freeGraphicsMemory(moduleDebugArea);
} }
TEST(OsAgnosticMemoryManager, givenEnabledLocalMemoryWhenAllocatingGraphicsMemoryForIsaInSystemMemoryThenBaseAddressIsEqualToInternalHeapBaseAddress) {
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
hwInfo->featureTable.ftrLocalMemory = true;
MockMemoryManager memoryManager(false, true, *executionEnvironment);
AllocationData allocationData;
allocationData.type = GraphicsAllocation::AllocationType::KERNEL_ISA;
allocationData.flags.useSystemMemory = 1;
allocationData.size = 4096;
auto allocation = memoryManager.allocateGraphicsMemory(allocationData);
ASSERT_NE(nullptr, allocation);
auto instructionHeapBaseAddress = memoryManager.getInternalHeapBaseAddress(0, false);
EXPECT_EQ(instructionHeapBaseAddress, GmmHelper::decanonize(allocation->getGpuBaseAddress()));
memoryManager.freeGraphicsMemory(allocation);
}
TEST(OsAgnosticMemoryManager, givenForcedSystemMemoryForIsaAndEnabledLocalMemoryWhenAllocatingGraphicsMemoryThenBaseAddressIsEqualToInternalHeapBaseAddress) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceSystemMemoryPlacement.set(1 << (static_cast<uint32_t>(GraphicsAllocation::AllocationType::KERNEL_ISA) - 1));
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
hwInfo->featureTable.ftrLocalMemory = true;
MockMemoryManager memoryManager(false, true, *executionEnvironment);
size_t kernelIsaSize = 4096;
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties({0, kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA, 1});
ASSERT_NE(nullptr, allocation);
auto instructionHeapBaseAddress = memoryManager.getInternalHeapBaseAddress(0, false);
EXPECT_EQ(instructionHeapBaseAddress, GmmHelper::decanonize(allocation->getGpuBaseAddress()));
memoryManager.freeGraphicsMemory(allocation);
}
class MemoryManagerWithAsyncDeleterTest : public ::testing::Test { class MemoryManagerWithAsyncDeleterTest : public ::testing::Test {
public: public:
MemoryManagerWithAsyncDeleterTest() : memoryManager(false, false){}; MemoryManagerWithAsyncDeleterTest() : memoryManager(false, false){};

View File

@ -92,11 +92,9 @@ ErrorCode CommandContainer::initialize(Device *device) {
} }
} }
auto &hwHelper = HwHelper::get(getDevice()->getHardwareInfo().platform.eRenderCoreFamily);
indirectObjectHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), allocationIndirectHeaps[IndirectHeap::Type::INDIRECT_OBJECT]->isAllocatedInLocalMemoryPool()); indirectObjectHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), allocationIndirectHeaps[IndirectHeap::Type::INDIRECT_OBJECT]->isAllocatedInLocalMemoryPool());
instructionHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), !hwHelper.useSystemMemoryPlacementForISA(getDevice()->getHardwareInfo())); instructionHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), device->getMemoryManager()->isLocalMemoryUsedForIsa(device->getRootDeviceIndex()));
iddBlock = nullptr; iddBlock = nullptr;
nextIddInBlock = this->getNumIddPerBlock(); nextIddInBlock = this->getNumIddPerBlock();

View File

@ -399,7 +399,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
auto stateBaseAddressCmdOffset = commandStreamCSR.getUsed(); auto stateBaseAddressCmdOffset = commandStreamCSR.getUsed();
auto pCmd = static_cast<STATE_BASE_ADDRESS *>(commandStreamCSR.getSpace(sizeof(STATE_BASE_ADDRESS))); auto pCmd = static_cast<STATE_BASE_ADDRESS *>(commandStreamCSR.getSpace(sizeof(STATE_BASE_ADDRESS)));
STATE_BASE_ADDRESS cmd; STATE_BASE_ADDRESS cmd;
auto instructionHeapBaseAddress = getMemoryManager()->getInternalHeapBaseAddress(rootDeviceIndex, !hwHelper.useSystemMemoryPlacementForISA(peekHwInfo())); auto instructionHeapBaseAddress = getMemoryManager()->getInternalHeapBaseAddress(rootDeviceIndex, getMemoryManager()->isLocalMemoryUsedForIsa(rootDeviceIndex));
StateBaseAddressHelper<GfxFamily>::programStateBaseAddress( StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(
&cmd, &cmd,
&dsh, &dsh,

View File

@ -52,6 +52,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu
gfxPartitions.push_back(std::make_unique<GfxPartition>(reservedCpuAddressRange)); gfxPartitions.push_back(std::make_unique<GfxPartition>(reservedCpuAddressRange));
anyLocalMemorySupported |= this->localMemorySupported[rootDeviceIndex]; anyLocalMemorySupported |= this->localMemorySupported[rootDeviceIndex];
isLocalMemoryUsedForIsa(rootDeviceIndex);
} }
if (anyLocalMemorySupported) { if (anyLocalMemorySupported) {
@ -440,14 +441,14 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo); hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo);
allocationData.flags.useSystemMemory |= properties.flags.forceSystemMemory; allocationData.flags.useSystemMemory |= properties.flags.forceSystemMemory;
overrideAllocationData(allocationData, properties);
allocationData.flags.isUSMHostAllocation = properties.flags.isUSMHostAllocation;
return true; return true;
} }
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) { GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) {
AllocationData allocationData; AllocationData allocationData;
getAllocationData(allocationData, properties, hostPtr, createStorageInfoFromProperties(properties)); getAllocationData(allocationData, properties, hostPtr, createStorageInfoFromProperties(properties));
overrideAllocationData(allocationData, properties);
allocationData.flags.isUSMHostAllocation = properties.flags.isUSMHostAllocation;
AllocationStatus status = AllocationStatus::Error; AllocationStatus status = AllocationStatus::Error;
GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status); GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
@ -783,6 +784,17 @@ bool MemoryManager::isAllocationTypeToCapture(GraphicsAllocation::AllocationType
return false; return false;
} }
bool MemoryManager::isLocalMemoryUsedForIsa(uint32_t rootDeviceIndex) {
std::call_once(checkIsaPlacementOnce, [&] {
AllocationProperties properties = {rootDeviceIndex, 0x1000, GraphicsAllocation::AllocationType::KERNEL_ISA, 1};
AllocationData data;
getAllocationData(data, properties, nullptr, StorageInfo());
isaInLocalMemory = !data.flags.useSystemMemory;
});
return isaInLocalMemory;
}
bool MemoryTransferHelper::transferMemoryToAllocation(bool useBlitter, const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory, size_t srcSize) { bool MemoryTransferHelper::transferMemoryToAllocation(bool useBlitter, const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory, size_t srcSize) {
if (useBlitter) { if (useBlitter) {
if (BlitHelperFunctions::blitMemoryToAllocation(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}) == BlitOperationResult::Success) { if (BlitHelperFunctions::blitMemoryToAllocation(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}) == BlitOperationResult::Success) {

View File

@ -209,6 +209,7 @@ class MemoryManager {
virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){}; virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){};
virtual void disableGemCloseWorkerForNewResidencyModel(){}; virtual void disableGemCloseWorkerForNewResidencyModel(){};
bool isLocalMemoryUsedForIsa(uint32_t rootDeviceIndex);
protected: protected:
bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo); bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo);
@ -261,6 +262,8 @@ class MemoryManager {
std::unique_ptr<PageFaultManager> pageFaultManager; std::unique_ptr<PageFaultManager> pageFaultManager;
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange; OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
HeapAssigner heapAssigner; HeapAssigner heapAssigner;
std::once_flag checkIsaPlacementOnce;
bool isaInLocalMemory = false;
}; };
std::unique_ptr<DeferredDeleter> createDeferredDeleter(); std::unique_ptr<DeferredDeleter> createDeferredDeleter();

View File

@ -7,6 +7,7 @@
#include "shared/source/command_container/cmdcontainer.h" #include "shared/source/command_container/cmdcontainer.h"
#include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_memory_manager.h"
@ -140,6 +141,29 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeThenEverythingIs
pDevice->getMemoryManager()->getInternalHeapBaseAddress(0, !hwHelper.useSystemMemoryPlacementForISA(pDevice->getHardwareInfo()))); pDevice->getMemoryManager()->getInternalHeapBaseAddress(0, !hwHelper.useSystemMemoryPlacementForISA(pDevice->getHardwareInfo())));
} }
TEST_F(CommandContainerTest, givenEnabledLocalMemoryAndIsaInSystemMemoryWhenCmdContainerIsInitializedThenInstructionBaseAddressIsSetToInternalHeap) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceSystemMemoryPlacement.set(1 << (static_cast<uint32_t>(GraphicsAllocation::AllocationType::KERNEL_ISA) - 1));
auto executionEnvironment = new NEO::ExecutionEnvironment();
const size_t numDevices = 1;
executionEnvironment->prepareRootDeviceEnvironments(numDevices);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
hwInfo->featureTable.ftrLocalMemory = true;
auto device = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
auto instructionHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(0, false);
CommandContainer cmdContainer;
auto status = cmdContainer.initialize(device.get());
EXPECT_EQ(ErrorCode::SUCCESS, status);
EXPECT_EQ(instructionHeapBaseAddress, cmdContainer.getInstructionHeapBaseAddress());
}
TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateGfxMemoryFailsThenErrorIsReturned) { TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateGfxMemoryFailsThenErrorIsReturned) {
CommandContainer cmdContainer; CommandContainer cmdContainer;
pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(0, *pDevice->executionEnvironment)); pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(0, *pDevice->executionEnvironment));