From cd5f85052e9f575fba6811f288e8ea353708088f Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Sun, 25 Nov 2018 14:58:12 -0800 Subject: [PATCH] AUB CSR with a separate function to submit batch buffer Move code related to batch buffer submission from flush to dedicated function Add parameter to pass aub file name from AubCenter to AubManager Change-Id: I20abb3c8bd92114b3bc9caa2a6291dc1bbddad2a --- runtime/aub/aub_center.cpp | 5 +- runtime/aub/aub_center.h | 2 +- runtime/aub_mem_dump/aub_stream_stubs.cpp | 2 +- .../aub_command_stream_receiver_hw.h | 1 + .../aub_command_stream_receiver_hw.inl | 331 +++++++++--------- .../execution_environment.cpp | 4 +- .../execution_environment.h | 2 +- runtime/platform/platform.cpp | 2 +- third_party/aub_stream/headers/aub_manager.h | 2 +- .../aub_stream/headers/hardware_context.h | 2 + unit_tests/aub/aub_center_tests.cpp | 2 +- .../aub_center_using_aubstream_lib_tests.cpp | 2 +- ...aub_center_using_aubstream_stubs_tests.cpp | 2 +- .../command_stream/aub_file_stream_tests.cpp | 13 + .../execution_environment_tests.cpp | 15 +- unit_tests/mocks/mock_aub_csr.h | 5 + unit_tests/mocks/mock_execution_environment.h | 8 +- 17 files changed, 219 insertions(+), 181 deletions(-) diff --git a/runtime/aub/aub_center.cpp b/runtime/aub/aub_center.cpp index c8d78a82af..dbf5ae4c0a 100644 --- a/runtime/aub/aub_center.cpp +++ b/runtime/aub/aub_center.cpp @@ -10,10 +10,9 @@ #include "runtime/os_interface/debug_settings_manager.h" namespace OCLRT { -AubCenter::AubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled) { +AubCenter::AubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled, const std::string &aubFileName) { if (DebugManager.flags.UseAubStream.get()) { - std::string filename("aub.aub"); - aubManager.reset(AubDump::AubManager::create(pHwInfo->pPlatform->eRenderCoreFamily, 1, 1, localMemoryEnabled, filename)); + aubManager.reset(AubDump::AubManager::create(pHwInfo->pPlatform->eRenderCoreFamily, 1, 1, localMemoryEnabled, pHwInfo->capabilityTable.aubDeviceId, aubFileName)); } addressMapper = std::make_unique(); streamProvider = std::make_unique(); diff --git a/runtime/aub/aub_center.h b/runtime/aub/aub_center.h index 6914b8c0d0..945a24c7f6 100644 --- a/runtime/aub/aub_center.h +++ b/runtime/aub/aub_center.h @@ -17,7 +17,7 @@ struct HardwareInfo; class AubCenter { public: - AubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled); + AubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled, const std::string &aubFileName); virtual ~AubCenter() = default; void initPhysicalAddressAllocator(PhysicalAddressAllocator *pPhysicalAddressAllocator) { diff --git a/runtime/aub_mem_dump/aub_stream_stubs.cpp b/runtime/aub_mem_dump/aub_stream_stubs.cpp index 8eceb890a3..80d008ad05 100644 --- a/runtime/aub_mem_dump/aub_stream_stubs.cpp +++ b/runtime/aub_mem_dump/aub_stream_stubs.cpp @@ -9,7 +9,7 @@ namespace AubDump { -AubManager *AubManager::create(uint32_t gfxFamily, uint32_t devicesCount, size_t memoryBankSizeInGB, bool localMemorySupported, std::string &aubFileName) { +AubManager *AubManager::create(uint32_t gfxFamily, uint32_t devicesCount, size_t memoryBankSizeInGB, bool localMemorySupported, uint32_t deviceId, const std::string &aubFileName) { return nullptr; } diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 96177f3f49..1be2e15473 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -53,6 +53,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::AUBCommandStreamReceiverHw(const Hardware subCaptureManager(std::make_unique(fileName)), standalone(standalone) { - executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled); + executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled, fileName); auto aubCenter = executionEnvironment.aubCenter.get(); UNRECOVERABLE_IF(nullptr == aubCenter); @@ -173,9 +173,13 @@ const std::string &AUBCommandStreamReceiverHw::getFileName() { template void AUBCommandStreamReceiverHw::initializeEngine(size_t engineIndex) { auto engineInstance = allEngineInstances[engineIndex]; - auto mmioBase = getCsTraits(engineInstance).mmioBase; + auto csTraits = getCsTraits(engineInstance); auto &engineInfo = engineInfoTable[engineIndex]; + if (engineInfo.pLRCA) { + return; + } + this->initGlobalMMIO(); initEngineMMIO(engineInstance); this->initAdditionalMMIO(); @@ -211,11 +215,10 @@ void AUBCommandStreamReceiverHw::initializeEngine(size_t engineIndex) AubGTTData data = {0}; getGTTData(reinterpret_cast(physHWSP), data); AUB::reserveAddressGGTT(*stream, engineInfo.ggttHWSP, sizeHWSP, physHWSP, data); - stream->writeMMIO(mmioBase + 0x2080, engineInfo.ggttHWSP); + stream->writeMMIO(csTraits.mmioBase + 0x2080, engineInfo.ggttHWSP); } // Allocate the LRCA - auto csTraits = getCsTraits(engineInstance); const size_t sizeLRCA = csTraits.sizeLRCA; const size_t alignLRCA = csTraits.alignLRCA; auto pLRCABase = alignedMalloc(sizeLRCA, alignLRCA); @@ -280,6 +283,8 @@ void AUBCommandStreamReceiverHw::initializeEngine(size_t engineIndex) // Create a context to facilitate AUB dumping of memory using PPGTT addContextToken(getDumpHandle()); + + DEBUG_BREAK_IF(!engineInfo.pLRCA); } template @@ -325,14 +330,8 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer auto streamLocked = getAubStream()->lockStream(); auto engineIndex = getEngineIndex(engineType); auto engineInstance = allEngineInstances[engineIndex]; - engineType = engineInstance.type; - uint32_t mmioBase = getCsTraits(engineInstance).mmioBase; - auto &engineInfo = engineInfoTable[engineIndex]; - if (!engineInfo.pLRCA) { - initializeEngine(engineIndex); - DEBUG_BREAK_IF(!engineInfo.pLRCA); - } + initializeEngine(engineIndex); // Write our batch buffer auto pBatchBuffer = ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset); @@ -352,30 +351,6 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer } } - { - { - std::ostringstream str; - str << "ppgtt: " << std::hex << std::showbase << pBatchBuffer; - getAubStream()->addComment(str.str().c_str()); - } - - auto physBatchBuffer = ppgtt->map(static_cast(batchBufferGpuAddress), sizeBatchBuffer, - getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation), - this->getMemoryBank(batchBuffer.commandBufferAllocation)); - AubHelperHw aubHelperHw(this->localMemoryEnabled); - AUB::reserveAddressPPGTT(*stream, static_cast(batchBufferGpuAddress), sizeBatchBuffer, physBatchBuffer, - getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation), - aubHelperHw); - - AUB::addMemoryWrite( - *stream, - physBatchBuffer, - pBatchBuffer, - sizeBatchBuffer, - this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary), - AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary); - } - if (this->standalone) { if (this->dispatchMode == DispatchMode::ImmediateDispatch) { if (!DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { @@ -387,129 +362,8 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer } } processResidency(allocationsForResidency, osContext); - if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { - addGUCStartMessage(static_cast(reinterpret_cast(pBatchBuffer)), engineType); - addPatchInfoComments(); - } - // Add a batch buffer start to the ring buffer - auto previousTail = engineInfo.tailRingBuffer; - { - typedef typename GfxFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; - typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; - typedef typename GfxFamily::MI_NOOP MI_NOOP; - - auto pTail = ptrOffset(engineInfo.pRingBuffer, engineInfo.tailRingBuffer); - auto ggttTail = ptrOffset(engineInfo.ggttRingBuffer, engineInfo.tailRingBuffer); - - auto sizeNeeded = - sizeof(MI_BATCH_BUFFER_START) + - sizeof(MI_LOAD_REGISTER_IMM); - - auto tailAlignment = sizeof(uint64_t); - sizeNeeded = alignUp(sizeNeeded, tailAlignment); - - if (engineInfo.tailRingBuffer + sizeNeeded >= engineInfo.sizeRingBuffer) { - // Pad the remaining ring with NOOPs - auto sizeToWrap = engineInfo.sizeRingBuffer - engineInfo.tailRingBuffer; - memset(pTail, 0, sizeToWrap); - // write remaining ring - - auto physDumpStart = ggtt->map(ggttTail, sizeToWrap, this->getGTTBits(), getMemoryBankForGtt()); - AUB::addMemoryWrite( - *stream, - physDumpStart, - pTail, - sizeToWrap, - this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer), - AubMemDump::DataTypeHintValues::TraceCommandBuffer); - previousTail = 0; - engineInfo.tailRingBuffer = 0; - pTail = engineInfo.pRingBuffer; - } else if (engineInfo.tailRingBuffer == 0) { - // Add a LRI if this is our first submission - auto lri = MI_LOAD_REGISTER_IMM::sInit(); - lri.setRegisterOffset(mmioBase + 0x2244); - lri.setDataDword(0x00010000); - *(MI_LOAD_REGISTER_IMM *)pTail = lri; - pTail = ((MI_LOAD_REGISTER_IMM *)pTail) + 1; - } - - // Add our BBS - auto bbs = MI_BATCH_BUFFER_START::sInit(); - bbs.setBatchBufferStartAddressGraphicsaddress472(static_cast(batchBufferGpuAddress)); - bbs.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT); - *(MI_BATCH_BUFFER_START *)pTail = bbs; - pTail = ((MI_BATCH_BUFFER_START *)pTail) + 1; - - // Compute our new ring tail. - engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer); - - // Add NOOPs as needed as our tail needs to be aligned - while (engineInfo.tailRingBuffer % tailAlignment) { - *(MI_NOOP *)pTail = MI_NOOP::sInit(); - pTail = ((MI_NOOP *)pTail) + 1; - engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer); - } - UNRECOVERABLE_IF((engineInfo.tailRingBuffer % tailAlignment) != 0); - - // Only dump the new commands - auto ggttDumpStart = ptrOffset(engineInfo.ggttRingBuffer, previousTail); - auto dumpStart = ptrOffset(engineInfo.pRingBuffer, previousTail); - auto dumpLength = engineInfo.tailRingBuffer - previousTail; - - // write ring - { - std::ostringstream str; - str << "ggtt: " << std::hex << std::showbase << ggttDumpStart; - getAubStream()->addComment(str.str().c_str()); - } - - auto physDumpStart = ggtt->map(ggttDumpStart, dumpLength, this->getGTTBits(), getMemoryBankForGtt()); - AUB::addMemoryWrite( - *stream, - physDumpStart, - dumpStart, - dumpLength, - this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer), - AubMemDump::DataTypeHintValues::TraceCommandBuffer); - - // update the ring mmio tail in the LRCA - { - std::ostringstream str; - str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttLRCA + 0x101c; - getAubStream()->addComment(str.str().c_str()); - } - - auto physLRCA = ggtt->map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRingBuffer), this->getGTTBits(), getMemoryBankForGtt()); - AUB::addMemoryWrite( - *stream, - physLRCA + 0x101c, - &engineInfo.tailRingBuffer, - sizeof(engineInfo.tailRingBuffer), - this->getAddressSpace(getCsTraits(engineInstance).aubHintLRCA)); - - DEBUG_BREAK_IF(engineInfo.tailRingBuffer >= engineInfo.sizeRingBuffer); - } - - // Submit our execlist by submitting to the execlist submit ports - { - typename AUB::MiContextDescriptorReg contextDescriptor = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; - - contextDescriptor.sData.Valid = true; - contextDescriptor.sData.ForcePageDirRestore = false; - contextDescriptor.sData.ForceRestore = false; - contextDescriptor.sData.Legacy = true; - contextDescriptor.sData.FaultSupport = 0; - contextDescriptor.sData.PrivilegeAccessOrPPGTT = true; - contextDescriptor.sData.ADor64bitSupport = AUB::Traits::addressingBits > 32; - - auto ggttLRCA = engineInfo.ggttLRCA; - contextDescriptor.sData.LogicalRingCtxAddress = ggttLRCA / 4096; - contextDescriptor.sData.ContextID = 0; - - submitLRCA(engineInstance, contextDescriptor); - } + submitBatchBuffer(engineIndex, batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this->getMemoryBank(batchBuffer.commandBufferAllocation), getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation)); pollForCompletion(engineInstance); if (this->standalone) { @@ -567,6 +421,158 @@ bool AUBCommandStreamReceiverHw::addPatchInfoComments() { return true; } +template +void AUBCommandStreamReceiverHw::submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) { + auto engineInstance = allEngineInstances[engineIndex]; + auto csTraits = getCsTraits(engineInstance); + auto &engineInfo = engineInfoTable[engineIndex]; + + { + { + std::ostringstream str; + str << "ppgtt: " << std::hex << std::showbase << batchBuffer; + getAubStream()->addComment(str.str().c_str()); + } + + auto physBatchBuffer = ppgtt->map(static_cast(batchBufferGpuAddress), batchBufferSize, entryBits, memoryBank); + AubHelperHw aubHelperHw(this->localMemoryEnabled); + AUB::reserveAddressPPGTT(*stream, static_cast(batchBufferGpuAddress), batchBufferSize, physBatchBuffer, + entryBits, aubHelperHw); + + AUB::addMemoryWrite( + *stream, + physBatchBuffer, + batchBuffer, + batchBufferSize, + this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary), + AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary); + } + + if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { + addGUCStartMessage(static_cast(reinterpret_cast(batchBuffer)), engineInstance.type); + addPatchInfoComments(); + } + + // Add a batch buffer start to the ring buffer + auto previousTail = engineInfo.tailRingBuffer; + { + typedef typename GfxFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; + typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + typedef typename GfxFamily::MI_NOOP MI_NOOP; + + auto pTail = ptrOffset(engineInfo.pRingBuffer, engineInfo.tailRingBuffer); + auto ggttTail = ptrOffset(engineInfo.ggttRingBuffer, engineInfo.tailRingBuffer); + + auto sizeNeeded = + sizeof(MI_BATCH_BUFFER_START) + + sizeof(MI_LOAD_REGISTER_IMM); + + auto tailAlignment = sizeof(uint64_t); + sizeNeeded = alignUp(sizeNeeded, tailAlignment); + + if (engineInfo.tailRingBuffer + sizeNeeded >= engineInfo.sizeRingBuffer) { + // Pad the remaining ring with NOOPs + auto sizeToWrap = engineInfo.sizeRingBuffer - engineInfo.tailRingBuffer; + memset(pTail, 0, sizeToWrap); + // write remaining ring + + auto physDumpStart = ggtt->map(ggttTail, sizeToWrap, this->getGTTBits(), getMemoryBankForGtt()); + AUB::addMemoryWrite( + *stream, + physDumpStart, + pTail, + sizeToWrap, + this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer), + AubMemDump::DataTypeHintValues::TraceCommandBuffer); + previousTail = 0; + engineInfo.tailRingBuffer = 0; + pTail = engineInfo.pRingBuffer; + } else if (engineInfo.tailRingBuffer == 0) { + // Add a LRI if this is our first submission + auto lri = MI_LOAD_REGISTER_IMM::sInit(); + lri.setRegisterOffset(csTraits.mmioBase + 0x2244); + lri.setDataDword(0x00010000); + *(MI_LOAD_REGISTER_IMM *)pTail = lri; + pTail = ((MI_LOAD_REGISTER_IMM *)pTail) + 1; + } + + // Add our BBS + auto bbs = MI_BATCH_BUFFER_START::sInit(); + bbs.setBatchBufferStartAddressGraphicsaddress472(static_cast(batchBufferGpuAddress)); + bbs.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT); + *(MI_BATCH_BUFFER_START *)pTail = bbs; + pTail = ((MI_BATCH_BUFFER_START *)pTail) + 1; + + // Compute our new ring tail. + engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer); + + // Add NOOPs as needed as our tail needs to be aligned + while (engineInfo.tailRingBuffer % tailAlignment) { + *(MI_NOOP *)pTail = MI_NOOP::sInit(); + pTail = ((MI_NOOP *)pTail) + 1; + engineInfo.tailRingBuffer = (uint32_t)ptrDiff(pTail, engineInfo.pRingBuffer); + } + UNRECOVERABLE_IF((engineInfo.tailRingBuffer % tailAlignment) != 0); + + // Only dump the new commands + auto ggttDumpStart = ptrOffset(engineInfo.ggttRingBuffer, previousTail); + auto dumpStart = ptrOffset(engineInfo.pRingBuffer, previousTail); + auto dumpLength = engineInfo.tailRingBuffer - previousTail; + + // write ring + { + std::ostringstream str; + str << "ggtt: " << std::hex << std::showbase << ggttDumpStart; + getAubStream()->addComment(str.str().c_str()); + } + + auto physDumpStart = ggtt->map(ggttDumpStart, dumpLength, this->getGTTBits(), getMemoryBankForGtt()); + AUB::addMemoryWrite( + *stream, + physDumpStart, + dumpStart, + dumpLength, + this->getAddressSpace(AubMemDump::DataTypeHintValues::TraceCommandBuffer), + AubMemDump::DataTypeHintValues::TraceCommandBuffer); + + // update the ring mmio tail in the LRCA + { + std::ostringstream str; + str << "ggtt: " << std::hex << std::showbase << engineInfo.ggttLRCA + 0x101c; + getAubStream()->addComment(str.str().c_str()); + } + + auto physLRCA = ggtt->map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRingBuffer), this->getGTTBits(), getMemoryBankForGtt()); + AUB::addMemoryWrite( + *stream, + physLRCA + 0x101c, + &engineInfo.tailRingBuffer, + sizeof(engineInfo.tailRingBuffer), + this->getAddressSpace(csTraits.aubHintLRCA)); + + DEBUG_BREAK_IF(engineInfo.tailRingBuffer >= engineInfo.sizeRingBuffer); + } + + // Submit our execlist by submitting to the execlist submit ports + { + typename AUB::MiContextDescriptorReg contextDescriptor = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + contextDescriptor.sData.Valid = true; + contextDescriptor.sData.ForcePageDirRestore = false; + contextDescriptor.sData.ForceRestore = false; + contextDescriptor.sData.Legacy = true; + contextDescriptor.sData.FaultSupport = 0; + contextDescriptor.sData.PrivilegeAccessOrPPGTT = true; + contextDescriptor.sData.ADor64bitSupport = AUB::Traits::addressingBits > 32; + + auto ggttLRCA = engineInfo.ggttLRCA; + contextDescriptor.sData.LogicalRingCtxAddress = ggttLRCA / 4096; + contextDescriptor.sData.ContextID = 0; + + submitLRCA(engineInstance, contextDescriptor); + } +} + template void AUBCommandStreamReceiverHw::submitLRCA(EngineInstanceT engineInstance, const typename AUBCommandStreamReceiverHw::MiContextDescriptorReg &contextDescriptor) { auto mmioBase = getCsTraits(engineInstance).mmioBase; @@ -617,17 +623,16 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA if ((size == 0) || !gfxAllocation.isAubWritable()) return false; - { - std::ostringstream str; - str << "ppgtt: " << std::hex << std::showbase << gpuAddress << " end address: " << gpuAddress + size << " cpu address: " << cpuAddress << " device mask: " << gfxAllocation.devicesBitfield << " size: " << std::dec << size; - getAubStream()->addComment(str.str().c_str()); - } - if (cpuAddress == nullptr) { DEBUG_BREAK_IF(gfxAllocation.isLocked()); cpuAddress = this->getMemoryManager()->lockResource(&gfxAllocation); gfxAllocation.setLocked(true); } + { + std::ostringstream str; + str << "ppgtt: " << std::hex << std::showbase << gpuAddress << " end address: " << gpuAddress + size << " cpu address: " << cpuAddress << " device mask: " << gfxAllocation.devicesBitfield << " size: " << std::dec << size; + getAubStream()->addComment(str.str().c_str()); + } AubHelperHw aubHelperHw(this->localMemoryEnabled); diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 9dee3f0b05..5b65e2ebc2 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -23,9 +23,9 @@ ExecutionEnvironment::ExecutionEnvironment() = default; ExecutionEnvironment::~ExecutionEnvironment() = default; extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); -void ExecutionEnvironment::initAubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled) { +void ExecutionEnvironment::initAubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled, const std::string &aubFileName) { if (!aubCenter) { - aubCenter.reset(new AubCenter(pHwInfo, localMemoryEnabled)); + aubCenter.reset(new AubCenter(pHwInfo, localMemoryEnabled, aubFileName)); } } void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) { diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 06bd4be2d6..b8656d5de2 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -37,7 +37,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject ExecutionEnvironment(); ~ExecutionEnvironment() override; - MOCKABLE_VIRTUAL void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled); + MOCKABLE_VIRTUAL void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled, const std::string &aubFileName); void initGmm(const HardwareInfo *hwInfo); bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex, uint32_t deviceCsrIndex); void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex, uint32_t deviceCsrIndex); diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index ecffa3f1d7..d64f2e8e60 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -168,7 +168,7 @@ bool Platform::initialize() { CommandStreamReceiverType csrType = this->devices[0]->getEngine(0).commandStreamReceiver->getType(); if (csrType != CommandStreamReceiverType::CSR_HW) { - executionEnvironment->initAubCenter(&hwInfo[0], this->devices[0]->getEnableLocalMemory()); + executionEnvironment->initAubCenter(&hwInfo[0], this->devices[0]->getEnableLocalMemory(), "aubfile"); } this->fillGlobalDispatchTable(); diff --git a/third_party/aub_stream/headers/aub_manager.h b/third_party/aub_stream/headers/aub_manager.h index 205f4e38c5..d98ace6b99 100644 --- a/third_party/aub_stream/headers/aub_manager.h +++ b/third_party/aub_stream/headers/aub_manager.h @@ -18,7 +18,7 @@ class AubManager { virtual ~AubManager() = default; virtual HardwareContext *createHardwareContext(uint32_t device, uint32_t engine) = 0; - static AubManager *create(uint32_t gfxFamily, uint32_t devicesCount, size_t memoryBankSizeInGB, bool localMemorySupported, std::string &aubFileName); + static AubManager *create(uint32_t gfxFamily, uint32_t devicesCount, size_t memoryBankSizeInGB, bool localMemorySupported, uint32_t deviceId, const std::string &aubFileName); }; } // namespace AubDump diff --git a/third_party/aub_stream/headers/hardware_context.h b/third_party/aub_stream/headers/hardware_context.h index 5aa0324960..2c1bd7c70d 100644 --- a/third_party/aub_stream/headers/hardware_context.h +++ b/third_party/aub_stream/headers/hardware_context.h @@ -7,6 +7,7 @@ #pragma once #include +#include namespace AubDump { @@ -16,6 +17,7 @@ struct HardwareContext { virtual void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank) = 0; virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) = 0; virtual void freeMemory(uint64_t gfxAddress, size_t size) = 0; + virtual ~HardwareContext() = default; }; } // namespace AubDump diff --git a/unit_tests/aub/aub_center_tests.cpp b/unit_tests/aub/aub_center_tests.cpp index 0f826e7d2d..c7b10552b8 100644 --- a/unit_tests/aub/aub_center_tests.cpp +++ b/unit_tests/aub/aub_center_tests.cpp @@ -18,6 +18,6 @@ TEST(AubCenter, GivenUseAubStreamDebugVariableNotSetWhenAubCenterIsCreatedThenAu DebugManagerStateRestore restorer; DebugManager.flags.UseAubStream.set(false); - MockAubCenter aubCenter(platformDevices[0], false); + MockAubCenter aubCenter(platformDevices[0], false, ""); EXPECT_EQ(nullptr, aubCenter.aubManager.get()); } diff --git a/unit_tests/aub/aub_center_using_aubstream_lib_tests.cpp b/unit_tests/aub/aub_center_using_aubstream_lib_tests.cpp index fd850abb3d..859bcdc0d1 100644 --- a/unit_tests/aub/aub_center_using_aubstream_lib_tests.cpp +++ b/unit_tests/aub/aub_center_using_aubstream_lib_tests.cpp @@ -18,7 +18,7 @@ TEST(AubCenter, GivenUseAubStreamDebugVariableSetWhenAubCenterIsCreatedThenAubCe DebugManagerStateRestore restorer; DebugManager.flags.UseAubStream.set(true); - MockAubCenter aubCenter(platformDevices[0], false); + MockAubCenter aubCenter(platformDevices[0], false, ""); EXPECT_NE(nullptr, aubCenter.aubManager.get()); } diff --git a/unit_tests/aub/aub_center_using_aubstream_stubs_tests.cpp b/unit_tests/aub/aub_center_using_aubstream_stubs_tests.cpp index 229d3cfa32..f11ad08584 100644 --- a/unit_tests/aub/aub_center_using_aubstream_stubs_tests.cpp +++ b/unit_tests/aub/aub_center_using_aubstream_stubs_tests.cpp @@ -18,7 +18,7 @@ TEST(AubCenter, GivenUseAubStreamDebugVariableSetWhenAubCenterIsCreatedThenAubMa DebugManagerStateRestore restorer; DebugManager.flags.UseAubStream.set(true); - MockAubCenter aubCenter(platformDevices[0], false); + MockAubCenter aubCenter(platformDevices[0], false, ""); EXPECT_EQ(nullptr, aubCenter.aubManager.get()); } diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index e5f5a7b50e..a214d241cd 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -118,6 +118,19 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenF EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); } +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallSubmitBatchBuffer) { + auto aubExecutionEnvironment = getEnvironment>(false, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + auto engineType = OCLRT::ENGINE_RCS; + ResidencyContainer allocationsForResidency = {}; + + aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); + EXPECT_TRUE(aubCsr->submitBatchBufferCalled); +} + HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallPollForCompletion) { auto aubExecutionEnvironment = getEnvironment>(false, true, false); auto aubCsr = aubExecutionEnvironment->template getCsr>(); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 93e33ddb8f..7a7e07d897 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -20,6 +20,7 @@ #include "test.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_memory_manager.h" #include "unit_tests/utilities/destructor_counted.h" #include "unit_tests/helpers/unit_test_helper.h" @@ -123,16 +124,24 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultip EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0][0].get()); } +TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsReceivesCorrectInputParams) { + MockExecutionEnvironment executionEnvironment; + executionEnvironment.initAubCenter(platformDevices[0], true, "test.aub"); + EXPECT_TRUE(executionEnvironment.initAubCenterCalled); + EXPECT_TRUE(executionEnvironment.localMemoryEnabledReceived); + EXPECT_STREQ(executionEnvironment.aubFileNameReceived.c_str(), "test.aub"); +} + TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) { ExecutionEnvironment executionEnvironment; - executionEnvironment.initAubCenter(platformDevices[0], false); + executionEnvironment.initAubCenter(platformDevices[0], false, ""); auto currentAubCenter = executionEnvironment.aubCenter.get(); EXPECT_NE(nullptr, currentAubCenter); auto currentAubStreamProvider = currentAubCenter->getStreamProvider(); EXPECT_NE(nullptr, currentAubStreamProvider); auto currentAubFileStream = currentAubStreamProvider->getStream(); EXPECT_NE(nullptr, currentAubFileStream); - executionEnvironment.initAubCenter(platformDevices[0], false); + executionEnvironment.initAubCenter(platformDevices[0], false, ""); EXPECT_EQ(currentAubCenter, executionEnvironment.aubCenter.get()); EXPECT_EQ(currentAubStreamProvider, executionEnvironment.aubCenter->getStreamProvider()); EXPECT_EQ(currentAubFileStream, executionEnvironment.aubCenter->getStreamProvider()->getStream()); @@ -170,7 +179,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; struct AubCenterMock : public DestructorCounted { - AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId, platformDevices[0], false) {} + AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId, platformDevices[0], false, "") {} }; struct CommandStreamReceiverMock : public DestructorCounted { CommandStreamReceiverMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index cb327fb9e5..6ea0403206 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -71,11 +71,16 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { void initProgrammingFlags() override { initProgrammingFlagsCalled = true; } + void submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override { + AUBCommandStreamReceiverHw::submitBatchBuffer(engineIndex, batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits); + submitBatchBufferCalled = true; + } void pollForCompletion(EngineInstanceT engineInstance) override { pollForCompletionCalled = true; } bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; + bool submitBatchBufferCalled = false; bool pollForCompletionCalled = false; void initFile(const std::string &fileName) override { diff --git a/unit_tests/mocks/mock_execution_environment.h b/unit_tests/mocks/mock_execution_environment.h index 25ee0082c5..36cb0fb69c 100644 --- a/unit_tests/mocks/mock_execution_environment.h +++ b/unit_tests/mocks/mock_execution_environment.h @@ -11,10 +11,14 @@ namespace OCLRT { struct MockExecutionEnvironment : ExecutionEnvironment { MockExecutionEnvironment() = default; - void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled) override { + void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled, const std::string &aubFileName) override { initAubCenterCalled = true; - ExecutionEnvironment::initAubCenter(hwInfo, localMemoryEnabled); + localMemoryEnabledReceived = localMemoryEnabled; + aubFileNameReceived = aubFileName; + ExecutionEnvironment::initAubCenter(hwInfo, localMemoryEnabled, aubFileName); } bool initAubCenterCalled = false; + bool localMemoryEnabledReceived = false; + std::string aubFileNameReceived = ""; }; } // namespace OCLRT