/* * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/aub/aub_center.h" #include "shared/source/command_stream/aub_command_stream_receiver_hw.h" #include "shared/source/command_stream/preemption.h" #include "shared/source/command_stream/wait_status.h" #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_info.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/dispatch_flags_helper.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/test_macros/mock_method_macros.h" #include namespace NEO { struct MockAubFileStreamMockMmioWrite : public AubMemDump::AubFileStream { void writeMMIOImpl(uint32_t offset, uint32_t value) override { mmioList.push_back(std::make_pair(offset, value)); } bool isOnMmioList(const MMIOPair &mmio) { bool mmioFound = false; for (auto &mmioPair : mmioList) { if (mmioPair.first == mmio.first && mmioPair.second == mmio.second) { mmioFound = true; break; } } return mmioFound; } std::vector> mmioList; }; template struct MockAubCsrToTestDumpContext : public AUBCommandStreamReceiverHw { using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; void addContextToken(uint32_t dumpHandle) override { handle = dumpHandle; } uint32_t handle = 0; }; template struct MockAubCsr : public AUBCommandStreamReceiverHw { using CommandStreamReceiverHw::defaultSshSize; using AUBCommandStreamReceiverHw::taskCount; using AUBCommandStreamReceiverHw::latestSentTaskCount; using AUBCommandStreamReceiverHw::pollForCompletionTaskCount; using AUBCommandStreamReceiverHw::getParametersForMemory; using AUBCommandStreamReceiverHw::writeMemory; using AUBCommandStreamReceiverHw::pollForCompletion; using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; MockAubCsr(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex, const DeviceBitfield deviceBitfield) : AUBCommandStreamReceiverHw("", true, executionEnvironment, rootDeviceIndex, deviceBitfield) {} CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart, const IndirectHeap *dsh, const IndirectHeap *ioh, const IndirectHeap *ssh, TaskCountType taskLevel, DispatchFlags &dispatchFlags, Device &device) override { recordedDispatchFlags = dispatchFlags; return AUBCommandStreamReceiverHw::flushTask(commandStream, commandStreamStart, dsh, ioh, ssh, taskLevel, dispatchFlags, device); } CompletionStamp flushTaskStateless(LinearStream &commandStream, size_t commandStreamStart, const IndirectHeap *dsh, const IndirectHeap *ioh, const IndirectHeap *ssh, TaskCountType taskLevel, DispatchFlags &dispatchFlags, Device &device) override { recordedDispatchFlags = dispatchFlags; return AUBCommandStreamReceiverHw::flushTaskStateless(commandStream, commandStreamStart, dsh, ioh, ssh, taskLevel, dispatchFlags, device); } DispatchMode peekDispatchMode() const { return this->dispatchMode; } GraphicsAllocation *getTagAllocation() const { return this->tagAllocation; } bool flushBatchedSubmissions() override { flushBatchedSubmissionsCalled = true; return true; } void initProgrammingFlags() override { initProgrammingFlagsCalled = true; } void initializeEngine() override { AUBCommandStreamReceiverHw::initializeEngine(); initializeEngineCalled = true; } void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override { AUBCommandStreamReceiverHw::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits); writeMemoryCalled = true; } bool writeMemory(GraphicsAllocation &gfxAllocation) override { writeMemoryGfxAllocCalled = true; return AUBCommandStreamReceiverHw::writeMemory(gfxAllocation); } void writeMMIO(uint32_t offset, uint32_t value) override { AUBCommandStreamReceiverHw::writeMMIO(offset, value); writeMMIOCalled = true; } void submitBatchBufferAub(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override { AUBCommandStreamReceiverHw::submitBatchBufferAub(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits); submitBatchBufferCalled = true; batchBufferGpuAddressPassed = batchBufferGpuAddress; } void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) override { CommandStreamReceiverSimulatedHw::writeMemoryWithAubManager(graphicsAllocation, isChunkCopy, gpuVaChunkOffset, chunkSize); writeMemoryWithAubManagerCalled = true; } void pollForCompletion(bool skipTaskCountCheck) override { AUBCommandStreamReceiverHw::pollForCompletion(skipTaskCountCheck); pollForCompletionCalled = true; skipTaskCountCheckForCompletionPoll = skipTaskCountCheck; } bool expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) override { expectMemoryEqualCalled = true; return AUBCommandStreamReceiverHw::expectMemoryEqual(gfxAddress, srcAddress, length); } bool expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) override { expectMemoryNotEqualCalled = true; return AUBCommandStreamReceiverHw::expectMemoryNotEqual(gfxAddress, srcAddress, length); } bool expectMemoryCompressed(void *gfxAddress, const void *srcAddress, size_t length) override { expectMemoryCompressedCalled = true; return AUBCommandStreamReceiverHw::expectMemoryCompressed(gfxAddress, srcAddress, length); } WaitStatus waitForCompletionWithTimeout(const WaitParams ¶ms, TaskCountType taskCountToWait) override { return NEO::WaitStatus::ready; } void addAubComment(const char *message) override { AUBCommandStreamReceiverHw::addAubComment(message); addAubCommentCalled = true; } void dumpAllocation(GraphicsAllocation &gfxAllocation) override { AUBCommandStreamReceiverHw::dumpAllocation(gfxAllocation); dumpAllocationCalled = true; } bool isMultiOsContextCapable() const override { return multiOsContextCapable; } DispatchFlags recordedDispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); uint64_t batchBufferGpuAddressPassed = 0u; bool multiOsContextCapable = false; bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; bool initializeEngineCalled = false; bool writeMemoryCalled = false; bool writeMemoryGfxAllocCalled = false; bool writeMemoryWithAubManagerCalled = false; bool writeMMIOCalled = false; bool submitBatchBufferCalled = false; bool pollForCompletionCalled = false; bool expectMemoryEqualCalled = false; bool expectMemoryNotEqualCalled = false; bool expectMemoryCompressedCalled = false; bool addAubCommentCalled = false; bool dumpAllocationCalled = false; bool skipTaskCountCheckForCompletionPoll = false; bool lockStreamCalled = false; std::unique_lock lockStream() override { lockStreamCalled = true; return AUBCommandStreamReceiverHw::lockStream(); } void initFile(const std::string &fileName) override { fileIsOpen = true; openFileName = fileName; } void closeFile() override { fileIsOpen = false; openFileName = ""; } bool isFileOpen() const override { return fileIsOpen; } const std::string getFileName() override { return openFileName; } bool fileIsOpen = false; std::string openFileName = ""; ADDMETHOD_NOBASE(addPatchInfoComments, bool, true, ()); using CommandStreamReceiverHw::localMemoryEnabled; }; struct AubExecutionEnvironment { std::unique_ptr executionEnvironment; GraphicsAllocation *commandBuffer = nullptr; std::unique_ptr commandStreamReceiver; template CsrType *getCsr() { return static_cast(commandStreamReceiver.get()); } ~AubExecutionEnvironment() { if (commandBuffer) { executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } } }; template std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) { std::unique_ptr executionEnvironment(new ExecutionEnvironment); DeviceBitfield deviceBitfield(1); executionEnvironment->prepareRootDeviceEnvironments(1); uint32_t rootDeviceIndex = 0u; executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(defaultHwInfo.get()); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initGmm(); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter()); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setDummyBlitProperties(rootDeviceIndex); executionEnvironment->initializeMemoryManager(); auto commandStreamReceiver = std::make_unique("", standalone, *executionEnvironment, rootDeviceIndex, deviceBitfield); auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), EngineDescriptorHelper::getDefaultDescriptor({getChosenEngineType(*defaultHwInfo), EngineUsage::regular}, PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); commandStreamReceiver->setupContext(*osContext); if (createTagAllocation) { commandStreamReceiver->initializeTagAllocation(); } commandStreamReceiver->createGlobalFenceAllocation(); std::unique_ptr aubExecutionEnvironment(new AubExecutionEnvironment); if (allocateCommandBuffer) { aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, MemoryConstants::pageSize}); } aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); aubExecutionEnvironment->commandStreamReceiver = std::move(commandStreamReceiver); return aubExecutionEnvironment; } } // namespace NEO