mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Prefetch kmd-migrated shared allocation to multiple subdevices
Related-To: NEO-6740 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
145f249f0c
commit
ba003dd7dc
@ -254,6 +254,7 @@ DECLARE_DEBUG_VARIABLE(bool, PrintTimestampPacketContents, false, "prints all ti
|
||||
DECLARE_DEBUG_VARIABLE(bool, WddmResidencyLogger, false, "gather Wddm residency statistics to file")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintBOCreateDestroyResult, false, "tracks the result of creation and destruction of BOs")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintBOBindingResult, false, "tracks the result of binding and unbinding of BOs")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintBOPrefetchingResult, false, "tracks the result of prefetching BOs")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintTagAllocationAddress, false, "Print tag allocation address for each engine")
|
||||
DECLARE_DEBUG_VARIABLE(bool, ProvideVerboseImplicitFlush, false, "provides verbose messages about implicit flush mechanism")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintBlitDispatchDetails, false, "Print blit dispatch details")
|
||||
|
@ -116,6 +116,10 @@ void GraphicsAllocation::prepareHostPtrForResidency(CommandStreamReceiver *csr)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GraphicsAllocation::getNumHandlesForKmdSharedAllocation(uint32_t numBanks) {
|
||||
return (numBanks > 1) && (DebugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.get() != 0) ? numBanks : 1u;
|
||||
}
|
||||
|
||||
constexpr uint32_t GraphicsAllocation::objectNotUsed;
|
||||
constexpr uint32_t GraphicsAllocation::objectNotResident;
|
||||
constexpr uint32_t GraphicsAllocation::objectAlwaysResident;
|
||||
|
@ -217,6 +217,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
type == AllocationType::DEBUG_SBA_TRACKING_BUFFER;
|
||||
}
|
||||
|
||||
static uint32_t getNumHandlesForKmdSharedAllocation(uint32_t numBanks);
|
||||
|
||||
void *getReservedAddressPtr() const {
|
||||
return this->reservedAddressRangeInfo.addressPtr;
|
||||
}
|
||||
|
@ -179,6 +179,21 @@ int DrmAllocation::bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vecto
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DrmAllocation::prefetchBO(BufferObject *bo, uint32_t subDeviceId) {
|
||||
auto drm = bo->peekDrm();
|
||||
auto ioctlHelper = drm->getIoctlHelper();
|
||||
auto memoryClassDevice = ioctlHelper->getDrmParamValue(DrmParam::MemoryClassDevice);
|
||||
auto region = static_cast<uint32_t>((memoryClassDevice << 16u) | subDeviceId);
|
||||
auto vmId = drm->getVirtualMemoryAddressSpace(subDeviceId);
|
||||
|
||||
auto result = ioctlHelper->setVmPrefetch(bo->peekAddress(), bo->peekSize(), region, vmId);
|
||||
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOPrefetchingResult.get(), stdout,
|
||||
"prefetch BO=%d to VM %u, range: %llx - %llx, size: %lld, region: %x, result: %d\n",
|
||||
bo->peekHandle(), vmId, bo->peekAddress(), ptrOffset(bo->peekAddress(), bo->peekSize()), bo->peekSize(), region, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void DrmAllocation::registerBOBindExtHandle(Drm *drm) {
|
||||
if (!drm->resourceRegistrationEnabled()) {
|
||||
return;
|
||||
@ -318,15 +333,18 @@ bool DrmAllocation::setMemAdvise(Drm *drm, MemAdviseFlags flags) {
|
||||
|
||||
bool DrmAllocation::setMemPrefetch(Drm *drm, uint32_t subDeviceId) {
|
||||
bool success = true;
|
||||
auto ioctlHelper = drm->getIoctlHelper();
|
||||
auto memoryClassDevice = ioctlHelper->getDrmParamValue(DrmParam::MemoryClassDevice);
|
||||
auto vmId = drm->getVirtualMemoryAddressSpace(subDeviceId);
|
||||
auto numHandles = GraphicsAllocation::getNumHandlesForKmdSharedAllocation(storageInfo.getNumBanks());
|
||||
|
||||
for (auto bo : bufferObjects) {
|
||||
if (bo != nullptr) {
|
||||
auto region = static_cast<uint32_t>((memoryClassDevice << 16u) | subDeviceId);
|
||||
success &= ioctlHelper->setVmPrefetch(bo->peekAddress(), bo->peekSize(), region, vmId);
|
||||
if (numHandles > 1) {
|
||||
for (uint8_t subDeviceId = 0u; subDeviceId < EngineLimits::maxHandleCount; subDeviceId++) {
|
||||
if (storageInfo.memoryBanks.test(subDeviceId)) {
|
||||
auto bo = this->getBOs()[subDeviceId];
|
||||
success &= prefetchBO(bo, subDeviceId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto bo = this->getBO();
|
||||
success = prefetchBO(bo, subDeviceId);
|
||||
}
|
||||
|
||||
return success;
|
||||
|
@ -109,6 +109,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
MOCKABLE_VIRTUAL int makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
||||
MOCKABLE_VIRTUAL int bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
||||
MOCKABLE_VIRTUAL int bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
||||
MOCKABLE_VIRTUAL bool prefetchBO(BufferObject *bo, uint32_t subDeviceId);
|
||||
MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm);
|
||||
void freeRegisteredBOBindExtHandles(Drm *drm);
|
||||
void linkWithRegisteredHandle(uint32_t handle);
|
||||
|
@ -1859,15 +1859,12 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const
|
||||
BufferObjects bos{};
|
||||
auto currentAddress = cpuPointer;
|
||||
auto remainingSize = size;
|
||||
auto getNumHandles = [](uint32_t numBanks) -> uint32_t {
|
||||
return (numBanks > 1) && (DebugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.get() != 0) ? numBanks : 1u;
|
||||
};
|
||||
auto numHandles = GraphicsAllocation::getNumHandlesForKmdSharedAllocation(allocationData.storageInfo.getNumBanks());
|
||||
|
||||
auto handles = getNumHandles(allocationData.storageInfo.getNumBanks());
|
||||
for (auto handleId = 0u; handleId < handles; handleId++) {
|
||||
for (auto handleId = 0u; handleId < numHandles; handleId++) {
|
||||
uint32_t handle = 0;
|
||||
|
||||
auto currentSize = alignUp(remainingSize / (handles - handleId), MemoryConstants::pageSize64k);
|
||||
auto currentSize = alignUp(remainingSize / (numHandles - handleId), MemoryConstants::pageSize64k);
|
||||
if (currentSize == 0) {
|
||||
break;
|
||||
}
|
||||
@ -1917,7 +1914,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if (handles > 1) {
|
||||
if (numHandles > 1) {
|
||||
allocation->storageInfo = allocationData.storageInfo;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,12 @@ class MockDrmAllocation : public DrmAllocation {
|
||||
using DrmAllocation::memoryPool;
|
||||
using DrmAllocation::registeredBoBindHandles;
|
||||
|
||||
MockDrmAllocation(AllocationType allocationType, MemoryPool pool) : DrmAllocation(0, allocationType, nullptr, nullptr, 0, static_cast<size_t>(0), pool) {
|
||||
MockDrmAllocation(AllocationType allocationType, MemoryPool pool)
|
||||
: DrmAllocation(0, allocationType, nullptr, nullptr, 0, static_cast<size_t>(0), pool) {
|
||||
}
|
||||
|
||||
MockDrmAllocation(AllocationType allocationType, MemoryPool pool, BufferObjects &bos)
|
||||
: DrmAllocation(0, 0, allocationType, bos, nullptr, 0, static_cast<size_t>(0), pool) {
|
||||
}
|
||||
|
||||
void registerBOBindExtHandle(Drm *drm) override {
|
||||
@ -61,12 +66,20 @@ class MockDrmAllocation : public DrmAllocation {
|
||||
return bindBOsRetValue;
|
||||
}
|
||||
|
||||
bool prefetchBO(BufferObject *bo, uint32_t subDeviceId) override {
|
||||
prefetchBOCalled = true;
|
||||
subDeviceIdsReceived.push_back(subDeviceId);
|
||||
return DrmAllocation::prefetchBO(bo, subDeviceId);
|
||||
}
|
||||
|
||||
ADDMETHOD_NOBASE(makeBOsResident, int, 0, (OsContext * osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind));
|
||||
|
||||
bool registerBOBindExtHandleCalled = false;
|
||||
bool markedForCapture = false;
|
||||
bool bindBOsCalled = false;
|
||||
int bindBOsRetValue = 0;
|
||||
bool prefetchBOCalled = false;
|
||||
std::vector<uint32_t> subDeviceIdsReceived;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
@ -91,6 +91,7 @@ PrintTimestampPacketContents = 0
|
||||
WddmResidencyLogger = 0
|
||||
PrintBOCreateDestroyResult = 0
|
||||
PrintBOBindingResult = 0
|
||||
PrintBOPrefetchingResult = 0
|
||||
PrintDriverDiagnostics = -1
|
||||
PrintDeviceAndEngineIdOnSubmission = 0
|
||||
EnableDirectSubmission = -1
|
||||
|
@ -5,6 +5,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_aub_csr.h"
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
@ -197,6 +198,19 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsImageThenAllocationIsNotLockabl
|
||||
EXPECT_FALSE(GraphicsAllocation::isLockable(AllocationType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(GraphicsAllocationTest, givenNumMemoryBanksWhenGettingNumHandlesForKmdSharedAllocationThenReturnCorrectValue) {
|
||||
DebugManagerStateRestore restore;
|
||||
|
||||
EXPECT_EQ(1u, GraphicsAllocation::getNumHandlesForKmdSharedAllocation(1));
|
||||
EXPECT_EQ(2u, GraphicsAllocation::getNumHandlesForKmdSharedAllocation(2));
|
||||
|
||||
DebugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.set(0);
|
||||
EXPECT_EQ(1u, GraphicsAllocation::getNumHandlesForKmdSharedAllocation(2));
|
||||
|
||||
DebugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.set(1);
|
||||
EXPECT_EQ(2u, GraphicsAllocation::getNumHandlesForKmdSharedAllocation(2));
|
||||
}
|
||||
|
||||
TEST(GraphicsAllocationTest, givenDefaultAllocationWhenGettingNumHandlesThenOneIsReturned) {
|
||||
MockGraphicsAllocation graphicsAllocation;
|
||||
EXPECT_EQ(1u, graphicsAllocation.getNumGmms());
|
||||
|
@ -4162,7 +4162,35 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemAdviseIsCalledThenUp
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThenReturnTrue) {
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThenPrefetchBOsToMultipleSubDevices) {
|
||||
TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment);
|
||||
BufferObject bo0(mock, 3, 1, 1024, 0);
|
||||
BufferObject bo1(mock, 3, 2, 1024, 0);
|
||||
BufferObjects bos{&bo0, &bo1};
|
||||
|
||||
MockDrmAllocation drmAllocation(AllocationType::UNIFIED_SHARED_MEMORY, MemoryPool::LocalMemory, bos);
|
||||
drmAllocation.storageInfo.memoryBanks = 0x3;
|
||||
|
||||
memoryManager.registeredEngines = EngineControlContainer{this->device->allEngines};
|
||||
for (auto engine : memoryManager.registeredEngines) {
|
||||
engine.osContext->incRefInternal();
|
||||
}
|
||||
|
||||
EXPECT_TRUE(memoryManager.setMemPrefetch(&drmAllocation, 0, rootDeviceIndex));
|
||||
|
||||
EXPECT_TRUE(drmAllocation.bindBOsCalled);
|
||||
EXPECT_TRUE(drmAllocation.prefetchBOCalled);
|
||||
|
||||
ASSERT_EQ(2u, drmAllocation.subDeviceIdsReceived.size());
|
||||
for (uint32_t subDeviceId = 0; subDeviceId < drmAllocation.subDeviceIdsReceived.size(); subDeviceId++) {
|
||||
EXPECT_EQ(subDeviceId, drmAllocation.subDeviceIdsReceived[subDeviceId]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenCreateKmdMigratedSharedAllocationWithMultipleBOsSetToFalseWhenSetMemPrefetchIsCalledThenPrefetchBOToSubdevice) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateKmdMigratedSharedAllocationWithMultipleBOs.set(false);
|
||||
|
||||
TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment);
|
||||
BufferObject bo(mock, 3, 1, 1024, 0);
|
||||
|
||||
@ -4177,6 +4205,10 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThen
|
||||
EXPECT_TRUE(memoryManager.setMemPrefetch(&drmAllocation, 0, rootDeviceIndex));
|
||||
|
||||
EXPECT_TRUE(drmAllocation.bindBOsCalled);
|
||||
EXPECT_TRUE(drmAllocation.prefetchBOCalled);
|
||||
|
||||
ASSERT_EQ(1u, drmAllocation.subDeviceIdsReceived.size());
|
||||
EXPECT_EQ(0u, drmAllocation.subDeviceIdsReceived[0]);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchFailsToBindBufferObjectThenReturnFalse) {
|
||||
@ -4196,6 +4228,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchFailsToBindB
|
||||
EXPECT_FALSE(memoryManager.setMemPrefetch(&drmAllocation, 0, rootDeviceIndex));
|
||||
|
||||
EXPECT_TRUE(drmAllocation.bindBOsCalled);
|
||||
EXPECT_FALSE(drmAllocation.prefetchBOCalled);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenPageFaultIsUnSupportedWhenCallingBindBoOnBufferAllocationThenAllocationShouldNotPageFaultAndExplicitResidencyIsNotRequired) {
|
||||
|
Reference in New Issue
Block a user