Skip to content

Commit 8410bd6

Browse files
Remove device index from command stream receiver
Change-Id: Ia84b0cb8e03260ec940ee0b175b12693e528b8aa Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 99e4928 commit 8410bd6

12 files changed

+22
-24
lines changed

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void CommandStreamReceiver::ensureCommandBufferAllocation(LinearStream &commandS
126126
auto allocation = this->getInternalAllocationStorage()->obtainReusableAllocation(allocationSize, allocationType).release();
127127
if (allocation == nullptr) {
128128
const AllocationProperties commandStreamAllocationProperties{true, allocationSize, allocationType,
129-
isMultiOsContextCapable(), getDeviceIndexForAllocation()};
129+
isMultiOsContextCapable(), getDeviceIndex()};
130130
allocation = this->getMemoryManager()->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
131131
}
132132
DEBUG_BREAK_IF(allocation == nullptr);
@@ -297,7 +297,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType
297297
return *heap;
298298
}
299299

300-
uint32_t CommandStreamReceiver::getDeviceIndexForAllocation() const {
300+
uint32_t CommandStreamReceiver::getDeviceIndex() const {
301301
return osContext->getDeviceBitfield().any() ? static_cast<uint32_t>(Math::log2(static_cast<uint32_t>(osContext->getDeviceBitfield().to_ulong()))) : 0u;
302302
}
303303

@@ -325,7 +325,7 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
325325

326326
if (!heapMemory) {
327327
heapMemory = getMemoryManager()->allocateGraphicsMemoryWithProperties({true, finalHeapSize, allocationType,
328-
isMultiOsContextCapable(), getDeviceIndexForAllocation()});
328+
isMultiOsContextCapable(), getDeviceIndex()});
329329
} else {
330330
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
331331
}

runtime/command_stream/command_stream_receiver.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class CommandStreamReceiver {
155155

156156
size_t defaultSshSize;
157157

158-
void setDeviceIndex(uint32_t deviceIndex) { this->deviceIndex = deviceIndex; }
159158
AllocationsList &getTemporaryAllocations();
160159
AllocationsList &getAllocationsForReuse();
161160
InternalAllocationStorage *getInternalAllocationStorage() const { return internalAllocationStorage.get(); }
@@ -191,7 +190,7 @@ class CommandStreamReceiver {
191190

192191
protected:
193192
void cleanupResources();
194-
uint32_t getDeviceIndexForAllocation() const;
193+
MOCKABLE_VIRTUAL uint32_t getDeviceIndex() const;
195194

196195
std::unique_ptr<FlushStampTracker> flushStamp;
197196
std::unique_ptr<SubmissionAggregator> submissionAggregator;
@@ -232,7 +231,6 @@ class CommandStreamReceiver {
232231
PreemptionMode lastPreemptionMode = PreemptionMode::Initial;
233232
uint64_t totalMemoryUsed = 0u;
234233

235-
uint32_t deviceIndex = 0u;
236234
// taskCount - # of tasks submitted
237235
uint32_t taskCount = 0;
238236
uint32_t lastSentL3Config = 0;

runtime/command_stream/command_stream_receiver_simulated_common_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ template <typename GfxFamily>
2525
class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw<GfxFamily> {
2626
protected:
2727
using CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw;
28-
using CommandStreamReceiverHw<GfxFamily>::deviceIndex;
2928
using CommandStreamReceiverHw<GfxFamily>::osContext;
29+
using CommandStreamReceiverHw<GfxFamily>::getDeviceIndex;
3030
using AUB = typename AUBFamilyMapper<GfxFamily>::AUB;
3131
using MiContextDescriptorReg = typename AUB::MiContextDescriptorReg;
3232

runtime/command_stream/command_stream_receiver_simulated_common_hw_bdw_plus.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getGTTData(void *memory,
2929

3030
template <typename GfxFamily>
3131
uint32_t CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getMemoryBankForGtt() const {
32-
return MemoryBanks::getBank(this->deviceIndex);
32+
return MemoryBanks::getBank(getDeviceIndex());
3333
}
3434

3535
template <typename GfxFamily>

runtime/command_stream/definitions/command_stream_receiver_simulated_hw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ class CommandStreamReceiverSimulatedHw : public CommandStreamReceiverSimulatedCo
1717
protected:
1818
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::CommandStreamReceiverSimulatedCommonHw;
1919
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::osContext;
20+
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getDeviceIndex;
2021

2122
public:
2223
uint32_t getMemoryBank(GraphicsAllocation *allocation) const {
23-
return MemoryBanks::getBank(this->deviceIndex);
24+
return MemoryBanks::getBank(getDeviceIndex());
2425
}
2526
int getAddressSpace(int hint) {
2627
return AubMemDump::AddressSpaceValues::TraceNonlocal;

runtime/execution_environment/execution_environment.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ bool ExecutionEnvironment::initializeCommandStreamReceiver(uint32_t deviceIndex,
6060
if (HwHelper::get(hwInfo->platform.eRenderCoreFamily).isPageTableManagerSupported(*hwInfo)) {
6161
commandStreamReceiver->createPageTableManager();
6262
}
63-
commandStreamReceiver->setDeviceIndex(deviceIndex);
6463
this->commandStreamReceivers[deviceIndex][deviceCsrIndex] = std::move(commandStreamReceiver);
6564
return true;
6665
}

runtime/os_interface/linux/drm_command_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
5959
std::vector<drm_i915_gem_exec_object2> execObjectsStorage;
6060
Drm *drm;
6161
gemCloseWorkerMode gemCloseWorkerOperationMode;
62+
uint32_t handleIndex = 0u;
6263
};
6364
} // namespace NEO

unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenOsContextIsSetThenCreateH
180180
pDevice->executionEnvironment->aubCenter = std::unique_ptr<MockAubCenter>(mockAubCenter);
181181

182182
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(static_cast<AUBCommandStreamReceiverHw<FamilyType> *>(AUBCommandStreamReceiver::create(fileName, true, *pDevice->executionEnvironment)));
183-
aubCsr->setDeviceIndex(deviceIndex);
184183
EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get());
185184

186185
aubCsr->setupContext(osContext);
@@ -844,7 +843,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic
844843
std::unique_ptr<MemoryManager> memoryManager(nullptr);
845844
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>("", true, *pDevice->executionEnvironment));
846845
memoryManager.reset(new OsAgnosticMemoryManager(*pDevice->executionEnvironment));
847-
846+
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
848847
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
849848

850849
aubCsr->setAubWritable(false, *gfxAllocation);
@@ -856,7 +855,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic
856855
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphicsAllocationSizeIsZeroThenWriteMemoryIsNotAllowed) {
857856
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>("", true, *pDevice->executionEnvironment));
858857
MockGraphicsAllocation gfxAllocation((void *)0x1234, 0);
859-
858+
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
860859
EXPECT_FALSE(aubCsr->writeMemory(gfxAllocation));
861860
}
862861

@@ -874,7 +873,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAllocat
874873
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAllocationSizeInAllocationViewIsZeroThenWriteMemoryIsNotAllowed) {
875874
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>("", true, *pDevice->executionEnvironment);
876875
AllocationView allocationView(0x1234, 0);
877-
876+
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
878877
EXPECT_FALSE(aubCsr->writeMemory(allocationView));
879878
}
880879

unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh
491491
executionEnvironment->memoryManager.reset(memoryManager);
492492

493493
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>("", true, *executionEnvironment));
494+
auto osContext = memoryManager->createAndRegisterOsContext(aubCsr.get(), getChosenEngineType(**platformDevices), 0, PreemptionMode::Disabled, false);
495+
aubCsr->setupContext(*osContext);
494496
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
495497

496498
memoryManager->lockResource(gfxAllocation);
@@ -542,6 +544,7 @@ HWTEST_F(AubCommandStreamReceiverTests, whenGetMemoryBankForGttIsCalledThenCorre
542544
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", true, *pDevice->executionEnvironment));
543545
aubCsr->localMemoryEnabled = false;
544546

547+
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
545548
auto bank = aubCsr->getMemoryBankForGtt();
546549
EXPECT_EQ(MemoryBanks::MainBank, bank);
547550
}
@@ -648,6 +651,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe
648651
pDevice->executionEnvironment->aubCenter.reset(new AubCenter());
649652

650653
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>("", false, *pDevice->executionEnvironment);
654+
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
651655
std::unique_ptr<MemoryManager> memoryManager(new OsAgnosticMemoryManager(*pDevice->executionEnvironment));
652656

653657
PhysicalAddressAllocator allocator;

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,24 +625,22 @@ INSTANTIATE_TEST_CASE_P(
625625
CommandStreamReceiverWithAubSubCaptureTest,
626626
testing::ValuesIn(aubSubCaptureStatus));
627627

628-
TEST(CommandStreamReceiverDeviceIndexTest, givenCommandStreamReceiverWithDeviceIndexDifferentThanDeviceBitfieldInOsContextWhenGetDeviceIndexForAllocationThenUseHighestBitFromOsContext) {
628+
TEST(CommandStreamReceiverDeviceIndexTest, givenCsrWithOsContextWhenGetDeviceIndexThenGetHighestEnabledBitInDeviceBitfield) {
629629
ExecutionEnvironment executioneEnvironment;
630630
executioneEnvironment.initializeMemoryManager();
631631
MockCommandStreamReceiver csr(executioneEnvironment);
632-
csr.deviceIndex = 1;
633-
auto osContext = executioneEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b01, PreemptionMode::Disabled, false);
632+
auto osContext = executioneEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b10, PreemptionMode::Disabled, false);
634633

635634
csr.setupContext(*osContext);
636-
EXPECT_EQ(0u, csr.getDeviceIndexForAllocation());
635+
EXPECT_EQ(1u, csr.getDeviceIndex());
637636
}
638637

639-
TEST(CommandStreamReceiverDeviceIndexTest, givenCommandStreamReceiverWithOsContextWithoutDeviceBitfieldsWhenGetDeviceIndexForAllocationThenZeroIsReturned) {
638+
TEST(CommandStreamReceiverDeviceIndexTest, givenOsContextWithNoDeviceBitfieldWhenGettingDeviceIndexThenZeroIsReturned) {
640639
ExecutionEnvironment executioneEnvironment;
641640
executioneEnvironment.initializeMemoryManager();
642641
MockCommandStreamReceiver csr(executioneEnvironment);
643-
csr.deviceIndex = 1;
644642
auto osContext = executioneEnvironment.memoryManager->createAndRegisterOsContext(&csr, aub_stream::EngineType::ENGINE_RCS, 0b00, PreemptionMode::Disabled, false);
645643

646644
csr.setupContext(*osContext);
647-
EXPECT_EQ(0u, csr.getDeviceIndexForAllocation());
645+
EXPECT_EQ(0u, csr.getDeviceIndex());
648646
}

unit_tests/libult/ult_command_stream_receiver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
2525
using BaseClass = CommandStreamReceiverHw<GfxFamily>;
2626

2727
public:
28-
using BaseClass::deviceIndex;
2928
using BaseClass::dshState;
3029
using BaseClass::getScratchPatchAddress;
3130
using BaseClass::getScratchSpaceController;

unit_tests/mocks/mock_csr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ class MockFlatBatchBufferHelper : public FlatBatchBufferHelperHw<GfxFamily> {
246246
class MockCommandStreamReceiver : public CommandStreamReceiver {
247247
public:
248248
using CommandStreamReceiver::CommandStreamReceiver;
249-
using CommandStreamReceiver::deviceIndex;
250-
using CommandStreamReceiver::getDeviceIndexForAllocation;
249+
using CommandStreamReceiver::getDeviceIndex;
251250
using CommandStreamReceiver::internalAllocationStorage;
252251
using CommandStreamReceiver::latestFlushedTaskCount;
253252
using CommandStreamReceiver::latestSentTaskCount;

0 commit comments

Comments
 (0)