From fcb9a591b0b9ced5d7bfe9583533ba4b1f1ab8af Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Mon, 5 Mar 2018 22:16:21 +0100 Subject: [PATCH] Add AUB generation in parallel to execution on TBX This commit adds support for AUB capturing with simultaneous execution on TBX Change-Id: I046bac6b953708007c525050fbf9357120a310b6 --- Jenkinsfile | 2 +- runtime/aub_mem_dump/aub_mem_dump.h | 1 + runtime/aub_mem_dump/aub_mem_dump.inl | 13 ++ .../aub_command_stream_receiver_hw.inl | 9 +- .../command_stream_receiver_with_aub_dump.inl | 1 - .../create_command_stream_impl.cpp | 10 +- .../tbx_command_stream_receiver.cpp | 6 +- .../tbx_command_stream_receiver.h | 6 +- .../tbx_command_stream_receiver_hw.h | 8 +- .../tbx_command_stream_receiver_hw.inl | 54 ++++--- runtime/gen8/tbx_command_stream_receiver.cpp | 4 +- runtime/gen9/tbx_command_stream_receiver.cpp | 4 +- runtime/helpers/options.h | 4 +- .../create_command_stream_receiver_tests.cpp | 1 + .../command_stream/get_devices_tests.cpp | 2 + .../tbx_command_stream_fixture.cpp | 4 +- .../tbx_command_stream_tests.cpp | 145 ++++++++++++++++-- 17 files changed, 216 insertions(+), 58 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7a915a2cc0..37b558e0e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy neoDependenciesRev='741938-782' strategy='EQUAL' -allowedF=41 +allowedF=40 allowedCD=337 diff --git a/runtime/aub_mem_dump/aub_mem_dump.h b/runtime/aub_mem_dump/aub_mem_dump.h index 5ae79d3cb1..e21c5931d6 100644 --- a/runtime/aub_mem_dump/aub_mem_dump.h +++ b/runtime/aub_mem_dump/aub_mem_dump.h @@ -283,6 +283,7 @@ struct AubDump : public TypeSelector, AubPageTabl static void addMemoryWrite(Stream &stream, uint64_t addr, const void *memory, size_t blockSize, int addressSpace, int hint = DataTypeHintValues::TraceNotype); static uint64_t reserveAddressGGTT(Stream &stream, uint32_t addr, size_t size, uint64_t physStart); static uint64_t reserveAddressGGTT(Stream &stream, const void *memory, size_t size, uint64_t physStart); + static void reserveAddressGGTTAndWriteMmeory(Stream &stream, uintptr_t gfxAddress, const void *memory, uint64_t physAddress, size_t size, size_t offset); private: static uint64_t reserveAddress(Stream &stream, uint32_t addr, size_t size, unsigned int addressSpace /* = AddressSpaceValues::TraceGttEntry*/, uint64_t physStart); diff --git a/runtime/aub_mem_dump/aub_mem_dump.inl b/runtime/aub_mem_dump/aub_mem_dump.inl index 1ff8e3dd32..90b5925878 100644 --- a/runtime/aub_mem_dump/aub_mem_dump.inl +++ b/runtime/aub_mem_dump/aub_mem_dump.inl @@ -24,6 +24,7 @@ #include "aub_mem_dump.h" #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/ptr_math.h" +#include "runtime/memory_manager/memory_constants.h" #include #include @@ -128,6 +129,18 @@ uint64_t AubDump::reserveAddressGGTT(typename Traits::Stream &stream, co return AubDump::reserveAddress(stream, gfxAddress, size, AddressSpaceValues::TraceGttEntry, physStart); } +template +void AubDump::reserveAddressGGTTAndWriteMmeory(typename Traits::Stream &stream, uintptr_t gfxAddress, const void *memory, uint64_t physAddress, size_t size, size_t offset) { + auto vmAddr = (gfxAddress + offset) & ~(MemoryConstants::pageSize - 1); + auto pAddr = physAddress & ~(MemoryConstants::pageSize - 1); + + AubDump::reserveAddressPPGTT(stream, vmAddr, MemoryConstants::pageSize, pAddr); + + AubDump::addMemoryWrite(stream, physAddress, + reinterpret_cast(reinterpret_cast(memory) + offset), + size, AubMemDump::AddressSpaceValues::TraceNonlocal); +} + template uint64_t AubPageTableHelper32::reserveAddressPPGTT(typename Traits::Stream &stream, uintptr_t gfxAddress, size_t blockSize, uint64_t physAddress) { auto startAddress = gfxAddress; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index b819e9a20b..9edc183921 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -456,14 +456,7 @@ bool AUBCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxA } PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) { - static const size_t pageSize = 4096; - auto vmAddr = (static_cast(gpuAddress) + offset) & ~(pageSize - 1); - auto pAddr = physAddress & ~(pageSize - 1); - - AUB::reserveAddressPPGTT(stream, vmAddr, pageSize, pAddr); - AUB::addMemoryWrite(stream, physAddress, - reinterpret_cast(reinterpret_cast(cpuAddress) + offset), - size, AubMemDump::AddressSpaceValues::TraceNonlocal); + AUB::reserveAddressGGTTAndWriteMmeory(stream, static_cast(gpuAddress), cpuAddress, physAddress, size, offset); }; ppgtt.pageWalk(static_cast(gpuAddress), size, 0, walker); diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl index 72113db08b..6ab4aca1d0 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl @@ -22,7 +22,6 @@ #include "runtime/command_stream/command_stream_receiver_with_aub_dump.h" #include "runtime/command_stream/aub_command_stream_receiver.h" -#include "runtime/command_stream/tbx_command_stream_receiver.h" namespace OCLRT { diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index 76b2002087..50e0f320fa 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -53,11 +53,18 @@ CommandStreamReceiver *createCommandStreamImpl(const HardwareInfo *pHwInfo) { pHwInfo->pSkuTable, pHwInfo->pWaTable, pHwInfo->pSysInfo); - commandStreamReceiver = TbxCommandStreamReceiver::create(*pHwInfo); + commandStreamReceiver = TbxCommandStreamReceiver::create(*pHwInfo, false); break; case CSR_HW_WITH_AUB: commandStreamReceiver = funcCreate(*pHwInfo, true); break; + case CSR_TBX_WITH_AUB: + Gmm::initContext(pHwInfo->pPlatform, + pHwInfo->pSkuTable, + pHwInfo->pWaTable, + pHwInfo->pSysInfo); + commandStreamReceiver = TbxCommandStreamReceiver::create(*pHwInfo, true); + break; default: break; } @@ -74,6 +81,7 @@ bool getDevicesImpl(HardwareInfo **hwInfo, size_t &numDevicesReturned) { switch (csr) { case CSR_AUB: case CSR_TBX: { + case CSR_TBX_WITH_AUB: auto productFamily = DebugManager.flags.ProductFamilyOverride.get(); auto hwInfoConst = *platformDevices; for (int j = 0; j < IGFX_MAX_PRODUCT; j++) { diff --git a/runtime/command_stream/tbx_command_stream_receiver.cpp b/runtime/command_stream/tbx_command_stream_receiver.cpp index c67bf390aa..09c38d67ad 100644 --- a/runtime/command_stream/tbx_command_stream_receiver.cpp +++ b/runtime/command_stream/tbx_command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,7 +29,7 @@ namespace OCLRT { TbxCommandStreamReceiverCreateFunc tbxCommandStreamReceiverFactory[IGFX_MAX_CORE] = {}; -CommandStreamReceiver *TbxCommandStreamReceiver::create(const HardwareInfo &hwInfo) { +CommandStreamReceiver *TbxCommandStreamReceiver::create(const HardwareInfo &hwInfo, bool withAubDump) { if (hwInfo.pPlatform->eRenderCoreFamily >= IGFX_MAX_CORE) { DEBUG_BREAK_IF(!false); @@ -38,6 +38,6 @@ CommandStreamReceiver *TbxCommandStreamReceiver::create(const HardwareInfo &hwIn auto pCreate = tbxCommandStreamReceiverFactory[hwInfo.pPlatform->eRenderCoreFamily]; - return pCreate ? pCreate(hwInfo) : nullptr; + return pCreate ? pCreate(hwInfo, withAubDump) : nullptr; } } diff --git a/runtime/command_stream/tbx_command_stream_receiver.h b/runtime/command_stream/tbx_command_stream_receiver.h index 57c179bc15..4ed51d8e72 100644 --- a/runtime/command_stream/tbx_command_stream_receiver.h +++ b/runtime/command_stream/tbx_command_stream_receiver.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -58,10 +58,10 @@ class TbxStream : public AubMemDump::AubStream { }; struct TbxCommandStreamReceiver { - static CommandStreamReceiver *create(const HardwareInfo &hwInfo); + static CommandStreamReceiver *create(const HardwareInfo &hwInfo, bool withAubDump); using TbxStream = OCLRT::TbxStream; }; -typedef CommandStreamReceiver *(*TbxCommandStreamReceiverCreateFunc)(const HardwareInfo &hwInfoIn); +typedef CommandStreamReceiver *(*TbxCommandStreamReceiverCreateFunc)(const HardwareInfo &hwInfoIn, bool withAubDump); } // namespace OCLRT diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index 432629fd76..99c9128f10 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -46,18 +46,20 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverHw { public: FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override; - void makeResident(GraphicsAllocation &gfxAllocation) override; void makeCoherent(void *address, size_t length) override; + void processResidency(ResidencyContainer *allocationsForResidency) override; + bool writeMemory(GraphicsAllocation &gfxAllocation); + // Family specific version void submitLRCA(EngineType engineType, const MiContextDescriptorReg &contextDescriptor); void pollForCompletion(EngineType engineType); void initGlobalMMIO(); void initEngineMMIO(EngineType engineType); - static CommandStreamReceiver *create(const HardwareInfo &hwInfoIn); + static CommandStreamReceiver *create(const HardwareInfo &hwInfoIn, bool withAubDump); - TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn); + TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, void *ptr); ~TbxCommandStreamReceiverHw() override; void initializeEngine(EngineType engineType); diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index 602b56a05f..00514ba441 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -25,12 +25,13 @@ #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/ptr_math.h" #include "runtime/memory_manager/graphics_allocation.h" +#include "runtime/command_stream/command_stream_receiver_with_aub_dump.h" #include namespace OCLRT { template -TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn) +TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, void *ptr) : BaseClass(hwInfoIn) { for (auto &engineInfo : engineInfoTable) { engineInfo.pLRCA = nullptr; @@ -156,8 +157,13 @@ void TbxCommandStreamReceiverHw::initializeEngine(EngineType engineTy } template -CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const HardwareInfo &hwInfoIn) { - auto csr = new TbxCommandStreamReceiverHw(hwInfoIn); +CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const HardwareInfo &hwInfoIn, bool withAubDump) { + TbxCommandStreamReceiverHw *csr; + if (withAubDump) { + csr = new CommandStreamReceiverWithAUBDump>(hwInfoIn); + } else { + csr = new TbxCommandStreamReceiverHw(hwInfoIn, nullptr); + } // Open our stream csr->stream.open(nullptr); @@ -196,6 +202,9 @@ FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer AubMemDump::DataTypeHintValues::TraceBatchBufferPrimary); } + // Write allocations for residency + processResidency(allocationsForResidency); + // Add a batch buffer start to the RCS auto previousTail = engineInfo.tailRCS; { @@ -323,31 +332,32 @@ void TbxCommandStreamReceiverHw::pollForCompletion(EngineType engineT } template -void TbxCommandStreamReceiverHw::makeResident(GraphicsAllocation &gfxAllocation) { - if (gfxAllocation.residencyTaskCount < (int)this->taskCount) { - auto cpuAddress = gfxAllocation.getUnderlyingBuffer(); - auto gpuAddress = gfxAllocation.getGpuAddress(); - auto size = gfxAllocation.getUnderlyingBufferSize(); +bool TbxCommandStreamReceiverHw::writeMemory(GraphicsAllocation &gfxAllocation) { + auto cpuAddress = gfxAllocation.getUnderlyingBuffer(); + auto gpuAddress = gfxAllocation.getGpuAddress(); + auto size = gfxAllocation.getUnderlyingBufferSize(); - if ((size == 0) || !!(gfxAllocation.getAllocationType() & GraphicsAllocation::ALLOCATION_TYPE_NON_AUB_WRITABLE)) - return; + if (size == 0) + return false; - PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) { - static const size_t pageSize = 4096; - auto vmAddr = (static_cast(gpuAddress) + offset) & ~(pageSize - 1); - auto pAddr = physAddress & ~(pageSize - 1); + PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) { + AUB::reserveAddressGGTTAndWriteMmeory(stream, static_cast(gpuAddress), cpuAddress, physAddress, size, offset); + }; + ppgtt.pageWalk(static_cast(gpuAddress), size, 0, walker); - AUB::reserveAddressPPGTT(stream, vmAddr, pageSize, pAddr); + return true; +} - AUB::addMemoryWrite(stream, physAddress, - reinterpret_cast(reinterpret_cast(cpuAddress) + offset), - size, AubMemDump::AddressSpaceValues::TraceNonlocal); - }; - ppgtt.pageWalk(static_cast(gpuAddress), size, 0, walker); +template +void TbxCommandStreamReceiverHw::processResidency(ResidencyContainer *allocationsForResidency) { + auto &residencyAllocations = allocationsForResidency ? *allocationsForResidency : this->getMemoryManager()->getResidencyAllocations(); - this->getMemoryManager()->pushAllocationForResidency(&gfxAllocation); + for (auto &gfxAllocation : residencyAllocations) { + if (!writeMemory(*gfxAllocation)) { + DEBUG_BREAK_IF(!(gfxAllocation->getUnderlyingBufferSize() == 0)); + } + gfxAllocation->residencyTaskCount = this->taskCount + 1; } - gfxAllocation.residencyTaskCount = (int)this->taskCount; } template diff --git a/runtime/gen8/tbx_command_stream_receiver.cpp b/runtime/gen8/tbx_command_stream_receiver.cpp index 540c5b2bf2..59b33d1078 100644 --- a/runtime/gen8/tbx_command_stream_receiver.cpp +++ b/runtime/gen8/tbx_command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,7 @@ #include "hw_cmds.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.inl" +#include "runtime/command_stream/command_stream_receiver_with_aub_dump.inl" #include "runtime/helpers/base_object.h" #include "runtime/helpers/array_count.h" @@ -39,4 +40,5 @@ void populateFactoryTable>() { } template class TbxCommandStreamReceiverHw; +template class CommandStreamReceiverWithAUBDump>; } diff --git a/runtime/gen9/tbx_command_stream_receiver.cpp b/runtime/gen9/tbx_command_stream_receiver.cpp index 120d26ad60..55ed83f310 100644 --- a/runtime/gen9/tbx_command_stream_receiver.cpp +++ b/runtime/gen9/tbx_command_stream_receiver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,7 @@ #include "hw_cmds.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.inl" +#include "runtime/command_stream/command_stream_receiver_with_aub_dump.inl" #include "runtime/helpers/base_object.h" #include "runtime/helpers/array_count.h" @@ -39,4 +40,5 @@ void populateFactoryTable>() { } template class TbxCommandStreamReceiverHw; +template class CommandStreamReceiverWithAUBDump>; } diff --git a/runtime/helpers/options.h b/runtime/helpers/options.h index 708f0d4eb6..a6c8db1802 100644 --- a/runtime/helpers/options.h +++ b/runtime/helpers/options.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -39,6 +39,8 @@ enum CommandStreamReceiverType { CSR_TBX, // Use receiver for real HW and capture AUB file CSR_HW_WITH_AUB, + // Use TBX server and capture AUB file + CSR_TBX_WITH_AUB, // Number of CSR types CSR_TYPES_NUM }; diff --git a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp index 5ecf8817f0..2e6b27ac98 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -69,6 +69,7 @@ static CommandStreamReceiverType commandStreamReceiverTypes[] = { CSR_AUB, CSR_TBX, CSR_HW_WITH_AUB, + CSR_TBX_WITH_AUB, CSR_TYPES_NUM}; INSTANTIATE_TEST_CASE_P( diff --git a/unit_tests/command_stream/get_devices_tests.cpp b/unit_tests/command_stream/get_devices_tests.cpp index 0a32cd36a3..ecacd37f00 100644 --- a/unit_tests/command_stream/get_devices_tests.cpp +++ b/unit_tests/command_stream/get_devices_tests.cpp @@ -69,6 +69,7 @@ HWTEST_P(GetDevicesTest, givenGetDevicesWhenCsrIsSetToValidTypeThenTheFuntionRet break; case CSR_AUB: case CSR_TBX: + case CSR_TBX_WITH_AUB: EXPECT_TRUE(ret); EXPECT_NE(nullptr, hwInfo); EXPECT_EQ(1u, numDevices); @@ -102,6 +103,7 @@ static CommandStreamReceiverType commandStreamReceiverTypes[] = { CSR_AUB, CSR_TBX, CSR_HW_WITH_AUB, + CSR_TBX_WITH_AUB, CSR_TYPES_NUM}; INSTANTIATE_TEST_CASE_P( diff --git a/unit_tests/command_stream/tbx_command_stream_fixture.cpp b/unit_tests/command_stream/tbx_command_stream_fixture.cpp index f32194d713..5130cb650f 100644 --- a/unit_tests/command_stream/tbx_command_stream_fixture.cpp +++ b/unit_tests/command_stream/tbx_command_stream_fixture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -33,7 +33,7 @@ namespace OCLRT { void TbxCommandStreamFixture::SetUp(MockDevice *pDevice) { // Create our TBX command stream receiver based on HW type const auto &hwInfo = pDevice->getHardwareInfo(); - pCommandStreamReceiver = TbxCommandStreamReceiver::create(hwInfo); + pCommandStreamReceiver = TbxCommandStreamReceiver::create(hwInfo, false); ASSERT_NE(nullptr, pCommandStreamReceiver); mmTbx = pCommandStreamReceiver->createMemoryManager(false); pDevice->resetCommandStreamReceiver(pCommandStreamReceiver); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index c216972868..9f4fdaa33c 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -52,19 +52,19 @@ struct TbxFixture : public TbxCommandStreamFixture, } }; -typedef Test Tbx_command_stream; +typedef Test TbxCommandStreamTests; -TEST_F(Tbx_command_stream, DISABLED_testFactory) { +TEST_F(TbxCommandStreamTests, DISABLED_testFactory) { } -HWTEST_F(Tbx_command_stream, DISABLED_testTbxMemoryManager) { +HWTEST_F(TbxCommandStreamTests, DISABLED_testTbxMemoryManager) { TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; TbxMemoryManager *getMM = tbxCsr->getMemoryManager(); EXPECT_NE(nullptr, getMM); EXPECT_EQ(1 * GB, getMM->getSystemSharedMemory()); } -TEST_F(Tbx_command_stream, DISABLED_makeResident) { +TEST_F(TbxCommandStreamTests, DISABLED_makeResident) { uint8_t buffer[0x10000]; size_t size = sizeof(buffer); @@ -74,14 +74,14 @@ TEST_F(Tbx_command_stream, DISABLED_makeResident) { mmTbx->freeGraphicsMemory(graphicsAllocation); } -TEST_F(Tbx_command_stream, DISABLED_makeResidentOnZeroSizedBufferShouldDoNothing) { +TEST_F(TbxCommandStreamTests, DISABLED_makeResidentOnZeroSizedBufferShouldDoNothing) { GraphicsAllocation graphicsAllocation(nullptr, 0); pCommandStreamReceiver->makeResident(graphicsAllocation); pCommandStreamReceiver->makeNonResident(graphicsAllocation); } -TEST_F(Tbx_command_stream, DISABLED_flush) { +TEST_F(TbxCommandStreamTests, DISABLED_flush) { char buffer[4096]; memset(buffer, 0, 4096); LinearStream cs(buffer, 4096); @@ -90,7 +90,7 @@ TEST_F(Tbx_command_stream, DISABLED_flush) { pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); } -HWTEST_F(Tbx_command_stream, DISABLED_flushUntilTailRCSLargerThanSizeRCS) { +HWTEST_F(TbxCommandStreamTests, DISABLED_flushUntilTailRCSLargerThanSizeRCS) { char buffer[4096]; memset(buffer, 0, 4096); LinearStream cs(buffer, 4096); @@ -108,7 +108,7 @@ HWTEST_F(Tbx_command_stream, DISABLED_flushUntilTailRCSLargerThanSizeRCS) { engineInfo.sizeRCS = size; } -HWTEST_F(Tbx_command_stream, DISABLED_getCsTraits) { +HWTEST_F(TbxCommandStreamTests, DISABLED_getCsTraits) { TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; tbxCsr->getCsTraits(EngineType::ENGINE_RCS); tbxCsr->getCsTraits(EngineType::ENGINE_BCS); @@ -120,7 +120,7 @@ HWTEST_F(Tbx_command_stream, DISABLED_getCsTraits) { TEST(TbxCommandStreamReceiverTest, DISABLED_createShouldReturnFunctionPointer) { TbxCommandStreamReceiver tbx; const HardwareInfo *hwInfo = platformDevices[0]; - CommandStreamReceiver *csr = tbx.create(*hwInfo); + CommandStreamReceiver *csr = tbx.create(*hwInfo, false); EXPECT_NE(nullptr, csr); delete csr; } @@ -135,7 +135,7 @@ TEST(TbxCommandStreamReceiverTest, createShouldReturnNullptrForEmptyEntryInFacto auto pCreate = tbxCommandStreamReceiverFactory[family]; tbxCommandStreamReceiverFactory[family] = nullptr; - CommandStreamReceiver *csr = tbx.create(*hwInfo); + CommandStreamReceiver *csr = tbx.create(*hwInfo, false); EXPECT_EQ(nullptr, csr); tbxCommandStreamReceiverFactory[family] = pCreate; @@ -149,8 +149,131 @@ TEST(TbxCommandStreamReceiverTest, givenTbxCommandStreamReceiverWhenItIsCreatedW const_cast(hwInfo.pPlatform)->eRenderCoreFamily = GFXCORE_FAMILY_FORCE_ULONG; // wrong gfx core family - CommandStreamReceiver *csr = TbxCommandStreamReceiver::create(hwInfo); + CommandStreamReceiver *csr = TbxCommandStreamReceiver::create(hwInfo, false); EXPECT_EQ(nullptr, csr); const_cast(hwInfo.pPlatform)->eRenderCoreFamily = family; } + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsCalledForGraphicsAllocationThenItShouldPushAllocationForResidencyToMemoryManager) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_EQ(0u, memoryManager->getResidencyAllocations().size()); + + tbxCsr->makeResident(*graphicsAllocation); + + EXPECT_EQ(1u, memoryManager->getResidencyAllocations().size()); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentHasAlreadyBeenCalledForGraphicsAllocationThenItShouldNotPushAllocationForResidencyAgainToMemoryManager) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_EQ(0u, memoryManager->getResidencyAllocations().size()); + + tbxCsr->makeResident(*graphicsAllocation); + + EXPECT_EQ(1u, memoryManager->getResidencyAllocations().size()); + + tbxCsr->makeResident(*graphicsAllocation); + + EXPECT_EQ(1u, memoryManager->getResidencyAllocations().size()); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenWriteMemoryIsCalledForGraphicsAllocationWithNonZeroSizeThenItShouldReturnTrue) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_TRUE(tbxCsr->writeMemory(*graphicsAllocation)); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenWriteMemoryIsCalledForGraphicsAllocationWithZeroSizeThenItShouldReturnFalse) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + GraphicsAllocation graphicsAllocation((void *)0x1234, 0); + + EXPECT_FALSE(tbxCsr->writeMemory(graphicsAllocation)); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidencyIsCalledWithoutAllocationsForResidencyThenItShouldProcessAllocationsFromMemoryManager) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); + + memoryManager->pushAllocationForResidency(graphicsAllocation); + tbxCsr->processResidency(nullptr); + + EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); + EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidencyIsCalledWithAllocationsForResidencyThenItShouldProcessGivenAllocations) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); + + ResidencyContainer allocationsForResidency = {graphicsAllocation}; + tbxCsr->processResidency(&allocationsForResidency); + + EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); + EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledThenItShouldProcessAllocationsForResidency) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + ASSERT_NE(nullptr, graphicsAllocation); + + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, MemoryConstants::pageSize); + ASSERT_NE(nullptr, commandBuffer); + + LinearStream cs(commandBuffer); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + auto engineType = OCLRT::ENGINE_RCS; + ResidencyContainer allocationsForResidency = {graphicsAllocation}; + + EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); + + tbxCsr->flush(batchBuffer, engineType, &allocationsForResidency); + + EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); + EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); + + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(graphicsAllocation); +}