Allow perContext VMs

Related-To: NEO-4637

Change-Id: I599aba9c1c06fd9414cfa14ebb2de3fc504d1cad
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe 2020-07-15 08:07:53 +02:00 committed by sys_ocldev
parent 43f4be3393
commit 7aea294c85
7 changed files with 52 additions and 6 deletions

View File

@ -103,10 +103,11 @@ Drm *Drm::create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &
}
}
if (!drmObject->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()))) {
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "INFO: Device doesn't support GEM Virtual Memory\n");
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
if (!drmObject->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()))) {
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "INFO: Device doesn't support GEM Virtual Memory\n");
}
}
return drmObject.release();
}
} // namespace NEO

View File

@ -430,6 +430,23 @@ TEST_F(DrmTests, whenDrmIsCreatedWithMultipleSubDevicesThenCreateMultipleVirtual
}
}
TEST_F(DrmTests, givenRequiredPerContextMemorySpaceWhenDrmIsCreatedThenGetVirtualMemoryAddressSpaceReturnsZeroAndVMsAreNotCreated) {
DebugManagerStateRestore restore;
DebugManager.flags.CreateMultipleSubDevices.set(2);
rootDeviceEnvironment->executionEnvironment.setPerContextMemorySpace();
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
EXPECT_NE(drm, nullptr);
EXPECT_TRUE(drm->isPerContextVMRequired());
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
for (auto id = 0u; id < numSubDevices; id++) {
EXPECT_EQ(0u, drm->getVirtualMemoryAddressSpace(id));
}
EXPECT_EQ(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
}
TEST_F(DrmTests, givenDrmIsCreatedWhenCreateVirtualMemoryFailsThenReturnVirtualMemoryIdZeroAndPrintDebugMessage) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.PrintDebugMessages.set(true);

View File

@ -35,12 +35,15 @@ class DrmMock : public Drm {
using Drm::nonPersistentContextsSupported;
using Drm::preemptionSupported;
using Drm::query;
using Drm::requirePerContextVM;
using Drm::sliceCountChangeSupported;
using Drm::virtualMemoryIds;
DrmMock(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {
sliceCountChangeSupported = true;
createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
}
}
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {}
DrmMock() : DrmMock(*platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}

View File

@ -35,7 +35,9 @@ Drm *Drm::create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &
return *pDrmToReturnFromCreateFunc;
}
auto drm = new DrmMockDefault(rootDeviceEnvironment);
drm->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
drm->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
}
return drm;
}
} // namespace NEO

View File

@ -359,3 +359,17 @@ TEST(DrmTest, givenDrmWhenCreatingOsContextThenCreateDrmContextWithVmId) {
EXPECT_EQ(1u, contextIds.size());
EXPECT_EQ(SysCalls::vmId, contextIds[0]);
}
TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicitVmIdPerContextIsUsed) {
auto &rootEnv = *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0];
rootEnv.executionEnvironment.setPerContextMemorySpace();
DrmMock drmMock;
EXPECT_TRUE(drmMock.requirePerContextVM);
OsContextLinux osContext1(drmMock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false);
EXPECT_EQ(0u, drmMock.receivedCreateContextId);
OsContextLinux osContext2(drmMock, 5u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false);
EXPECT_EQ(0u, drmMock.receivedCreateContextId);
}

View File

@ -56,6 +56,10 @@ constexpr const char *getIoctlParamString(int param) {
} // namespace IoctlHelper
Drm::Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {
requirePerContextVM = rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired();
}
int Drm::ioctl(unsigned long request, void *arg) {
int ret;
SYSTEM_ENTER();

View File

@ -94,6 +94,9 @@ class Drm {
bool areNonPersistentContextsSupported() const { return nonPersistentContextsSupported; }
void checkNonPersistentContextsSupport();
void setNonPersistentContext(uint32_t drmContextId);
bool isPerContextVMRequired() {
return requirePerContextVM;
}
MemoryInfo *getMemoryInfo() const {
return memoryInfo.get();
@ -115,12 +118,14 @@ class Drm {
drm_i915_gem_context_param_sseu sseu{};
bool preemptionSupported = false;
bool nonPersistentContextsSupported = false;
bool requirePerContextVM = false;
std::unique_ptr<HwDeviceId> hwDeviceId;
int deviceId = 0;
int revisionId = 0;
GTTYPE eGtType = GTTYPE_UNDEFINED;
RootDeviceEnvironment &rootDeviceEnvironment;
Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {}
Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
std::unique_ptr<EngineInfo> engineInfo;
std::unique_ptr<MemoryInfo> memoryInfo;
std::vector<uint32_t> virtualMemoryIds;