diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index ef3cd401b2..bd14a78dd0 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -216,7 +216,13 @@ class CommandStreamReceiver { return globalFenceAllocation; } - GraphicsAllocation *getWorkPartitionAllocation() const { return workPartitionAllocation; } + GraphicsAllocation *getWorkPartitionAllocation() const { + if (primaryCsr) { + return primaryCsr->getWorkPartitionAllocation(); + } + return workPartitionAllocation; + } + GraphicsAllocation *getGlobalStatelessHeapAllocation() const { if (primaryCsr) { return primaryCsr->getGlobalStatelessHeapAllocation(); diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 735a916755..4ba0c98c52 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -530,12 +530,12 @@ CompletionStamp CommandStreamReceiverHw::flushTask( this->makeResident(*tagAllocation); - if (globalFenceAllocation) { - makeResident(*globalFenceAllocation); + if (getGlobalFenceAllocation()) { + makeResident(*getGlobalFenceAllocation()); } - if (preemptionAllocation) { - makeResident(*preemptionAllocation); + if (getPreemptionAllocation()) { + makeResident(*getPreemptionAllocation()); } bool debuggingEnabled = device.getDebugger() != nullptr; @@ -549,8 +549,8 @@ CompletionStamp CommandStreamReceiverHw::flushTask( makeResident(*debugSurface); } - if (workPartitionAllocation) { - makeResident(*workPartitionAllocation); + if (getWorkPartitionAllocation()) { + makeResident(*getWorkPartitionAllocation()); } auto rtBuffer = device.getRTMemoryBackedBuffer(); @@ -846,7 +846,7 @@ inline WaitStatus CommandStreamReceiverHw::waitForTaskCountWithKmdNot template inline void CommandStreamReceiverHw::programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags) { - PreemptionHelper::programCmdStream(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, preemptionAllocation); + PreemptionHelper::programCmdStream(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, getPreemptionAllocation()); this->lastPreemptionMode = dispatchFlags.preemptionMode; } @@ -866,7 +866,7 @@ inline void CommandStreamReceiverHw::programStateSip(LinearStream &cm template inline void CommandStreamReceiverHw::programPreamble(LinearStream &csr, Device &device, uint32_t &newL3Config) { if (!this->isPreambleSent) { - PreambleHelper::programPreamble(&csr, device, newL3Config, this->preemptionAllocation, EngineHelpers::isBcs(osContext->getEngineType())); + PreambleHelper::programPreamble(&csr, device, newL3Config, getPreemptionAllocation(), EngineHelpers::isBcs(osContext->getEngineType())); this->isPreambleSent = true; this->lastSentL3Config = newL3Config; } @@ -2116,12 +2116,12 @@ void CommandStreamReceiverHw::handleImmediateFlushAllocationsResidenc LinearStream &csrStream) { this->makeResident(*tagAllocation); - if (globalFenceAllocation) { - makeResident(*globalFenceAllocation); + if (getGlobalFenceAllocation()) { + makeResident(*getGlobalFenceAllocation()); } - if (workPartitionAllocation) { - makeResident(*workPartitionAllocation); + if (getWorkPartitionAllocation()) { + makeResident(*getWorkPartitionAllocation()); } if (device.getRTMemoryBackedBuffer()) { @@ -2132,8 +2132,8 @@ void CommandStreamReceiverHw::handleImmediateFlushAllocationsResidenc makeResident(*csrStream.getGraphicsAllocation()); } - if (preemptionAllocation) { - makeResident(*preemptionAllocation); + if (getPreemptionAllocation()) { + makeResident(*getPreemptionAllocation()); } if (device.isStateSipRequired()) { diff --git a/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp b/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp index 53cdd05c97..fd989539ba 100644 --- a/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp +++ b/shared/source/xe2_hpg_core/command_stream_receiver_hw_xe2_hpg_core.cpp @@ -39,8 +39,8 @@ void populateFactoryTable>() { template <> void CommandStreamReceiverHw::programEnginePrologue(LinearStream &csr) { if (!this->isEnginePrologueSent) { - if (globalFenceAllocation) { - EncodeMemoryFence::encodeSystemMemoryFence(csr, globalFenceAllocation); + if (getGlobalFenceAllocation()) { + EncodeMemoryFence::encodeSystemMemoryFence(csr, getGlobalFenceAllocation()); } this->isEnginePrologueSent = true; } @@ -49,7 +49,7 @@ void CommandStreamReceiverHw::programEnginePrologue(LinearStream &csr) { template <> size_t CommandStreamReceiverHw::getCmdSizeForPrologue() const { if (!this->isEnginePrologueSent) { - if (globalFenceAllocation) { + if (getGlobalFenceAllocation()) { return EncodeMemoryFence::getSystemMemoryFenceSize(); } } diff --git a/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp b/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp index 6b0011b337..044a707bd6 100644 --- a/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/command_stream_receiver_hw_xe_hpc_core.cpp @@ -39,8 +39,8 @@ void populateFactoryTable>() { template <> void CommandStreamReceiverHw::programEnginePrologue(LinearStream &csr) { if (!this->isEnginePrologueSent) { - if (globalFenceAllocation) { - EncodeMemoryFence::encodeSystemMemoryFence(csr, globalFenceAllocation); + if (getGlobalFenceAllocation()) { + EncodeMemoryFence::encodeSystemMemoryFence(csr, getGlobalFenceAllocation()); } this->isEnginePrologueSent = true; } @@ -49,7 +49,7 @@ void CommandStreamReceiverHw::programEnginePrologue(LinearStream &csr) { template <> size_t CommandStreamReceiverHw::getCmdSizeForPrologue() const { if (!this->isEnginePrologueSent) { - if (globalFenceAllocation) { + if (getGlobalFenceAllocation()) { return EncodeMemoryFence::getSystemMemoryFenceSize(); } } diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index d1060dfe78..f5fdf0d384 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -5699,6 +5699,60 @@ HWTEST_F(CommandStreamReceiverContextGroupTest, givenSecondaryCsrWhenGettingInte } } +HWTEST_F(CommandStreamReceiverContextGroupTest, givenSecondaryRootCsrWhenGettingInternalAllocationsThenAllocationFromPrimnaryCsrAreReturned) { + HardwareInfo hwInfo = *defaultHwInfo; + if (hwInfo.capabilityTable.defaultEngineType != aub_stream::EngineType::ENGINE_CCS) { + GTEST_SKIP(); + } + + DebugManagerStateRestore dbgRestorer; + debugManager.flags.ContextGroupSize.set(5); + + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.defaultEngineType = aub_stream::ENGINE_CCS; + hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1; + hwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; + + UltDeviceFactory deviceFactory{1, 2}; + auto device = deviceFactory.rootDevices[0]; + const auto &gfxCoreHelper = device->getRootDeviceEnvironment().getHelper(); + + const auto ccsIndex = 0; + auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)]; + auto secondaryEnginesCount = secondaryEngines.engines.size(); + ASSERT_EQ(5u, secondaryEnginesCount); + + EXPECT_TRUE(secondaryEngines.engines[0].commandStreamReceiver->isInitialized()); + + auto primaryCsr = secondaryEngines.engines[0].commandStreamReceiver; + primaryCsr->createGlobalStatelessHeap(); + + for (uint32_t secondaryIndex = 1; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}, false); + } + + for (uint32_t i = 0; i < secondaryEngines.highPriorityEnginesTotal; i++) { + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}, false); + } + + for (uint32_t secondaryIndex = 0; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { + + if (secondaryIndex > 0) { + EXPECT_NE(primaryCsr->getTagAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); + } + + if (gfxCoreHelper.isFenceAllocationRequired(hwInfo)) { + EXPECT_EQ(primaryCsr->getGlobalFenceAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); + } + + EXPECT_EQ(primaryCsr->getPreemptionAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); + EXPECT_EQ(primaryCsr->getGlobalStatelessHeapAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeapAllocation()); + EXPECT_EQ(primaryCsr->getGlobalStatelessHeap(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeap()); + EXPECT_EQ(primaryCsr->getPrimaryScratchSpaceController(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPrimaryScratchSpaceController()); + EXPECT_EQ(primaryCsr->getWorkPartitionAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getWorkPartitionAllocation()); + } +} + HWTEST_F(CommandStreamReceiverContextGroupTest, givenContextGroupWhenCreatingEnginesThenSetCorrectMaxOsContextCount) { HardwareInfo hwInfo = *defaultHwInfo;