mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Moving rootDeviceIndex from DrmMemoryOperationsHandlerBind to base class
This fix will allow all DrmMemoryOperationsHandler objects to be sorted correctly Related-To: NEO-7505 Signed-off-by: Andrzej Koska andrzej.koska@intel.com
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
fa44d61fd8
commit
52c7c96635
@ -1355,6 +1355,8 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenVmBindAvailableUseWaitCall
|
||||
|
||||
struct MockMergeResidencyContainerMemoryOperationsHandler : public DrmMemoryOperationsHandlerDefault {
|
||||
using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault;
|
||||
MockMergeResidencyContainerMemoryOperationsHandler(uint32_t rootDeviceIndex)
|
||||
: DrmMemoryOperationsHandlerDefault(rootDeviceIndex){};
|
||||
|
||||
ADDMETHOD_NOBASE(mergeWithResidencyContainer, NEO::MemoryOperationsStatus, NEO::MemoryOperationsStatus::SUCCESS,
|
||||
(OsContext * osContext, ResidencyContainer &residencyContainer));
|
||||
@ -1371,7 +1373,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMergeWithResidencyContaine
|
||||
}
|
||||
};
|
||||
|
||||
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(new MockMergeResidencyContainerMemoryOperationsHandler());
|
||||
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(new MockMergeResidencyContainerMemoryOperationsHandler(rootDeviceIndex));
|
||||
auto operationHandler = static_cast<MockMergeResidencyContainerMemoryOperationsHandler *>(executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.get());
|
||||
operationHandler->mergeWithResidencyContainerResult = NEO::MemoryOperationsStatus::FAILED;
|
||||
|
||||
@ -1402,7 +1404,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMergeWithResidencyContaine
|
||||
}
|
||||
};
|
||||
|
||||
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(new MockMergeResidencyContainerMemoryOperationsHandler());
|
||||
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(new MockMergeResidencyContainerMemoryOperationsHandler(rootDeviceIndex));
|
||||
auto operationHandler = static_cast<MockMergeResidencyContainerMemoryOperationsHandler *>(executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.get());
|
||||
operationHandler->mergeWithResidencyContainerResult = NEO::MemoryOperationsStatus::OUT_OF_MEMORY;
|
||||
|
||||
|
@ -46,14 +46,14 @@ void ExecutionEnvironment::sortNeoDevicesDRM() {
|
||||
if (pciOrderVar) {
|
||||
std::vector<uint32_t> presortIndex;
|
||||
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
|
||||
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
|
||||
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
|
||||
presortIndex.push_back(drm->getRootDeviceIndex());
|
||||
}
|
||||
|
||||
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberDRM);
|
||||
|
||||
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
|
||||
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
|
||||
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
|
||||
if (drm->getRootDeviceIndex() != presortIndex[i]) {
|
||||
drm->setRootDeviceIndex(presortIndex[i]);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class Drm;
|
||||
class OsContext;
|
||||
class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
public:
|
||||
DrmMemoryOperationsHandler() = default;
|
||||
DrmMemoryOperationsHandler(uint32_t rootDeviceIndex) : rootDeviceIndex(rootDeviceIndex){};
|
||||
~DrmMemoryOperationsHandler() override = default;
|
||||
|
||||
virtual MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
|
||||
@ -27,7 +27,15 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
|
||||
static std::unique_ptr<DrmMemoryOperationsHandler> create(Drm &drm, uint32_t rootDeviceIndex);
|
||||
|
||||
uint32_t getRootDeviceIndex() const {
|
||||
return this->rootDeviceIndex;
|
||||
}
|
||||
void setRootDeviceIndex(uint32_t index) {
|
||||
this->rootDeviceIndex = index;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::mutex mutex;
|
||||
uint32_t rootDeviceIndex = 0;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
@ -23,8 +23,7 @@
|
||||
namespace NEO {
|
||||
|
||||
DrmMemoryOperationsHandlerBind::DrmMemoryOperationsHandlerBind(const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t rootDeviceIndex)
|
||||
: rootDeviceEnvironment(rootDeviceEnvironment),
|
||||
rootDeviceIndex(rootDeviceIndex){};
|
||||
: DrmMemoryOperationsHandler(rootDeviceIndex), rootDeviceEnvironment(rootDeviceEnvironment){};
|
||||
|
||||
DrmMemoryOperationsHandlerBind::~DrmMemoryOperationsHandlerBind() = default;
|
||||
|
||||
|
@ -27,18 +27,9 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler {
|
||||
|
||||
MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
|
||||
|
||||
uint32_t getRootDeviceIndex() {
|
||||
return this->rootDeviceIndex;
|
||||
}
|
||||
void setRootDeviceIndex(uint32_t index) {
|
||||
this->rootDeviceIndex = index;
|
||||
}
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL int evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield);
|
||||
MemoryOperationsStatus evictUnusedAllocationsImpl(std::vector<GraphicsAllocation *> &allocationsForEviction, bool waitForCompletion);
|
||||
|
||||
const RootDeviceEnvironment &rootDeviceEnvironment;
|
||||
uint32_t rootDeviceIndex = 0;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
@ -19,7 +19,7 @@ std::unique_ptr<DrmMemoryOperationsHandler> DrmMemoryOperationsHandler::create(D
|
||||
return std::make_unique<DrmMemoryOperationsHandlerBind>(drm.getRootDeviceEnvironment(), rootDeviceIndex);
|
||||
}
|
||||
|
||||
return std::make_unique<DrmMemoryOperationsHandlerDefault>();
|
||||
return std::make_unique<DrmMemoryOperationsHandlerDefault>(rootDeviceIndex);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
@ -13,7 +13,9 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault() = default;
|
||||
DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault(uint32_t rootDeviceIndex)
|
||||
: DrmMemoryOperationsHandler(rootDeviceIndex){};
|
||||
;
|
||||
DrmMemoryOperationsHandlerDefault::~DrmMemoryOperationsHandlerDefault() = default;
|
||||
|
||||
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
|
||||
|
@ -14,7 +14,7 @@ namespace NEO {
|
||||
class OsContextLinux;
|
||||
class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
|
||||
public:
|
||||
DrmMemoryOperationsHandlerDefault();
|
||||
DrmMemoryOperationsHandlerDefault(uint32_t rootDeviceIndex);
|
||||
~DrmMemoryOperationsHandlerDefault() override;
|
||||
|
||||
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "shared/source/os_interface/linux/drm_allocation.h"
|
||||
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
|
||||
#include "shared/source/os_interface/linux/os_context_linux.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/source/utilities/tag_allocator.h"
|
||||
@ -29,6 +30,7 @@
|
||||
#include "shared/test/common/mocks/mock_execution_environment.h"
|
||||
#include "shared/test/common/mocks/mock_gmm_client_context.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture_prelim.h"
|
||||
#include "shared/test/common/test_macros/hw_test.h"
|
||||
|
||||
#include <memory>
|
||||
@ -152,6 +154,96 @@ TEST_F(DrmMemoryOperationsHandlerBindMultiRootDeviceTest, whenSetNewResourceBoun
|
||||
}
|
||||
}
|
||||
|
||||
template <uint32_t numRootDevices>
|
||||
struct DrmMemoryOperationsHandlerBindFixture2 : public ::testing::Test {
|
||||
public:
|
||||
void setUp(bool setPerContextVms) {
|
||||
DebugManager.flags.DeferOsContextInitialization.set(0);
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2u);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
|
||||
executionEnvironment = new ExecutionEnvironment;
|
||||
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
||||
for (uint32_t i = 0u; i < numRootDevices; i++) {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
|
||||
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
||||
}
|
||||
executionEnvironment->calculateMaxOsContextCount();
|
||||
for (uint32_t i = 0u; i < numRootDevices; i++) {
|
||||
auto mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[i]);
|
||||
mock->setBindAvailable();
|
||||
if (setPerContextVms) {
|
||||
mock->setPerContextVMRequired(setPerContextVms);
|
||||
mock->incrementVmId = true;
|
||||
}
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
|
||||
if (i == 0) {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.reset(new DrmMemoryOperationsHandlerDefault(i));
|
||||
} else {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.reset(new MockDrmMemoryOperationsHandlerBind(*executionEnvironment->rootDeviceEnvironments[i].get(), i));
|
||||
}
|
||||
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
||||
|
||||
devices.emplace_back(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, i));
|
||||
}
|
||||
memoryManager = std::make_unique<TestedDrmMemoryManager>(*executionEnvironment);
|
||||
deviceDefault = devices[0].get();
|
||||
device = devices[1].get();
|
||||
mock = executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<DrmQueryMock>();
|
||||
operationHandlerDefault = static_cast<DrmMemoryOperationsHandlerDefault *>(executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.get());
|
||||
operationHandler = static_cast<MockDrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[1]->memoryOperationsInterface.get());
|
||||
memoryManagerBackup = executionEnvironment->memoryManager.release();
|
||||
executionEnvironment->memoryManager.reset(memoryManager.get());
|
||||
memoryManager->registeredEngines = memoryManagerBackup->getRegisteredEngines();
|
||||
}
|
||||
void SetUp() override {
|
||||
setUp(false);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
executionEnvironment->memoryManager.release();
|
||||
executionEnvironment->memoryManager.reset(memoryManagerBackup);
|
||||
memoryManager->getRegisteredEngines().clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
MockDevice *device;
|
||||
MockDevice *deviceDefault;
|
||||
std::vector<std::unique_ptr<MockDevice>> devices;
|
||||
std::unique_ptr<TestedDrmMemoryManager> memoryManager;
|
||||
DrmMemoryOperationsHandlerDefault *operationHandlerDefault = nullptr;
|
||||
MockDrmMemoryOperationsHandlerBind *operationHandler = nullptr;
|
||||
DebugManagerStateRestore restorer;
|
||||
DrmQueryMock *mock;
|
||||
MemoryManager *memoryManagerBackup;
|
||||
};
|
||||
|
||||
using DrmMemoryOperationsHandlerBindMultiRootDeviceTest2 = DrmMemoryOperationsHandlerBindFixture2<2u>;
|
||||
|
||||
TEST_F(DrmMemoryOperationsHandlerBindMultiRootDeviceTest2, givenOperationHandlersWhenRootDeviceIndexIsChangedThenEvictSucceeds) {
|
||||
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize});
|
||||
auto allocationDefult = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{deviceDefault->getRootDeviceIndex(), MemoryConstants::pageSize});
|
||||
|
||||
EXPECT_EQ(operationHandlerDefault->getRootDeviceIndex(), 0u);
|
||||
EXPECT_EQ(operationHandler->getRootDeviceIndex(), 1u);
|
||||
|
||||
operationHandlerDefault->makeResident(device, ArrayRef<GraphicsAllocation *>(&allocationDefult, 1));
|
||||
operationHandler->makeResident(device, ArrayRef<GraphicsAllocation *>(&allocation, 1));
|
||||
|
||||
operationHandlerDefault->setRootDeviceIndex(1u);
|
||||
operationHandler->setRootDeviceIndex(0u);
|
||||
EXPECT_EQ(operationHandlerDefault->getRootDeviceIndex(), 1u);
|
||||
EXPECT_EQ(operationHandler->getRootDeviceIndex(), 0u);
|
||||
|
||||
EXPECT_EQ(operationHandlerDefault->evict(device, *allocationDefult), MemoryOperationsStatus::SUCCESS);
|
||||
EXPECT_EQ(operationHandler->evict(device, *allocation), MemoryOperationsStatus::SUCCESS);
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocationDefult);
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
using DrmMemoryOperationsHandlerBindTest = DrmMemoryOperationsHandlerBindFixture<1u>;
|
||||
|
||||
TEST_F(DrmMemoryOperationsHandlerBindTest, whenNoSpaceLeftOnDeviceThenEvictUnusedAllocations) {
|
||||
|
@ -14,13 +14,13 @@
|
||||
using namespace NEO;
|
||||
|
||||
struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault {
|
||||
using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault;
|
||||
using DrmMemoryOperationsHandlerDefault::residency;
|
||||
};
|
||||
|
||||
struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandlerDefault>();
|
||||
|
||||
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandlerDefault>(0);
|
||||
allocationPtr = &graphicsAllocation;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user