Skip to content

Commit

Permalink
Improve EngineInstance usage in Aub CSR
Browse files Browse the repository at this point in the history
Change-Id: I9097f7cc8c930fcf531744af9bddfa38b2c5e1da
Signed-off-by: Dunajski, Bartosz <[email protected]>
  • Loading branch information
BartoszDunajski authored and Compute-Runtime-Automation committed Dec 18, 2018
1 parent 6dd4548 commit 403fedf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 40 deletions.
6 changes: 3 additions & 3 deletions runtime/command_stream/aub_command_stream_receiver_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
}

auto streamLocked = getAubStream()->lockStream();
auto engineIndex = this->getEngineIndex(osContext->getEngineType().type);
auto engineInstance = allEngineInstances[engineIndex];

auto engineIndex = this->getEngineIndex(osContext->getEngineType());

initializeEngine(engineIndex);

Expand Down Expand Up @@ -363,7 +363,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer

submitBatchBuffer(engineIndex, batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this->getMemoryBank(batchBuffer.commandBufferAllocation), this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));

pollForCompletion(engineInstance);
pollForCompletion(osContext->getEngineType());
if (this->standalone) {
*this->tagAddress = this->peekLatestSentTaskCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw<Gf
uint64_t getPPGTTAdditionalBits(GraphicsAllocation *gfxAllocation);
void getGTTData(void *memory, AubGTTData &data);
uint32_t getMemoryBankForGtt() const;
size_t getEngineIndexFromInstance(EngineInstanceT engineInstance);
size_t getEngineIndex(EngineType engineType);
size_t getEngineIndex(EngineInstanceT engineInstance);

AubMemDump::AubStream *stream;
size_t gpgpuEngineIndex = EngineInstanceConstants::numGpgpuEngineInstances - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ uint32_t CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getMemoryBankForGtt(
}

template <typename GfxFamily>
size_t CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getEngineIndexFromInstance(EngineInstanceT engineInstance) {
size_t CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getEngineIndex(EngineInstanceT engineInstance) {
auto findCriteria = [&](const auto &it) { return it.type == engineInstance.type && it.id == engineInstance.id; };
auto findResult = std::find_if(allEngineInstances.begin(), allEngineInstances.end(), findCriteria);
UNRECOVERABLE_IF(findResult == allEngineInstances.end());
return findResult - allEngineInstances.begin();
}

template <typename GfxFamily>
size_t CommandStreamReceiverSimulatedCommonHw<GfxFamily>::getEngineIndex(EngineType engineType) {
return getEngineIndexFromInstance(engineType);
}
} // namespace OCLRT
6 changes: 2 additions & 4 deletions runtime/command_stream/tbx_command_stream_receiver_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,9 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const Hardw

template <typename GfxFamily>
FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
auto engineType = osContext->getEngineType().type;
auto engineIndex = this->getEngineIndex(osContext->getEngineType().type);
auto engineInstance = allEngineInstances[engineIndex];
auto &engineInstance = osContext->getEngineType();
uint32_t mmioBase = getCsTraits(engineInstance).mmioBase;
auto &engineInfo = engineInfoTable[engineType];
auto &engineInfo = engineInfoTable[engineInstance.type];

if (!engineInfo.pLRCA) {
initializeEngine(engineInstance);
Expand Down
38 changes: 15 additions & 23 deletions unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,25 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngi
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
EXPECT_NE(nullptr, aubCsr);

EXPECT_TRUE(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_RCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_RCS, 1)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_BCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_VCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_VECS, 0)) < allEngineInstances.size());

EXPECT_THROW(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_RCS, 2)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_BCS, 1)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_VCS, 1)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndexFromInstance(EngineInstanceT(EngineType::ENGINE_VECS, 1)), std::exception);
EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 1)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_BCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_VCS, 0)) < allEngineInstances.size());
EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_VECS, 0)) < allEngineInstances.size());

EXPECT_THROW(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 2)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_BCS, 1)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_VCS, 1)), std::exception);
EXPECT_THROW(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_VECS, 1)), std::exception);
}

HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngineIndexIsCalledForGivenEngineTypeThenEngineIndexForThatTypeIsReturned) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
EXPECT_NE(nullptr, aubCsr);

auto engineIndex = aubCsr->getEngineIndex(EngineType::ENGINE_RCS);
auto engineIndex = aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 1));
EXPECT_EQ(EngineType::ENGINE_RCS, allEngineInstances[engineIndex].type);

engineIndex = aubCsr->getEngineIndex(EngineType::ENGINE_BCS);
EXPECT_EQ(EngineType::ENGINE_BCS, allEngineInstances[engineIndex].type);

engineIndex = aubCsr->getEngineIndex(EngineType::ENGINE_VCS);
EXPECT_EQ(EngineType::ENGINE_VCS, allEngineInstances[engineIndex].type);

engineIndex = aubCsr->getEngineIndex(EngineType::ENGINE_VECS);
EXPECT_EQ(EngineType::ENGINE_VECS, allEngineInstances[engineIndex].type);
EXPECT_EQ(1, allEngineInstances[engineIndex].id);
}

HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenItIsCreatedWithDefaultSettingsThenItHasBatchedDispatchModeEnabled) {
Expand Down Expand Up @@ -273,8 +265,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl

auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto engineType = OCLRT::ENGINE_RCS;
auto engineIndex = aubCsr1->getEngineIndex(engineType);
auto engineType = gpgpuEngineInstances[0].type;
auto engineIndex = aubCsr1->getEngineIndex(gpgpuEngineInstances[0]);

aubCsr1->initializeEngine(engineIndex);
EXPECT_NE(0u, aubCsr1->engineInfoTable[engineType].ggttLRCA);
Expand All @@ -294,7 +286,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs

BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
ResidencyContainer allocationsForResidency = {};
auto engineIndex = aubCsr->getEngineIndexFromInstance(aubCsr->getOsContext().getEngineType());
auto engineIndex = aubCsr->getEngineIndex(aubCsr->getOsContext().getEngineType());
aubCsr->flush(batchBuffer, allocationsForResidency);
EXPECT_NE(nullptr, aubCsr->engineInfoTable[engineIndex].pLRCA);
EXPECT_NE(nullptr, aubCsr->engineInfoTable[engineIndex].pGlobalHWStatusPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenEngineI
auto aubCsr = std::make_unique<MockAubCsrToTestDumpContext<FamilyType>>(**platformDevices, "", true, executionEnvironment);
EXPECT_NE(nullptr, aubCsr);

auto engineType = OCLRT::ENGINE_RCS;
auto engineIndex = aubCsr->getEngineIndex(engineType);
auto engineIndex = aubCsr->getEngineIndex(gpgpuEngineInstances[0]);

aubCsr->initializeEngine(engineIndex);
EXPECT_NE(0u, aubCsr->handle);
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/command_stream/aub_file_stream_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitializeEngineIs
comments.push_back(std::string(str));
return true;
}));
auto engineIndex = aubCsr->getEngineIndex(OCLRT::ENGINE_RCS);
auto engineIndex = aubCsr->getEngineIndex(gpgpuEngineInstances[0]);
aubCsr->initializeEngine(engineIndex);

#define QTR(a) #a
Expand Down

0 comments on commit 403fedf

Please sign in to comment.