diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 5138ce6896..03fe3fc2a5 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -56,6 +56,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::initFile(const std::string &fileName if (!aubManager->isOpen()) { aubManager->open(fileName); UNRECOVERABLE_IF(!aubManager->isOpen()); + + std::ostringstream str; + str << "driver version: " << driverVersion; + aubManager->addComment(str.str().c_str()); } return; } @@ -167,11 +172,6 @@ void AUBCommandStreamReceiverHw::initializeEngine() { // Write driver version { -#define QTR(a) #a -#define TOSTR(b) QTR(b) - const std::string driverVersion = TOSTR(NEO_DRIVER_VERSION); -#undef QTR -#undef TOSTR std::ostringstream str; str << "driver version: " << driverVersion; getAubStream()->addComment(str.str().c_str()); @@ -773,6 +773,15 @@ void AUBCommandStreamReceiverHw::activateAubSubCapture(const MultiDis } } +template +void AUBCommandStreamReceiverHw::addAubComment(const char *message) { + if (aubManager) { + aubManager->addComment(message); + return; + } + getAubStream()->addComment(message); +} + template uint32_t AUBCommandStreamReceiverHw::getDumpHandle() { return hashPtrToU32(this); diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 3d2c725416..b66bf4c267 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -245,6 +245,8 @@ ResidencyContainer &CommandStreamReceiver::getEvictionAllocations() { void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {} +void CommandStreamReceiver::addAubComment(const char *comment) {} + GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { UNRECOVERABLE_IF(debugSurface != nullptr); debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::UNDECIDED}); diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 9cbfead3ec..b597fbe19f 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -136,6 +136,7 @@ class CommandStreamReceiver { MOCKABLE_VIRTUAL void initProgrammingFlags(); virtual void activateAubSubCapture(const MultiDispatchInfo &dispatchInfo); + virtual void addAubComment(const char *comment); IndirectHeap &getIndirectHeap(IndirectHeap::Type heapType, size_t minRequiredSize); void allocateHeapMemory(IndirectHeap::Type heapType, size_t minRequiredSize, IndirectHeap *&indirectHeap); diff --git a/runtime/helpers/neo_driver_version.h b/runtime/helpers/neo_driver_version.h new file mode 100644 index 0000000000..55e34ced48 --- /dev/null +++ b/runtime/helpers/neo_driver_version.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "driver_version.h" + +#ifdef QTR +#undef QTR +#endif + +#ifdef TOSTR +#undef TOSTR +#endif + +#define QTR(a) #a +#define TOSTR(b) QTR(b) + +namespace NEO { +constexpr const char *driverVersion = TOSTR(NEO_DRIVER_VERSION); +} + +#undef QTR +#undef TOSTR diff --git a/third_party/aub_stream/headers/aub_manager.h b/third_party/aub_stream/headers/aub_manager.h index 17b5158664..6f73aa4e1a 100644 --- a/third_party/aub_stream/headers/aub_manager.h +++ b/third_party/aub_stream/headers/aub_manager.h @@ -24,6 +24,7 @@ class AubManager { virtual bool isOpen() = 0; virtual const std::string getFileName() = 0; + virtual void addComment(const char *message) = 0; virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize) = 0; static AubManager *create(uint32_t productFamily, uint32_t devicesCount, uint64_t memoryBankSize, bool localMemorySupported, uint32_t streamMode); diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index c325ce6e9f..c1ef045a97 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -8,6 +8,7 @@ #include "runtime/aub_mem_dump/page_table_entry_bits.h" #include "runtime/command_stream/aub_command_stream_receiver_hw.h" #include "runtime/helpers/hardware_context_controller.h" +#include "runtime/helpers/neo_driver_version.h" #include "runtime/os_interface/os_context.h" #include "test.h" #include "unit_tests/fixtures/aub_command_stream_receiver_fixture.h" @@ -201,6 +202,35 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenI EXPECT_FALSE(aubCsr->pollForCompletionCalled); } +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenCallingAddAubCommentThenCallAddCommentOnAubFileStream) { + auto aubFileStream = std::make_unique(); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + aubCsr->stream = aubFileStream.get(); + + const char *comment = "message"; + aubCsr->addAubComment(comment); + + EXPECT_TRUE(aubCsr->addAubCommentCalled); + EXPECT_TRUE(aubFileStream->addCommentCalled); + EXPECT_STREQ(comment, aubFileStream->receivedComment.c_str()); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithAubManagerWhenCallingAddAubCommentThenCallAddCommentOnAubManager) { + MockAubCsr aubCsr("", true, *pDevice->executionEnvironment); + MockOsContext osContext(0, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false); + aubCsr.setupContext(osContext); + auto mockAubManager = static_cast(aubCsr.aubManager); + ASSERT_NE(nullptr, mockAubManager); + + const char *comment = "message"; + aubCsr.addAubComment(comment); + + EXPECT_TRUE(aubCsr.addAubCommentCalled); + EXPECT_TRUE(mockAubManager->addCommentCalled); + EXPECT_STREQ(comment, mockAubManager->receivedComment.c_str()); +} + HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenCallingInsertAubWaitInstructionThenCallPollForCompletion) { auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); @@ -613,16 +643,24 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitializeEngineIs })); aubCsr->initializeEngine(); -#define QTR(a) #a -#define TOSTR(b) QTR(b) - const std::string expectedVersion = TOSTR(NEO_DRIVER_VERSION); -#undef QTR -#undef TOSTR - - std::string commentWithDriverVersion = "driver version: " + expectedVersion; + std::string commentWithDriverVersion = "driver version: " + std::string(driverVersion); EXPECT_EQ(commentWithDriverVersion, comments[0]); } +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithAubManagerWhenInitFileIsCalledThenMemTraceCommentWithDriverVersionIsPutIntoAubStream) { + auto mockAubManager = std::make_unique(); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + + aubCsr->aubManager = mockAubManager.get(); + + std::string fileName = "file_name.aub"; + aubCsr->initFile(fileName); + + std::string commentWithDriverVersion = "driver version: " + std::string(driverVersion); + EXPECT_EQ(mockAubManager->receivedComment, commentWithDriverVersion); +} + HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenNoPatchInfoDataObjectsThenCommentsAreEmpty) { auto mockAubFileStream = std::make_unique(); auto aubExecutionEnvironment = getEnvironment>(false, true, true); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 4f47abfa57..b537134df6 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -325,6 +325,12 @@ HWTEST_F(CommandStreamReceiverTest, givenTimestampPacketAllocatorWhenAskingForTa EXPECT_NE(node1, node2); } +HWTEST_F(CommandStreamReceiverTest, givenUltCommandStreamReceiverWhenAddAubCommentIsCalledThenCallAddAubCommentOnCsr) { + auto &csr = pDevice->getUltCommandStreamReceiver(); + csr.addAubComment("message"); + EXPECT_TRUE(csr.addAubCommentCalled); +} + TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllocationIsCalledThenCorrectAllocationIsReturned) { ExecutionEnvironment executionEnvironment; MockCommandStreamReceiver csr(executionEnvironment); diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index ee6e236a2b..57e4274070 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -123,6 +123,10 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ CommandStreamReceiverHw::activateAubSubCapture(dispatchInfo); activateAubSubCaptureCalled = true; } + void addAubComment(const char *message) override { + CommandStreamReceiverHw::addAubComment(message); + addAubCommentCalled = true; + } void flushBatchedSubmissions() override { CommandStreamReceiverHw::flushBatchedSubmissions(); flushBatchedSubmissionsCalled = true; @@ -140,6 +144,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ std::atomic recursiveLockCounter; bool createPageTableManagerCalled = false; bool activateAubSubCaptureCalled = false; + bool addAubCommentCalled = false; bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; LinearStream *lastFlushedCommandStream = nullptr; diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index bbd143d766..3ea74fcb4c 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -114,6 +114,10 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait) { return true; } + void addAubComment(const char *message) { + AUBCommandStreamReceiverHw::addAubComment(message); + addAubCommentCalled = true; + } bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; bool initializeEngineCalled = false; @@ -123,6 +127,7 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { bool pollForCompletionCalled = false; bool expectMemoryEqualCalled = false; bool expectMemoryNotEqualCalled = false; + bool addAubCommentCalled = false; void initFile(const std::string &fileName) override { fileIsOpen = true; diff --git a/unit_tests/mocks/mock_aub_file_stream.h b/unit_tests/mocks/mock_aub_file_stream.h index 6ef6d39c8b..941c48bf1c 100644 --- a/unit_tests/mocks/mock_aub_file_stream.h +++ b/unit_tests/mocks/mock_aub_file_stream.h @@ -57,6 +57,11 @@ struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { addressSpaceCapturedFromExpectMemory = addressSpace; compareOperationFromExpectMemory = compareOperation; } + bool addComment(const char *message) override { + receivedComment.assign(message); + addCommentCalled = true; + return true; + } void registerPoll(uint32_t registerOffset, uint32_t mask, uint32_t value, bool pollNotEqual, uint32_t timeoutAction) override { registerPollCalled = true; AUBCommandStreamReceiver::AubFileStream::registerPoll(registerOffset, mask, value, pollNotEqual, timeoutAction); @@ -68,6 +73,8 @@ struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { mutable bool isOpenCalled = false; mutable bool getFileNameCalled = false; bool registerPollCalled = false; + bool addCommentCalled = false; + std::string receivedComment = ""; bool flushCalled = false; bool lockStreamCalled = false; uint32_t mmioRegisterFromExpectMMIO = 0; diff --git a/unit_tests/mocks/mock_aub_manager.h b/unit_tests/mocks/mock_aub_manager.h index da8a919987..9cef2c2baf 100644 --- a/unit_tests/mocks/mock_aub_manager.h +++ b/unit_tests/mocks/mock_aub_manager.h @@ -74,6 +74,11 @@ class MockAubManager : public aub_stream::AubManager { return fileName; } + void addComment(const char *message) override { + receivedComment.assign(message); + addCommentCalled = true; + } + void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 65536) override { writeMemoryCalled = true; } @@ -83,6 +88,8 @@ class MockAubManager : public aub_stream::AubManager { bool closeCalled = false; bool isOpenCalled = false; bool getFileNameCalled = false; + bool addCommentCalled = false; + std::string receivedComment = ""; bool writeMemoryCalled = false; uint32_t contextFlags = 0;