TBX CSR with an option to create and operate on hardware context
Change-Id: Ib5febc8e36e61195a5fcce91e1783117717ff6cb
This commit is contained in:
parent
4b1871bf0e
commit
541ab5af50
|
@ -12,6 +12,10 @@
|
|||
#include "runtime/memory_manager/address_mapper.h"
|
||||
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "runtime/memory_manager/page_table.h"
|
||||
#include "third_party/aub_stream/headers/aub_manager.h"
|
||||
#include "third_party/aub_stream/headers/hardware_context.h"
|
||||
|
||||
using namespace AubDump;
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
|
@ -41,17 +45,22 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
|
|||
|
||||
void processResidency(ResidencyContainer &allocationsForResidency) override;
|
||||
void waitBeforeMakingNonResidentWhenRequired() override;
|
||||
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield);
|
||||
bool writeMemory(GraphicsAllocation &gfxAllocation);
|
||||
|
||||
// Family specific version
|
||||
void pollForCompletion(EngineInstanceT engineInstance);
|
||||
MOCKABLE_VIRTUAL void submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits);
|
||||
MOCKABLE_VIRTUAL void pollForCompletion(EngineInstanceT engineInstance);
|
||||
|
||||
static CommandStreamReceiver *create(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment);
|
||||
|
||||
TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment);
|
||||
~TbxCommandStreamReceiverHw() override;
|
||||
|
||||
void initializeEngine(EngineInstanceT engineInstance);
|
||||
void initializeEngine(size_t engineIndex);
|
||||
|
||||
AubManager *aubManager = nullptr;
|
||||
std::unique_ptr<HardwareContext> hardwareContext;
|
||||
|
||||
struct EngineInfo {
|
||||
void *pLRCA;
|
||||
|
@ -62,7 +71,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
|
|||
uint32_t ggttRCS;
|
||||
size_t sizeRCS;
|
||||
uint32_t tailRCS;
|
||||
} engineInfoTable[EngineType::NUM_ENGINES];
|
||||
} engineInfoTable[EngineInstanceConstants::numAllEngineInstances] = {};
|
||||
|
||||
MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override {
|
||||
return new TbxMemoryManager(enable64kbPages, enableLocalMemory, this->executionEnvironment);
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
*/
|
||||
|
||||
#include "hw_cmds.h"
|
||||
#include "runtime/aub/aub_center.h"
|
||||
#include "runtime/aub/aub_helper.h"
|
||||
#include "runtime/aub_mem_dump/page_table_entry_bits.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
#include "runtime/helpers/hw_helper.h"
|
||||
|
@ -28,6 +30,14 @@ TbxCommandStreamReceiverHw<GfxFamily>::TbxCommandStreamReceiverHw(const Hardware
|
|||
: BaseClass(hwInfoIn, executionEnvironment) {
|
||||
|
||||
physicalAddressAllocator.reset(this->createPhysicalAddressAllocator(&hwInfoIn));
|
||||
executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled, "");
|
||||
auto aubCenter = executionEnvironment.aubCenter.get();
|
||||
UNRECOVERABLE_IF(nullptr == aubCenter);
|
||||
|
||||
aubManager = aubCenter->getAubManager();
|
||||
if (aubManager) {
|
||||
hardwareContext = std::unique_ptr<HardwareContext>(aubManager->createHardwareContext(0, hwInfoIn.capabilityTable.defaultEngineType));
|
||||
}
|
||||
|
||||
ppgtt = std::make_unique<std::conditional<is64bit, PML4, PDPE>::type>(physicalAddressAllocator.get());
|
||||
ggtt = std::make_unique<PDPE>(physicalAddressAllocator.get());
|
||||
|
@ -71,9 +81,19 @@ TbxCommandStreamReceiverHw<GfxFamily>::~TbxCommandStreamReceiverHw() {
|
|||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineInstanceT engineInstance) {
|
||||
auto mmioBase = this->getCsTraits(engineInstance).mmioBase;
|
||||
auto &engineInfo = engineInfoTable[engineInstance.type];
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(size_t engineIndex) {
|
||||
if (hardwareContext) {
|
||||
hardwareContext->initialize();
|
||||
return;
|
||||
}
|
||||
|
||||
auto engineInstance = allEngineInstances[engineIndex];
|
||||
auto csTraits = this->getCsTraits(engineInstance);
|
||||
auto &engineInfo = engineInfoTable[engineIndex];
|
||||
|
||||
if (engineInfo.pLRCA) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->initGlobalMMIO();
|
||||
this->initEngineMMIO(engineInstance);
|
||||
|
@ -91,11 +111,10 @@ void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineInstanceT eng
|
|||
AubGTTData data = {0};
|
||||
this->getGTTData(reinterpret_cast<void *>(physHWSP), data);
|
||||
AUB::reserveAddressGGTT(tbxStream, engineInfo.ggttHWSP, sizeHWSP, physHWSP, data);
|
||||
tbxStream.writeMMIO(AubMemDump::computeRegisterOffset(mmioBase, 0x2080), engineInfo.ggttHWSP);
|
||||
tbxStream.writeMMIO(AubMemDump::computeRegisterOffset(csTraits.mmioBase, 0x2080), engineInfo.ggttHWSP);
|
||||
}
|
||||
|
||||
// Allocate the LRCA
|
||||
auto csTraits = this->getCsTraits(engineInstance);
|
||||
const size_t sizeLRCA = csTraits.sizeLRCA;
|
||||
const size_t alignLRCA = csTraits.alignLRCA;
|
||||
auto pLRCABase = alignedMalloc(sizeLRCA, alignLRCA);
|
||||
|
@ -145,6 +164,8 @@ void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineInstanceT eng
|
|||
this->getAddressSpace(csTraits.aubHintLRCA),
|
||||
csTraits.aubHintLRCA);
|
||||
}
|
||||
|
||||
DEBUG_BREAK_IF(!engineInfo.pLRCA);
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
|
@ -168,42 +189,62 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const Hardw
|
|||
|
||||
template <typename GfxFamily>
|
||||
FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
||||
auto &engineInstance = osContext->getEngineType();
|
||||
uint32_t mmioBase = this->getCsTraits(engineInstance).mmioBase;
|
||||
auto &engineInfo = engineInfoTable[engineInstance.type];
|
||||
auto engineIndex = this->getEngineIndex(osContext->getEngineType());
|
||||
|
||||
if (!engineInfo.pLRCA) {
|
||||
initializeEngine(engineInstance);
|
||||
DEBUG_BREAK_IF(!engineInfo.pLRCA);
|
||||
}
|
||||
initializeEngine(engineIndex);
|
||||
|
||||
// Write our batch buffer
|
||||
auto pBatchBuffer = ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset);
|
||||
auto batchBufferGpuAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
|
||||
auto currentOffset = batchBuffer.usedSize;
|
||||
DEBUG_BREAK_IF(currentOffset < batchBuffer.startOffset);
|
||||
auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset;
|
||||
{
|
||||
auto physBatchBuffer = ppgtt->map(reinterpret_cast<uintptr_t>(pBatchBuffer), sizeBatchBuffer,
|
||||
this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation),
|
||||
this->getMemoryBank(batchBuffer.commandBufferAllocation));
|
||||
|
||||
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
||||
AUB::reserveAddressPPGTT(tbxStream, reinterpret_cast<uintptr_t>(pBatchBuffer), sizeBatchBuffer, physBatchBuffer,
|
||||
this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation),
|
||||
aubHelperHw);
|
||||
|
||||
AUB::addMemoryWrite(
|
||||
tbxStream,
|
||||
physBatchBuffer,
|
||||
pBatchBuffer,
|
||||
sizeBatchBuffer,
|
||||
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary),
|
||||
AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary);
|
||||
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
|
||||
CommandStreamReceiver::makeResident(*batchBuffer.commandBufferAllocation);
|
||||
} else {
|
||||
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
|
||||
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId());
|
||||
}
|
||||
|
||||
// Write allocations for residency
|
||||
processResidency(allocationsForResidency);
|
||||
|
||||
submitBatchBuffer(engineIndex, batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this->getMemoryBank(batchBuffer.commandBufferAllocation), this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
|
||||
|
||||
pollForCompletion(osContext->getEngineType());
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) {
|
||||
if (hardwareContext) {
|
||||
if (batchBufferSize) {
|
||||
hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto engineInstance = allEngineInstances[engineIndex];
|
||||
auto csTraits = this->getCsTraits(engineInstance);
|
||||
auto &engineInfo = engineInfoTable[engineIndex];
|
||||
|
||||
{
|
||||
auto physBatchBuffer = ppgtt->map(static_cast<uintptr_t>(batchBufferGpuAddress), batchBufferSize, entryBits, memoryBank);
|
||||
|
||||
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
||||
AUB::reserveAddressPPGTT(tbxStream, static_cast<uintptr_t>(batchBufferGpuAddress), batchBufferSize, physBatchBuffer,
|
||||
entryBits, aubHelperHw);
|
||||
|
||||
AUB::addMemoryWrite(
|
||||
tbxStream,
|
||||
physBatchBuffer,
|
||||
batchBuffer,
|
||||
batchBufferSize,
|
||||
this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary),
|
||||
AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary);
|
||||
}
|
||||
|
||||
// Add a batch buffer start to the RCS
|
||||
auto previousTail = engineInfo.tailRCS;
|
||||
{
|
||||
|
@ -237,7 +278,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
|||
} else if (engineInfo.tailRCS == 0) {
|
||||
// Add a LRI if this is our first submission
|
||||
auto lri = MI_LOAD_REGISTER_IMM::sInit();
|
||||
lri.setRegisterOffset(AubMemDump::computeRegisterOffset(mmioBase, 0x2244));
|
||||
lri.setRegisterOffset(AubMemDump::computeRegisterOffset(csTraits.mmioBase, 0x2244));
|
||||
lri.setDataDword(0x00010000);
|
||||
*(MI_LOAD_REGISTER_IMM *)pTail = lri;
|
||||
pTail = ((MI_LOAD_REGISTER_IMM *)pTail) + 1;
|
||||
|
@ -245,7 +286,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
|||
|
||||
// Add our BBS
|
||||
auto bbs = MI_BATCH_BUFFER_START::sInit();
|
||||
bbs.setBatchBufferStartAddressGraphicsaddress472(AUB::ptrToPPGTT(pBatchBuffer));
|
||||
bbs.setBatchBufferStartAddressGraphicsaddress472(AUB::ptrToPPGTT(batchBuffer));
|
||||
bbs.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
|
||||
*(MI_BATCH_BUFFER_START *)pTail = bbs;
|
||||
pTail = ((MI_BATCH_BUFFER_START *)pTail) + 1;
|
||||
|
@ -302,13 +343,15 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
|||
|
||||
this->submitLRCA(engineInstance, contextDescriptor);
|
||||
}
|
||||
|
||||
pollForCompletion(engineInstance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::pollForCompletion(EngineInstanceT engineInstance) {
|
||||
if (hardwareContext) {
|
||||
hardwareContext->pollForCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
typedef typename AubMemDump::CmdServicesMemTraceRegisterPoll CmdServicesMemTraceRegisterPoll;
|
||||
|
||||
auto mmioBase = this->getCsTraits(engineInstance).mmioBase;
|
||||
|
@ -321,6 +364,24 @@ void TbxCommandStreamReceiverHw<GfxFamily>::pollForCompletion(EngineInstanceT en
|
|||
CmdServicesMemTraceRegisterPoll::TimeoutActionValues::Abort);
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) {
|
||||
if (hardwareContext) {
|
||||
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
|
||||
hardwareContext->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint);
|
||||
return;
|
||||
}
|
||||
|
||||
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
||||
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
|
||||
AUB::reserveAddressGGTTAndWriteMmeory(tbxStream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, entryBits,
|
||||
aubHelperHw);
|
||||
};
|
||||
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, entryBits, walker, memoryBank);
|
||||
}
|
||||
|
||||
template <typename GfxFamily>
|
||||
bool TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxAllocation) {
|
||||
auto cpuAddress = gfxAllocation.getUnderlyingBuffer();
|
||||
|
@ -330,14 +391,8 @@ bool TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxA
|
|||
if (size == 0)
|
||||
return false;
|
||||
|
||||
AubHelperHw<GfxFamily> aubHelperHw(this->localMemoryEnabled);
|
||||
writeMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), this->getPPGTTAdditionalBits(&gfxAllocation), gfxAllocation.devicesBitfield);
|
||||
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
|
||||
AUB::reserveAddressGGTTAndWriteMmeory(tbxStream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, this->getPPGTTAdditionalBits(&gfxAllocation),
|
||||
aubHelperHw);
|
||||
};
|
||||
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, this->getPPGTTAdditionalBits(&gfxAllocation), walker, this->getMemoryBank(&gfxAllocation));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -353,6 +408,11 @@ void TbxCommandStreamReceiverHw<GfxFamily>::processResidency(ResidencyContainer
|
|||
|
||||
template <typename GfxFamily>
|
||||
void TbxCommandStreamReceiverHw<GfxFamily>::makeCoherent(GraphicsAllocation &gfxAllocation) {
|
||||
if (hardwareContext) {
|
||||
hardwareContext->readMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize());
|
||||
return;
|
||||
}
|
||||
|
||||
auto cpuAddress = gfxAllocation.getUnderlyingBuffer();
|
||||
auto gpuAddress = gfxAllocation.getGpuAddress();
|
||||
auto length = gfxAllocation.getUnderlyingBufferSize();
|
||||
|
|
|
@ -18,6 +18,7 @@ struct HardwareContext {
|
|||
virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 65536) = 0;
|
||||
virtual void freeMemory(uint64_t gfxAddress, size_t size) = 0;
|
||||
virtual void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) = 0;
|
||||
virtual void readMemory(uint64_t gfxAddress, void *memory, size_t size) = 0;
|
||||
virtual ~HardwareContext() = default;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "unit_tests/gen_common/gen_cmd_parse.h"
|
||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "unit_tests/mocks/mock_aub_center.h"
|
||||
#include "unit_tests/mocks/mock_aub_manager.h"
|
||||
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
||||
#include "unit_tests/mocks/mock_tbx_csr.h"
|
||||
#include "test.h"
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -42,21 +45,6 @@ struct TbxFixture : public TbxCommandStreamFixture,
|
|||
}
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
class MockTbxCsr : public TbxCommandStreamReceiverHw<GfxFamily> {
|
||||
public:
|
||||
using CommandStreamReceiver::latestFlushedTaskCount;
|
||||
MockTbxCsr(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment)
|
||||
: TbxCommandStreamReceiverHw<GfxFamily>(hwInfoIn, executionEnvironment) {}
|
||||
|
||||
void makeCoherent(GraphicsAllocation &gfxAllocation) override {
|
||||
auto tagAddress = reinterpret_cast<uint32_t *>(gfxAllocation.getUnderlyingBuffer());
|
||||
*tagAddress = this->latestFlushedTaskCount;
|
||||
makeCoherentCalled = true;
|
||||
}
|
||||
bool makeCoherentCalled = false;
|
||||
};
|
||||
|
||||
typedef Test<TbxFixture> TbxCommandStreamTests;
|
||||
typedef Test<DeviceFixture> TbxCommandSteamSimpleTest;
|
||||
|
||||
|
@ -308,7 +296,7 @@ HWTEST_F(TbxCommandStreamTests, givenDbgDeviceIdFlagIsSetWhenTbxCsrIsCreatedThen
|
|||
|
||||
HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenWaitBeforeMakeNonResidentWhenRequiredIsCalledWithBlockingFlagTrueThenFunctionStallsUntilMakeCoherentUpdatesTagAddress) {
|
||||
uint32_t tag = 0;
|
||||
MockTbxCsr<FamilyType> tbxCsr(*platformDevices[0], *pDevice->executionEnvironment);
|
||||
MockTbxCsrToTestWaitBeforeMakingNonResident<FamilyType> tbxCsr(*platformDevices[0], *pDevice->executionEnvironment);
|
||||
|
||||
tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemory(MockAllocationProperties{false, sizeof(tag)}, &tag));
|
||||
|
||||
|
@ -343,3 +331,112 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCommandStreamReceiverWhenPhysicalAdd
|
|||
ASSERT_NE(nullptr, allocator);
|
||||
hwInfoHelper.pSkuTable = nullptr;
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenItIsCreatedWithUseAubStreamFalseThenDontInitializeAubManager) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.UseAubStream.set(false);
|
||||
|
||||
const HardwareInfo &hwInfo = *platformDevices[0];
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
auto tbxCsr = std::make_unique<TbxCommandStreamReceiverHw<FamilyType>>(hwInfo, executionEnvironment);
|
||||
EXPECT_EQ(nullptr, executionEnvironment.aubCenter->getAubManager());
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenItIsCreatedWithAubManagerThenCreateHardwareContext) {
|
||||
const HardwareInfo &hwInfo = *platformDevices[0];
|
||||
MockAubManager *mockManager = new MockAubManager();
|
||||
MockAubCenter *mockAubCenter = new MockAubCenter(&hwInfo, false, "");
|
||||
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager);
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
executionEnvironment.aubCenter = std::unique_ptr<MockAubCenter>(mockAubCenter);
|
||||
auto tbxCsr = std::make_unique<TbxCommandStreamReceiverHw<FamilyType>>(hwInfo, executionEnvironment);
|
||||
EXPECT_NE(nullptr, tbxCsr->hardwareContext);
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
|
||||
auto mockManager = std::make_unique<MockAubManager>();
|
||||
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
|
||||
|
||||
auto tbxExecutionEnvironment = getEnvironment<MockTbxCsr<FamilyType>>(true, true);
|
||||
auto tbxCsr = tbxExecutionEnvironment->template getCsr<MockTbxCsr<FamilyType>>();
|
||||
tbxCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
|
||||
|
||||
LinearStream cs(tbxExecutionEnvironment->commandBuffer);
|
||||
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 1, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
|
||||
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
|
||||
ResidencyContainer allocationsForResidency = {&allocation};
|
||||
|
||||
tbxCsr->flush(batchBuffer, allocationsForResidency);
|
||||
|
||||
EXPECT_TRUE(mockHardwareContext->initializeCalled);
|
||||
EXPECT_TRUE(mockHardwareContext->writeMemoryCalled);
|
||||
EXPECT_TRUE(mockHardwareContext->submitCalled);
|
||||
EXPECT_TRUE(mockHardwareContext->pollForCompletionCalled);
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverInBatchedModeWhenFlushIsCalledThenItShouldMakeCommandBufferResident) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::BatchedDispatch));
|
||||
|
||||
auto mockManager = std::make_unique<MockAubManager>();
|
||||
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
|
||||
|
||||
auto tbxExecutionEnvironment = getEnvironment<MockTbxCsr<FamilyType>>(true, true);
|
||||
auto tbxCsr = tbxExecutionEnvironment->template getCsr<MockTbxCsr<FamilyType>>();
|
||||
tbxCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
|
||||
|
||||
LinearStream cs(tbxExecutionEnvironment->commandBuffer);
|
||||
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 1, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
|
||||
ResidencyContainer allocationsForResidency;
|
||||
|
||||
tbxCsr->flush(batchBuffer, allocationsForResidency);
|
||||
|
||||
EXPECT_TRUE(mockHardwareContext->writeMemoryCalled);
|
||||
EXPECT_EQ(1u, batchBuffer.commandBufferAllocation->getResidencyTaskCount(tbxCsr->getOsContext().getContextId()));
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledWithZeroSizedBufferThenSubmitIsNotCalledOnHwContext) {
|
||||
auto mockManager = std::make_unique<MockAubManager>();
|
||||
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
|
||||
|
||||
auto tbxExecutionEnvironment = getEnvironment<MockTbxCsr<FamilyType>>(true, true);
|
||||
auto tbxCsr = tbxExecutionEnvironment->template getCsr<MockTbxCsr<FamilyType>>();
|
||||
tbxCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
|
||||
|
||||
LinearStream cs(tbxExecutionEnvironment->commandBuffer);
|
||||
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
|
||||
ResidencyContainer allocationsForResidency;
|
||||
|
||||
tbxCsr->flush(batchBuffer, allocationsForResidency);
|
||||
|
||||
EXPECT_FALSE(mockHardwareContext->submitCalled);
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
|
||||
auto mockManager = std::make_unique<MockAubManager>();
|
||||
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
|
||||
|
||||
auto tbxExecutionEnvironment = getEnvironment<MockTbxCsr<FamilyType>>(true, true);
|
||||
auto tbxCsr = tbxExecutionEnvironment->template getCsr<MockTbxCsr<FamilyType>>();
|
||||
tbxCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
|
||||
|
||||
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
|
||||
ResidencyContainer allocationsForResidency = {&allocation};
|
||||
tbxCsr->processResidency(allocationsForResidency);
|
||||
|
||||
EXPECT_TRUE(mockHardwareContext->writeMemoryCalled);
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeCoherentIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
|
||||
auto mockManager = std::make_unique<MockAubManager>();
|
||||
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
|
||||
|
||||
auto tbxExecutionEnvironment = getEnvironment<MockTbxCsr<FamilyType>>(true, true);
|
||||
auto tbxCsr = tbxExecutionEnvironment->template getCsr<MockTbxCsr<FamilyType>>();
|
||||
tbxCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
|
||||
|
||||
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
|
||||
tbxCsr->makeCoherent(allocation);
|
||||
|
||||
EXPECT_TRUE(mockHardwareContext->readMemoryCalled);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ set(IGDRCL_SRCS_tests_mocks
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/mock_source_level_debugger.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_submissions_aggregator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_svm_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h
|
||||
)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ struct MockHardwareContext : public HardwareContext {
|
|||
void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) override { writeMemoryCalled = true; }
|
||||
void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; }
|
||||
void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; }
|
||||
void readMemory(uint64_t gfxAddress, void *memory, size_t size) override { readMemoryCalled = true; };
|
||||
|
||||
bool initializeCalled = false;
|
||||
bool pollForCompletionCalled = false;
|
||||
|
@ -27,6 +28,7 @@ struct MockHardwareContext : public HardwareContext {
|
|||
bool writeMemoryCalled = false;
|
||||
bool freeMemoryCalled = false;
|
||||
bool expectMemoryCalled = false;
|
||||
bool readMemoryCalled = false;
|
||||
};
|
||||
|
||||
class MockAubManager : public AubManager {
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/aub/aub_center.h"
|
||||
#include "runtime/command_stream/preemption.h"
|
||||
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/helpers/hw_info.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include <string>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
template <typename GfxFamily>
|
||||
class MockTbxCsrToTestWaitBeforeMakingNonResident : public TbxCommandStreamReceiverHw<GfxFamily> {
|
||||
public:
|
||||
using CommandStreamReceiver::latestFlushedTaskCount;
|
||||
MockTbxCsrToTestWaitBeforeMakingNonResident(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment)
|
||||
: TbxCommandStreamReceiverHw<GfxFamily>(hwInfoIn, executionEnvironment) {}
|
||||
|
||||
void makeCoherent(GraphicsAllocation &gfxAllocation) override {
|
||||
auto tagAddress = reinterpret_cast<uint32_t *>(gfxAllocation.getUnderlyingBuffer());
|
||||
*tagAddress = this->latestFlushedTaskCount;
|
||||
makeCoherentCalled = true;
|
||||
}
|
||||
bool makeCoherentCalled = false;
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
class MockTbxCsr : public TbxCommandStreamReceiverHw<GfxFamily> {
|
||||
public:
|
||||
MockTbxCsr(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment)
|
||||
: TbxCommandStreamReceiverHw<GfxFamily>(hwInfoIn, executionEnvironment) {}
|
||||
|
||||
void initializeEngine(size_t engineIndex) {
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(engineIndex);
|
||||
initializeEngineCalled = true;
|
||||
}
|
||||
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) {
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits, devicesBitfield);
|
||||
writeMemoryCalled = true;
|
||||
}
|
||||
void submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override {
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(engineIndex, batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits);
|
||||
submitBatchBufferCalled = true;
|
||||
}
|
||||
void pollForCompletion(EngineInstanceT engineInstance) override {
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::pollForCompletion(engineInstance);
|
||||
pollForCompletionCalled = true;
|
||||
}
|
||||
void makeCoherent(GraphicsAllocation &gfxAllocation) override {
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::makeCoherent(gfxAllocation);
|
||||
makeCoherentCalled = true;
|
||||
}
|
||||
bool initializeEngineCalled = false;
|
||||
bool writeMemoryCalled = false;
|
||||
bool submitBatchBufferCalled = false;
|
||||
bool pollForCompletionCalled = false;
|
||||
bool expectMemoryEqualCalled = false;
|
||||
bool expectMemoryNotEqualCalled = false;
|
||||
bool makeCoherentCalled = false;
|
||||
};
|
||||
|
||||
struct TbxExecutionEnvironment {
|
||||
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
|
||||
GraphicsAllocation *commandBuffer = nullptr;
|
||||
template <typename CsrType>
|
||||
CsrType *getCsr() {
|
||||
return static_cast<CsrType *>(executionEnvironment->commandStreamReceivers[0][0].get());
|
||||
}
|
||||
~TbxExecutionEnvironment() {
|
||||
if (commandBuffer) {
|
||||
executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CsrType>
|
||||
std::unique_ptr<TbxExecutionEnvironment> getEnvironment(bool createTagAllocation, bool allocateCommandBuffer) {
|
||||
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
|
||||
executionEnvironment->aubCenter.reset(new AubCenter());
|
||||
|
||||
executionEnvironment->commandStreamReceivers.resize(1);
|
||||
executionEnvironment->commandStreamReceivers[0][0] = std::make_unique<CsrType>(*platformDevices[0], *executionEnvironment);
|
||||
executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false));
|
||||
if (createTagAllocation) {
|
||||
executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation();
|
||||
}
|
||||
|
||||
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(getChosenEngineType(*platformDevices[0]), PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
|
||||
executionEnvironment->commandStreamReceivers[0][0]->setOsContext(*osContext);
|
||||
|
||||
std::unique_ptr<TbxExecutionEnvironment> tbxExecutionEnvironment(new TbxExecutionEnvironment);
|
||||
if (allocateCommandBuffer) {
|
||||
tbxExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
|
||||
}
|
||||
tbxExecutionEnvironment->executionEnvironment = std::move(executionEnvironment);
|
||||
return tbxExecutionEnvironment;
|
||||
}
|
||||
} // namespace OCLRT
|
Loading…
Reference in New Issue