From ee797c2f1400ce836f1833fc82589444345c9456 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Thu, 20 Sep 2018 00:36:44 +0200 Subject: [PATCH] Multiple AUB CSRs to operate on a single file stream This commit introduces AUB stream provider class to produce a single file stream in multi device scenarios with multiple AUB CSRs. Change-Id: Id70e0d680459d34f4291b9e56aa39d960f025ac6 --- runtime/aub_mem_dump/aub_mem_dump.h | 3 + runtime/command_stream/CMakeLists.txt | 1 + .../aub_command_stream_receiver.cpp | 6 +- .../aub_command_stream_receiver_hw.h | 4 +- .../aub_command_stream_receiver_hw.inl | 63 +++++---- runtime/command_stream/aub_stream_provider.h | 30 +++++ .../execution_environment.cpp | 6 + .../execution_environment.h | 3 + .../aub_command_stream_receiver_tests.cpp | 120 +++++++++++++++--- .../execution_environment_tests.cpp | 27 +++- 10 files changed, 213 insertions(+), 50 deletions(-) create mode 100644 runtime/command_stream/aub_stream_provider.h diff --git a/runtime/aub_mem_dump/aub_mem_dump.h b/runtime/aub_mem_dump/aub_mem_dump.h index 230cd37e90..549a68f92a 100644 --- a/runtime/aub_mem_dump/aub_mem_dump.h +++ b/runtime/aub_mem_dump/aub_mem_dump.h @@ -9,6 +9,7 @@ #include #include #include +#include #ifndef BIT #define BIT(x) (((uint64_t)1) << (x)) @@ -137,9 +138,11 @@ struct AubFileStream : public AubStream { MOCKABLE_VIRTUAL void flush(); MOCKABLE_VIRTUAL void expectMemory(uint64_t physAddress, const void *memory, size_t size, uint32_t addressSpace); MOCKABLE_VIRTUAL bool addComment(const char *message); + MOCKABLE_VIRTUAL std::unique_lock lockStream(); std::ofstream fileHandle; std::string fileName; + std::mutex mutex; }; template diff --git a/runtime/command_stream/CMakeLists.txt b/runtime/command_stream/CMakeLists.txt index 42690bf727..626d5e5ef6 100644 --- a/runtime/command_stream/CMakeLists.txt +++ b/runtime/command_stream/CMakeLists.txt @@ -10,6 +10,7 @@ set(RUNTIME_SRCS_COMMAND_STREAM ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_hw.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_hw.inl + ${CMAKE_CURRENT_SOURCE_DIR}/aub_stream_provider.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver.cpp diff --git a/runtime/command_stream/aub_command_stream_receiver.cpp b/runtime/command_stream/aub_command_stream_receiver.cpp index c031087da9..8f654ac8e2 100644 --- a/runtime/command_stream/aub_command_stream_receiver.cpp +++ b/runtime/command_stream/aub_command_stream_receiver.cpp @@ -137,7 +137,7 @@ void AubFileStream::writeMemoryWriteHeader(uint64_t physAddress, size_t size, ui } void AubFileStream::writeGTT(uint32_t gttOffset, uint64_t entry) { - fileHandle.write(reinterpret_cast(&entry), sizeof(entry)); + write(reinterpret_cast(&entry), sizeof(entry)); } void AubFileStream::writePTE(uint64_t physAddress, uint64_t entry) { @@ -247,4 +247,8 @@ bool AubFileStream::addComment(const char *message) { return true; } +std::unique_lock AubFileStream::lockStream() { + return std::unique_lock(mutex); +} + } // namespace AubMemDump diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index ee031fc1b7..437a30d3e0 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -54,6 +54,8 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw { AUBCommandStreamReceiverHw(const AUBCommandStreamReceiverHw &) = delete; AUBCommandStreamReceiverHw &operator=(const AUBCommandStreamReceiverHw &) = delete; + MOCKABLE_VIRTUAL void openFile(const std::string &fileName); + MOCKABLE_VIRTUAL bool reopenFile(const std::string &fileName); MOCKABLE_VIRTUAL void initFile(const std::string &fileName); MOCKABLE_VIRTUAL void closeFile(); MOCKABLE_VIRTUAL bool isFileOpen(); @@ -81,7 +83,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw { uint32_t tailRingBuffer; } engineInfoTable[EngineType::NUM_ENGINES] = {}; - std::unique_ptr stream; + AUBCommandStreamReceiver::AubFileStream *stream; std::unique_ptr subCaptureManager; uint32_t aubDeviceId; bool standalone; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 2985136f65..72ad299218 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -8,7 +8,9 @@ #include "hw_cmds.h" #include "runtime/aub/aub_helper.h" #include "runtime/aub_mem_dump/page_table_entry_bits.h" +#include "runtime/command_stream/aub_stream_provider.h" #include "runtime/command_stream/aub_subcapture.h" +#include "runtime/execution_environment/execution_environment.h" #include "runtime/gmm_helper/gmm.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/resource_info.h" @@ -27,7 +29,6 @@ namespace OCLRT { template AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment) : BaseClass(hwInfoIn, executionEnvironment), - stream(std::make_unique()), subCaptureManager(std::make_unique(fileName)), standalone(standalone) { @@ -40,6 +41,8 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware if (DebugManager.flags.CsrDispatchMode.get()) { this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get(); } + executionEnvironment.initAubStreamProvider(); + stream = executionEnvironment.aubStreamProvider->getStream(); if (DebugManager.flags.AUBDumpSubCaptureMode.get()) { this->subCaptureManager->subCaptureMode = static_cast(DebugManager.flags.AUBDumpSubCaptureMode.get()); this->subCaptureManager->subCaptureFilter.dumpKernelStartIdx = static_cast(DebugManager.flags.AUBDumpFilterKernelStartIdx.get()); @@ -58,7 +61,6 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware template AUBCommandStreamReceiverHw::~AUBCommandStreamReceiverHw() { - AUBCommandStreamReceiverHw::closeFile(); freeEngineInfoTable(); } @@ -85,19 +87,41 @@ void AUBCommandStreamReceiverHw::initEngineMMIO(EngineType engineType } template -void AUBCommandStreamReceiverHw::initFile(const std::string &fileName) { - stream.reset(new AUBCommandStreamReceiver::AubFileStream()); +void AUBCommandStreamReceiverHw::openFile(const std::string &fileName) { + auto streamLocked = stream->lockStream(); + initFile(fileName); +} - // Open our file - stream->open(fileName.c_str()); - - if (!stream->isOpen()) { - // This DEBUG_BREAK_IF most probably means you are not executing aub tests with correct current directory (containing aub_out folder) - // try adding _aub - DEBUG_BREAK_IF(true); +template +bool AUBCommandStreamReceiverHw::reopenFile(const std::string &fileName) { + auto streamLocked = stream->lockStream(); + if (isFileOpen()) { + if (fileName != getFileName()) { + closeFile(); + freeEngineInfoTable(); + } + } + if (!isFileOpen()) { + initFile(fileName); + return true; + } + return false; +} + +template +void AUBCommandStreamReceiverHw::initFile(const std::string &fileName) { + if (!stream->isOpen()) { + // Open our file + stream->open(fileName.c_str()); + + if (!stream->isOpen()) { + // This DEBUG_BREAK_IF most probably means you are not executing aub tests with correct current directory (containing aub_out folder) + // try adding _aub + DEBUG_BREAK_IF(true); + } + // Add the file header + stream->init(AubMemDump::SteppingValues::A, aubDeviceId); } - // Add the file header - stream->init(AubMemDump::SteppingValues::A, aubDeviceId); } template @@ -235,7 +259,7 @@ CommandStreamReceiver *AUBCommandStreamReceiverHw::create(const Hardw auto csr = new AUBCommandStreamReceiverHw(hwInfoIn, fileName, standalone, executionEnvironment); if (!csr->subCaptureManager->isSubCaptureMode()) { - csr->initFile(fileName); + csr->openFile(fileName); } return csr; @@ -253,6 +277,7 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer } } + auto streamLocked = stream->lockStream(); uint32_t mmioBase = getCsTraits(engineType).mmioBase; auto &engineInfo = engineInfoTable[engineType]; @@ -621,14 +646,8 @@ void AUBCommandStreamReceiverHw::activateAubSubCapture(const MultiDis bool active = subCaptureManager->activateSubCapture(dispatchInfo); if (active) { std::string subCaptureFile = subCaptureManager->getSubCaptureFileName(dispatchInfo); - if (isFileOpen()) { - if (subCaptureFile != getFileName()) { - closeFile(); - freeEngineInfoTable(); - } - } - if (!isFileOpen()) { - initFile(subCaptureFile); + auto isReopened = reopenFile(subCaptureFile); + if (isReopened) { dumpAubNonWritable = true; } } diff --git a/runtime/command_stream/aub_stream_provider.h b/runtime/command_stream/aub_stream_provider.h new file mode 100644 index 0000000000..078e6f94d0 --- /dev/null +++ b/runtime/command_stream/aub_stream_provider.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/aub_mem_dump/aub_mem_dump.h" +#include + +namespace OCLRT { + +class AubStreamProvider { + public: + virtual ~AubStreamProvider() = default; + + virtual AubMemDump::AubFileStream *getStream() = 0; +}; + +class AubFileStreamProvider : public AubStreamProvider { + public: + AubMemDump::AubFileStream *getStream() override { + return &stream; + }; + + protected: + AubMemDump::AubFileStream stream; +}; +} // namespace OCLRT diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 9c7a2617da..de73cd9295 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -6,6 +6,7 @@ */ #include "runtime/execution_environment/execution_environment.h" +#include "runtime/command_stream/aub_stream_provider.h" #include "runtime/command_stream/command_stream_receiver.h" #include "runtime/compiler_interface/compiler_interface.h" #include "runtime/source_level_debugger/source_level_debugger.h" @@ -21,6 +22,11 @@ ExecutionEnvironment::ExecutionEnvironment() = default; ExecutionEnvironment::~ExecutionEnvironment() = default; extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); +void ExecutionEnvironment::initAubStreamProvider() { + if (!aubStreamProvider) { + aubStreamProvider.reset(new AubFileStreamProvider()); + } +} void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) { if (!gmmHelper) { gmmHelper.reset(new GmmHelper(hwInfo)); diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 695eb8fd3b..7fa4eed528 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -13,6 +13,7 @@ #include namespace OCLRT { +class AubStreamProvider; class GmmHelper; class CommandStreamReceiver; class MemoryManager; @@ -34,6 +35,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject ExecutionEnvironment(); ~ExecutionEnvironment() override; + void initAubStreamProvider(); void initGmm(const HardwareInfo *hwInfo); bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex); void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex); @@ -45,6 +47,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject std::unique_ptr osInterface; std::unique_ptr memoryManager; + std::unique_ptr aubStreamProvider; std::vector> commandStreamReceivers; std::unique_ptr builtins; std::unique_ptr compilerInterface; 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 e12ff84a03..6f326029d5 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -98,10 +98,20 @@ struct MockAubCsrToTestDumpAubNonWritable : public AUBCommandStreamReceiverHw lockStream() override { + lockStreamCalled = true; + return AUBCommandStreamReceiver::AubFileStream::lockStream(); + } + uint32_t initCalledCnt = 0; bool flushCalled = false; + bool lockStreamCalled = false; }; struct GmockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { @@ -201,6 +211,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre aubCsr->setMemoryManager(nullptr); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyOperateOnSingleFileStream) { + ExecutionEnvironment executionEnvironment; + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + EXPECT_EQ(aubCsr1->stream, aubCsr2->stream); +} + HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) { DebugManagerStateRestore stateRestore; DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast(AubSubCaptureManager::SubCaptureMode::Filter)); @@ -253,6 +270,81 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFil EXPECT_TRUE(aubCsr->getFileName().empty()); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileWithSpecifiedNameIsReopened) { + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + std::string fileName = "file_name.aub"; + std::string newFileName = "new_file_name.aub"; + + aubCsr->reopenFile(fileName); + EXPECT_TRUE(aubCsr->isFileOpen()); + EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str()); + + aubCsr->reopenFile(newFileName); + EXPECT_TRUE(aubCsr->isFileOpen()); + EXPECT_STREQ(newFileName.c_str(), aubCsr->getFileName().c_str()); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileShouldBeInitializedWithHeaderOnce) { + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + std::string fileName = "file_name.aub"; + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + aubCsr->initFile(fileName); + aubCsr->initFile(fileName); + + EXPECT_EQ(1u, mockAubFileStreamPtr->initCalledCnt); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenOpenFileIsCalledThenFileStreamShouldBeLocked) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + std::string fileName = "file_name.aub"; + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + aubCsr->openFile(fileName); + EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileStreamShouldBeLocked) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + std::string fileName = "file_name.aub"; + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + aubCsr->reopenFile(fileName); + EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + auto engineType = OCLRT::ENGINE_RCS; + ResidencyContainer allocationsForResidency = {}; + + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); + EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); +} + HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentCalledMultipleTimesAffectsResidencyOnce) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); @@ -1375,7 +1467,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPat std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; std::vector comments; @@ -1390,8 +1482,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPat EXPECT_EQ("PatchInfoData\n", comments[0]); EXPECT_EQ("AllocationsList\n", comments[1]); - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) { @@ -1402,7 +1492,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs std::unique_ptr mockAubFileStream(new MockAubFileStream()); MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; @@ -1410,8 +1500,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs aubCsr->flush(batchBuffer, engineType, &allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(mockAubFileStreamPtr->flushCalled); - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenFirstAddCommentsFailsThenFunctionReturnsFalse) { @@ -1424,13 +1512,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenFirst std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(1).WillOnce(Return(false)); bool result = aubCsr->addPatchInfoComments(); EXPECT_FALSE(result); - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSecondAddCommentsFailsThenFunctionReturnsFalse) { @@ -1443,13 +1529,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSecon std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillOnce(Return(true)).WillOnce(Return(false)); bool result = aubCsr->addPatchInfoComments(); EXPECT_FALSE(result); - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatchInfoDataObjectsAddedThenCommentsAreNotEmpty) { @@ -1462,7 +1546,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatch std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; PatchInfoData patchInfoData[2] = {{0xAAAAAAAA, 128u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 256u, PatchInfoAllocationType::Default}, {0xBBBBBBBB, 128u, PatchInfoAllocationType::Default, 0xDDDDDDDD, 256u, PatchInfoAllocationType::Default}}; @@ -1522,8 +1606,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatch EXPECT_TRUE(line.size() > 9); lineNo++; } - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourceAllocationIsNullThenDoNotAddToAllocationsList) { @@ -1536,7 +1618,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourc std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; PatchInfoData patchInfoData = {0x0, 0u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 0u, PatchInfoAllocationType::Default}; EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); @@ -1578,8 +1660,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourc EXPECT_TRUE(line.size() > 9); lineNo++; } - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTargetAllocationIsNullThenDoNotAddToAllocationsList) { @@ -1592,7 +1672,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTarge std::unique_ptr mockAubFileStream(new GmockAubFileStream()); GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); ASSERT_NE(nullptr, mockAubFileStreamPtr); - mockAubFileStream.swap(aubCsr->stream); + aubCsr->stream = mockAubFileStreamPtr; PatchInfoData patchInfoData = {0xAAAAAAAA, 0u, PatchInfoAllocationType::Default, 0x0, 0u, PatchInfoAllocationType::Default}; EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); @@ -1634,8 +1714,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTarge EXPECT_TRUE(line.size() > 9); lineNo++; } - - mockAubFileStream.swap(aubCsr->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForEmptyPatchInfoListThenIndirectPatchCommandBufferIsNotCreated) { diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 04e5ba705b..0479a0ec15 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -6,6 +6,7 @@ */ #include "runtime/built_ins/built_ins.h" +#include "runtime/command_stream/aub_stream_provider.h" #include "runtime/compiler_interface/compiler_interface.h" #include "runtime/device/device.h" #include "runtime/execution_environment/execution_environment.h" @@ -119,13 +120,25 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultip EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0u].get()); } +TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubStreamProviderIsCalledThenItIsInitalizedOnce) { + ExecutionEnvironment executionEnvironment; + executionEnvironment.initAubStreamProvider(); + auto currentAubStreamProvider = executionEnvironment.aubStreamProvider.get(); + EXPECT_NE(nullptr, currentAubStreamProvider); + auto currentAubFileStream = currentAubStreamProvider->getStream(); + EXPECT_NE(nullptr, currentAubFileStream); + executionEnvironment.initAubStreamProvider(); + EXPECT_EQ(currentAubStreamProvider, executionEnvironment.aubStreamProvider.get()); + EXPECT_EQ(currentAubFileStream, executionEnvironment.aubStreamProvider->getStream()); +} + TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) { auto executionEnvironment = std::make_unique(); executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0u); executionEnvironment->initializeMemoryManager(false, false, 0u); EXPECT_NE(nullptr, executionEnvironment->memoryManager); } -static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector>) + sizeof(std::mutex) + (is64bit ? 72 : 40), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); +static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector>) + sizeof(std::mutex) + (is64bit ? 80 : 44), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) { uint32_t destructorId = 0u; @@ -133,15 +146,18 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct MockExecutionEnvironment : ExecutionEnvironment { using ExecutionEnvironment::gmmHelper; }; - struct GmmHelperMock : public DestructorCounted { + struct GmmHelperMock : public DestructorCounted { GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, hwInfo) {} }; - struct OsInterfaceMock : public DestructorCounted { + struct OsInterfaceMock : public DestructorCounted { OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; - struct MemoryMangerMock : public DestructorCounted { + struct MemoryMangerMock : public DestructorCounted { MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; + struct AubFileStreamProviderMock : public DestructorCounted { + AubFileStreamProviderMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} + }; struct CommandStreamReceiverMock : public DestructorCounted { CommandStreamReceiverMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; @@ -159,13 +175,14 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->gmmHelper = std::make_unique(destructorId, platformDevices[0]); executionEnvironment->osInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId); + executionEnvironment->aubStreamProvider = std::make_unique(destructorId); executionEnvironment->commandStreamReceivers.push_back(std::make_unique(destructorId)); executionEnvironment->builtins = std::make_unique(destructorId); executionEnvironment->compilerInterface = std::make_unique(destructorId); executionEnvironment->sourceLevelDebugger = std::make_unique(destructorId); executionEnvironment.reset(nullptr); - EXPECT_EQ(7u, destructorId); + EXPECT_EQ(8u, destructorId); } TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) {