diff --git a/runtime/command_stream/definitions/engine_node.h b/runtime/command_stream/definitions/engine_node.h index c87a24125f..7e93406c25 100644 --- a/runtime/command_stream/definitions/engine_node.h +++ b/runtime/command_stream/definitions/engine_node.h @@ -42,4 +42,5 @@ static constexpr std::array namespace OCLRT { -constexpr uint32_t maxOsContextCount = (4u * static_cast(EngineInstanceConstants::numGpgpuEngineInstances)) + 1; - struct ResidencyData { ResidencyData() { std::fill_n(resident, sizeof(resident), false); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index c770adedb5..624487bce0 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -398,11 +398,10 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhe TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesAreUsedThenResidencyIsProperlyHandled) { auto executionEnvironment = new ExecutionEnvironment; - std::unique_ptr device0(Device::create(nullptr, executionEnvironment, 0u)); - std::unique_ptr device1(Device::create(nullptr, executionEnvironment, 1u)); + std::unique_ptr device(Device::create(nullptr, executionEnvironment, 0u)); - auto &commandStreamReceiver0 = device0->getCommandStreamReceiver(); - auto &commandStreamReceiver1 = device1->getCommandStreamReceiver(); + auto &commandStreamReceiver0 = *executionEnvironment->commandStreamReceivers[0][0]; + auto &commandStreamReceiver1 = *executionEnvironment->commandStreamReceivers[0][1]; auto csr0ContextId = commandStreamReceiver0.getOsContext().getContextId(); auto csr1ContextId = commandStreamReceiver1.getOsContext().getContextId(); diff --git a/unit_tests/command_stream/submissions_aggregator_tests.cpp b/unit_tests/command_stream/submissions_aggregator_tests.cpp index 680afed815..d7546859a9 100644 --- a/unit_tests/command_stream/submissions_aggregator_tests.cpp +++ b/unit_tests/command_stream/submissions_aggregator_tests.cpp @@ -500,11 +500,16 @@ TEST(SubmissionsAggregator, givenMultipleOsContextsWhenAggregatingGraphicsAlloca submissionsAggregator.recordCommandBuffer(cmdBuffer0); submissionsAggregator.recordCommandBuffer(cmdBuffer1); - submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget, 3u); - EXPECT_EQ(1u, alloc0.getInspectionId(3u)); - EXPECT_EQ(1u, alloc1.getInspectionId(3u)); - EXPECT_EQ(1u, alloc2.getInspectionId(3u)); - EXPECT_EQ(1u, alloc3.getInspectionId(3u)); + + EXPECT_EQ(0u, alloc0.getInspectionId(1u)); + EXPECT_EQ(0u, alloc1.getInspectionId(1u)); + EXPECT_EQ(0u, alloc2.getInspectionId(1u)); + EXPECT_EQ(0u, alloc3.getInspectionId(1u)); + submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget, 1u); + EXPECT_EQ(1u, alloc0.getInspectionId(1u)); + EXPECT_EQ(1u, alloc1.getInspectionId(1u)); + EXPECT_EQ(1u, alloc2.getInspectionId(1u)); + EXPECT_EQ(1u, alloc3.getInspectionId(1u)); } TEST(SubmissionsAggregator, givenMultipleOsContextsWhenAggregatingGraphicsAllocationsThenDoNotUpdateInspectionIdsOfOtherContexts) { @@ -524,15 +529,15 @@ TEST(SubmissionsAggregator, givenMultipleOsContextsWhenAggregatingGraphicsAlloca submissionsAggregator.recordCommandBuffer(cmdBuffer0); submissionsAggregator.recordCommandBuffer(cmdBuffer1); - submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget, 3u); + submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget, 1u); for (auto osContextId = 0u; osContextId < alloc1.usageInfos.size(); osContextId++) { - if (osContextId != 3u) { + if (osContextId != 1u) { EXPECT_EQ(0u, alloc0.getInspectionId(osContextId)); } } for (auto osContextId = 0u; osContextId < alloc0.usageInfos.size(); osContextId++) { - if (osContextId != 3u) { + if (osContextId != 1u) { EXPECT_EQ(0u, alloc0.getInspectionId(osContextId)); } } diff --git a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp index a533d2d435..35da7e4551 100644 --- a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp +++ b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp @@ -39,9 +39,9 @@ struct DeferrableAllocationDeletionTest : ::testing::Test { auto executionEnvironment = std::make_unique(); memoryManager = new MockMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - device1.reset(Device::create(nullptr, executionEnvironment.release(), 0u)); - hwTag = device1->getDefaultEngine().commandStreamReceiver->getTagAddress(); - device1ContextId = device1->getDefaultEngine().osContext->getContextId(); + device.reset(Device::create(nullptr, executionEnvironment.release(), 0u)); + hwTag = device->getDefaultEngine().commandStreamReceiver->getTagAddress(); + defaultOsContextId = device->getDefaultEngine().osContext->getContextId(); asyncDeleter = std::make_unique(); asyncDeleter->addClient(); } @@ -51,21 +51,21 @@ struct DeferrableAllocationDeletionTest : ::testing::Test { } std::unique_ptr asyncDeleter; MockMemoryManager *memoryManager = nullptr; - std::unique_ptr device1; - uint32_t device1ContextId = 0; + std::unique_ptr device; + uint32_t defaultOsContextId = 0; volatile uint32_t *hwTag = nullptr; }; TEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationWhenApplyThenWaitForEachTaskCount) { auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); - allocation->updateTaskCount(1u, device1ContextId); + allocation->updateTaskCount(1u, defaultOsContextId); *hwTag = 0u; asyncDeleter->deferDeletion(new DeferrableAllocationDeletion(*memoryManager, *allocation)); while (!asyncDeleter->queue.peekIsEmpty()) // wait for async thread to get allocation from queue std::this_thread::yield(); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); - EXPECT_TRUE(allocation->isUsedByOsContext(device1ContextId)); + EXPECT_TRUE(allocation->isUsedByOsContext(defaultOsContextId)); // let async thread exit asyncDeleter->allowExit = true; @@ -77,24 +77,23 @@ TEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationWhenApplyThenW } HWTEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByTwoOsContextsWhenApplyDeletionThenWaitForBothContextsAndFlushNotReadyCsr) { - std::unique_ptr device2(Device::create(nullptr, device1->getExecutionEnvironment(), 1u)); - auto device2ContextId = device2->getDefaultEngine().osContext->getContextId(); + auto &nonDefaultCommandStreamReceiver = static_cast &>(*device->getExecutionEnvironment()->commandStreamReceivers[0][1]); + auto nonDefaultOsContextId = nonDefaultCommandStreamReceiver.getOsContext().getContextId(); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 0u; - *device2->getDefaultEngine().commandStreamReceiver->getTagAddress() = 1u; - allocation->updateTaskCount(1u, device1ContextId); - allocation->updateTaskCount(1u, device2ContextId); - EXPECT_TRUE(allocation->isUsedByOsContext(device1ContextId)); - EXPECT_TRUE(allocation->isUsedByOsContext(device2ContextId)); + *nonDefaultCommandStreamReceiver.getTagAddress() = 1u; + allocation->updateTaskCount(1u, defaultOsContextId); + allocation->updateTaskCount(1u, nonDefaultOsContextId); + EXPECT_TRUE(allocation->isUsedByOsContext(defaultOsContextId)); + EXPECT_TRUE(allocation->isUsedByOsContext(nonDefaultOsContextId)); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); - EXPECT_FALSE(device1->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled); - EXPECT_FALSE(device2->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled); + EXPECT_FALSE(device->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled); + EXPECT_FALSE(nonDefaultCommandStreamReceiver.flushBatchedSubmissionsCalled); asyncDeleter->deferDeletion(new DeferrableAllocationDeletion(*memoryManager, *allocation)); - while (allocation->isUsedByOsContext(device2ContextId)) // wait for second context completion signal + while (allocation->isUsedByOsContext(nonDefaultOsContextId) && !device->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled) // wait for second context completion signal std::this_thread::yield(); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); - EXPECT_TRUE(device1->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled); - EXPECT_FALSE(device2->getUltCommandStreamReceiver().flushBatchedSubmissionsCalled); + EXPECT_FALSE(nonDefaultCommandStreamReceiver.flushBatchedSubmissionsCalled); asyncDeleter->allowExit = true; *hwTag = 1u; } @@ -117,8 +116,8 @@ TEST_F(DeferrableAllocationDeletionTest, givenTwoAllocationsUsedByOneOsContextsE auto allocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 1u; - allocation1->updateTaskCount(2u, device1ContextId); - allocation2->updateTaskCount(1u, device1ContextId); + allocation1->updateTaskCount(2u, defaultOsContextId); + allocation2->updateTaskCount(1u, defaultOsContextId); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); EXPECT_TRUE(allocation1->isUsed()); EXPECT_TRUE(allocation2->isUsed()); @@ -134,7 +133,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenTwoAllocationsUsedByOneOsContextsE TEST_F(DeferrableAllocationDeletionTest, givenNotCompletedAllocationWhenDeletionIsAppliedThenReturnFalse) { auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 0u; - allocation->updateTaskCount(1u, device1ContextId); + allocation->updateTaskCount(1u, defaultOsContextId); EXPECT_EQ(0u, memoryManager->freeGraphicsMemoryCalled); DeferrableAllocationDeletion deletion{*memoryManager, *allocation}; EXPECT_FALSE(deletion.apply()); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 0d1c5b146c..d05f45238e 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1458,26 +1458,23 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultCsrWhenChec HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultDeviceWhenCheckingUsageBeforeDestroyThenStoreItAsTemporaryAllocation) { ExecutionEnvironment executionEnvironment; executionEnvironment.incRefInternal(); - auto defaultDevice = std::unique_ptr(Device::create(platformDevices[0], &executionEnvironment, 0u)); - auto nonDefaultDevice = std::unique_ptr(Device::create(platformDevices[0], &executionEnvironment, 1u)); - auto engine = nonDefaultDevice->getDefaultEngine(); - auto commandStreamReceiver = reinterpret_cast *>(engine.commandStreamReceiver); - auto osContextId = engine.osContext->getContextId(); + auto device = std::unique_ptr(Device::create(platformDevices[0], &executionEnvironment, 0u)); + auto &defaultCommandStreamReceiver = device->getCommandStreamReceiver(); + auto &nonDefaultCommandStreamReceiver = static_cast &>(*executionEnvironment.commandStreamReceivers[0][1]); auto memoryManager = executionEnvironment.memoryManager.get(); auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); - auto notReadyTaskCount = *commandStreamReceiver->getTagAddress() + 1; + auto notReadyTaskCount = *nonDefaultCommandStreamReceiver.getTagAddress() + 1; - EXPECT_NE(defaultDevice->getDeviceIndex(), nonDefaultDevice->getDeviceIndex()); - EXPECT_EQ(2u, executionEnvironment.commandStreamReceivers.size()); + EXPECT_NE(defaultCommandStreamReceiver.getOsContext().getContextId(), nonDefaultCommandStreamReceiver.getOsContext().getContextId()); - commandStreamReceiver->taskCount = notReadyTaskCount; - commandStreamReceiver->latestFlushedTaskCount = notReadyTaskCount; - graphicsAllocation->updateTaskCount(notReadyTaskCount, osContextId); + nonDefaultCommandStreamReceiver.taskCount = notReadyTaskCount; + nonDefaultCommandStreamReceiver.latestFlushedTaskCount = notReadyTaskCount; + graphicsAllocation->updateTaskCount(notReadyTaskCount, nonDefaultCommandStreamReceiver.getOsContext().getContextId()); - EXPECT_TRUE(commandStreamReceiver->getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); + EXPECT_TRUE(nonDefaultCommandStreamReceiver.getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(graphicsAllocation); - EXPECT_FALSE(commandStreamReceiver->getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); - (*commandStreamReceiver->getTagAddress())++; + EXPECT_FALSE(nonDefaultCommandStreamReceiver.getInternalAllocationStorage()->getTemporaryAllocations().peekIsEmpty()); + (*nonDefaultCommandStreamReceiver.getTagAddress())++; // no need to call freeGraphicsAllocation } diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index f2eec2571a..7320200b8b 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -74,14 +74,13 @@ TEST(WddmAllocationTest, givenAllocationIsTrimCandidateInOneOsContextWhenGetting allocation.setTrimCandidateListPosition(osContext.getContextId(), 700u); EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(0u)); EXPECT_EQ(700u, allocation.getTrimCandidateListPosition(1u)); - EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(2u)); } TEST(WddmAllocationTest, givenAllocationCreatedWithOsContextCountOneWhenItIsCreatedThenMaxOsContextCountIsUsedInstead) { WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false}; - allocation.setTrimCandidateListPosition(3u, 700u); - EXPECT_EQ(700u, allocation.getTrimCandidateListPosition(3u)); - EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(2u)); + allocation.setTrimCandidateListPosition(1u, 700u); + EXPECT_EQ(700u, allocation.getTrimCandidateListPosition(1u)); + EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition(0u)); } TEST(WddmAllocationTest, givenRequestedContextIdTooLargeWhenGettingTrimCandidateListPositionThenReturnUnusedPosition) {