fix: create dedicated class for root device indices to store unique values

remove method to removing duplicates from StackVec as the method
implicitly sorted the vector

Related-To: GSD-4692
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-06-12 13:52:45 +00:00
committed by Compute-Runtime-Automation
parent 52651991c2
commit 4f72835b7d
31 changed files with 184 additions and 172 deletions

View File

@@ -70,7 +70,7 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
for (auto device : this->devices) {
auto neoDevice = device->getNEODevice();
context->getDevices().insert(std::make_pair(neoDevice->getRootDeviceIndex(), device->toHandle()));
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
neoDevice->getDeviceBitfield()});
context->addDeviceHandle(device->toHandle());
@@ -79,14 +79,12 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
for (uint32_t i = 0; i < numDevices; i++) {
auto neoDevice = Device::fromHandle(phDevices[i])->getNEODevice();
context->getDevices().insert(std::make_pair(neoDevice->getRootDeviceIndex(), phDevices[i]));
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(),
neoDevice->getDeviceBitfield()});
}
}
context->rootDeviceIndices.remove_duplicates();
return ZE_RESULT_SUCCESS;
}
@@ -216,7 +214,8 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
enableRootDeviceDebugger(neoDevice);
this->rootDeviceIndices.push_back(rootDeviceIndex);
this->rootDeviceIndices.pushUnique(rootDeviceIndex);
this->deviceBitfields.insert({rootDeviceIndex, neoDevice->getDeviceBitfield()});
auto pNeoDevice = neoDevice.release();
@@ -234,7 +233,6 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
return returnValue;
}
}
this->rootDeviceIndices.remove_duplicates();
if (this->devices.size() == 0) {
return ZE_RESULT_ERROR_UNINITIALIZED;

View File

@@ -69,14 +69,13 @@ ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32
}
devices.push_back(eventDevice);
rootDeviceIndices.push_back(eventDevice->getNEODevice()->getRootDeviceIndex());
rootDeviceIndices.pushUnique(eventDevice->getNEODevice()->getRootDeviceIndex());
if (maxRootDeviceIndex < eventDevice->getNEODevice()->getRootDeviceIndex()) {
maxRootDeviceIndex = eventDevice->getNEODevice()->getRootDeviceIndex();
}
isImplicitScalingCapable |= eventDevice->isImplicitScalingCapable();
}
rootDeviceIndices.remove_duplicates();
auto &rootDeviceEnvironment = getDevice()->getNEODevice()->getRootDeviceEnvironment();
auto &l0GfxCoreHelper = rootDeviceEnvironment.getHelper<L0GfxCoreHelper>();

View File

@@ -255,7 +255,7 @@ void GetMemHandlePtrTestFixture::setUp() {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -124,7 +124,7 @@ struct MemoryExportImportTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -236,7 +236,7 @@ struct MemoryExportImportWSLTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -332,7 +332,7 @@ struct MemoryExportImportWinHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -597,7 +597,7 @@ struct MemoryOpenIpcHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -737,7 +737,7 @@ struct MemoryExportImportImplicitScalingTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -74,12 +74,11 @@ void Mock<DriverHandle>::setupDevices(std::vector<std::unique_ptr<NEO::Device>>
this->numDevices = static_cast<uint32_t>(neoDevices.size());
for (auto &neoDevice : neoDevices) {
ze_result_t returnValue = ZE_RESULT_SUCCESS;
this->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
this->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
this->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
auto device = Device::create(this, neoDevice.release(), false, &returnValue);
this->devices.push_back(device);
}
this->rootDeviceIndices.remove_duplicates();
}
Mock<DriverHandle>::~Mock(){};

View File

@@ -2184,10 +2184,9 @@ struct MultipleDevicesFixture : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
DebugManagerStateRestore restorer;
@@ -2483,10 +2482,9 @@ struct MultipleDevicesP2PFixture : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
DebugManagerStateRestore restorer;

View File

@@ -684,6 +684,47 @@ TEST_F(DriverTestMultipleFamilySupport, whenInitializingDriverWithArrayOfDevices
L0::GlobalDriver = nullptr;
}
TEST(MultiRootDeviceDriverTest, whenInitializingDriverHandleWithMultipleDevicesThenOrderInRootDeviceIndicesMatchesOrderInDeviceVector) {
Mock<DriverHandle> driverHandle;
for (auto &device : driverHandle.devices) {
delete device;
}
driverHandle.devices.clear();
UltDeviceFactory deviceFactory{3, 0};
NEO::DeviceVector inputDevices;
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.rootDevices[2]));
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.rootDevices[0]));
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.rootDevices[1]));
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle.initialize(std::move(inputDevices)));
EXPECT_EQ(3u, driverHandle.devices.size());
EXPECT_EQ(3u, driverHandle.rootDeviceIndices.size());
EXPECT_EQ(2u, driverHandle.rootDeviceIndices[0]);
EXPECT_EQ(0u, driverHandle.rootDeviceIndices[1]);
EXPECT_EQ(1u, driverHandle.rootDeviceIndices[2]);
}
TEST(MultiSubDeviceDriverTest, whenInitializingDriverHandleWithMultipleDevicesWithSameRootDeviceIndexThenIndicesInRootDeviceIndicesAreNotDuplicated) {
Mock<DriverHandle> driverHandle;
for (auto &device : driverHandle.devices) {
delete device;
}
driverHandle.devices.clear();
UltDeviceFactory deviceFactory{1, 3};
NEO::DeviceVector inputDevices;
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.subDevices[2]));
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.subDevices[0]));
inputDevices.push_back(std::unique_ptr<NEO::Device>(deviceFactory.subDevices[1]));
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle.initialize(std::move(inputDevices)));
EXPECT_EQ(3u, driverHandle.devices.size());
EXPECT_EQ(1u, driverHandle.rootDeviceIndices.size());
EXPECT_EQ(0u, driverHandle.rootDeviceIndices[0]);
}
struct DriverTestMultipleFamilyNoSupport : public ::testing::Test {
void SetUp() override {

View File

@@ -116,7 +116,7 @@ struct EventPoolFailTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -193,7 +193,7 @@ struct MemoryExportImportObtainFdTest : public ::testing::Test {
}
device = driverHandle->devices[0];
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -611,7 +611,7 @@ struct MemoryObtainFdTest : public ::testing::Test {
}
device = driverHandle->devices[0];
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -1132,7 +1132,7 @@ struct ZexHostPointerTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -1294,7 +1294,7 @@ struct FreeExtTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -1787,7 +1787,7 @@ struct OutOfMemoryTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -1863,7 +1863,7 @@ struct MemoryRelaxedSizeTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -2370,7 +2370,7 @@ struct MemoryExportImportFailTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -3087,10 +3087,9 @@ struct MultipleDevicePeerAllocationFailTest : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
DebugManagerStateRestore restorer;
@@ -3177,10 +3176,9 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, driverHandle->devices[0]->isImplicitScalingCapable());
prevSvmAllocsManager = driverHandle->svmAllocsManager;
@@ -4009,7 +4007,7 @@ struct MemoryFailedOpenIpcHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -4047,7 +4045,7 @@ struct MemoryFailedOpenIpcHandleImplicitScalingTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -4329,7 +4327,7 @@ struct MemoryBitfieldTest : testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -4390,7 +4388,7 @@ TEST(MemoryBitfieldTests, givenDeviceWithValidBitfieldWhenAllocatingSharedMemory
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
memoryManager->recentlyPassedDeviceBitfield = {};
@@ -4825,7 +4823,7 @@ struct SharedAllocFailTests : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
@@ -4897,10 +4895,9 @@ struct SharedAllocMultiDeviceTests : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
void TearDown() override {
@@ -4974,10 +4971,9 @@ struct MemAllocMultiSubDeviceTests : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
void TearDown() override {
@@ -5121,10 +5117,9 @@ struct MultipleDevicePeerImageTest : public ::testing::Test {
auto device = driverHandle->devices[i];
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}
context->rootDeviceIndices.remove_duplicates();
}
void TearDown() override {}

View File

@@ -158,7 +158,7 @@ struct MemoryGetIpcHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -394,7 +394,7 @@ TEST_F(MemoryIPCTests,
contextInvalid = std::make_unique<ContextFdMock>(driverHandle.get());
EXPECT_NE(contextInvalid, nullptr);
contextInvalid->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
contextInvalid->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
contextInvalid->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
contextInvalid->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
ze_ipc_mem_handle_t ipcHandle;
@@ -547,7 +547,7 @@ struct MemoryGetIpcHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -175,7 +175,7 @@ TEST_F(MemoryIPCTests,
contextInvalid = std::make_unique<ContextHandleMock>(driverHandle.get());
EXPECT_NE(contextInvalid, nullptr);
contextInvalid->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
contextInvalid->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
contextInvalid->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
contextInvalid->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
ze_ipc_mem_handle_t ipcHandle;
@@ -302,7 +302,7 @@ struct MemoryGetIpcHandleTest : public ::testing::Test {
EXPECT_NE(context, nullptr);
context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle()));
auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.push_back(neoDevice->getRootDeviceIndex());
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
}

View File

@@ -230,10 +230,9 @@ bool Context::createImpl(const cl_context_properties *properties,
bool containsDeviceWithSubdevices = false;
for (const auto &device : inputDevices) {
rootDeviceIndices.push_back(device->getRootDeviceIndex());
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
containsDeviceWithSubdevices |= device->getNumGenericSubDevices() > 1;
}
rootDeviceIndices.remove_duplicates();
this->driverDiagnostics = driverDiagnostics.release();
if (rootDeviceIndices.size() > 1 && containsDeviceWithSubdevices && !DebugManager.flags.EnableMultiRootDeviceContexts.get()) {

View File

@@ -276,11 +276,10 @@ Buffer *Buffer::create(Context *context,
pRootDeviceIndices = &context->getRootDeviceIndices();
} else {
for (const auto &device : memoryProperties.associatedDevices) {
rootDeviceIndices.push_back(device->getRootDeviceIndex());
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
}
defaultDevice = memoryProperties.associatedDevices[0];
defaultRootDeviceIndex = rootDeviceIndices[0];
rootDeviceIndices.remove_duplicates();
pRootDeviceIndices = &rootDeviceIndices;
}

View File

@@ -143,11 +143,10 @@ Image *Image::create(Context *context,
pRootDeviceIndices = &context->getRootDeviceIndices();
} else {
for (const auto &device : memoryProperties.associatedDevices) {
rootDeviceIndices.push_back(device->getRootDeviceIndex());
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
}
defaultDevice = memoryProperties.associatedDevices[0];
defaultRootDeviceIndex = rootDeviceIndices[0];
rootDeviceIndices.remove_duplicates();
pRootDeviceIndices = &rootDeviceIndices;
}

View File

@@ -1790,10 +1790,9 @@ HWTEST_F(CreateHostUnifiedMemoryAllocationTest,
auto maxRootDeviceIndex = numDevices - 1u;
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.reserve(numDevices);
rootDeviceIndices.push_back(0u);
rootDeviceIndices.push_back(1u);
rootDeviceIndices.push_back(2u);
rootDeviceIndices.pushUnique(0u);
rootDeviceIndices.pushUnique(1u);
rootDeviceIndices.pushUnique(2u);
auto rootDeviceIndex = rootDeviceIndices.at(0);
auto deviceBitfield = device0->getDeviceBitfield();
@@ -1836,9 +1835,8 @@ HWTEST_F(CreateHostUnifiedMemoryAllocationTest,
auto maxRootDeviceIndex = numDevices - 1u;
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.reserve(numDevices);
rootDeviceIndices.push_back(0u);
rootDeviceIndices.push_back(2u);
rootDeviceIndices.pushUnique(0u);
rootDeviceIndices.pushUnique(2u);
auto noProgramedRootDeviceIndex = 1u;
auto rootDeviceIndex = rootDeviceIndices.at(0);

View File

@@ -3045,7 +3045,7 @@ TEST(MemoryManagerTest, givenMemoryManagerWithLocalMemoryWhenCreatingMultiGraphi
memoryManager.freeGraphicsMemory(localMemoryAllocation);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.pushUnique(mockRootDeviceIndex);
MultiGraphicsAllocation multiGraphicsAllocation(mockRootDeviceIndex);
@@ -3067,11 +3067,11 @@ TEST(MemoryManagerTest, givenDuplicateRootDeviceIndicesWhenCreatingMultiGraphics
AllocationProperties allocationProperties{mockRootDeviceIndex, MemoryConstants::pageSize, AllocationType::SVM_GPU, systemMemoryBitfield};
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.pushUnique(mockRootDeviceIndex);
rootDeviceIndices.pushUnique(mockRootDeviceIndex);
rootDeviceIndices.pushUnique(mockRootDeviceIndex);
EXPECT_EQ(3u, rootDeviceIndices.size());
EXPECT_EQ(1u, rootDeviceIndices.size());
MultiGraphicsAllocation multiGraphicsAllocation(mockRootDeviceIndex);

View File

@@ -100,9 +100,8 @@ std::unique_ptr<AsyncEventsHandler> &MockContext::getAsyncEventsHandlerUniquePtr
void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSpecialQueue) {
for (auto &pClDevice : devices) {
pClDevice->incRefInternal();
rootDeviceIndices.push_back(pClDevice->getRootDeviceIndex());
rootDeviceIndices.pushUnique(pClDevice->getRootDeviceIndex());
}
rootDeviceIndices.remove_duplicates();
maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
specialQueues.resize(maxRootDeviceIndex + 1u);

View File

@@ -625,10 +625,10 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValueOnSomeOfMultipleEngine
}
TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressRangeIsNonZero) {
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager->getGmmHelper(0);
EXPECT_EQ(0u, rootDeviceIndexReserved);
EXPECT_NE(0u, gmmHelper->decanonize(addressRange.address));

View File

@@ -481,7 +481,7 @@ void CommandStreamReceiver::setTagAllocation(GraphicsAllocation *allocation) {
MultiGraphicsAllocation &CommandStreamReceiver::createTagsMultiAllocation() {
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.push_back(rootDeviceIndex);
rootDeviceIndices.pushUnique(rootDeviceIndex);
auto maxRootDeviceIndex = static_cast<uint32_t>(this->executionEnvironment.rootDeviceEnvironments.size() - 1);
auto allocations = new MultiGraphicsAllocation(maxRootDeviceIndex);

View File

@@ -52,10 +52,10 @@ void DebuggerL0::initialize() {
device->getDeviceBitfield()};
if (!singleAddressSpaceSbaTracking) {
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(device->getRootDeviceIndex());
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
uint32_t rootDeviceIndexReserved = 0;
sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
UNRECOVERABLE_IF(sbaTrackingGpuVa.address == 0u);
properties.gpuAddress = sbaTrackingGpuVa.address;
}

View File

@@ -32,7 +32,7 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
const auto allocationType = constant ? AllocationType::CONSTANT_SURFACE : AllocationType::GLOBAL_SURFACE;
if (globalsAreExported && (svmAllocManager != nullptr)) {
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.push_back(rootDeviceIndex);
rootDeviceIndices.pushUnique(rootDeviceIndex);
std::map<uint32_t, DeviceBitfield> subDeviceBitfields;
subDeviceBitfields.insert({rootDeviceIndex, deviceBitfield});
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, 1, rootDeviceIndices, subDeviceBitfields);

View File

@@ -10,6 +10,7 @@
#include "shared/source/helpers/debug_helpers.h"
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <limits>
#include <tuple>
@@ -247,22 +248,6 @@ class StackVec { // NOLINT(clang-analyzer-optin.performance.Padding)
++onStackSize;
}
void sort() {
std::sort(this->begin(), this->end());
}
void remove_duplicates() { // NOLINT(readability-identifier-naming)
if (1 >= this->size()) {
return;
}
this->sort();
const auto last = std::unique(this->begin(), this->end());
auto currentEnd = this->end();
while (last != currentEnd--) {
this->pop_back();
}
}
void pop_back() { // NOLINT(readability-identifier-naming)
if (usesDynamicMem()) {
dynamicMem->pop_back();
@@ -481,5 +466,23 @@ bool operator!=(const StackVec<T, LhsStackCaps> &lhs,
}
constexpr size_t MaxRootDeviceIndices = 16;
using RootDeviceIndicesContainer = StackVec<uint32_t, MaxRootDeviceIndices>;
class RootDeviceIndicesContainer : protected StackVec<uint32_t, MaxRootDeviceIndices> {
public:
using StackVec<uint32_t, MaxRootDeviceIndices>::StackVec;
using StackVec<uint32_t, MaxRootDeviceIndices>::at;
using StackVec<uint32_t, MaxRootDeviceIndices>::begin;
using StackVec<uint32_t, MaxRootDeviceIndices>::end;
using StackVec<uint32_t, MaxRootDeviceIndices>::size;
using StackVec<uint32_t, MaxRootDeviceIndices>::operator[];
inline void pushUnique(uint32_t rootDeviceIndex) {
if (!indexPresent.test(rootDeviceIndex)) {
push_back(rootDeviceIndex);
indexPresent.set(rootDeviceIndex);
}
}
protected:
std::bitset<MaxRootDeviceIndices> indexPresent{};
};
using RootDeviceIndicesMap = StackVec<std::tuple<uint32_t, uint32_t>, MaxRootDeviceIndices>;

View File

@@ -64,9 +64,8 @@ TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGr
RootDeviceIndicesContainer rootDeviceIndices;
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < getNumRootDevices(); ++rootDeviceIndex) {
rootDeviceIndices.push_back(rootDeviceIndex);
rootDeviceIndices.pushUnique(rootDeviceIndex);
}
rootDeviceIndices.remove_duplicates();
auto maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
auto tagsMultiAllocation = new MultiGraphicsAllocation(maxRootDeviceIndex);
@@ -92,9 +91,8 @@ TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGr
RootDeviceIndicesContainer rootDeviceIndices;
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < getNumRootDevices(); ++rootDeviceIndex) {
rootDeviceIndices.push_back(rootDeviceIndex);
rootDeviceIndices.pushUnique(rootDeviceIndex);
}
rootDeviceIndices.remove_duplicates();
auto maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
auto tagsMultiAllocation = new MultiGraphicsAllocation(maxRootDeviceIndex);

View File

@@ -197,10 +197,10 @@ HWTEST_F(MemoryhManagerMultiContextResourceTests, givenAllocationUsedByManyOsCon
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressFromGfxPartitionIsUsed) {
MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 10;
auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager.getGmmHelper(0);
EXPECT_EQ(0u, rootDeviceIndexReserved);
EXPECT_LE(memoryManager.getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address));
@@ -212,10 +212,10 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReserv
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReservedOnIndex1AndFreedThenAddressFromGfxPartitionIsUsed) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 2u);
OsAgnosticMemoryManager memoryManager(executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(1);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(1);
uint32_t rootDeviceIndexReserved = 10;
auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager.reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager.getGmmHelper(1);
EXPECT_EQ(1u, rootDeviceIndexReserved);
EXPECT_LE(memoryManager.getGfxPartition(1)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address));
@@ -227,22 +227,22 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressIsReserv
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWihtInvalidSizeThenFailureReturnsNullAddressRange) {
MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 10;
// emulate GPU address space exhaust
memoryManager.getGfxPartition(0)->heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000);
auto addressRange = memoryManager.reserveGpuAddress(0ull, (size_t)(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) * 2), rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager.reserveGpuAddress(0ull, (size_t)(memoryManager.getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) * 2), rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_EQ(static_cast<int>(addressRange.address), 0);
}
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservationIsAttemptedWithAnInvalidRequiredPtrThenADifferentRangeIsReturned) {
MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 10;
auto addressRange = memoryManager.reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager.reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_EQ(0u, rootDeviceIndexReserved);
EXPECT_NE(static_cast<int>(addressRange.address), 0x1234);
EXPECT_NE(static_cast<int>(addressRange.size), 0);

View File

@@ -107,7 +107,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
memoryManager = new TestedDrmMemoryManager(true, false, false, *executionEnvironment);
@@ -157,7 +157,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
memoryManager = new TestedDrmMemoryManager(true, false, false, *executionEnvironment);
@@ -198,7 +198,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);
@@ -269,7 +269,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);

View File

@@ -163,7 +163,7 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndMem
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);
@@ -210,7 +210,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndMemory
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);
@@ -269,7 +269,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenMultiRootDeviceEnvironmentAndMe
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
rootDeviceIndices.push_back(rootDeviceIndex);
rootDeviceIndices.pushUnique(rootDeviceIndex);
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);
@@ -302,7 +302,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndNoMemo
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
rootDeviceIndices.pushUnique(i);
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);

View File

@@ -296,10 +296,10 @@ TEST_F(DrmMemoryManagerTest, GivenAllocatePhysicalDeviceMemoryThenSuccessReturne
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedAtIndex1ThenAddressFromGfxPartitionIsUsed) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(1);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(1);
uint32_t rootDeviceIndexReserved = 0;
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager->getGmmHelper(1);
EXPECT_EQ(rootDeviceIndexReserved, 1u);
@@ -310,10 +310,10 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressFromGfxPartitionIsUsed) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager->getGmmHelper(0);
EXPECT_LE(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address));
@@ -323,24 +323,24 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWithAnInvalidRequiredPtrThenDifferentRangeReturned) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memoryManager->reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0x1234, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_NE(static_cast<int>(addressRange.address), 0x1234);
EXPECT_NE(static_cast<int>(addressRange.size), 0);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWhichFailsThenNullRangeReturned) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
// emulate GPU address space exhaust
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
memoryManager->getGfxPartition(0)->heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000);
size_t invalidSize = (size_t)memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_STANDARD) + MemoryConstants::pageSize;
auto addressRange = memoryManager->reserveGpuAddress(0ull, invalidSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0ull, invalidSize, rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_EQ(static_cast<int>(addressRange.address), 0);
}
@@ -6606,10 +6606,10 @@ TEST_F(DrmMemoryManagerTest, givenMakeBosResidentSuccessWhenRegisteringMemoryAll
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGpuAddressReservationIsAttemptedWithKnownAddressAtIndex1ThenAddressFromGfxPartitionIsUsed) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(1);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(1);
uint32_t rootDeviceIndexReserved = 0;
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memoryManager->reserveGpuAddress(0ull, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memoryManager->getGmmHelper(1);
EXPECT_EQ(rootDeviceIndexReserved, 1u);
@@ -6617,7 +6617,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenGp
EXPECT_GT(memoryManager->getGfxPartition(1)->getHeapLimit(HeapIndex::HEAP_STANDARD), gmmHelper->decanonize(addressRange.address));
uint64_t requiredAddr = addressRange.address;
memoryManager->freeGpuAddress(addressRange, 1);
addressRange = memoryManager->reserveGpuAddress(requiredAddr, MemoryConstants::pageSize, rootDevices, &rootDeviceIndexReserved);
addressRange = memoryManager->reserveGpuAddress(requiredAddr, MemoryConstants::pageSize, rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_EQ(rootDeviceIndexReserved, 1u);
EXPECT_EQ(addressRange.address, requiredAddr);

View File

@@ -47,10 +47,10 @@ class WddmMemManagerFixture {
typedef ::Test<WddmMemManagerFixture> WddmMemoryReservationTests;
TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReservedAndFreedThenAddressFromGfxPartitionIsUsed) {
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memManager->getGmmHelper(0);
EXPECT_EQ(rootDeviceIndexReserved, 0u);
@@ -60,11 +60,11 @@ TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReserve
}
TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReservedWithInvalidStartAddresThenDifferentAddressReserved) {
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
uint64_t invalidAddress = 0x1234;
auto addressRange = memManager->reserveGpuAddress(invalidAddress, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memManager->reserveGpuAddress(invalidAddress, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memManager->getGmmHelper(0);
EXPECT_NE(invalidAddress, addressRange.address);
@@ -75,13 +75,13 @@ TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReserve
}
TEST_F(WddmMemoryReservationTests, givenWddmMemoryManagerWhenGpuAddressIsReservedWithValidStartAddresThenSameAddressReserved) {
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
auto previousAddress = addressRange.address;
memManager->freeGpuAddress(addressRange, 0);
auto newAddressRange = memManager->reserveGpuAddress(previousAddress, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto newAddressRange = memManager->reserveGpuAddress(previousAddress, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
auto gmmHelper = memManager->getGmmHelper(0);
EXPECT_EQ(previousAddress, addressRange.address);
@@ -106,10 +106,10 @@ TEST(WddmMemoryReservationFailTest, givenWddmMemoryManagerWhenGpuAddressReservat
wddm->failReserveGpuVirtualAddress = true;
memManager = std::unique_ptr<MemoryReservationMock>(new MemoryReservationMock(*executionEnvironment));
RootDeviceIndicesContainer rootDevices;
rootDevices.push_back(0);
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDevices, &rootDeviceIndexReserved);
auto addressRange = memManager->reserveGpuAddress(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved);
EXPECT_EQ(addressRange.address, 0ull);
EXPECT_EQ(addressRange.size, 0u);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -1704,34 +1704,21 @@ TEST(StackVec, GivenStackVecWithDynamicMemWhenSelfAssignedThenMemoryIsReused) {
}
}
TEST(StackVec, GivenVectorWithDuplicatesWhenRemovingDuplicatesThenVectorIsSortedAndDuplicatesRemoved) {
StackVec<uint32_t, 8> stackVec = {6, 5, 4, 3, 2, 1, 5, 4, 5, 4, 2, 4, 3, 1, 6, 1};
ASSERT_EQ(stackVec.size(), 16u);
TEST(StackVec, whenPushingUniqueToRootDeviceIndicesContainerThenOnlyUniqueValuesArePopulated) {
StackVec<uint32_t, 8> input = {6, 5, 4, 3, 2, 1, 5, 4, 5, 4, 2, 4, 3, 1, 6, 1};
ASSERT_EQ(input.size(), 16u);
stackVec.remove_duplicates();
EXPECT_EQ(stackVec.size(), 6u);
const StackVec<uint32_t, 8> expectedStackVec = {1, 2, 3, 4, 5, 6};
EXPECT_EQ(stackVec, expectedStackVec);
}
RootDeviceIndicesContainer rootDeviceIndices{};
TEST(StackVec, GivenVectorWithoutDuplicatesWhenRemovingDuplicatesThenVectorIsSorted) {
StackVec<uint32_t, 8> stackVec = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
ASSERT_EQ(stackVec.size(), 16u);
for (auto &index : input) {
rootDeviceIndices.pushUnique(index);
}
stackVec.remove_duplicates();
EXPECT_EQ(stackVec.size(), 16u);
const StackVec<uint32_t, 8> expectedStackVec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
EXPECT_EQ(stackVec, expectedStackVec);
}
TEST(StackVec, GivenSortedVectorWithoutDuplicatesWhenRemovingDuplicatesThenVectorIsUnchanged) {
StackVec<uint32_t, 8> stackVec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
ASSERT_EQ(stackVec.size(), 16u);
stackVec.remove_duplicates();
EXPECT_EQ(stackVec.size(), 16u);
const StackVec<uint32_t, 8> expectedStackVec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
EXPECT_EQ(stackVec, expectedStackVec);
EXPECT_EQ(rootDeviceIndices.size(), 6u);
const RootDeviceIndicesContainer expectedContainer = {6, 5, 4, 3, 2, 1};
for (auto i = 0u; i < rootDeviceIndices.size(); i++) {
EXPECT_EQ(rootDeviceIndices[i], expectedContainer[i]);
}
}
int sum(ArrayRef<int> a) {