AUB CSR with a separate function to write memory

Move common code related to writing memory to dedicated function

Change-Id: I4ac8ec779cb40146bd27b8e40728d81d3b5b4276
This commit is contained in:
Milczarek, Slawomir
2018-11-26 18:17:57 -08:00
parent cc414b0530
commit 3b8ff44d55
9 changed files with 57 additions and 28 deletions

View File

@@ -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()

View File

@@ -116,6 +116,11 @@ if(${GENERATE_EXECUTABLE})
$<TARGET_OBJECTS:${BUILTINS_BINARIES_LIB_NAME}>
$<TARGET_OBJECTS:${SCHEDULER_BINARY_LIB_NAME}>
)
if(DEFINED AUB_STREAM_DIR)
list(APPEND NEO_DYNAMIC_LIB__TARGET_OBJECTS $<TARGET_OBJECTS:${AUB_STREAM_ENABLE_LIB_NAME}>)
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)

View File

@@ -36,6 +36,10 @@ class AubCenter {
return streamProvider.get();
}
AubDump::AubManager *getAubManager() const {
return aubManager.get();
}
protected:
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
std::unique_ptr<AddressMapper> addressMapper;

View File

@@ -43,6 +43,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
return static_cast<AubMemDump::AubFileStream *>(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);

View File

@@ -608,6 +608,24 @@ void AUBCommandStreamReceiverHw<GfxFamily>::makeNonResidentExternal(uint64_t gpu
}
}
template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::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<GfxFamily> aubHelperHw(this->localMemoryEnabled);
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, entryBits,
aubHelperHw);
};
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, entryBits, walker, memoryBank);
}
template <typename GfxFamily>
bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxAllocation) {
auto cpuAddress = ptrOffset(gfxAllocation.getUnderlyingBuffer(), static_cast<size_t>(gfxAllocation.allocationOffset));
@@ -625,20 +643,8 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::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<GfxFamily> aubHelperHw(this->localMemoryEnabled);
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, getPPGTTAdditionalBits(&gfxAllocation),
aubHelperHw);
};
ppgtt->pageWalk(static_cast<uintptr_t>(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);

View File

@@ -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
$<TARGET_OBJECTS:${BUILTINS_SOURCES_LIB_NAME}>
$<TARGET_OBJECTS:${SCHEDULER_BINARY_LIB_NAME}>
@@ -17,6 +17,14 @@ add_executable(igdrcl_aub_tests
$<TARGET_OBJECTS:igdrcl_libult_env>
)
if(DEFINED AUB_STREAM_DIR)
list(APPEND IGDRCL_AUB_TESTS__TARGET_OBJECTS $<TARGET_OBJECTS:${AUB_STREAM_ENABLE_LIB_NAME}>)
endif()
add_executable(igdrcl_aub_tests
${IGDRCL_AUB_TESTS__TARGET_OBJECTS}
)
set_target_properties(igdrcl_aub_tests PROPERTIES FOLDER ${TEST_PROJECTS_FOLDER})
if(WIN32)

View File

@@ -118,8 +118,8 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenF
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallSubmitBatchBuffer) {
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(false, true, false);
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedFunctions) {
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
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<MockAubCsr<FamilyType>>(false, true, false);
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
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);
}

View File

@@ -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, "");

View File

@@ -71,15 +71,21 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
void initProgrammingFlags() override {
initProgrammingFlagsCalled = true;
}
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) {
AUBCommandStreamReceiverHw<GfxFamily>::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<GfxFamily>::submitBatchBuffer(engineIndex, batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits);
submitBatchBufferCalled = true;
}
void pollForCompletion(EngineInstanceT engineInstance) override {
AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletion(engineInstance);
pollForCompletionCalled = true;
}
bool flushBatchedSubmissionsCalled = false;
bool initProgrammingFlagsCalled = false;
bool writeMemoryCalled = false;
bool submitBatchBufferCalled = false;
bool pollForCompletionCalled = false;