diff --git a/runtime/command_queue/command_queue_hw.h b/runtime/command_queue/command_queue_hw.h index b0d6c8b137..258512c8c5 100644 --- a/runtime/command_queue/command_queue_hw.h +++ b/runtime/command_queue/command_queue_hw.h @@ -65,7 +65,7 @@ class CommandQueueHw : public CommandQueue { } if (getCmdQueueProperties(properties, CL_QUEUE_PROPERTIES) & static_cast(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)) { - device->getCommandStreamReceiver().overrideDispatchPolicy(CommandStreamReceiver::BatchedDispatch); + device->getCommandStreamReceiver().overrideDispatchPolicy(DispatchMode::BatchedDispatch); } } diff --git a/runtime/command_queue/enqueue_common.h b/runtime/command_queue/enqueue_common.h index f960875060..fbacef1350 100644 --- a/runtime/command_queue/enqueue_common.h +++ b/runtime/command_queue/enqueue_common.h @@ -259,7 +259,7 @@ void CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { for (auto &dispatchInfo : multiDispatchInfo) { for (auto &patchInfoData : dispatchInfo.getKernel()->getPatchInfoDataList()) { - commandStreamReceiver.setPatchInfoData(patchInfoData); + commandStreamReceiver.getFlatBatchBufferHelper().setPatchInfoData(patchInfoData); } } } diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 596b92242c..803adb1cb5 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -63,13 +63,10 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw { MemoryManager *createMemoryManager(bool enable64kbPages) override { this->memoryManager = new OsAgnosticMemoryManager(enable64kbPages); + this->flatBatchBufferHelper->setMemoryManager(this->memoryManager); return this->memoryManager; } - bool setPatchInfoData(PatchInfoData &data) override; - - std::vector patchInfoCollection; - static const AubMemDump::LrcaHelper &getCsTraits(EngineType engineType); struct EngineInfo { @@ -91,7 +88,8 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw { // remap CPU VA -> GGTT VA AddressMapper gttRemap; - MOCKABLE_VIRTUAL void *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer); MOCKABLE_VIRTUAL bool addPatchInfoComments(); + void addGUCStartMessage(uint64_t batchBufferAddress, EngineType engineType); + uint32_t getGUCWorkQueueItemHeader(EngineType engineType); }; } // namespace OCLRT diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index d2e0ad09c8..cc84fd6c85 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -37,9 +37,9 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware : BaseClass(hwInfoIn), stream(std::unique_ptr(new AUBCommandStreamReceiver::AubFileStream())), standalone(standalone) { - this->dispatchMode = CommandStreamReceiver::DispatchMode::BatchedDispatch; + this->dispatchMode = DispatchMode::BatchedDispatch; if (DebugManager.flags.CsrDispatchMode.get()) { - this->dispatchMode = (CommandStreamReceiver::DispatchMode)DebugManager.flags.CsrDispatchMode.get(); + this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get(); } for (auto &engineInfo : engineInfoTable) { engineInfo.pLRCA = nullptr; @@ -221,8 +221,8 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset; std::unique_ptr> flatBatchBuffer(nullptr, [&](void *ptr) { this->getMemoryManager()->alignedFreeWrapper(ptr); }); - if (DebugManager.flags.FlattenBatchBufferForAUBDump.get() && (this->dispatchMode == CommandStreamReceiver::DispatchMode::ImmediateDispatch)) { - flatBatchBuffer.reset(flattenBatchBuffer(batchBuffer, sizeBatchBuffer)); + if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { + flatBatchBuffer.reset(this->flatBatchBufferHelper->flattenBatchBuffer(batchBuffer, sizeBatchBuffer, this->dispatchMode)); if (flatBatchBuffer.get() != nullptr) { pBatchBuffer = flatBatchBuffer.get(); } @@ -248,7 +248,7 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer } if (this->standalone) { - if (this->dispatchMode == CommandStreamReceiver::DispatchMode::ImmediateDispatch) { + if (this->dispatchMode == DispatchMode::ImmediateDispatch) { if (!DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { makeResident(*batchBuffer.commandBufferAllocation); } @@ -259,6 +259,7 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer processResidency(allocationsForResidency); } if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { + addGUCStartMessage(static_cast(reinterpret_cast(pBatchBuffer)), engineType); addPatchInfoComments(); } @@ -387,32 +388,13 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer return 0; } -template -void *AUBCommandStreamReceiverHw::flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer) { - void *flatBatchBuffer = nullptr; - - if (batchBuffer.chainedBatchBuffer) { - batchBuffer.chainedBatchBuffer->setTypeAubNonWritable(); - auto sizeMainBatchBuffer = batchBuffer.chainedBatchBufferStartOffset - batchBuffer.startOffset; - auto flatBatchBufferSize = alignUp(sizeMainBatchBuffer + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); - flatBatchBuffer = this->getMemoryManager()->alignedMallocWrapper(flatBatchBufferSize, MemoryConstants::pageSize); - UNRECOVERABLE_IF(flatBatchBuffer == nullptr); - // Copy FLB - memcpy_s(flatBatchBuffer, sizeMainBatchBuffer, ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset), sizeMainBatchBuffer); - // Copy SLB - memcpy_s(ptrOffset(flatBatchBuffer, sizeMainBatchBuffer), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), batchBuffer.chainedBatchBuffer->getUnderlyingBuffer(), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize()); - sizeBatchBuffer = flatBatchBufferSize; - } - return flatBatchBuffer; -} - template bool AUBCommandStreamReceiverHw::addPatchInfoComments() { std::map allocationsMap; std::ostringstream str; str << "PatchInfoData" << std::endl; - for (auto &patchInfoData : this->patchInfoCollection) { + for (auto &patchInfoData : this->flatBatchBufferHelper->getPatchInfoCollection()) { str << std::hex << patchInfoData.sourceAllocation << ";"; str << std::hex << patchInfoData.sourceAllocationOffset << ";"; str << std::hex << patchInfoData.sourceType << ";"; @@ -432,7 +414,7 @@ bool AUBCommandStreamReceiverHw::addPatchInfoComments() { } } bool result = stream->addComment(str.str().c_str()); - this->patchInfoCollection.clear(); + this->flatBatchBufferHelper->getPatchInfoCollection().clear(); if (!result) { return false; } @@ -547,8 +529,41 @@ void AUBCommandStreamReceiverHw::addContextToken() { } template -bool AUBCommandStreamReceiverHw::setPatchInfoData(PatchInfoData &data) { - patchInfoCollection.push_back(data); - return true; +void AUBCommandStreamReceiverHw::addGUCStartMessage(uint64_t batchBufferAddress, EngineType engineType) { + typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + + auto bufferSize = sizeof(uint32_t) + sizeof(MI_BATCH_BUFFER_START); + + std::unique_ptr> buffer(this->getMemoryManager()->alignedMallocWrapper(bufferSize, MemoryConstants::pageSize), [&](void *ptr) { this->getMemoryManager()->alignedFreeWrapper(ptr); }); + LinearStream linearStream(buffer.get(), bufferSize); + + uint32_t *header = static_cast(linearStream.getSpace(sizeof(uint32_t))); + *header = getGUCWorkQueueItemHeader(engineType); + + MI_BATCH_BUFFER_START *miBatchBufferStart = linearStream.getSpaceForCmd(); + DEBUG_BREAK_IF(bufferSize != linearStream.getUsed()); + miBatchBufferStart->init(); + miBatchBufferStart->setBatchBufferStartAddressGraphicsaddress472(AUB::ptrToPPGTT(buffer.get())); + miBatchBufferStart->setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT); + + auto physBufferAddres = ppgtt.map(reinterpret_cast(buffer.get()), bufferSize); + AUB::reserveAddressPPGTT(*stream, reinterpret_cast(buffer.get()), bufferSize, physBufferAddres); + + AUB::addMemoryWrite( + *stream, + physBufferAddres, + buffer.get(), + bufferSize, + AubMemDump::AddressSpaceValues::TraceNonlocal); + + PatchInfoData patchInfoData(batchBufferAddress, 0u, PatchInfoAllocationType::Default, reinterpret_cast(buffer.get()), sizeof(uint32_t) + sizeof(MI_BATCH_BUFFER_START) - sizeof(uint64_t), PatchInfoAllocationType::GUCStartMessage); + this->flatBatchBufferHelper->setPatchInfoData(patchInfoData); } + +template +uint32_t AUBCommandStreamReceiverHw::getGUCWorkQueueItemHeader(EngineType engineType) { + uint32_t GUCWorkQueueItemHeader = 0x00030001; + return GUCWorkQueueItemHeader; +} + } // namespace OCLRT diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 3bcf94b235..a6cf078ff4 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -127,6 +127,9 @@ MemoryManager *CommandStreamReceiver::getMemoryManager() { void CommandStreamReceiver::setMemoryManager(MemoryManager *mm) { memoryManager = mm; + if (flatBatchBufferHelper) { + flatBatchBufferHelper->setMemoryManager(mm); + } } LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 079970ac06..84b0073262 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -27,6 +27,7 @@ #include "runtime/helpers/completion_stamp.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/address_patch.h" +#include "runtime/helpers/flat_batch_buffer_helper.h" #include "runtime/command_stream/csr_definitions.h" #include #include @@ -40,16 +41,16 @@ class MemoryManager; class OSInterface; class GraphicsAllocation; +enum class DispatchMode { + DeviceDefault = 0, //default for given device + ImmediateDispatch, //everything is submitted to the HW immediately + AdaptiveDispatch, //dispatching is handled to async thread, which combines batch buffers basing on load (not implemented) + BatchedDispatchWithCounter, //dispatching is batched, after n commands there is implicit flush (not implemented) + BatchedDispatch // dispatching is batched, explicit clFlush is required +}; + class CommandStreamReceiver { public: - enum DispatchMode { - DeviceDefault = 0, //default for given device - ImmediateDispatch, //everything is submitted to the HW immediately - AdaptiveDispatch, //dispatching is handled to async thread, which combines batch buffers basing on load (not implemented) - BatchedDispatchWithCounter, //dispatching is batched, after n commands there is implicit flush (not implemented) - BatchedDispatch // dispatching is batched, explicit clFlush is required - }; - enum class SamplerCacheFlushState { samplerCacheFlushNotRequired, samplerCacheFlushBefore, //add sampler cache flush before Walker with redescribed image @@ -102,7 +103,7 @@ class CommandStreamReceiver { uint32_t peekLatestFlushedTaskCount() const { return latestFlushedTaskCount; } - void overrideDispatchPolicy(CommandStreamReceiver::DispatchMode overrideValue) { this->dispatchMode = overrideValue; } + void overrideDispatchPolicy(DispatchMode overrideValue) { this->dispatchMode = overrideValue; } virtual void overrideMediaVFEStateDirty(bool dirty) { mediaVfeStateDirty = dirty; } @@ -122,8 +123,8 @@ class CommandStreamReceiver { void setSamplerCacheFlushRequired(SamplerCacheFlushState value) { this->samplerCacheFlushRequired = value; } - // Collect patch info data - virtual bool setPatchInfoData(PatchInfoData &data) { return false; } + FlatBatchBufferHelper &getFlatBatchBufferHelper() { return *flatBatchBufferHelper.get(); } + void overwriteFlatBatchBufferHelper(FlatBatchBufferHelper *newHelper) { flatBatchBufferHelper.reset(newHelper); } protected: void setDisableL3Cache(bool val) { @@ -167,11 +168,12 @@ class CommandStreamReceiver { std::unique_ptr osInterface; std::unique_ptr submissionAggregator; - DispatchMode dispatchMode = ImmediateDispatch; + DispatchMode dispatchMode = DispatchMode::ImmediateDispatch; bool disableL3Cache = false; uint32_t requiredScratchSize = 0; uint64_t totalMemoryUsed = 0u; SamplerCacheFlushState samplerCacheFlushRequired = SamplerCacheFlushState::samplerCacheFlushNotRequired; + std::unique_ptr flatBatchBufferHelper; }; typedef CommandStreamReceiver *(*CommandStreamReceiverCreateFunc)(const HardwareInfo &hwInfoIn, bool withAubDump); diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index e5dbc71e8e..bbd42e657b 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -55,7 +55,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { int getRequiredPipeControlSize() const; static void addBatchBufferEnd(LinearStream &commandStream, void **patchLocation); - static void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress); + void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress); static void alignToCacheLine(LinearStream &commandStream); size_t getRequiredCmdStreamSize(const DispatchFlags &dispatchFlags); @@ -71,13 +71,12 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { const HardwareInfo &peekHwInfo() const { return hwInfo; } void collectStateBaseAddresPatchInfo( - uint64_t baseAddress, + uint64_t commandBufferAddress, uint64_t commandOffset, const LinearStream &dsh, const LinearStream &ioh, const LinearStream &ssh, - uint64_t generalStateBase, - uint64_t internalHeapBaseAddress); + uint64_t generalStateBase); void resetKmdNotifyHelper(KmdNotifyHelper *newHelper); diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 2ce070a0fd..0a72b671e0 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -25,6 +25,7 @@ #include "runtime/device/device.h" #include "runtime/gtpin/gtpin_notify.h" #include "runtime/helpers/cache_policy.h" +#include "runtime/helpers/flat_batch_buffer_helper_hw.h" #include "runtime/helpers/preamble.h" #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/state_base_address.h" @@ -41,6 +42,7 @@ template CommandStreamReceiverHw::CommandStreamReceiverHw(const HardwareInfo &hwInfoIn) : hwInfo(hwInfoIn) { requiredThreadArbitrationPolicy = PreambleHelper::getDefaultThreadArbitrationPolicy(); resetKmdNotifyHelper(new KmdNotifyHelper(&(hwInfoIn.capabilityTable.kmdNotifyProperties))); + flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw(this->memoryManager)); } template @@ -64,6 +66,9 @@ inline void CommandStreamReceiverHw::addBatchBufferStart(MI_BATCH_BUF *commandBufferMemory = GfxFamily::cmdInitBatchBufferStart; commandBufferMemory->setBatchBufferStartAddressGraphicsaddress472(startAddress); commandBufferMemory->setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT); + if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { + flatBatchBufferHelper->registerBatchBufferStartAddress(reinterpret_cast(commandBufferMemory), startAddress); + } } template @@ -135,7 +140,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( Device *device = this->getMemoryManager()->device; if (dispatchFlags.blocking || dispatchFlags.dcFlush || dispatchFlags.guardCommandBufferWithPipeControl) { - if (this->dispatchMode == ImmediateDispatch) { + if (this->dispatchMode == DispatchMode::ImmediateDispatch) { //for ImmediateDispatch we will send this right away, therefore this pipe control will close the level //for BatchedSubmissions it will be nooped and only last ppc in batch will be emitted. levelClosed = true; @@ -178,6 +183,18 @@ CompletionStamp CommandStreamReceiverHw::flushTask( this->latestSentTaskCount = taskCount + 1; DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "taskCount", taskCount); + if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { + flatBatchBufferHelper->setPatchInfoData(PatchInfoData(address, 0u, + PatchInfoAllocationType::TagAddress, + commandStreamTask.getGraphicsAllocation()->getGpuAddress(), + commandStreamTask.getUsed() - 2 * sizeof(uint64_t), + PatchInfoAllocationType::Default)); + flatBatchBufferHelper->setPatchInfoData(PatchInfoData(address, 0u, + PatchInfoAllocationType::TagValue, + commandStreamTask.getGraphicsAllocation()->getGpuAddress(), + commandStreamTask.getUsed() - sizeof(uint64_t), + PatchInfoAllocationType::Default)); + } } if (DebugManager.flags.ForceSLML3Config.get()) { @@ -277,7 +294,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( latestSentStatelessMocsConfig = requiredL3Index; if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { - collectStateBaseAddresPatchInfo(commandStream.getGpuBase(), stateBaseAddressCmdOffset, dsh, ioh, ssh, newGSHbase, memoryManager->getInternalHeapBaseAddress()); + collectStateBaseAddresPatchInfo(commandStream.getGraphicsAllocation()->getGpuAddress(), stateBaseAddressCmdOffset, dsh, ioh, ssh, newGSHbase); } } @@ -344,6 +361,14 @@ CompletionStamp CommandStreamReceiverHw::flushTask( // Add MI_BATCH_BUFFER_START to chain from CSR -> Task auto pBBS = reinterpret_cast(commandStreamCSR.getSpace(sizeof(MI_BATCH_BUFFER_START))); addBatchBufferStart(pBBS, ptrOffset(commandStreamTask.getGraphicsAllocation()->getGpuAddress(), commandStreamStartTask)); + if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { + flatBatchBufferHelper->registerCommandChunk(commandStreamTask.getGraphicsAllocation()->getGpuAddress(), + reinterpret_cast(commandStreamTask.getCpuBase()), + commandStreamStartTask, + static_cast(ptrDiff(bbEndLocation, + commandStreamTask.getGraphicsAllocation()->getGpuAddress())) + + sizeof(MI_BATCH_BUFFER_START)); + } auto commandStreamAllocation = commandStreamTask.getGraphicsAllocation(); DEBUG_BREAK_IF(commandStreamAllocation == nullptr); @@ -418,7 +443,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( template inline void CommandStreamReceiverHw::flushBatchedSubmissions() { - if (this->dispatchMode == this->ImmediateDispatch) { + if (this->dispatchMode == DispatchMode::ImmediateDispatch) { return; } typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; @@ -449,9 +474,15 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { currentPipeControlForNooping = primaryCmdBuffer->pipeControlThatMayBeErasedLocation; epiloguePipeControlLocation = primaryCmdBuffer->epiloguePipeControlLocation; + if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { + flatBatchBufferHelper->registerCommandChunk(primaryCmdBuffer.get()->batchBuffer, sizeof(MI_BATCH_BUFFER_START)); + } while (nextCommandBuffer && nextCommandBuffer->inspectionId == primaryCmdBuffer->inspectionId) { //noop pipe control if (currentPipeControlForNooping) { + if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { + flatBatchBufferHelper->removePipeControlData(pipeControlLocationSize, currentPipeControlForNooping); + } memset(currentPipeControlForNooping, 0, pipeControlLocationSize); } //obtain next candidate for nooping @@ -463,6 +494,10 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { auto nextCommandBufferAddress = nextCommandBuffer->batchBuffer.commandBufferAllocation->getUnderlyingBuffer(); auto offsetedCommandBuffer = (uint64_t)ptrOffset(nextCommandBufferAddress, nextCommandBuffer->batchBuffer.startOffset); addBatchBufferStart((MI_BATCH_BUFFER_START *)currentBBendLocation, offsetedCommandBuffer); + if (DebugManager.flags.FlattenBatchBufferForAUBDump.get()) { + flatBatchBufferHelper->registerCommandChunk(nextCommandBuffer->batchBuffer, sizeof(MI_BATCH_BUFFER_START)); + } + currentBBendLocation = nextCommandBuffer->batchBufferEndLocation; lastTaskCount = nextCommandBuffer->taskCount; nextCommandBuffer = nextCommandBuffer->next; @@ -659,22 +694,19 @@ void CommandStreamReceiverHw::collectStateBaseAddresPatchInfo( const LinearStream &dsh, const LinearStream &ioh, const LinearStream &ssh, - uint64_t generalStateBase, - uint64_t internalHeapOffset) { + uint64_t generalStateBase) { typedef typename GfxFamily::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; - PatchInfoData dynamicStatePatchInfo = {dsh.getGpuBase(), 0u, PatchInfoAllocationType::DynamicStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::DYNAMICSTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; + PatchInfoData dynamicStatePatchInfo = {dsh.getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::DynamicStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::DYNAMICSTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; PatchInfoData generalStatePatchInfo = {generalStateBase, 0u, PatchInfoAllocationType::GeneralStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::GENERALSTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; - PatchInfoData surfaceStatePatchInfo = {ssh.getGpuBase(), 0u, PatchInfoAllocationType::SurfaceStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::SURFACESTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; - PatchInfoData indirectObjectPatchInfo = {ioh.getGpuBase(), 0u, PatchInfoAllocationType::IndirectObjectHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INDIRECTOBJECTBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; - PatchInfoData instructionPatchInfo = {internalHeapOffset, 0u, PatchInfoAllocationType::InstructionHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INSTRUCTIONBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; + PatchInfoData surfaceStatePatchInfo = {ssh.getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::SurfaceStateHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::SURFACESTATEBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; + PatchInfoData indirectObjectPatchInfo = {ioh.getGraphicsAllocation()->getGpuAddress(), 0u, PatchInfoAllocationType::IndirectObjectHeap, baseAddress, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INDIRECTOBJECTBASEADDRESS_BYTEOFFSET, PatchInfoAllocationType::Default}; - setPatchInfoData(dynamicStatePatchInfo); - setPatchInfoData(generalStatePatchInfo); - setPatchInfoData(surfaceStatePatchInfo); - setPatchInfoData(indirectObjectPatchInfo); - setPatchInfoData(instructionPatchInfo); + flatBatchBufferHelper->setPatchInfoData(dynamicStatePatchInfo); + flatBatchBufferHelper->setPatchInfoData(generalStatePatchInfo); + flatBatchBufferHelper->setPatchInfoData(surfaceStatePatchInfo); + flatBatchBufferHelper->setPatchInfoData(indirectObjectPatchInfo); } template diff --git a/runtime/enable_gens.cmake b/runtime/enable_gens.cmake index b487c38020..c190052a6c 100644 --- a/runtime/enable_gens.cmake +++ b/runtime/enable_gens.cmake @@ -37,6 +37,7 @@ set(RUNTIME_SRCS_GENX_BASE device_enqueue.h device_queue.cpp command_stream_receiver_hw.cpp + flat_batch_buffer_helper_hw.cpp gpgpu_walker.cpp hw_cmds.h hw_cmds_generated.h diff --git a/runtime/gen8/aub_command_stream_receiver.cpp b/runtime/gen8/aub_command_stream_receiver.cpp index 57fc8cd551..0a5922f25f 100644 --- a/runtime/gen8/aub_command_stream_receiver.cpp +++ b/runtime/gen8/aub_command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,4 +38,4 @@ void populateFactoryTable>() { } template class AUBCommandStreamReceiverHw; -} +} // namespace OCLRT diff --git a/runtime/gen8/flat_batch_buffer_helper_hw.cpp b/runtime/gen8/flat_batch_buffer_helper_hw.cpp new file mode 100644 index 0000000000..bcce05e714 --- /dev/null +++ b/runtime/gen8/flat_batch_buffer_helper_hw.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "hw_cmds.h" +#include "runtime/helpers/flat_batch_buffer_helper_hw.inl" + +namespace OCLRT { + +constexpr uint32_t LOW32_BIT_MASK = 0x0000FFFFFFFFULL; + +typedef BDWFamily Family; + +template <> +void FlatBatchBufferHelperHw::sdiSetAddress(typename Family::MI_STORE_DATA_IMM *sdiCommand, uint64_t address) { + sdiCommand->setAddress(static_cast(address & LOW32_BIT_MASK)); + sdiCommand->setAddressHigh(static_cast(address >> 32)); +} + +template <> +void FlatBatchBufferHelperHw::sdiSetStoreQword(typename Family::MI_STORE_DATA_IMM *sdiCommand, bool setQword) { + sdiCommand->setStoreQword(setQword ? Family::MI_STORE_DATA_IMM::STORE_QWORD_STORE_QWORD : Family::MI_STORE_DATA_IMM::STORE_QWORD_STORE_DWORD); +} + +template class FlatBatchBufferHelperHw; +} // namespace OCLRT diff --git a/runtime/gen8/hw_cmds_generated.h b/runtime/gen8/hw_cmds_generated.h index 7be7f624f0..9965568d35 100644 --- a/runtime/gen8/hw_cmds_generated.h +++ b/runtime/gen8/hw_cmds_generated.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -3969,4 +3969,33 @@ typedef struct tagMI_REPORT_PERF_COUNT { } } MI_REPORT_PERF_COUNT; STATIC_ASSERT(16 == sizeof(MI_REPORT_PERF_COUNT)); +struct MI_USER_INTERRUPT { + union tagTheStructure { + struct tagCommon { + uint32_t Reserved_0 : BITFIELD_RANGE(0, 22); + uint32_t MICommandOpcode : BITFIELD_RANGE(23, 28); + uint32_t CommandType : BITFIELD_RANGE(29, 31); + } Common; + uint32_t RawData[1]; + } TheStructure; + enum MI_COMMAND_OPCODE { + MI_COMMAND_OPCODE_MI_USER_INTERRUPT = 2, + }; + enum COMMAND_TYPE { + COMMAND_TYPE_MI_COMMAND = 0, + }; + inline void init(void) { + memset(&TheStructure, 0, sizeof(TheStructure)); + TheStructure.Common.MICommandOpcode = MI_COMMAND_OPCODE_MI_USER_INTERRUPT; + } + static MI_USER_INTERRUPT sInit(void) { + MI_USER_INTERRUPT state; + state.init(); + return state; + } + inline uint32_t &getRawData(const uint32_t index) { + return TheStructure.RawData[index]; + } +}; +STATIC_ASSERT(4 == sizeof(MI_USER_INTERRUPT)); #pragma pack() diff --git a/runtime/gen9/aub_command_stream_receiver.cpp b/runtime/gen9/aub_command_stream_receiver.cpp index a860b0d64d..16615db230 100644 --- a/runtime/gen9/aub_command_stream_receiver.cpp +++ b/runtime/gen9/aub_command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,4 +38,4 @@ void populateFactoryTable>() { } template class AUBCommandStreamReceiverHw; -} +} // namespace OCLRT diff --git a/runtime/gen9/flat_batch_buffer_helper_hw.cpp b/runtime/gen9/flat_batch_buffer_helper_hw.cpp new file mode 100644 index 0000000000..9d6c15557b --- /dev/null +++ b/runtime/gen9/flat_batch_buffer_helper_hw.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 - 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "hw_cmds.h" +#include "runtime/helpers/flat_batch_buffer_helper_hw.inl" + +namespace OCLRT { + +typedef SKLFamily Family; + +template <> +void FlatBatchBufferHelperHw::sdiSetAddress(typename Family::MI_STORE_DATA_IMM *sdiCommand, uint64_t address) { + sdiCommand->setAddressGraphicsaddress472(address); +} + +template <> +void FlatBatchBufferHelperHw::sdiSetStoreQword(typename Family::MI_STORE_DATA_IMM *sdiCommand, bool setQword) { + sdiCommand->setStoreQword(setQword); +} + +template class FlatBatchBufferHelperHw; +} // namespace OCLRT diff --git a/runtime/gen9/hw_cmds_generated.h b/runtime/gen9/hw_cmds_generated.h index 170cd41d1e..6add351a8c 100644 --- a/runtime/gen9/hw_cmds_generated.h +++ b/runtime/gen9/hw_cmds_generated.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -4162,4 +4162,33 @@ typedef struct tagSTATE_SIP { } } STATE_SIP; STATIC_ASSERT(12 == sizeof(STATE_SIP)); +struct MI_USER_INTERRUPT { + union tagTheStructure { + struct tagCommon { + uint32_t Reserved_0 : BITFIELD_RANGE(0, 22); + uint32_t MICommandOpcode : BITFIELD_RANGE(23, 28); + uint32_t CommandType : BITFIELD_RANGE(29, 31); + } Common; + uint32_t RawData[1]; + } TheStructure; + enum MI_COMMAND_OPCODE { + MI_COMMAND_OPCODE_MI_USER_INTERRUPT = 2, + }; + enum COMMAND_TYPE { + COMMAND_TYPE_MI_COMMAND = 0, + }; + inline void init(void) { + memset(&TheStructure, 0, sizeof(TheStructure)); + TheStructure.Common.MICommandOpcode = MI_COMMAND_OPCODE_MI_USER_INTERRUPT; + } + static MI_USER_INTERRUPT sInit(void) { + MI_USER_INTERRUPT state; + state.init(); + return state; + } + inline uint32_t &getRawData(const uint32_t index) { + return TheStructure.RawData[index]; + } +}; +STATIC_ASSERT(4 == sizeof(MI_USER_INTERRUPT)); #pragma pack() diff --git a/runtime/helpers/CMakeLists.txt b/runtime/helpers/CMakeLists.txt index 22433b0118..31f20a7f11 100644 --- a/runtime/helpers/CMakeLists.txt +++ b/runtime/helpers/CMakeLists.txt @@ -44,6 +44,10 @@ set(RUNTIME_SRCS_HELPERS_BASE ${CMAKE_CURRENT_SOURCE_DIR}/error_mappers.h ${CMAKE_CURRENT_SOURCE_DIR}/file_io.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_io.h + ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper.h + ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper_hw.h + ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper_hw.inl ${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp.h ${CMAKE_CURRENT_SOURCE_DIR}/get_info.h diff --git a/runtime/helpers/address_patch.h b/runtime/helpers/address_patch.h index 25c7059245..a8f32a0d17 100644 --- a/runtime/helpers/address_patch.h +++ b/runtime/helpers/address_patch.h @@ -32,7 +32,10 @@ enum PatchInfoAllocationType { DynamicStateHeap, IndirectObjectHeap, SurfaceStateHeap, - InstructionHeap + InstructionHeap, + TagAddress, + TagValue, + GUCStartMessage, }; struct PatchInfoData { @@ -42,5 +45,50 @@ struct PatchInfoData { uint64_t targetAllocation; uint64_t targetAllocationOffset; PatchInfoAllocationType targetType; + uint32_t patchAddressSize; + + PatchInfoData(uint64_t sourceAllocation, + uint64_t sourceAllocationOffset, + PatchInfoAllocationType sourceType, + uint64_t targetAllocation, + uint64_t targetAllocationOffset, + PatchInfoAllocationType targetType, + uint32_t patchAddressSize) + : sourceAllocation(sourceAllocation), + sourceAllocationOffset(sourceAllocationOffset), + sourceType(sourceType), + targetAllocation(targetAllocation), + targetAllocationOffset(targetAllocationOffset), + targetType(targetType), + patchAddressSize(patchAddressSize) { + } + + PatchInfoData(uint64_t sourceAllocation, + uint64_t sourceAllocationOffset, + PatchInfoAllocationType sourceType, + uint64_t targetAllocation, + uint64_t targetAllocationOffset, + PatchInfoAllocationType targetType) + : sourceAllocation(sourceAllocation), + sourceAllocationOffset(sourceAllocationOffset), + sourceType(sourceType), + targetAllocation(targetAllocation), + targetAllocationOffset(targetAllocationOffset), + targetType(targetType), + patchAddressSize(sizeof(void *)) { + } + + bool requiresIndirectPatching() { + return (targetType != PatchInfoAllocationType::Default && targetType != PatchInfoAllocationType::GUCStartMessage); + } +}; + +struct CommandChunk { + uint64_t baseAddressCpu = 0; + uint64_t baseAddressGpu = 0; + uint64_t startOffset = 0; + uint64_t endOffset = 0; + uint64_t batchBufferStartLocation = 0; + uint64_t batchBufferStartAddress = 0; }; } // namespace OCLRT \ No newline at end of file diff --git a/runtime/helpers/flat_batch_buffer_helper.cpp b/runtime/helpers/flat_batch_buffer_helper.cpp new file mode 100644 index 0000000000..bb61840004 --- /dev/null +++ b/runtime/helpers/flat_batch_buffer_helper.cpp @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "runtime/helpers/flat_batch_buffer_helper.h" + +namespace OCLRT { + +bool FlatBatchBufferHelper::setPatchInfoData(const PatchInfoData &data) { + patchInfoCollection.push_back(data); + return true; +} +bool FlatBatchBufferHelper::removePatchInfoData(uint64_t targetLocation) { + for (auto it = patchInfoCollection.begin(); it != patchInfoCollection.end(); ++it) { + if (it->targetAllocation + it->targetAllocationOffset == targetLocation) { + patchInfoCollection.erase(it); + break; + } + } + return true; +} + +bool FlatBatchBufferHelper::registerCommandChunk(uint64_t baseCpu, uint64_t baseGpu, uint64_t startOffset, uint64_t endOffset) { + + CommandChunk commandChunk; + commandChunk.baseAddressGpu = baseGpu; + commandChunk.baseAddressCpu = baseCpu; + commandChunk.startOffset = startOffset; + commandChunk.endOffset = endOffset; + return registerCommandChunk(commandChunk); +} + +bool FlatBatchBufferHelper::registerCommandChunk(BatchBuffer &batchBuffer, size_t batchBufferStartCommandSize) { + CommandChunk commandChunk; + commandChunk.baseAddressGpu = batchBuffer.stream->getGraphicsAllocation()->getGpuAddress(); + commandChunk.baseAddressCpu = reinterpret_cast(batchBuffer.stream->getCpuBase()); + commandChunk.startOffset = batchBuffer.startOffset; + commandChunk.endOffset = batchBuffer.chainedBatchBufferStartOffset + batchBufferStartCommandSize; + return registerCommandChunk(commandChunk); +} + +bool FlatBatchBufferHelper::registerCommandChunk(CommandChunk &commandChunk) { + commandChunkList.push_back(commandChunk); + return true; +} + +bool FlatBatchBufferHelper::registerBatchBufferStartAddress(uint64_t commandAddress, uint64_t startAddress) { + batchBufferStartAddressSequence.insert(std::pair(commandAddress, startAddress)); + return true; +} + +void FlatBatchBufferHelper::fixCrossThreadDataInfo(std::vector &data, size_t offsetCrossThreadData, uint64_t gpuAddress) { + for (auto &patchInfoData : data) { + if (patchInfoData.sourceType == PatchInfoAllocationType::KernelArg) { + patchInfoData.targetAllocation = gpuAddress; + patchInfoData.targetAllocationOffset += offsetCrossThreadData; + } + } +} +}; \ No newline at end of file diff --git a/runtime/helpers/flat_batch_buffer_helper.h b/runtime/helpers/flat_batch_buffer_helper.h new file mode 100644 index 0000000000..7184117eaf --- /dev/null +++ b/runtime/helpers/flat_batch_buffer_helper.h @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#pragma once + +#include "runtime/helpers/address_patch.h" +#include "runtime/command_stream/submissions_aggregator.h" +#include +#include + +namespace OCLRT { + +enum class DispatchMode; +class MemoryManager; + +class FlatBatchBufferHelper { + public: + FlatBatchBufferHelper(MemoryManager *memoryManager) : memoryManager(memoryManager) {} + virtual ~FlatBatchBufferHelper(){}; + MOCKABLE_VIRTUAL bool setPatchInfoData(const PatchInfoData &data); + MOCKABLE_VIRTUAL bool removePatchInfoData(uint64_t targetLocation); + MOCKABLE_VIRTUAL bool registerCommandChunk(uint64_t baseCpu, uint64_t baseGpu, uint64_t startOffset, uint64_t endOffset); + MOCKABLE_VIRTUAL bool registerCommandChunk(CommandChunk &commandChunk); + MOCKABLE_VIRTUAL bool registerCommandChunk(BatchBuffer &batchBuffer, size_t batchBufferStartCommandSize); + MOCKABLE_VIRTUAL bool registerBatchBufferStartAddress(uint64_t commandAddress, uint64_t startAddress); + virtual void *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) = 0; + virtual char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) = 0; + virtual void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) = 0; + void setMemoryManager(MemoryManager *memoryManager) { this->memoryManager = memoryManager; } + static void fixCrossThreadDataInfo(std::vector &data, size_t offsetCrossThreadData, uint64_t gpuAddress); + + std::vector &getCommandChunkList() { return commandChunkList; } + std::vector &getPatchInfoCollection() { return patchInfoCollection; } + std::map &getBatchBufferStartAddressSequence() { return batchBufferStartAddressSequence; } + + protected: + MemoryManager *memoryManager = nullptr; + + std::vector patchInfoCollection; + std::vector commandChunkList; + std::map batchBufferStartAddressSequence; +}; + +} // namespace OCLRT \ No newline at end of file diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.h b/runtime/helpers/flat_batch_buffer_helper_hw.h new file mode 100644 index 0000000000..c275089150 --- /dev/null +++ b/runtime/helpers/flat_batch_buffer_helper_hw.h @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#pragma once + +#include "runtime/helpers/flat_batch_buffer_helper.h" + +namespace OCLRT { + +template +class FlatBatchBufferHelperHw : public FlatBatchBufferHelper { + public: + FlatBatchBufferHelperHw(MemoryManager *memoryManager) : FlatBatchBufferHelper(memoryManager) {} + void *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) override; + char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) override; + void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) override; + static void sdiSetAddress(typename GfxFamily::MI_STORE_DATA_IMM *sdiCommand, uint64_t address); + static void sdiSetStoreQword(typename GfxFamily::MI_STORE_DATA_IMM *sdiCommand, bool setQword); +}; + +} // namespace OCLRT \ No newline at end of file diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.inl b/runtime/helpers/flat_batch_buffer_helper_hw.inl new file mode 100644 index 0000000000..8268c6e3da --- /dev/null +++ b/runtime/helpers/flat_batch_buffer_helper_hw.inl @@ -0,0 +1,196 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "runtime/helpers/flat_batch_buffer_helper_hw.h" +#include "runtime/command_stream/command_stream_receiver.h" +#include "runtime/memory_manager/memory_manager.h" +#include "runtime/helpers/string.h" + +namespace OCLRT { + +template +void *FlatBatchBufferHelperHw::flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) { + typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + typedef typename GfxFamily::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END; + typedef typename GfxFamily::MI_USER_INTERRUPT MI_USER_INTERRUPT; + + void *flatBatchBuffer = nullptr; + + size_t indirectPatchCommandsSize = 0u; + std::vector indirectPatchInfo; + std::unique_ptr indirectPatchCommands(getIndirectPatchCommands(indirectPatchCommandsSize, indirectPatchInfo)); + + if (dispatchMode == DispatchMode::ImmediateDispatch) { + if (batchBuffer.chainedBatchBuffer) { + batchBuffer.chainedBatchBuffer->setAllocationType(batchBuffer.chainedBatchBuffer->getAllocationType() | GraphicsAllocation::ALLOCATION_TYPE_NON_AUB_WRITABLE); + auto sizeMainBatchBuffer = batchBuffer.chainedBatchBufferStartOffset - batchBuffer.startOffset; + + auto flatBatchBufferSize = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); + flatBatchBuffer = this->memoryManager->alignedMallocWrapper(flatBatchBufferSize, MemoryConstants::pageSize); + UNRECOVERABLE_IF(flatBatchBuffer == nullptr); + // Copy main batchbuffer + memcpy_s(flatBatchBuffer, sizeMainBatchBuffer, ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset), sizeMainBatchBuffer); + // Copy indirect patch commands + memcpy_s(ptrOffset(flatBatchBuffer, sizeMainBatchBuffer), indirectPatchCommandsSize, indirectPatchCommands.get(), indirectPatchCommandsSize); + // Copy chained batchbuffer + memcpy_s(ptrOffset(flatBatchBuffer, sizeMainBatchBuffer + indirectPatchCommandsSize), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), batchBuffer.chainedBatchBuffer->getUnderlyingBuffer(), batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize()); + sizeBatchBuffer = flatBatchBufferSize; + patchInfoCollection.insert(std::end(patchInfoCollection), std::begin(indirectPatchInfo), std::end(indirectPatchInfo)); + } + } else if (dispatchMode == DispatchMode::BatchedDispatch) { + CommandChunk firstChunk; + for (auto &chunk : commandChunkList) { + bool found = false; + for (auto &batchBuffer : batchBufferStartAddressSequence) { + if ((batchBuffer.first <= chunk.baseAddressGpu + chunk.endOffset) && (batchBuffer.first >= chunk.baseAddressGpu + chunk.startOffset)) { + chunk.batchBufferStartLocation = batchBuffer.first; + chunk.batchBufferStartAddress = batchBuffer.second; + chunk.endOffset = chunk.batchBufferStartLocation - chunk.baseAddressGpu; + } + if (batchBuffer.second == chunk.baseAddressGpu + chunk.startOffset) { + found = true; + } + } + if (!found) { + firstChunk = chunk; + } + } + + std::vector orderedChunks; + CommandChunk &nextChunk = firstChunk; + while (true) { + bool hasNextChunk = false; + for (auto &chunk : commandChunkList) { + if (nextChunk.batchBufferStartAddress == chunk.baseAddressGpu + chunk.startOffset) { + hasNextChunk = true; + orderedChunks.push_back(nextChunk); + nextChunk = chunk; + break; + } + } + if (!hasNextChunk) { + nextChunk.endOffset -= sizeof(MI_BATCH_BUFFER_START); + orderedChunks.push_back(nextChunk); + break; + } + } + + uint64_t flatBatchBufferSize = 0u; + std::vector patchInfoCopy = patchInfoCollection; + patchInfoCollection.clear(); + + for (auto &chunk : orderedChunks) { + for (auto &patch : patchInfoCopy) { + if (patch.targetAllocation + patch.targetAllocationOffset >= chunk.baseAddressGpu + chunk.startOffset && patch.targetAllocation + patch.targetAllocationOffset <= chunk.baseAddressGpu + chunk.endOffset) { + patch.targetAllocationOffset = patch.targetAllocationOffset - chunk.startOffset + flatBatchBufferSize + indirectPatchCommandsSize; + patchInfoCollection.push_back(patch); + } + } + flatBatchBufferSize += chunk.endOffset - chunk.startOffset; + } + patchInfoCollection.insert(std::end(patchInfoCollection), std::begin(indirectPatchInfo), std::end(indirectPatchInfo)); + + flatBatchBufferSize += sizeof(MI_USER_INTERRUPT); + flatBatchBufferSize += sizeof(MI_BATCH_BUFFER_END); + flatBatchBufferSize += indirectPatchCommandsSize; + + flatBatchBufferSize = alignUp(flatBatchBufferSize, MemoryConstants::pageSize); + flatBatchBufferSize += CSRequirements::csOverfetchSize; + flatBatchBuffer = this->memoryManager->alignedMallocWrapper(static_cast(flatBatchBufferSize), MemoryConstants::pageSize); + + char *ptr = reinterpret_cast(flatBatchBuffer); + memcpy_s(ptr, indirectPatchCommandsSize, indirectPatchCommands.get(), indirectPatchCommandsSize); + ptr += indirectPatchCommandsSize; + for (auto &chunk : orderedChunks) { + size_t chunkSize = static_cast(chunk.endOffset - chunk.startOffset); + memcpy_s(ptr, + chunkSize, + reinterpret_cast(ptrOffset(chunk.baseAddressCpu, static_cast(chunk.startOffset))), + chunkSize); + ptr += chunkSize; + } + + auto pCmdMui = reinterpret_cast(ptr); + pCmdMui->init(); + ptr += sizeof(MI_USER_INTERRUPT); + + auto pCmdBBend = reinterpret_cast(ptr); + *pCmdBBend = GfxFamily::cmdInitBatchBufferEnd; + ptr += sizeof(MI_BATCH_BUFFER_END); + + sizeBatchBuffer = static_cast(flatBatchBufferSize); + commandChunkList.clear(); + batchBufferStartAddressSequence.clear(); + } + + return flatBatchBuffer; +} + +template +char *FlatBatchBufferHelperHw::getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) { + typedef typename GfxFamily::MI_STORE_DATA_IMM MI_STORE_DATA_IMM; + + indirectPatchCommandsSize = 0; + for (auto &patchInfoData : patchInfoCollection) { + if (patchInfoData.requiresIndirectPatching()) { + indirectPatchCommandsSize += sizeof(MI_STORE_DATA_IMM); + } + } + + uint64_t stiCommandOffset = 0; + std::vector patchInfoCopy = patchInfoCollection; + std::unique_ptr buffer(new char[indirectPatchCommandsSize]); + LinearStream indirectPatchCommandStream(buffer.get(), indirectPatchCommandsSize); + patchInfoCollection.clear(); + + for (auto &patchInfoData : patchInfoCopy) { + if (patchInfoData.requiresIndirectPatching()) { + auto storeDataImmediate = indirectPatchCommandStream.getSpaceForCmd(); + storeDataImmediate->init(); + sdiSetAddress(storeDataImmediate, patchInfoData.targetAllocation + patchInfoData.targetAllocationOffset); + sdiSetStoreQword(storeDataImmediate, patchInfoData.patchAddressSize != sizeof(uint32_t)); + storeDataImmediate->setDataDword0(static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) & 0x0000FFFFFFFFULL)); + storeDataImmediate->setDataDword1(static_cast((patchInfoData.sourceAllocation + patchInfoData.sourceAllocationOffset) >> 32)); + + PatchInfoData patchInfoForAddress(patchInfoData.targetAllocation, patchInfoData.targetAllocationOffset, patchInfoData.targetType, 0u, stiCommandOffset + sizeof(MI_STORE_DATA_IMM) - 2 * sizeof(uint64_t), PatchInfoAllocationType::Default); + PatchInfoData patchInfoForValue(patchInfoData.sourceAllocation, patchInfoData.sourceAllocationOffset, patchInfoData.sourceType, 0u, stiCommandOffset + sizeof(MI_STORE_DATA_IMM) - sizeof(uint64_t), PatchInfoAllocationType::Default); + indirectPatchInfo.push_back(patchInfoForAddress); + indirectPatchInfo.push_back(patchInfoForValue); + stiCommandOffset += sizeof(MI_STORE_DATA_IMM); + } else { + patchInfoCollection.push_back(patchInfoData); + } + } + return buffer.release(); +} +template +void FlatBatchBufferHelperHw::removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) { + typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL; + size_t numPipeControls = pipeControlLocationSize / sizeof(PIPE_CONTROL); + for (size_t i = 0; i < numPipeControls; i++) { + PIPE_CONTROL *erasedPipeControl = reinterpret_cast(pipeControlForNooping); + removePatchInfoData(reinterpret_cast(erasedPipeControl) + (i + 1) * sizeof(PIPE_CONTROL) - 2 * sizeof(uint64_t)); + removePatchInfoData(reinterpret_cast(erasedPipeControl) + (i + 1) * sizeof(PIPE_CONTROL) - sizeof(uint64_t)); + } +} + +}; // namespace OCLRT \ No newline at end of file diff --git a/runtime/helpers/kernel_commands.inl b/runtime/helpers/kernel_commands.inl index 5794d57e09..88b2ddc7a3 100644 --- a/runtime/helpers/kernel_commands.inl +++ b/runtime/helpers/kernel_commands.inl @@ -155,6 +155,7 @@ size_t KernelCommandsHelper::sendInterfaceDescriptorData( // Program the kernel start pointer pInterfaceDescriptor->setKernelStartPointerHigh(kernelStartOffset >> 32); pInterfaceDescriptor->setKernelStartPointer((uint32_t)kernelStartOffset); + // # of threads in thread group should be based on LWS. pInterfaceDescriptor->setNumberOfThreadsInGpgpuThreadGroup(threadsPerThreadGroup); @@ -234,10 +235,7 @@ size_t KernelCommandsHelper::sendCrossThreadData( memcpy_s(pDest, sizeCrossThreadData, kernel.getCrossThreadData(), sizeCrossThreadData); if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { - for (auto &patchInfoData : kernel.getPatchInfoDataList()) { - patchInfoData.targetAllocation = indirectHeap.getGpuBase(); - patchInfoData.targetAllocationOffset += offsetCrossThreadData; - } + FlatBatchBufferHelper::fixCrossThreadDataInfo(kernel.getPatchInfoDataList(), offsetCrossThreadData, indirectHeap.getGraphicsAllocation()->getGpuAddress()); } return offsetCrossThreadData + static_cast(indirectHeap.getHeapGpuStartOffset()); @@ -399,6 +397,11 @@ size_t KernelCommandsHelper::sendIndirectState( !!patchInfo.executionEnvironment->HasBarriers, preemptionMode); + if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { + PatchInfoData patchInfoData(kernelStartOffset, 0, PatchInfoAllocationType::InstructionHeap, dsh.getGraphicsAllocation()->getGpuAddress(), offsetInterfaceDescriptor, PatchInfoAllocationType::DynamicStateHeap); + kernel.getPatchInfoDataList().push_back(patchInfoData); + } + // Program media state flush to set interface descriptor offset KernelCommandsHelper::sendMediaStateFlush( commandStream, diff --git a/runtime/kernel/kernel.cpp b/runtime/kernel/kernel.cpp index 34aaf0bc6d..b6b343001a 100644 --- a/runtime/kernel/kernel.cpp +++ b/runtime/kernel/kernel.cpp @@ -1114,7 +1114,7 @@ cl_int Kernel::setArgBuffer(uint32_t argIndex, uint64_t addressToPatch = buffer->setArgStateless(patchLocation, patchSize, !this->isBuiltIn); if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { - PatchInfoData patchInfoData = {addressToPatch - buffer->getOffset(), buffer->getOffset(), PatchInfoAllocationType::KernelArg, reinterpret_cast(getCrossThreadData()), kernelArgInfo.kernelArgPatchInfoVector[0].crossthreadOffset, PatchInfoAllocationType::IndirectObjectHeap}; + PatchInfoData patchInfoData(addressToPatch - buffer->getOffset(), static_cast(buffer->getOffset()), PatchInfoAllocationType::KernelArg, reinterpret_cast(getCrossThreadData()), static_cast(kernelArgInfo.kernelArgPatchInfoVector[0].crossthreadOffset), PatchInfoAllocationType::IndirectObjectHeap, patchSize); this->patchInfoDataList.push_back(patchInfoData); } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index aaaad9ef73..90d9396bcc 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -54,7 +54,7 @@ class OsAgnosticMemoryManager : public MemoryManager { OsAgnosticMemoryManager(bool enable64kbPages = false) : MemoryManager(enable64kbPages) { uint64_t heap32Base = 0x80000000000ul; if (sizeof(uintptr_t) == 4) { - heap32Base = 0xC0000000; + heap32Base = 0x0; } allocator32Bit = std::unique_ptr(new Allocator32bit(heap32Base, GB - 2 * 4096)); }; diff --git a/unit_tests/api/cl_create_command_queue_tests.cpp b/unit_tests/api/cl_create_command_queue_tests.cpp index 005e0a434a..58b6d30ccd 100644 --- a/unit_tests/api/cl_create_command_queue_tests.cpp +++ b/unit_tests/api/cl_create_command_queue_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -78,10 +78,10 @@ HWTEST_F(clCreateCommandQueueTest, givenOoqParametersWhenQueueIsCreatedThenComma cl_int retVal = CL_SUCCESS; cl_queue_properties ooq = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; auto &csr = reinterpret_cast &>(pContext->getDevice(0)->getCommandStreamReceiver()); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode); + EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode); auto cmdq = clCreateCommandQueue(pContext, devices[0], ooq, &retVal); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::BatchedDispatch, csr.dispatchMode); + EXPECT_EQ(DispatchMode::BatchedDispatch, csr.dispatchMode); retVal = clReleaseCommandQueue(cmdq); } } // namespace ULT diff --git a/unit_tests/aub_tests/command_queue/enqueue_kernel_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_kernel_aub_tests.cpp index 8468b3df25..48855184c9 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_kernel_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_kernel_aub_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -276,7 +276,7 @@ HWTEST_F(AUBSimpleArg, givenAubCommandStreamerReceiverWhenBatchBufferFlateningIs DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); - pCmdQ->getDevice().getCommandStreamReceiver().overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + pCmdQ->getDevice().getCommandStreamReceiver().overrideDispatchPolicy(DispatchMode::ImmediateDispatch); auto retVal = pCmdQ->enqueueKernel( pKernel, diff --git a/unit_tests/aub_tests/gen9/skl/command_queue/run_kernel_aub_tests_skl.cpp b/unit_tests/aub_tests/gen9/skl/command_queue/run_kernel_aub_tests_skl.cpp index 2d7a172591..68f525a5ee 100644 --- a/unit_tests/aub_tests/gen9/skl/command_queue/run_kernel_aub_tests_skl.cpp +++ b/unit_tests/aub_tests/gen9/skl/command_queue/run_kernel_aub_tests_skl.cpp @@ -189,7 +189,7 @@ SKLTEST_F(AUBRunKernelIntegrateTest, ooqExecution) { ASSERT_NE(nullptr, pCmdQ2); auto &csr = pCmdQ2->getDevice().getCommandStreamReceiver(); - csr.overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + csr.overrideDispatchPolicy(DispatchMode::ImmediateDispatch); retVal = pCmdQ2->enqueueKernel( pKernel0, diff --git a/unit_tests/command_queue/enqueue_handler_tests.cpp b/unit_tests/command_queue/enqueue_handler_tests.cpp index 4a4bac5452..365decd5c1 100644 --- a/unit_tests/command_queue/enqueue_handler_tests.cpp +++ b/unit_tests/command_queue/enqueue_handler_tests.cpp @@ -232,8 +232,9 @@ HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) { } HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDumpIsNotSetThenPatchInfoDataIsNotTransferredToCSR) { - int32_t tag; - auto csr = new MockCsrBase(tag); + auto csr = new MockCsrHw2(*platformDevices[0]); + auto mockHelper = new MockFlatBatchBufferHelper(csr->getMemoryManager()); + csr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(csr); MockKernelWithInternals mockKernel(*pDevice); @@ -244,16 +245,18 @@ HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDu PatchInfoData patchInfoData = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap}; mockKernel.mockKernel->getPatchInfoDataList().push_back(patchInfoData); - EXPECT_CALL(*csr, setPatchInfoData(::testing::_)).Times(0); + EXPECT_CALL(*mockHelper, setPatchInfoData(::testing::_)).Times(0); mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); } HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDumpIsSetThenPatchInfoDataIsTransferredToCSR) { DebugManagerStateRestore dbgRestore; DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); + DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); - int32_t tag; - auto csr = new MockCsrBase(tag); + auto csr = new MockCsrHw2(*platformDevices[0]); + auto mockHelper = new MockFlatBatchBufferHelper(csr->getMemoryManager()); + csr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(csr); MockKernelWithInternals mockKernel(*pDevice); @@ -264,7 +267,9 @@ HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDu PatchInfoData patchInfoData = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap}; mockKernel.mockKernel->getPatchInfoDataList().push_back(patchInfoData); - EXPECT_CALL(*csr, setPatchInfoData(::testing::_)).Times(6); + EXPECT_CALL(*mockHelper, setPatchInfoData(::testing::_)).Times(8); + EXPECT_CALL(*mockHelper, registerCommandChunk(::testing::_)).Times(1); + EXPECT_CALL(*mockHelper, registerBatchBufferStartAddress(::testing::_, ::testing::_)).Times(1); mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); } diff --git a/unit_tests/command_queue/enqueue_kernel_mt_tests.cpp b/unit_tests/command_queue/enqueue_kernel_mt_tests.cpp index 8afc337450..06ea7f0dc6 100644 --- a/unit_tests/command_queue/enqueue_kernel_mt_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_mt_tests.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2017, Intel Corporation +* Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -31,7 +31,7 @@ typedef Test EnqueueKernelTest; HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledThenBatchesSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); diff --git a/unit_tests/command_queue/enqueue_kernel_tests.cpp b/unit_tests/command_queue/enqueue_kernel_tests.cpp index d22344a366..7a60601e8f 100644 --- a/unit_tests/command_queue/enqueue_kernel_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_tests.cpp @@ -1052,7 +1052,7 @@ HWTEST_F(EnqueueKernelTest, givenEnqueueWithGlobalWorkSizeWhenZeroValueIsPassedI HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenEnqueueKernelIsCalledThenKernelIsRecorded) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1083,7 +1083,7 @@ HWTEST_F(EnqueueKernelTest, givenDefaultCommandStreamReceiverWhenClFlushIsCalled HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeAndBatchedKernelWhenFlushIsCalledThenKernelIsSubmitted) { auto mockCsrmockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsrmockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsrmockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsrmockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1104,7 +1104,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeAndBatchedKe HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeAndBatchedKernelWhenFlushIsCalledTwiceThenNothingChanges) { auto mockCsrmockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsrmockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsrmockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsrmockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1125,7 +1125,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeAndBatchedKe HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenKernelIsEnqueuedTwiceThenTwoSubmissionsAreRecorded) { auto mockCsrmockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsrmockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsrmockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsrmockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1154,7 +1154,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenKernelIs HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenFlushIsCalledOnTwoBatchedKernelsThenTheyAreExecutedInOrder) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1172,7 +1172,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenFlushIsC HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledThenBatchesSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1191,7 +1191,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledThenBatchesS HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenThressEnqueueKernelsAreCalledThenBatchesSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1211,7 +1211,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenThressEnqueueKernelsAreCal HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenWaitForEventsIsCalledThenBatchedSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1235,7 +1235,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenWaitForEventsIsCalledThenB HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenCommandIsFlushedThenFlushStampIsUpdatedInCommandQueueCsrAndEvent) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1267,7 +1267,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenCommandIsFlushedThenFlushS HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenCommandWithEventIsFollowedByCommandWithoutEventThenFlushStampIsUpdatedInCommandQueueCsrAndEvent) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1299,7 +1299,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenCommandWithEventIsFollowed HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenClFlushIsCalledThenQueueFlushStampIsUpdated) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); MockKernelWithInternals mockKernel(*pDevice); @@ -1316,7 +1316,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenClFlushIsCalledThenQueueFl HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenWaitForEventsIsCalledWithUnflushedTaskCountThenBatchedSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1340,7 +1340,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenWaitForEventsIsCalledWithU HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledWithUnflushedTaskCountThenBatchedSubmissionsAreFlushed) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1367,7 +1367,7 @@ HWTEST_F(EnqueueKernelTest, givenOutOfOrderCommandQueueWhenEnqueueKernelIsMadeTh auto ooq = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1389,7 +1389,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelIsMadeThenP auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1411,7 +1411,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelThatHasShar auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1432,7 +1432,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelThatHasShar HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelThatHasSharedObjectsAsArgIsMadeThenPipeControlDoesntHaveDcFlush) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); MockKernelWithInternals mockKernel(*pDevice); @@ -1448,7 +1448,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelReturningEv auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1474,7 +1474,7 @@ HWTEST_F(EnqueueKernelTest, givenOutOfOrderCommandQueueWhenEnqueueKernelReturnin auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1499,7 +1499,7 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenBlockingCallIsMadeThenEven DebugManagerStateRestore stateRestore; DebugManager.flags.MakeEachEnqueueBlocking.set(true); auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); MockKernelWithInternals mockKernel(*pDevice); diff --git a/unit_tests/command_queue/ooq_task_tests.cpp b/unit_tests/command_queue/ooq_task_tests.cpp index 2ad120cf4d..64889718ef 100644 --- a/unit_tests/command_queue/ooq_task_tests.cpp +++ b/unit_tests/command_queue/ooq_task_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -138,7 +138,7 @@ HWTEST_F(OOQTaskTests, givenCommandQueueWithLowerTaskLevelThenCsrWhenItIsSubmitt HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenMultipleEnqueueAreDoneThenTaskLevelDoesntChnage) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); mockCsr->taskLevel = 100; EnqueueKernelHelper<>::enqueueKernel(this->pCmdQ, pKernel); @@ -153,7 +153,7 @@ HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenMultipleEnqueueAreDone HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowedByNewCommandsThenTheyHaveHigherTaskLevel) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); mockCsr->taskLevel = 100; EnqueueKernelHelper<>::enqueueKernel(this->pCmdQ, pKernel); @@ -172,7 +172,7 @@ HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowed HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowedByNewCommandsAndBarrierThenCsrTaskLevelIncreases) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); mockCsr->taskLevel = 100; EnqueueKernelHelper<>::enqueueKernel(this->pCmdQ, pKernel); @@ -192,7 +192,7 @@ HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowed HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowedByNewCommandsAndMarkerThenCsrTaskLevelIsNotIncreasing) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); mockCsr->taskLevel = 100; EnqueueKernelHelper<>::enqueueKernel(this->pCmdQ, pKernel); @@ -212,7 +212,7 @@ HWTEST_F(OOQTaskTests, givenCommandQueueAtTaskLevel100WhenItIsFlushedAndFollowed HWTEST_F(OOQTaskTests, givenTwoEnqueueCommandSynchronizedByEventsWhenTheyAreEnqueueThenSecondHasHigherTaskLevelThenFirst) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto currentTaskLevel = this->pCmdQ->taskLevel; cl_event retEvent; EnqueueKernelHelper<>::enqueueKernel(this->pCmdQ, pKernel, EnqueueKernelTraits::workDim, diff --git a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp index e2384a88ac..800bff6c38 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -21,6 +21,7 @@ */ #include "runtime/command_stream/aub_command_stream_receiver_hw.h" +#include "runtime/helpers/flat_batch_buffer_helper_hw.h" #include "runtime/helpers/hw_info.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/debug_settings_manager.h" @@ -28,6 +29,7 @@ #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_gmm.h" +#include "unit_tests/mocks/mock_csr.h" using namespace OCLRT; @@ -41,7 +43,7 @@ template struct MockAubCsr : public AUBCommandStreamReceiverHw { MockAubCsr(const HardwareInfo &hwInfoIn, bool standalone) : AUBCommandStreamReceiverHw(hwInfoIn, standalone){}; - CommandStreamReceiver::DispatchMode peekDispatchMode() const { + DispatchMode peekDispatchMode() const { return this->dispatchMode; } @@ -52,8 +54,6 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { void setLatestSentTaskCount(uint32_t latestSentTaskCount) { this->latestSentTaskCount = latestSentTaskCount; } - - MOCK_METHOD2(flattenBatchBuffer, void *(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer)); MOCK_METHOD0(addPatchInfoComments, bool(void)); }; @@ -76,14 +76,14 @@ TEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreat HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenItIsCreatedWithDefaultSettingsThenItHasBatchedDispatchModeEnabled) { DebugManager.flags.CsrDispatchMode.set(0); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::BatchedDispatch, aubCsr->peekDispatchMode()); + EXPECT_EQ(DispatchMode::BatchedDispatch, aubCsr->peekDispatchMode()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenItIsCreatedWithDebugSettingsThenItHasProperDispatchModeEnabled) { DebugManagerStateRestore stateRestore; - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, aubCsr->peekDispatchMode()); + EXPECT_EQ(DispatchMode::ImmediateDispatch, aubCsr->peekDispatchMode()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreatedThenMemoryManagerIsNotNull) { @@ -142,7 +142,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; // First flush typically includes a preamble and chain to command buffer - aubCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + aubCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); aubCsr->flush(batchBuffer, engineType, nullptr); EXPECT_EQ(0ull, aubCsr->engineInfoTable[engineType].tailRingBuffer % ringTailAlignment); @@ -199,7 +199,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - aubCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + aubCsr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); aubCsr->flush(batchBuffer, engineType, nullptr); EXPECT_NE(ObjectNotResident, commandBuffer->residencyTaskCount); @@ -256,7 +256,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - aubCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + aubCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); EXPECT_NE(ObjectNotResident, gfxAllocation->residencyTaskCount); @@ -380,10 +380,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic EXPECT_FALSE(aubCsr->writeMemory(gfxAllocation)); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferFlatteningThenNewCombinedBatchBufferIsCreated) { +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferFlatteningInImmediateDispatchModeThenNewCombinedBatchBufferIsCreated) { + std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); auto otherAllocation = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); @@ -397,7 +400,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB size_t sizeBatchBuffer = 0xffffu; - std::unique_ptr> flatBatchBuffer(aubCsr->flattenBatchBuffer(batchBuffer, sizeBatchBuffer), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); + std::unique_ptr> flatBatchBuffer(flatBatchBufferHelper->flattenBatchBuffer(batchBuffer, sizeBatchBuffer, DispatchMode::ImmediateDispatch), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); EXPECT_NE(nullptr, flatBatchBuffer.get()); EXPECT_EQ(alignUp(128u + 128u, 0x1000), sizeBatchBuffer); @@ -406,10 +409,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB memoryManager->freeGraphicsMemory(otherAllocation); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferAndNoChainedBatchBufferThenCombinedBatchBufferIsNotCreated) { +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferInImmediateDispatchModeAndNoChainedBatchBufferThenCombinedBatchBufferIsNotCreated) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); @@ -419,17 +424,182 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB size_t sizeBatchBuffer = 0xffffu; - std::unique_ptr> flatBatchBuffer(aubCsr->flattenBatchBuffer(batchBuffer, sizeBatchBuffer), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); + std::unique_ptr> flatBatchBuffer(flatBatchBufferHelper->flattenBatchBuffer(batchBuffer, sizeBatchBuffer, DispatchMode::ImmediateDispatch), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); EXPECT_EQ(nullptr, flatBatchBuffer.get()); EXPECT_EQ(0xffffu, sizeBatchBuffer); memoryManager->freeGraphicsMemory(commandBuffer); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferAndNotImmediateOrBatchedDispatchModeThenCombinedBatchBufferIsNotCreated) { + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); + + auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); + auto otherAllocation = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); + ASSERT_NE(nullptr, chainedBatchBuffer); + + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); + ASSERT_NE(nullptr, commandBuffer); + LinearStream cs(commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, chainedBatchBuffer, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + size_t sizeBatchBuffer = 0xffffu; + + std::unique_ptr> flatBatchBuffer(flatBatchBufferHelper->flattenBatchBuffer(batchBuffer, sizeBatchBuffer, DispatchMode::AdaptiveDispatch), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); + EXPECT_EQ(nullptr, flatBatchBuffer.get()); + EXPECT_EQ(0xffffu, sizeBatchBuffer); + + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(chainedBatchBuffer); + memoryManager->freeGraphicsMemory(otherAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenRegisterCommandChunkIsCalledThenNewChunkIsAddedToTheList) { + typedef typename FamilyType::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + GraphicsAllocation *commandBufferAllocation = memoryManager->allocateGraphicsMemory(4096, 4096); + ASSERT_NE(nullptr, commandBufferAllocation); + LinearStream cs(commandBufferAllocation); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + aubCsr->getFlatBatchBufferHelper().registerCommandChunk(batchBuffer, sizeof(MI_BATCH_BUFFER_START)); + ASSERT_EQ(1u, aubCsr->getFlatBatchBufferHelper().getCommandChunkList().size()); + EXPECT_EQ(128u + sizeof(MI_BATCH_BUFFER_START), aubCsr->getFlatBatchBufferHelper().getCommandChunkList()[0].endOffset); + + CommandChunk chunk; + chunk.endOffset = 0x123; + aubCsr->getFlatBatchBufferHelper().registerCommandChunk(chunk); + + ASSERT_EQ(2u, aubCsr->getFlatBatchBufferHelper().getCommandChunkList().size()); + EXPECT_EQ(0x123u, aubCsr->getFlatBatchBufferHelper().getCommandChunkList()[1].endOffset); + + memoryManager->freeGraphicsMemory(commandBufferAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenRemovePatchInfoDataIsCalledThenElementIsRemovedFromPatchInfoList) { + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + PatchInfoData patchInfoData(0xA000, 0x0, PatchInfoAllocationType::KernelArg, 0xB000, 0x0, PatchInfoAllocationType::Default); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData); + EXPECT_EQ(1u, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size()); + + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().removePatchInfoData(0xC000)); + EXPECT_EQ(1u, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size()); + + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().removePatchInfoData(0xB000)); + EXPECT_EQ(0u, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size()); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddGucStartMessageIsCalledThenBatchBufferAddressIsStoredInPatchInfoCollection) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); + + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + std::unique_ptr batchBuffer(new char[1024]); + aubCsr->addGUCStartMessage(static_cast(reinterpret_cast(batchBuffer.get())), EngineType::ENGINE_RCS); + + auto &patchInfoCollection = aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection(); + ASSERT_EQ(1u, patchInfoCollection.size()); + EXPECT_EQ(patchInfoCollection[0].sourceAllocation, reinterpret_cast(batchBuffer.get())); + EXPECT_EQ(patchInfoCollection[0].targetType, PatchInfoAllocationType::GUCStartMessage); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferFlatteningInBatchedDispatchModeThenNewCombinedBatchBufferIsCreated) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); + DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); + + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + CommandChunk chunk1; + CommandChunk chunk2; + CommandChunk chunk3; + + std::unique_ptr commands1(new char[0x100u]); + commands1.get()[0] = 0x1; + chunk1.baseAddressCpu = chunk1.baseAddressGpu = reinterpret_cast(commands1.get()); + chunk1.startOffset = 0u; + chunk1.endOffset = 0x50u; + + std::unique_ptr commands2(new char[0x100u]); + commands2.get()[0] = 0x2; + chunk2.baseAddressCpu = chunk2.baseAddressGpu = reinterpret_cast(commands2.get()); + chunk2.startOffset = 0u; + chunk2.endOffset = 0x50u; + aubCsr->getFlatBatchBufferHelper().registerBatchBufferStartAddress(reinterpret_cast(commands2.get() + 0x40), reinterpret_cast(commands1.get())); + + std::unique_ptr commands3(new char[0x100u]); + commands3.get()[0] = 0x3; + chunk3.baseAddressCpu = chunk3.baseAddressGpu = reinterpret_cast(commands3.get()); + chunk3.startOffset = 0u; + chunk3.endOffset = 0x50u; + aubCsr->getFlatBatchBufferHelper().registerBatchBufferStartAddress(reinterpret_cast(commands3.get() + 0x40), reinterpret_cast(commands2.get())); + + aubCsr->getFlatBatchBufferHelper().registerCommandChunk(chunk1); + aubCsr->getFlatBatchBufferHelper().registerCommandChunk(chunk2); + aubCsr->getFlatBatchBufferHelper().registerCommandChunk(chunk3); + + ASSERT_EQ(3u, aubCsr->getFlatBatchBufferHelper().getCommandChunkList().size()); + + PatchInfoData patchInfoData1(0xAAAu, 0xAu, PatchInfoAllocationType::IndirectObjectHeap, chunk1.baseAddressGpu, 0x10, PatchInfoAllocationType::Default); + PatchInfoData patchInfoData2(0xBBBu, 0xAu, PatchInfoAllocationType::IndirectObjectHeap, chunk1.baseAddressGpu, 0x60, PatchInfoAllocationType::Default); + PatchInfoData patchInfoData3(0xCCCu, 0xAu, PatchInfoAllocationType::IndirectObjectHeap, 0x0, 0x10, PatchInfoAllocationType::Default); + + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData1); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData2); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData3); + + ASSERT_EQ(3u, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size()); + + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); + ASSERT_NE(nullptr, commandBuffer); + LinearStream cs(commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + size_t sizeBatchBuffer = 0u; + + std::unique_ptr> flatBatchBuffer(aubCsr->getFlatBatchBufferHelper().flattenBatchBuffer(batchBuffer, sizeBatchBuffer, DispatchMode::BatchedDispatch), [&](void *ptr) { memoryManager->alignedFreeWrapper(ptr); }); + + EXPECT_NE(nullptr, flatBatchBuffer.get()); + EXPECT_EQ(alignUp(0x50u + 0x40u + 0x40u + CSRequirements::csOverfetchSize, 0x1000u), sizeBatchBuffer); + + ASSERT_EQ(1u, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection().size()); + EXPECT_EQ(0xAAAu, aubCsr->getFlatBatchBufferHelper().getPatchInfoCollection()[0].sourceAllocation); + + EXPECT_EQ(0u, aubCsr->getFlatBatchBufferHelper().getCommandChunkList().size()); + + EXPECT_EQ(0x3, static_cast(flatBatchBuffer.get())[0]); + EXPECT_EQ(0x2, static_cast(flatBatchBuffer.get())[0x40]); + EXPECT_EQ(0x1, static_cast(flatBatchBuffer.get())[0x40 + 0x40]); + + memoryManager->freeGraphicsMemory(commandBuffer); +} + HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefaultDebugConfigThenExpectFlattenBatchBufferIsNotCalled) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + aubCsr->overwriteFlatBatchBufferHelper(mockHelper); aubCsr->setTagAllocation(pDevice->getTagAllocation()); ASSERT_NE(nullptr, aubCsr->getTagAllocation()); @@ -442,7 +612,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefault auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - EXPECT_CALL(*aubCsr, flattenBatchBuffer(::testing::_, ::testing::_)).Times(0); + EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(0); aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); memoryManager->freeGraphicsMemory(commandBuffer); @@ -451,11 +621,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefault HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndImmediateDispatchModeThenExpectFlattenBatchBufferIsCalled) { DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + aubCsr->overwriteFlatBatchBufferHelper(mockHelper); aubCsr->setTagAllocation(pDevice->getTagAllocation()); ASSERT_NE(nullptr, aubCsr->getTagAllocation()); @@ -474,7 +646,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF std::unique_ptr ptr(alignedMalloc(4096, 4096), alignedFree); - EXPECT_CALL(*aubCsr, flattenBatchBuffer(::testing::_, ::testing::_)).WillOnce(::testing::Return(ptr.release())); + EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).WillOnce(::testing::Return(ptr.release())); aubCsr->flush(batchBuffer, engineType, nullptr); memoryManager->freeGraphicsMemory(commandBuffer); @@ -484,11 +656,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndImmediateDispatchModeAndThereIsNoChainedBatchBufferThenExpectFlattenBatchBufferIsCalledAnyway) { DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + aubCsr->overwriteFlatBatchBufferHelper(mockHelper); aubCsr->setTagAllocation(pDevice->getTagAllocation()); ASSERT_NE(nullptr, aubCsr->getTagAllocation()); @@ -500,20 +674,22 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; - EXPECT_CALL(*aubCsr, flattenBatchBuffer(::testing::_, ::testing::_)).Times(1); + EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(1); aubCsr->flush(batchBuffer, engineType, nullptr); memoryManager->freeGraphicsMemory(commandBuffer); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDispatchModeIsNotImmediateThenExpectFlattenBatchBufferIsNotCalled) { +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndBatchedDispatchModeThenExpectFlattenBatchBufferIsCalledAnyway) { DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); - aubCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + aubCsr->overwriteFlatBatchBufferHelper(mockHelper); aubCsr->setTagAllocation(pDevice->getTagAllocation()); ASSERT_NE(nullptr, aubCsr->getTagAllocation()); @@ -521,20 +697,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDispatc GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); + ResidencyContainer allocationsForResidency; - auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); - ASSERT_NE(nullptr, chainedBatchBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, chainedBatchBuffer, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; - ResidencyContainer allocationsForResidency = {chainedBatchBuffer}; - - EXPECT_CALL(*aubCsr, flattenBatchBuffer(::testing::_, ::testing::_)).Times(0); + EXPECT_CALL(*mockHelper, flattenBatchBuffer(::testing::_, ::testing::_, ::testing::_)).Times(1); aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); memoryManager->freeGraphicsMemory(commandBuffer); - memoryManager->freeGraphicsMemory(chainedBatchBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatchInfoCommentsForAUBDumpIsSetThenAddPatchInfoCommentsIsCalled) { @@ -681,8 +852,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatch PatchInfoData patchInfoData[2] = {{0xAAAAAAAA, 128u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 256u, PatchInfoAllocationType::Default}, {0xBBBBBBBB, 128u, PatchInfoAllocationType::Default, 0xDDDDDDDD, 256u, PatchInfoAllocationType::Default}}; - EXPECT_TRUE(aubCsr->setPatchInfoData(patchInfoData[0])); - EXPECT_TRUE(aubCsr->setPatchInfoData(patchInfoData[1])); + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[0])); + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[1])); std::vector comments; @@ -758,7 +929,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourc mockAubFileStream.swap(aubCsr->stream); PatchInfoData patchInfoData = {0x0, 0u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 0u, PatchInfoAllocationType::Default}; - EXPECT_TRUE(aubCsr->setPatchInfoData(patchInfoData)); + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); std::vector comments; @@ -819,7 +990,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTarge mockAubFileStream.swap(aubCsr->stream); PatchInfoData patchInfoData = {0xAAAAAAAA, 0u, PatchInfoAllocationType::Default, 0x0, 0u, PatchInfoAllocationType::Default}; - EXPECT_TRUE(aubCsr->setPatchInfoData(patchInfoData)); + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); std::vector comments; @@ -863,6 +1034,76 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTarge memoryManager->freeGraphicsMemory(commandBuffer); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForEmptyPatchInfoListThenIndirectPatchCommandBufferIsNotCreated) { + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + size_t indirectPatchCommandsSize = 0u; + std::vector indirectPatchInfo; + + std::unique_ptr commandBuffer(aubCsr->getFlatBatchBufferHelper().getIndirectPatchCommands(indirectPatchCommandsSize, indirectPatchInfo)); + EXPECT_EQ(0u, indirectPatchCommandsSize); + EXPECT_EQ(0u, indirectPatchInfo.size()); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForNonEmptyPatchInfoListThenIndirectPatchCommandBufferIsCreated) { + typedef typename FamilyType::MI_STORE_DATA_IMM MI_STORE_DATA_IMM; + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + PatchInfoData patchInfo1(0xA000, 0u, PatchInfoAllocationType::KernelArg, 0x6000, 0x100, PatchInfoAllocationType::IndirectObjectHeap); + PatchInfoData patchInfo2(0xB000, 0u, PatchInfoAllocationType::KernelArg, 0x6000, 0x200, PatchInfoAllocationType::IndirectObjectHeap); + PatchInfoData patchInfo3(0xC000, 0u, PatchInfoAllocationType::IndirectObjectHeap, 0x1000, 0x100, PatchInfoAllocationType::Default); + PatchInfoData patchInfo4(0xC000, 0u, PatchInfoAllocationType::Default, 0x2000, 0x100, PatchInfoAllocationType::GUCStartMessage); + + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfo1); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfo2); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfo3); + aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfo4); + + size_t indirectPatchCommandsSize = 0u; + std::vector indirectPatchInfo; + + std::unique_ptr commandBuffer(aubCsr->getFlatBatchBufferHelper().getIndirectPatchCommands(indirectPatchCommandsSize, indirectPatchInfo)); + EXPECT_EQ(4u, indirectPatchInfo.size()); + EXPECT_EQ(2u * sizeof(MI_STORE_DATA_IMM), indirectPatchCommandsSize); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddBatchBufferStartCalledAndBatchBUfferFlatteningEnabledThenBatchBufferStartAddressIsRegistered) { + typedef typename FamilyType::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + DebugManagerStateRestore dbgRestore; + DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); + + std::unique_ptr memoryManager(nullptr); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + memoryManager.reset(aubCsr->createMemoryManager(false)); + + MI_BATCH_BUFFER_START bbStart; + + aubCsr->addBatchBufferStart(&bbStart, 0xA000u); + std::map &batchBufferStartAddressSequence = aubCsr->getFlatBatchBufferHelper().getBatchBufferStartAddressSequence(); + + ASSERT_EQ(1u, batchBufferStartAddressSequence.size()); + std::pair addr = *batchBufferStartAddressSequence.begin(); + EXPECT_EQ(reinterpret_cast(&bbStart), addr.first); + EXPECT_EQ(0xA000u, addr.second); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenFlatBatchBufferHelperWhenSettingSroreQwordOnSDICommandThenAppropriateBitIsSet) { + typedef typename FamilyType::MI_STORE_DATA_IMM MI_STORE_DATA_IMM; + + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + + MI_STORE_DATA_IMM cmd; + cmd.init(); + FlatBatchBufferHelperHw::sdiSetStoreQword(&cmd, false); + EXPECT_EQ(0u, static_cast(cmd.getStoreQword())); + FlatBatchBufferHelperHw::sdiSetStoreQword(&cmd, true); + EXPECT_EQ(1u, static_cast(cmd.getStoreQword())); +} + class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryManager { public: GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override { diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index f1e8196a95..e9d97526ca 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -140,7 +140,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenconfigureCSRtoNonDirtyStateWh HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSubmittedViaCsrThenBbEndCoversPaddingEnoughToFitMiBatchBufferStart) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); configureCSRtoNonDirtyState(); @@ -161,7 +161,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSu HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSubmittedViaCommandStreamThenBbEndCoversPaddingEnoughToFitMiBatchBufferStart) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); CommandQueueHw commandQueue(nullptr, pDevice, 0); auto &commandStream = commandQueue.getCS(4096u); @@ -210,7 +210,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenflushTaskThenDshAndIoh HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThreadPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -1946,7 +1946,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateAndBatching auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -1980,7 +1980,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2036,7 +2036,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndTwoRecord auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2085,7 +2085,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2133,6 +2133,77 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco EXPECT_EQ(1, mockCsr->flushCalledCount); } +HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeThreeRecordedCommandBufferEnabledBatchBufferFlatteningAndPatchInfoCollectionWhenFlushBatchedSubmissionsIsCalledThenBatchBuffersAndPatchInfoAreCollected) { + DebugManagerStateRestore stateRestore; + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); + DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); + DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); + + typedef typename FamilyType::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END; + typedef typename FamilyType::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + typedef typename FamilyType::PIPE_CONTROL PIPE_CONTROL; + + CommandQueueHw commandQueue(nullptr, pDevice, 0); + auto &commandStream = commandQueue.getCS(4096u); + + auto mockCsr = new MockCsrHw2(*platformDevices[0]); + auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + mockCsr->overwriteFlatBatchBufferHelper(mockHelper); + pDevice->resetCommandStreamReceiver(mockCsr); + + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); + + auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); + mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); + + DispatchFlags dispatchFlags; + dispatchFlags.guardCommandBufferWithPipeControl = true; + dispatchFlags.outOfOrderExecutionAllowed = true; + + EXPECT_CALL(*mockHelper, setPatchInfoData(::testing::_)).Times(10); + EXPECT_CALL(*mockHelper, removePatchInfoData(::testing::_)).Times(4 * mockCsr->getRequiredPipeControlSize() / sizeof(PIPE_CONTROL)); + EXPECT_CALL(*mockHelper, registerCommandChunk(::testing::_)).Times(4); + EXPECT_CALL(*mockHelper, registerBatchBufferStartAddress(::testing::_, ::testing::_)).Times(3); + + mockCsr->flushTask(commandStream, + 0, + dsh, + ioh, + ssh, + taskLevel, + dispatchFlags); + + mockCsr->flushTask(commandStream, + 0, + dsh, + ioh, + ssh, + taskLevel, + dispatchFlags); + + mockCsr->flushTask(commandStream, + 0, + dsh, + ioh, + ssh, + taskLevel, + dispatchFlags); + + auto primaryBatch = mockedSubmissionsAggregator->peekCommandBuffers().peekHead(); + auto lastBatchBuffer = primaryBatch->next->next; + + auto bbEndLocation = primaryBatch->next->batchBufferEndLocation; + auto lastBatchBufferAddress = (uint64_t)ptrOffset(lastBatchBuffer->batchBuffer.commandBufferAllocation->getGpuAddress(), + lastBatchBuffer->batchBuffer.startOffset); + + mockCsr->flushBatchedSubmissions(); + + auto batchBufferStart = genCmdCast(bbEndLocation); + ASSERT_NE(nullptr, batchBufferStart); + EXPECT_EQ(lastBatchBufferAddress, batchBufferStart->getBatchBufferStartAddressGraphicsaddress472()); + EXPECT_EQ(1, mockCsr->flushCalledCount); +} + HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeRecordedCommandBuffersThatUsesAllResourceWhenFlushTaskIsCalledThenBatchBuffersAreNotCombined) { typedef typename FamilyType::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END; @@ -2144,7 +2215,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2209,7 +2280,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2280,7 +2351,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenRecorded auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2343,9 +2414,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenRecorded HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrCreatedWithDedicatedDebugFlagWhenItIsCreatedThenItHasProperDispatchMode) { DebugManagerStateRestore stateRestore; - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::AdaptiveDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::AdaptiveDispatch)); std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0])); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::AdaptiveDispatch, mockCsr->dispatchMode); + EXPECT_EQ(DispatchMode::AdaptiveDispatch, mockCsr->dispatchMode); } HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenBlockingCommandIsSendThenItIsFlushedAndNotBatched) { @@ -2355,7 +2426,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenBlocking auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2412,7 +2483,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; @@ -2463,7 +2534,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenWaitForT auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2502,7 +2573,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenEnqueueI auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2541,7 +2612,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenSusbsequ auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2598,7 +2669,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes mockCsr->setMemoryManager(mockedMemoryManager.get()); mockCsr->setTagAllocation(pDevice->getTagAllocation()); mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2651,7 +2722,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTwoTasks auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2730,7 +2801,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenDcFlushI auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; @@ -2757,7 +2828,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenCommandA auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; @@ -2787,7 +2858,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWithOutOfOrd auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; @@ -2817,7 +2888,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenDcFlushI auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2847,7 +2918,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndOoqFlagSe auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2903,7 +2974,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenPipeCont auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -2962,7 +3033,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenThreeTas auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -3098,7 +3169,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -3129,7 +3200,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -3160,7 +3231,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -3188,15 +3259,15 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCommandStreamerWhenAddPat CommandQueueHw commandQueue(nullptr, pDevice, 0); auto &commandStream = commandQueue.getCS(4096u); - int32_t tag; - auto mockCsr = new MockCsrBase(tag); + auto mockCsr = new MockCsrHw2(*platformDevices[0]); + auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + mockCsr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(mockCsr); DispatchFlags dispatchFlags; dispatchFlags.throttle = QueueThrottle::MEDIUM; - EXPECT_CALL(*mockCsr, setPatchInfoData(_)) - .Times(0); + EXPECT_CALL(*mockHelper, setPatchInfoData(_)).Times(0); mockCsr->flushTask(commandStream, 0, @@ -3214,20 +3285,20 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCommandStreamerWhenAddPat CommandQueueHw commandQueue(nullptr, pDevice, 0); auto &commandStream = commandQueue.getCS(4096u); - int32_t tag; - auto mockCsr = new MockCsrBase(tag); + auto mockCsr = new MockCsrHw2(*platformDevices[0]); + auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + mockCsr->overwriteFlatBatchBufferHelper(mockHelper); + pDevice->resetCommandStreamReceiver(mockCsr); DispatchFlags dispatchFlags; dispatchFlags.throttle = QueueThrottle::MEDIUM; std::vector patchInfoDataVector; - EXPECT_CALL(*mockCsr, setPatchInfoData(_)) - .Times(5) - .WillRepeatedly(Invoke([&](PatchInfoData &data) { - patchInfoDataVector.push_back(data); - return true; - })); + EXPECT_CALL(*mockHelper, setPatchInfoData(_)).Times(4).WillRepeatedly(Invoke([&](const PatchInfoData &data) { + patchInfoDataVector.push_back(data); + return true; + })); mockCsr->flushTask(commandStream, 0, @@ -3237,68 +3308,54 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCommandStreamerWhenAddPat taskLevel, dispatchFlags); - EXPECT_EQ(5u, patchInfoDataVector.size()); + EXPECT_EQ(4u, patchInfoDataVector.size()); for (auto &patchInfoData : patchInfoDataVector) { uint64_t expectedAddress = 0u; switch (patchInfoData.sourceType) { case PatchInfoAllocationType::DynamicStateHeap: - expectedAddress = dsh.getGpuBase(); + expectedAddress = dsh.getGraphicsAllocation()->getGpuAddress(); break; case PatchInfoAllocationType::SurfaceStateHeap: - expectedAddress = ssh.getGpuBase(); + expectedAddress = ssh.getGraphicsAllocation()->getGpuAddress(); break; case PatchInfoAllocationType::IndirectObjectHeap: - expectedAddress = ioh.getGpuBase(); - break; - case PatchInfoAllocationType::InstructionHeap: - expectedAddress = mockCsr->getMemoryManager()->getInternalHeapBaseAddress(); + expectedAddress = ioh.getGraphicsAllocation()->getGpuAddress(); break; default: expectedAddress = 0u; } EXPECT_EQ(expectedAddress, patchInfoData.sourceAllocation); EXPECT_EQ(0u, patchInfoData.sourceAllocationOffset); - EXPECT_EQ(commandStream.getGpuBase(), patchInfoData.targetAllocation); EXPECT_EQ(PatchInfoAllocationType::Default, patchInfoData.targetType); - EXPECT_NE(commandStream.getGpuBase(), patchInfoData.targetAllocationOffset); } } -HWTEST_F(CommandStreamReceiverFlushTaskTests, givenNonAubCsrWhenSetPatchInfoDataIsCalledThenNoDataIsCollected) { - std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0])); - PatchInfoData patchInfoData = {0u, 0u, PatchInfoAllocationType::Default, 0u, 0u, PatchInfoAllocationType::Default}; - EXPECT_FALSE(mockCsr->setPatchInfoData(patchInfoData)); -} - HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCsrWhenCollectStateBaseAddresPatchInfoIsCalledThenAppropriateAddressesAreTaken) { typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; - int32_t tag; - std::unique_ptr> mockCsr(new MockCsrBase(tag)); + std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0])); + auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + mockCsr->overwriteFlatBatchBufferHelper(mockHelper); std::vector patchInfoDataVector; - EXPECT_CALL(*mockCsr, setPatchInfoData(_)) - .Times(5) - .WillRepeatedly(Invoke([&](PatchInfoData &data) { - patchInfoDataVector.push_back(data); - return true; - })); + EXPECT_CALL(*mockHelper, setPatchInfoData(_)).Times(4).WillRepeatedly(Invoke([&](const PatchInfoData &data) { + patchInfoDataVector.push_back(data); + return true; + })); + EXPECT_CALL(*mockHelper, registerCommandChunk(_)).Times(0); uint64_t baseAddress = 0xabcdef; uint64_t commandOffset = 0xa; uint64_t generalStateBase = 0xff; - auto internalHeapBase = this->pDevice->getMemoryManager()->getInternalHeapBaseAddress(); + mockCsr->collectStateBaseAddresPatchInfo(baseAddress, commandOffset, dsh, ioh, ssh, generalStateBase); - mockCsr->collectStateBaseAddresPatchInfo(baseAddress, commandOffset, dsh, ioh, ssh, generalStateBase, internalHeapBase); - - ASSERT_EQ(patchInfoDataVector.size(), 5u); + ASSERT_EQ(patchInfoDataVector.size(), 4u); PatchInfoData dshPatch = patchInfoDataVector[0]; PatchInfoData gshPatch = patchInfoDataVector[1]; PatchInfoData sshPatch = patchInfoDataVector[2]; PatchInfoData iohPatch = patchInfoDataVector[3]; - PatchInfoData ihPatch = patchInfoDataVector[4]; for (auto &patch : patchInfoDataVector) { EXPECT_EQ(patch.targetAllocation, baseAddress); @@ -3306,19 +3363,15 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCsrWhenCollectStateBaseAd } //DSH - EXPECT_EQ(dshPatch.sourceAllocation, dsh.getGpuBase()); + EXPECT_EQ(dshPatch.sourceAllocation, dsh.getGraphicsAllocation()->getGpuAddress()); EXPECT_EQ(dshPatch.targetAllocationOffset, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::DYNAMICSTATEBASEADDRESS_BYTEOFFSET); - //IH - EXPECT_EQ(ihPatch.sourceAllocation, internalHeapBase); - EXPECT_EQ(ihPatch.targetAllocationOffset, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INSTRUCTIONBASEADDRESS_BYTEOFFSET); - //IOH - EXPECT_EQ(iohPatch.sourceAllocation, ioh.getGpuBase()); + EXPECT_EQ(iohPatch.sourceAllocation, ioh.getGraphicsAllocation()->getGpuAddress()); EXPECT_EQ(iohPatch.targetAllocationOffset, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::INDIRECTOBJECTBASEADDRESS_BYTEOFFSET); //SSH - EXPECT_EQ(sshPatch.sourceAllocation, ssh.getGpuBase()); + EXPECT_EQ(sshPatch.sourceAllocation, ssh.getGraphicsAllocation()->getGpuAddress()); EXPECT_EQ(sshPatch.targetAllocationOffset, commandOffset + STATE_BASE_ADDRESS::PATCH_CONSTANTS::SURFACESTATEBASEADDRESS_BYTEOFFSET); //GSH diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 326d392c7a..452542e07d 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -255,7 +255,7 @@ TEST_F(CommandStreamReceiverTest, givenForced32BitAddressingWhenDebugSurfaceIsAl HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefaultDispatchingPolicyIsImmediateSubmission) { auto &csr = pDevice->getUltCommandStreamReceiver(); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode); + EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode); } TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllocationIsCalledThenNullptrIsReturned) { diff --git a/unit_tests/command_stream/submissions_aggregator_tests.cpp b/unit_tests/command_stream/submissions_aggregator_tests.cpp index 14656f9c7e..c6e4e19df2 100644 --- a/unit_tests/command_stream/submissions_aggregator_tests.cpp +++ b/unit_tests/command_stream/submissions_aggregator_tests.cpp @@ -484,7 +484,7 @@ struct SubmissionsAggregatorTests : public ::testing::Test { template void overrideCsr(T *newCsr) { device->resetCommandStreamReceiver(newCsr); - newCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + newCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); } std::unique_ptr device; diff --git a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp index bc717aab42..cc3341dcd6 100644 --- a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp +++ b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp @@ -564,7 +564,7 @@ HWTEST_F(ParentKernelEnqueueFixture, ParentKernelEnqueuedWithSchedulerReturnInst HWTEST_F(ParentKernelEnqueueFixture, givenCsrInBatchingModeWhenExecutionModelKernelIsSubmittedThenItIsFlushed) { if (pDevice->getSupportedClVersion() >= 20) { auto mockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); diff --git a/unit_tests/helpers/kernel_commands_tests.cpp b/unit_tests/helpers/kernel_commands_tests.cpp index 8f563b882c..f33c7d7179 100644 --- a/unit_tests/helpers/kernel_commands_tests.cpp +++ b/unit_tests/helpers/kernel_commands_tests.cpp @@ -245,8 +245,11 @@ HWTEST_F(KernelCommandsTest, givenSendCrossThreadDataWhenWhenAddPatchInfoComment auto &indirectHeap = cmdQ.getIndirectHeap(IndirectHeap::INDIRECT_OBJECT, 8192); indirectHeap.getSpace(128u); - PatchInfoData patchInfoData = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap}; - kernel->getPatchInfoDataList().push_back(patchInfoData); + PatchInfoData patchInfoData1 = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap}; + PatchInfoData patchInfoData2 = {0xcccccccc, 0, PatchInfoAllocationType::IndirectObjectHeap, 0xdddddddd, 0, PatchInfoAllocationType::Default}; + + kernel->getPatchInfoDataList().push_back(patchInfoData1); + kernel->getPatchInfoDataList().push_back(patchInfoData2); auto offsetCrossThreadData = KernelCommandsHelper::sendCrossThreadData( indirectHeap, @@ -255,12 +258,12 @@ HWTEST_F(KernelCommandsTest, givenSendCrossThreadDataWhenWhenAddPatchInfoComment ASSERT_NE(0u, offsetCrossThreadData); EXPECT_EQ(128u, offsetCrossThreadData); - ASSERT_EQ(1u, kernel->getPatchInfoDataList().size()); + ASSERT_EQ(2u, kernel->getPatchInfoDataList().size()); EXPECT_EQ(0xaaaaaaaa, kernel->getPatchInfoDataList()[0].sourceAllocation); EXPECT_EQ(0u, kernel->getPatchInfoDataList()[0].sourceAllocationOffset); EXPECT_EQ(PatchInfoAllocationType::KernelArg, kernel->getPatchInfoDataList()[0].sourceType); EXPECT_NE(0xbbbbbbbb, kernel->getPatchInfoDataList()[0].targetAllocation); - EXPECT_EQ(indirectHeap.getGpuBase(), kernel->getPatchInfoDataList()[0].targetAllocation); + EXPECT_EQ(indirectHeap.getGraphicsAllocation()->getGpuAddress(), kernel->getPatchInfoDataList()[0].targetAllocation); EXPECT_NE(0u, kernel->getPatchInfoDataList()[0].targetAllocationOffset); EXPECT_EQ(offsetCrossThreadData, kernel->getPatchInfoDataList()[0].targetAllocationOffset); EXPECT_EQ(PatchInfoAllocationType::IndirectObjectHeap, kernel->getPatchInfoDataList()[0].targetType); diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index 6437d4be0e..d7b92635e8 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -23,6 +23,7 @@ #pragma once #include "runtime/command_stream/command_stream_receiver.h" #include "runtime/command_stream/command_stream_receiver_hw.h" +#include "runtime/helpers/flat_batch_buffer_helper_hw.h" #include "runtime/memory_manager/graphics_allocation.h" #include "runtime/helpers/options.h" #include "runtime/helpers/flush_stamp.h" @@ -89,8 +90,6 @@ class MockCsrBase : public UltCommandStreamReceiver { processEvictionCalled = true; } - MOCK_METHOD1(setPatchInfoData, bool(PatchInfoData &)); - ResidencyContainer madeResidentGfxAllocations; ResidencyContainer madeNonResidentGfxAllocations; int32_t *executionStamp; @@ -202,6 +201,17 @@ class MockCsrHw2 : public CommandStreamReceiverHw { DispatchFlags passedDispatchFlags = {}; }; +template +class MockFlatBatchBufferHelper : public FlatBatchBufferHelperHw { + public: + MockFlatBatchBufferHelper(MemoryManager *memoryManager) : FlatBatchBufferHelperHw(memoryManager) {} + MOCK_METHOD1(setPatchInfoData, bool(const PatchInfoData &)); + MOCK_METHOD1(removePatchInfoData, bool(uint64_t)); + MOCK_METHOD1(registerCommandChunk, bool(CommandChunk &)); + MOCK_METHOD2(registerBatchBufferStartAddress, bool(uint64_t, uint64_t)); + MOCK_METHOD3(flattenBatchBuffer, void *(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode)); +}; + class MockCommandStreamReceiver : public CommandStreamReceiver { public: using CommandStreamReceiver::latestSentTaskCount; diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 6f8624b2c6..d4e3ce8310 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -752,7 +752,7 @@ class DrmCommandStreamEnhancedFixture this->gemCloseWorkerOperationMode = overrideValue; } - void overrideDispatchPolicy(CommandStreamReceiver::DispatchMode overrideValue) { + void overrideDispatchPolicy(DispatchMode overrideValue) { this->dispatchMode = overrideValue; } @@ -986,7 +986,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr } TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingThenCommandBufferIsNotSubmitted) { - tCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + tCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); tCsr->overrideGemCloseWorkerOperationMode(gemCloseWorkerMode::gemCloseWorkerInactive); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); @@ -1046,7 +1046,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT } TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) { - tCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + tCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); tCsr->overrideGemCloseWorkerOperationMode(gemCloseWorkerMode::gemCloseWorkerInactive); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index 67697c6083..f831233279 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -66,7 +66,7 @@ class WddmCommandStreamFixture : public WddmFixtureMock { WddmFixtureMock::SetUp(); ASSERT_NE(wddm, nullptr); - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); csr = new WddmCommandStreamReceiver(*platformDevices[0], wddm); ASSERT_NE(nullptr, csr); @@ -105,7 +105,7 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture { void SetUp() { WddmFixture::SetUp(&gdi); ASSERT_NE(wddm, nullptr); - DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); csr = new WddmCommandStreamReceiver(*platformDevices[0], wddm); ASSERT_NE(nullptr, csr); @@ -651,7 +651,7 @@ struct MockWddmCsr : public WddmCommandStreamReceiver { using CommandStreamReceiver::getCS; using WddmCommandStreamReceiver::pageTableManagerInitialized; - void overrideDispatchPolicy(CommandStreamReceiver::DispatchMode overrideValue) { + void overrideDispatchPolicy(DispatchMode overrideValue) { this->dispatchMode = overrideValue; } @@ -670,7 +670,7 @@ struct MockWddmCsr : public WddmCommandStreamReceiver { HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) { std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], this->wddm)); mockCsr->setMemoryManager(memManager); - mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); @@ -747,7 +747,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt HWTEST_F(WddmDefaultTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) { DebugManager.flags.CsrDispatchMode.set(0); std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], this->wddm)); - EXPECT_EQ(CommandStreamReceiver::DispatchMode::BatchedDispatch, mockCsr->dispatchMode); + EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); } struct WddmCsrCompressionTests : WddmCommandStreamMockGdiTest { @@ -819,7 +819,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDon HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) { createMockWddm(); MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); - mockWddmCsr.overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockWddmCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch); auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); mockWddmCsr.setMemoryManager(memManager); @@ -854,7 +854,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn setCompressionEnabled(false); createMockWddm(); MockWddmCsr mockWddmCsr(hwInfo, myMockWddm.get()); - mockWddmCsr.overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + mockWddmCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index 3494c6c8d8..8715962f14 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -628,7 +628,11 @@ TEST_P(ProgramFromBinaryTest, givenProgramWhenItIsBeingBuildThenItContainsGraphi auto kernelIsa = graphicsAllocation->getUnderlyingBuffer(); EXPECT_NE(kernelInfo->heapInfo.pKernelHeap, kernelIsa); EXPECT_EQ(0, memcmp(kernelIsa, kernelInfo->heapInfo.pKernelHeap, kernelInfo->heapInfo.pKernelHeader->KernelHeapSize)); - EXPECT_NE(0u, graphicsAllocation->gpuBaseAddress); + if (sizeof(void *) == sizeof(uint32_t)) { + EXPECT_EQ(0u, graphicsAllocation->gpuBaseAddress); + } else { + EXPECT_NE(0u, graphicsAllocation->gpuBaseAddress); + } } TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelAllocationIsFreed) {