From 3b8ff44d5548908a0df8a613547e808fd2f8a691 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Mon, 26 Nov 2018 18:17:57 -0800 Subject: [PATCH] AUB CSR with a separate function to write memory Move common code related to writing memory to dedicated function Change-Id: I4ac8ec779cb40146bd27b8e40728d81d3b5b4276 --- CMakeLists.txt | 1 + runtime/CMakeLists.txt | 6 ++++ runtime/aub/aub_center.h | 4 +++ .../aub_command_stream_receiver_hw.h | 1 + .../aub_command_stream_receiver_hw.inl | 32 +++++++++++-------- unit_tests/aub_tests/CMakeLists.txt | 10 +++++- .../command_stream/aub_file_stream_tests.cpp | 18 +++-------- .../execution_environment_tests.cpp | 7 ++++ unit_tests/mocks/mock_aub_csr.h | 6 ++++ 9 files changed, 57 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7549bb274..74f29e5df9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -409,6 +409,7 @@ endif() add_subdirectory(third_party/gtest) if(DEFINED AUB_STREAM_DIR) + set(AUB_STREAM_ENABLE_LIB_NAME "aub_mem_dump_enable") add_subdirectory(${AUB_STREAM_DIR} ${CMAKE_BINARY_DIR}/aub_stream) endif() diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 783c9d000b..70ae8aeb83 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -116,6 +116,11 @@ if(${GENERATE_EXECUTABLE}) $ $ ) + + if(DEFINED AUB_STREAM_DIR) + list(APPEND NEO_DYNAMIC_LIB__TARGET_OBJECTS $) + endif() + add_library(${NEO_DYNAMIC_LIB_NAME} SHARED ${NEO_DYNAMIC_LIB__TARGET_OBJECTS} ) @@ -141,6 +146,7 @@ if(${GENERATE_EXECUTABLE}) target_include_directories(${NEO_DYNAMIC_LIB_NAME} BEFORE PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${INSTRUMENTATION_INCLUDE_PATH} + ${AUB_STREAM_DIR}/.. ) if(WIN32) diff --git a/runtime/aub/aub_center.h b/runtime/aub/aub_center.h index 945a24c7f6..59e34cf51c 100644 --- a/runtime/aub/aub_center.h +++ b/runtime/aub/aub_center.h @@ -36,6 +36,10 @@ class AubCenter { return streamProvider.get(); } + AubDump::AubManager *getAubManager() const { + return aubManager.get(); + } + protected: std::unique_ptr physicalAddressAllocator; std::unique_ptr addressMapper; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 9fd9744b9a..45dd3ff87b 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -43,6 +43,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw(this->stream); } + MOCKABLE_VIRTUAL void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield); MOCKABLE_VIRTUAL bool writeMemory(GraphicsAllocation &gfxAllocation); MOCKABLE_VIRTUAL bool writeMemory(AllocationView &allocationView); void expectMMIO(uint32_t mmioRegister, uint32_t expectedValue); diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 1848a24a69..f753d75de3 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -608,6 +608,24 @@ void AUBCommandStreamReceiverHw::makeNonResidentExternal(uint64_t gpu } } +template +void AUBCommandStreamReceiverHw::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) { + { + std::ostringstream str; + str << "ppgtt: " << std::hex << std::showbase << gpuAddress << " end address: " << gpuAddress + size << " cpu address: " << cpuAddress << " device mask: " << devicesBitfield << " size: " << std::dec << size; + getAubStream()->addComment(str.str().c_str()); + } + + AubHelperHw aubHelperHw(this->localMemoryEnabled); + + PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { + AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast(gpuAddress), cpuAddress, physAddress, size, offset, entryBits, + aubHelperHw); + }; + + ppgtt->pageWalk(static_cast(gpuAddress), size, 0, entryBits, walker, memoryBank); +} + template bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxAllocation) { auto cpuAddress = ptrOffset(gfxAllocation.getUnderlyingBuffer(), static_cast(gfxAllocation.allocationOffset)); @@ -625,20 +643,8 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA cpuAddress = this->getMemoryManager()->lockResource(&gfxAllocation); gfxAllocation.setLocked(true); } - { - std::ostringstream str; - str << "ppgtt: " << std::hex << std::showbase << gpuAddress << " end address: " << gpuAddress + size << " cpu address: " << cpuAddress << " device mask: " << gfxAllocation.devicesBitfield << " size: " << std::dec << size; - getAubStream()->addComment(str.str().c_str()); - } - AubHelperHw aubHelperHw(this->localMemoryEnabled); - - PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { - AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast(gpuAddress), cpuAddress, physAddress, size, offset, getPPGTTAdditionalBits(&gfxAllocation), - aubHelperHw); - }; - - ppgtt->pageWalk(static_cast(gpuAddress), size, 0, getPPGTTAdditionalBits(&gfxAllocation), walker, this->getMemoryBank(&gfxAllocation)); + writeMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), getPPGTTAdditionalBits(&gfxAllocation), gfxAllocation.devicesBitfield); if (gfxAllocation.isLocked()) { this->getMemoryManager()->unlockResource(&gfxAllocation); diff --git a/unit_tests/aub_tests/CMakeLists.txt b/unit_tests/aub_tests/CMakeLists.txt index f7950a272b..f185110ee5 100644 --- a/unit_tests/aub_tests/CMakeLists.txt +++ b/unit_tests/aub_tests/CMakeLists.txt @@ -8,7 +8,7 @@ project(igdrcl_aub_tests) include(${CMAKE_CURRENT_SOURCE_DIR}/common.cmake) -add_executable(igdrcl_aub_tests +list(APPEND IGDRCL_AUB_TESTS__TARGET_OBJECTS ${CMAKE_CURRENT_SOURCE_DIR}/aub_tests_configuration.cpp $ $ @@ -17,6 +17,14 @@ add_executable(igdrcl_aub_tests $ ) +if(DEFINED AUB_STREAM_DIR) + list(APPEND IGDRCL_AUB_TESTS__TARGET_OBJECTS $) +endif() + +add_executable(igdrcl_aub_tests + ${IGDRCL_AUB_TESTS__TARGET_OBJECTS} +) + set_target_properties(igdrcl_aub_tests PROPERTIES FOLDER ${TEST_PROJECTS_FOLDER}) if(WIN32) diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index a214d241cd..cb7828896e 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -118,8 +118,8 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenF EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); } -HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallSubmitBatchBuffer) { - auto aubExecutionEnvironment = getEnvironment>(false, true, false); +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedFunctions) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -128,19 +128,9 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenI ResidencyContainer allocationsForResidency = {}; aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); + + EXPECT_TRUE(aubCsr->writeMemoryCalled); EXPECT_TRUE(aubCsr->submitBatchBufferCalled); -} - -HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallPollForCompletion) { - auto aubExecutionEnvironment = getEnvironment>(false, true, false); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto engineType = OCLRT::ENGINE_RCS; - ResidencyContainer allocationsForResidency = {}; - - aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); EXPECT_TRUE(aubCsr->pollForCompletionCalled); } diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index f70838e8f6..af44ac7d61 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -132,6 +132,13 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCal EXPECT_STREQ(executionEnvironment.aubFileNameReceived.c_str(), "test.aub"); } +TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenGetAubManagerIsCalledThenReturnNull) { + ExecutionEnvironment executionEnvironment; + executionEnvironment.initAubCenter(platformDevices[0], false, ""); + auto aubManager = executionEnvironment.aubCenter->getAubManager(); + EXPECT_EQ(nullptr, aubManager); +} + TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) { ExecutionEnvironment executionEnvironment; executionEnvironment.initAubCenter(platformDevices[0], false, ""); diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index 39ff69741f..54cf66511c 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -71,15 +71,21 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { void initProgrammingFlags() override { initProgrammingFlagsCalled = true; } + void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) { + AUBCommandStreamReceiverHw::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits, devicesBitfield); + writeMemoryCalled = true; + } void submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override { AUBCommandStreamReceiverHw::submitBatchBuffer(engineIndex, batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits); submitBatchBufferCalled = true; } void pollForCompletion(EngineInstanceT engineInstance) override { + AUBCommandStreamReceiverHw::pollForCompletion(engineInstance); pollForCompletionCalled = true; } bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; + bool writeMemoryCalled = false; bool submitBatchBufferCalled = false; bool pollForCompletionCalled = false;