From a77f1de8a1458762c1b0e60e8f4e1554cf3ee00c Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Mon, 27 Jul 2020 17:37:51 +0200 Subject: [PATCH] Track StateBaseAddresses from cmdQ and cmdList Related-To: NEO-4637 Change-Id: Ia4b187df5f28fadf032ff24acb7ab32b05d0d261 Signed-off-by: Mateusz Hoppe --- level_zero/core/source/cmdlist/cmdlist_hw.h | 1 + level_zero/core/source/cmdlist/cmdlist_hw.inl | 21 +- .../core/source/cmdqueue/cmdqueue_hw_base.inl | 8 + .../core/source/debugger/CMakeLists.txt | 1 + .../core/source/debugger/debugger_l0.cpp | 12 ++ level_zero/core/source/debugger/debugger_l0.h | 29 +++ .../core/source/debugger/debugger_l0.inl | 54 ++++++ .../source/debugger/linux/debugger_l0_linux.h | 18 -- level_zero/core/source/dll/CMakeLists.txt | 6 + .../{debugger => dll}/linux/CMakeLists.txt | 5 +- .../linux/debugger_l0_linux.cpp | 4 +- .../{debugger => dll}/windows/CMakeLists.txt | 6 +- .../windows/debugger_l0_windows.cpp | 0 level_zero/core/source/gen11/CMakeLists.txt | 1 + .../core/source/gen11/debugger_gen11.cpp | 18 ++ level_zero/core/source/gen12lp/CMakeLists.txt | 1 + .../core/source/gen12lp/debugger_gen12lp.cpp | 18 ++ level_zero/core/source/gen8/CMakeLists.txt | 1 + level_zero/core/source/gen8/debugger_gen8.cpp | 19 ++ level_zero/core/source/gen9/CMakeLists.txt | 1 + level_zero/core/source/gen9/debugger_gen9.cpp | 18 ++ .../core/test/unit_tests/gen11/CMakeLists.txt | 1 + .../gen11/enable_l0_mocks_gen11.cpp | 20 ++ .../test/unit_tests/gen12lp/CMakeLists.txt | 1 + .../gen12lp/enable_l0_mocks_gen12lp.cpp | 20 ++ .../core/test/unit_tests/gen9/CMakeLists.txt | 1 + .../unit_tests/gen9/enable_l0_mocks_gen9.cpp | 20 ++ .../core/test/unit_tests/mocks/CMakeLists.txt | 1 + .../unit_tests/mocks/debugger_l0_create.cpp | 21 ++ .../test/unit_tests/mocks/mock_cmdqueue.h | 1 + .../test/unit_tests/mocks/mock_l0_debugger.h | 27 ++- .../sources/debugger/l0_debugger_fixture.h | 15 +- .../sources/debugger/test_l0_debugger.cpp | 179 +++++++++++++++++- .../source_level_debugger_tests.cpp | 13 ++ shared/source/debugger/debugger.h | 3 + .../source_level_debugger.h | 2 + .../test/unit_test/test_macros/header/test.h | 8 + 37 files changed, 528 insertions(+), 47 deletions(-) create mode 100644 level_zero/core/source/debugger/debugger_l0.inl delete mode 100644 level_zero/core/source/debugger/linux/debugger_l0_linux.h rename level_zero/core/source/{debugger => dll}/linux/CMakeLists.txt (53%) rename level_zero/core/source/{debugger => dll}/linux/debugger_l0_linux.cpp (52%) rename level_zero/core/source/{debugger => dll}/windows/CMakeLists.txt (57%) rename level_zero/core/source/{debugger => dll}/windows/debugger_l0_windows.cpp (100%) create mode 100644 level_zero/core/source/gen11/debugger_gen11.cpp create mode 100644 level_zero/core/source/gen12lp/debugger_gen12lp.cpp create mode 100644 level_zero/core/source/gen8/debugger_gen8.cpp create mode 100644 level_zero/core/source/gen9/debugger_gen9.cpp create mode 100644 level_zero/core/test/unit_tests/gen11/enable_l0_mocks_gen11.cpp create mode 100644 level_zero/core/test/unit_tests/gen12lp/enable_l0_mocks_gen12lp.cpp create mode 100644 level_zero/core/test/unit_tests/gen9/enable_l0_mocks_gen9.cpp create mode 100644 level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.h b/level_zero/core/source/cmdlist/cmdlist_hw.h index a5231ab093..23f194c592 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw.h @@ -192,6 +192,7 @@ struct CommandListCoreFamily : CommandListImp { void appendEventForProfilingCopyCommand(ze_event_handle_t hEvent, bool beforeWalker); void appendSignalEventPostWalker(ze_event_handle_t hEvent); bool useMemCopyToBlitFill(size_t patternSize); + void programStateBaseAddress(NEO::CommandContainer &container); uint64_t getInputBufferSize(NEO::ImageType imageType, uint64_t bytesPerPixel, const ze_image_region_t *region); virtual AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize); diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 13603fafae..f4629618b4 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -42,17 +42,16 @@ struct EncodeStateBaseAddress; template bool CommandListCoreFamily::initialize(Device *device, bool isCopyOnly) { using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + this->device = device; + this->commandListPreemptionMode = device->getDevicePreemptionMode(); + this->isCopyOnlyCmdList = isCopyOnly; if (!commandContainer.initialize(static_cast(device)->neoDevice)) { return false; } if (!isCopyOnly) { - NEO::EncodeStateBaseAddress::encode(commandContainer); - commandContainer.setDirtyStateForAllHeaps(false); + programStateBaseAddress(commandContainer); } - this->device = device; - this->commandListPreemptionMode = device->getDevicePreemptionMode(); - this->isCopyOnlyCmdList = isCopyOnly; return true; } @@ -1449,8 +1448,7 @@ ze_result_t CommandListCoreFamily::reset() { removeHostPtrAllocations(); commandContainer.reset(); - NEO::EncodeStateBaseAddress::encode(commandContainer); - commandContainer.setDirtyStateForAllHeaps(false); + programStateBaseAddress(commandContainer); return ZE_RESULT_SUCCESS; } @@ -1486,4 +1484,13 @@ ze_result_t CommandListCoreFamily::setGlobalWorkSizeIndirect(NEO: return ZE_RESULT_SUCCESS; } +template +void CommandListCoreFamily::programStateBaseAddress(NEO::CommandContainer &container) { + NEO::EncodeStateBaseAddress::encode(commandContainer); + if (device->getL0Debugger()) { + device->getL0Debugger()->captureStateBaseAddress(commandContainer); + } + commandContainer.setDirtyStateForAllHeaps(false); +} + } // namespace L0 diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl index 73d9e19277..494df5336a 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl @@ -60,6 +60,10 @@ void CommandQueueHw::programGeneralStateBaseAddress(uint64_t gsba gsbaInit = true; + if (device->getL0Debugger()) { + device->getL0Debugger()->programSbaTrackingCommands(commandStream, gsba, 0); + } + NEO::EncodeWA::encodeAdditionalPipelineSelect(*device->getNEODevice(), commandStream, false); } @@ -70,6 +74,10 @@ size_t CommandQueueHw::estimateStateBaseAddressCmdSize() { using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL; size_t size = sizeof(STATE_BASE_ADDRESS) + sizeof(PIPE_CONTROL) + NEO::EncodeWA::getAdditionalPipelineSelectSize(*device->getNEODevice()); + + if (device->getL0Debugger() != nullptr) { + size += device->getL0Debugger()->getSbaTrackingCommandsSize(1); + } return size; } diff --git a/level_zero/core/source/debugger/CMakeLists.txt b/level_zero/core/source/debugger/CMakeLists.txt index d1732bf966..fe850c6d8d 100644 --- a/level_zero/core/source/debugger/CMakeLists.txt +++ b/level_zero/core/source/debugger/CMakeLists.txt @@ -8,6 +8,7 @@ set(L0_SRCS_DEBUGGER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.cpp ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.h + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0.inl ) add_subdirectories() diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index 5d5095dfea..b51e9f7165 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -7,6 +7,7 @@ #include "level_zero/core/source/debugger/debugger_l0.h" +#include "shared/source/command_container/cmdcontainer.h" #include "shared/source/device/device.h" #include "shared/source/helpers/constants.h" #include "shared/source/memory_manager/allocation_properties.h" @@ -16,6 +17,9 @@ #include namespace L0 { + +DebugerL0CreateFn debuggerL0Factory[IGFX_MAX_CORE] = {}; + DebuggerL0::DebuggerL0(NEO::Device *device) : device(device) { isLegacyMode = false; @@ -54,4 +58,12 @@ bool DebuggerL0::isDebuggerActive() { return true; } +void DebuggerL0::captureStateBaseAddress(NEO::CommandContainer &container) { + uint64_t ssh = 0; + if (container.isHeapDirty(NEO::HeapType::SURFACE_STATE)) { + ssh = container.getIndirectHeap(NEO::HeapType::SURFACE_STATE)->getHeapGpuBase(); + } + programSbaTrackingCommands(*container.getCommandStream(), 0, ssh); +} + } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/debugger/debugger_l0.h b/level_zero/core/source/debugger/debugger_l0.h index fd712c1b26..b5d188b970 100644 --- a/level_zero/core/source/debugger/debugger_l0.h +++ b/level_zero/core/source/debugger/debugger_l0.h @@ -16,6 +16,7 @@ namespace NEO { class Device; class GraphicsAllocation; +class LinearStream; } // namespace NEO namespace L0 { @@ -51,10 +52,38 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass { return sbaTrackingGpuVa.address; } + void captureStateBaseAddress(NEO::CommandContainer &container) override; + + virtual size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) const = 0; + virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, uint64_t generalStateGpuVa, uint64_t surfaceStateGpuVa) const = 0; + protected: NEO::Device *device = nullptr; NEO::GraphicsAllocation *sbaAllocation = nullptr; std::unordered_map perContextSbaAllocations; NEO::AddressRange sbaTrackingGpuVa; }; + +using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device); +extern DebugerL0CreateFn debuggerL0Factory[]; + +template +class DebuggerL0Hw : public DebuggerL0 { + public: + static DebuggerL0 *allocate(NEO::Device *device); + + size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) const override; + void programSbaTrackingCommands(NEO::LinearStream &cmdStream, uint64_t generalStateGpuVa, uint64_t surfaceStateGpuVa) const override; + + protected: + DebuggerL0Hw(NEO::Device *device) : DebuggerL0(device){}; +}; + +template +struct DebuggerL0PopulateFactory { + DebuggerL0PopulateFactory() { + debuggerL0Factory[productFamily] = DebuggerL0Hw::allocate; + } +}; + } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/debugger/debugger_l0.inl b/level_zero/core/source/debugger/debugger_l0.inl new file mode 100644 index 0000000000..74dbd78d0f --- /dev/null +++ b/level_zero/core/source/debugger/debugger_l0.inl @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_stream/linear_stream.h" +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/helpers/hw_cmds.h" + +#include "level_zero/core/source/debugger/debugger_l0.h" + +namespace L0 { + +template +size_t DebuggerL0Hw::getSbaTrackingCommandsSize(size_t trackedAddressCount) const { + return trackedAddressCount * sizeof(typename GfxFamily::MI_STORE_DATA_IMM); +} + +template +void DebuggerL0Hw::programSbaTrackingCommands(NEO::LinearStream &cmdStream, uint64_t generalStateGpuVa, uint64_t surfaceStateGpuVa) const { + using MI_STORE_DATA_IMM = typename GfxFamily::MI_STORE_DATA_IMM; + auto gpuAddress = NEO::GmmHelper::decanonize(sbaTrackingGpuVa.address); + + if (generalStateGpuVa) { + MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; + storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress)); + storeDataImmediate.setStoreQword(true); + storeDataImmediate.setDataDword0(static_cast(generalStateGpuVa & 0x0000FFFFFFFFULL)); + storeDataImmediate.setDataDword1(static_cast(generalStateGpuVa >> 32)); + + auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); + *storeDataImmediateSpace = storeDataImmediate; + } + + if (surfaceStateGpuVa) { + MI_STORE_DATA_IMM storeDataImmediate = GfxFamily::cmdInitStoreDataImm; + storeDataImmediate.setAddress(gpuAddress + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress)); + storeDataImmediate.setStoreQword(true); + storeDataImmediate.setDataDword0(static_cast(surfaceStateGpuVa & 0x0000FFFFFFFFULL)); + storeDataImmediate.setDataDword1(static_cast(surfaceStateGpuVa >> 32)); + + auto storeDataImmediateSpace = cmdStream.getSpaceForCmd(); + *storeDataImmediateSpace = storeDataImmediate; + } +} + +template +DebuggerL0 *DebuggerL0Hw::allocate(NEO::Device *device) { + return new DebuggerL0Hw(device); +} + +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/debugger/linux/debugger_l0_linux.h b/level_zero/core/source/debugger/linux/debugger_l0_linux.h deleted file mode 100644 index e8352b0ff4..0000000000 --- a/level_zero/core/source/debugger/linux/debugger_l0_linux.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "level_zero/core/source/debugger/debugger_l0.h" - -namespace L0 { -class DebuggerL0Linux : public DebuggerL0 { - public: - DebuggerL0Linux(NEO::Device *device) : DebuggerL0(device) { - } - ~DebuggerL0Linux() override = default; -}; -} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/dll/CMakeLists.txt b/level_zero/core/source/dll/CMakeLists.txt index 16cd1046cc..69670e4070 100644 --- a/level_zero/core/source/dll/CMakeLists.txt +++ b/level_zero/core/source/dll/CMakeLists.txt @@ -8,4 +8,10 @@ set(L0_SRCS_DLL ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/disallow_deferred_deleter.cpp ) +add_subdirectories() +if(WIN32) + append_sources_from_properties(L0_SRCS_DLL L0_SRCS_DLL_WINDOWS) +else() + append_sources_from_properties(L0_SRCS_DLL L0_SRCS_DLL_LINUX) +endif() set_property(GLOBAL PROPERTY L0_SRCS_DLL ${L0_SRCS_DLL}) \ No newline at end of file diff --git a/level_zero/core/source/debugger/linux/CMakeLists.txt b/level_zero/core/source/dll/linux/CMakeLists.txt similarity index 53% rename from level_zero/core/source/debugger/linux/CMakeLists.txt rename to level_zero/core/source/dll/linux/CMakeLists.txt index dd0ace67c7..1316b1e63b 100644 --- a/level_zero/core/source/debugger/linux/CMakeLists.txt +++ b/level_zero/core/source/dll/linux/CMakeLists.txt @@ -4,10 +4,9 @@ # SPDX-License-Identifier: MIT # -set(L0_SRCS_DEBUGGER_LINUX +set(L0_SRCS_DLL_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_linux.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_linux.h ) -set_property(GLOBAL PROPERTY L0_SRCS_DEBUGGER_LINUX ${L0_SRCS_DEBUGGER_LINUX}) +set_property(GLOBAL PROPERTY L0_SRCS_DLL_LINUX ${L0_SRCS_DLL_LINUX}) diff --git a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp b/level_zero/core/source/dll/linux/debugger_l0_linux.cpp similarity index 52% rename from level_zero/core/source/debugger/linux/debugger_l0_linux.cpp rename to level_zero/core/source/dll/linux/debugger_l0_linux.cpp index e946455b48..82c8faa02d 100644 --- a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp +++ b/level_zero/core/source/dll/linux/debugger_l0_linux.cpp @@ -5,11 +5,11 @@ * */ -#include "level_zero/core/source/debugger/linux/debugger_l0_linux.h" +#include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { std::unique_ptr DebuggerL0::create(NEO::Device *device) { - return std::make_unique(device); + return std::unique_ptr(debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device)); } } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/debugger/windows/CMakeLists.txt b/level_zero/core/source/dll/windows/CMakeLists.txt similarity index 57% rename from level_zero/core/source/debugger/windows/CMakeLists.txt rename to level_zero/core/source/dll/windows/CMakeLists.txt index f9e9f02f51..ccebde8cd2 100644 --- a/level_zero/core/source/debugger/windows/CMakeLists.txt +++ b/level_zero/core/source/dll/windows/CMakeLists.txt @@ -4,11 +4,9 @@ # SPDX-License-Identifier: MIT # -set(L0_SRCS_DEBUGGER_WINDOWS +set(L0_SRCS_DLL_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_windows.cpp ) -if(WIN32) - set_property(GLOBAL PROPERTY L0_SRCS_DEBUGGER_WINDOWS ${L0_SRCS_DEBUGGER_WINDOWS}) -endif() \ No newline at end of file +set_property(GLOBAL PROPERTY L0_SRCS_DLL_WINDOWS ${L0_SRCS_DLL_WINDOWS}) diff --git a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp b/level_zero/core/source/dll/windows/debugger_l0_windows.cpp similarity index 100% rename from level_zero/core/source/debugger/windows/debugger_l0_windows.cpp rename to level_zero/core/source/dll/windows/debugger_l0_windows.cpp diff --git a/level_zero/core/source/gen11/CMakeLists.txt b/level_zero/core/source/gen11/CMakeLists.txt index 3d5a7113ed..5cb1611c54 100644 --- a/level_zero/core/source/gen11/CMakeLists.txt +++ b/level_zero/core/source/gen11/CMakeLists.txt @@ -8,6 +8,7 @@ if(SUPPORT_GEN11) set(HW_SOURCES_GEN11 ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist_gen11.inl + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_gen11.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enable_family_full_l0_gen11.cpp ) add_subdirectories() diff --git a/level_zero/core/source/gen11/debugger_gen11.cpp b/level_zero/core/source/gen11/debugger_gen11.cpp new file mode 100644 index 0000000000..8724968ef4 --- /dev/null +++ b/level_zero/core/source/gen11/debugger_gen11.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/debugger/debugger_l0.inl" + +namespace NEO { +struct ICLFamily; +using GfxFamily = ICLFamily; +} // namespace NEO + +namespace L0 { +template class DebuggerL0Hw; +static DebuggerL0PopulateFactory debuggerGen11; +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/gen12lp/CMakeLists.txt b/level_zero/core/source/gen12lp/CMakeLists.txt index 0e9a3ff79c..30f51d3319 100644 --- a/level_zero/core/source/gen12lp/CMakeLists.txt +++ b/level_zero/core/source/gen12lp/CMakeLists.txt @@ -8,6 +8,7 @@ if(SUPPORT_GEN12LP) set(HW_SOURCES_GEN12LP ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist_gen12lp.h + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_gen12lp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/cache_flush_gen12lp.inl ${CMAKE_CURRENT_SOURCE_DIR}/enable_family_full_l0_gen12lp.cpp ) diff --git a/level_zero/core/source/gen12lp/debugger_gen12lp.cpp b/level_zero/core/source/gen12lp/debugger_gen12lp.cpp new file mode 100644 index 0000000000..5673bc39a4 --- /dev/null +++ b/level_zero/core/source/gen12lp/debugger_gen12lp.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/debugger/debugger_l0.inl" + +namespace NEO { +struct TGLLPFamily; +using GfxFamily = TGLLPFamily; +} // namespace NEO + +namespace L0 { +template class DebuggerL0Hw; +static DebuggerL0PopulateFactory debuggerGen12lp; +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/gen8/CMakeLists.txt b/level_zero/core/source/gen8/CMakeLists.txt index 5b59c121f1..1d2d999550 100644 --- a/level_zero/core/source/gen8/CMakeLists.txt +++ b/level_zero/core/source/gen8/CMakeLists.txt @@ -7,6 +7,7 @@ if(SUPPORT_GEN8) set(HW_SOURCES_GEN8 ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_gen8.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enable_family_full_l0_gen8.cpp ) diff --git a/level_zero/core/source/gen8/debugger_gen8.cpp b/level_zero/core/source/gen8/debugger_gen8.cpp new file mode 100644 index 0000000000..8987c0d6fd --- /dev/null +++ b/level_zero/core/source/gen8/debugger_gen8.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/debugger/debugger_l0.inl" + +namespace NEO { + +struct BDWFamily; +using GfxFamily = BDWFamily; + +} // namespace NEO + +namespace L0 { +template class DebuggerL0Hw; +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/gen9/CMakeLists.txt b/level_zero/core/source/gen9/CMakeLists.txt index 405e48e477..cabb88e8cd 100644 --- a/level_zero/core/source/gen9/CMakeLists.txt +++ b/level_zero/core/source/gen9/CMakeLists.txt @@ -8,6 +8,7 @@ if(SUPPORT_GEN9) set(HW_SOURCES_GEN9 ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/cmdlist_gen9.inl + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_gen9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enable_family_full_l0_gen9.cpp ) diff --git a/level_zero/core/source/gen9/debugger_gen9.cpp b/level_zero/core/source/gen9/debugger_gen9.cpp new file mode 100644 index 0000000000..80b556bdf1 --- /dev/null +++ b/level_zero/core/source/gen9/debugger_gen9.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/debugger/debugger_l0.inl" + +namespace NEO { +struct SKLFamily; +using GfxFamily = SKLFamily; +} // namespace NEO + +namespace L0 { +template class DebuggerL0Hw; +static DebuggerL0PopulateFactory debuggerGen9; +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/gen11/CMakeLists.txt b/level_zero/core/test/unit_tests/gen11/CMakeLists.txt index 36ec113293..afc6de9191 100644 --- a/level_zero/core/test/unit_tests/gen11/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/gen11/CMakeLists.txt @@ -8,6 +8,7 @@ if(TESTS_GEN11) target_sources(${TARGET_NAME} PRIVATE ${COMPUTE_RUNTIME_ULT_GEN11} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/enable_l0_mocks_gen11.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdqueue_thread_arbitration_policy_gen11.cpp ) endif() \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/gen11/enable_l0_mocks_gen11.cpp b/level_zero/core/test/unit_tests/gen11/enable_l0_mocks_gen11.cpp new file mode 100644 index 0000000000..07687ace66 --- /dev/null +++ b/level_zero/core/test/unit_tests/gen11/enable_l0_mocks_gen11.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" + +namespace NEO { + +struct ICLFamily; +using GfxFamily = ICLFamily; +} // namespace NEO + +namespace L0 { +namespace ult { +static MockDebuggerL0HwPopulateFactory mockDebuggerGen11; +} +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/gen12lp/CMakeLists.txt b/level_zero/core/test/unit_tests/gen12lp/CMakeLists.txt index 894d3d6b65..28e23c7f2f 100644 --- a/level_zero/core/test/unit_tests/gen12lp/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/gen12lp/CMakeLists.txt @@ -8,6 +8,7 @@ if(TESTS_GEN12LP) target_sources(${TARGET_NAME} PRIVATE ${COMPUTE_RUNTIME_ULT_GEN12LP} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/enable_l0_mocks_gen12lp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_gen12lp.cpp ) diff --git a/level_zero/core/test/unit_tests/gen12lp/enable_l0_mocks_gen12lp.cpp b/level_zero/core/test/unit_tests/gen12lp/enable_l0_mocks_gen12lp.cpp new file mode 100644 index 0000000000..568f1464a4 --- /dev/null +++ b/level_zero/core/test/unit_tests/gen12lp/enable_l0_mocks_gen12lp.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" + +namespace NEO { + +struct TGLLPFamily; +using GfxFamily = TGLLPFamily; +} // namespace NEO + +namespace L0 { +namespace ult { +static MockDebuggerL0HwPopulateFactory mockDebuggerGen12lp; +} +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/gen9/CMakeLists.txt b/level_zero/core/test/unit_tests/gen9/CMakeLists.txt index 2d7d503ebb..2ad93f1914 100644 --- a/level_zero/core/test/unit_tests/gen9/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/gen9/CMakeLists.txt @@ -8,6 +8,7 @@ if(TESTS_GEN9) target_sources(${TARGET_NAME} PRIVATE ${COMPUTE_RUNTIME_ULT_GEN9} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/enable_l0_mocks_gen9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_launch_kernel_gen9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdqueue_thread_arbitration_policy_gen9.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_gen9.cpp diff --git a/level_zero/core/test/unit_tests/gen9/enable_l0_mocks_gen9.cpp b/level_zero/core/test/unit_tests/gen9/enable_l0_mocks_gen9.cpp new file mode 100644 index 0000000000..528a2f3a3f --- /dev/null +++ b/level_zero/core/test/unit_tests/gen9/enable_l0_mocks_gen9.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" + +namespace NEO { + +struct SKLFamily; +using GfxFamily = SKLFamily; +} // namespace NEO + +namespace L0 { +namespace ult { +static MockDebuggerL0HwPopulateFactory mockDebuggerGen9; +} +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt index 16d0c741fa..4667ce8c96 100644 --- a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt @@ -8,6 +8,7 @@ set(TARGET_NAME ${TARGET_NAME_L0}_mocks) set(L0_MOCKS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/debugger_l0_create.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_built_ins.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_built_ins.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_cmdlist.h diff --git a/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp new file mode 100644 index 0000000000..b9368b4605 --- /dev/null +++ b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" + +namespace L0 { +namespace ult { +DebugerL0CreateFn mockDebuggerL0HwFactory[IGFX_MAX_CORE]; +} +} // namespace L0 + +namespace L0 { +std::unique_ptr DebuggerL0::create(NEO::Device *device) { + return std::unique_ptr(ult::mockDebuggerL0HwFactory[device->getHardwareInfo().platform.eRenderCoreFamily](device)); +} + +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h b/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h index 5f25bc1969..5cd269aa93 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h +++ b/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h @@ -23,6 +23,7 @@ struct WhiteBox<::L0::CommandQueue> : public ::L0::CommandQueueImp { using BaseClass::device; using BaseClass::printfFunctionContainer; using BaseClass::synchronizeByPollingForTaskCount; + using CommandQueue::commandQueuePerThreadScratchSize; WhiteBox(Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc); diff --git a/level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h b/level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h index 873bc2911a..a9daebdefd 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h +++ b/level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h @@ -10,12 +10,33 @@ namespace L0 { namespace ult { +extern DebugerL0CreateFn mockDebuggerL0HwFactory[]; -class MockDebuggerL0 : public L0::DebuggerL0 { +template +class MockDebuggerL0Hw : public L0::DebuggerL0Hw { public: - using L0::DebuggerL0::DebuggerL0; using L0::DebuggerL0::perContextSbaAllocations; - ~MockDebuggerL0() override = default; + using L0::DebuggerL0::sbaTrackingGpuVa; + + MockDebuggerL0Hw(NEO::Device *device) : L0::DebuggerL0Hw(device) {} + ~MockDebuggerL0Hw() override = default; + + static DebuggerL0 *allocate(NEO::Device *device) { + return new MockDebuggerL0Hw(device); + } + + void captureStateBaseAddress(NEO::CommandContainer &container) override { + captureStateBaseAddressCount++; + L0::DebuggerL0Hw::captureStateBaseAddress(container); + } + uint32_t captureStateBaseAddressCount = 0; +}; + +template +struct MockDebuggerL0HwPopulateFactory { + MockDebuggerL0HwPopulateFactory() { + mockDebuggerL0HwFactory[productFamily] = MockDebuggerL0Hw::allocate; + } }; } // namespace ult diff --git a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h index 752a223da7..9d0c49cb7a 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h +++ b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h @@ -43,13 +43,14 @@ struct L0DebuggerFixture { L0::Device *device = nullptr; }; -struct MockL0DebuggerFixture : public L0DebuggerFixture { +struct L0DebuggerHwFixture : public L0DebuggerFixture { void SetUp() { L0DebuggerFixture::SetUp(); - mockDebugger = new MockDebuggerL0(neoDevice); - neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.reset(mockDebugger); + debuggerHw = mockDebuggerL0HwFactory[neoDevice->getHardwareInfo().platform.eRenderCoreFamily](neoDevice); + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.reset(debuggerHw); neoDevice->setDebuggerActive(true); neoDevice->setPreemptionMode(PreemptionMode::Disabled); + auto debugSurface = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties( {device->getRootDeviceIndex(), true, NEO::SipKernel::maxDbgSurfaceSize, @@ -62,9 +63,13 @@ struct MockL0DebuggerFixture : public L0DebuggerFixture { void TearDown() { L0DebuggerFixture::TearDown(); - mockDebugger = nullptr; + debuggerHw = nullptr; } - MockDebuggerL0 *mockDebugger = nullptr; + template + MockDebuggerL0Hw *getMockDebuggerL0Hw() { + return static_cast *>(debuggerHw); + } + DebuggerL0 *debuggerHw = nullptr; }; } // namespace ult diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp index 2165e3e6f0..0baf988b3e 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp @@ -7,6 +7,7 @@ #include "shared/source/command_stream/linear_stream.h" #include "shared/source/gen_common/reg_configs/reg_configs_common.h" +#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/preamble.h" #include "shared/source/os_interface/os_context.h" #include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h" @@ -20,7 +21,7 @@ namespace L0 { namespace ult { -using L0DebuggerTest = Test; +using L0DebuggerTest = Test; TEST_F(L0DebuggerTest, givenL0DebuggerWhenCallingIsLegacyThenFalseIsReturned) { EXPECT_FALSE(neoDevice->getDebugger()->isLegacy()); @@ -38,7 +39,7 @@ TEST_F(L0DebuggerTest, givenL0DebuggerWhenCallingIsDebuggerActiveThenTrueIsRetur EXPECT_TRUE(neoDevice->getDebugger()->isDebuggerActive()); } -TEST_F(L0DebuggerTest, givenL0DebuggerWhenCreatedThenPerContextSbaTrackingBuffersAreAllocated) { +HWTEST_F(L0DebuggerTest, givenL0DebuggerWhenCreatedThenPerContextSbaTrackingBuffersAreAllocated) { auto debugger = device->getL0Debugger(); ASSERT_NE(nullptr, debugger); @@ -57,14 +58,14 @@ TEST_F(L0DebuggerTest, givenL0DebuggerWhenCreatedThenPerContextSbaTrackingBuffer EXPECT_NE(allocations[i], allocations[i + 1]); } - EXPECT_EQ(device->getNEODevice()->getEngines().size(), mockDebugger->perContextSbaAllocations.size()); + EXPECT_EQ(device->getNEODevice()->getEngines().size(), getMockDebuggerL0Hw()->perContextSbaAllocations.size()); } -TEST_F(L0DebuggerTest, givenCreatedL0DebuggerThenSbaTrackingBuffersContainValidHeader) { +HWTEST_F(L0DebuggerTest, givenCreatedL0DebuggerThenSbaTrackingBuffersContainValidHeader) { auto debugger = device->getL0Debugger(); ASSERT_NE(nullptr, debugger); - for (auto &sbaBuffer : mockDebugger->perContextSbaAllocations) { + for (auto &sbaBuffer : getMockDebuggerL0Hw()->perContextSbaAllocations) { auto sbaAllocation = sbaBuffer.second; ASSERT_NE(nullptr, sbaAllocation); @@ -229,6 +230,93 @@ HWTEST_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedTwiceThen commandQueue->destroy(); } +using NotGen8Or11 = AreNotGfxCores; + +HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledAndRequiredGsbaWhenCommandListIsExecutedThenProgramGsbaWritesToSbaTrackingBuffer, NotGen8Or11) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + + ze_command_queue_desc_t queueDesc = {}; + auto cmdQ = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false); + ASSERT_NE(nullptr, cmdQ); + + auto commandQueue = whitebox_cast(cmdQ); + auto cmdQHw = static_cast *>(cmdQ); + + if (cmdQHw->estimateStateBaseAddressCmdSize() == 0) { + commandQueue->destroy(); + GTEST_SKIP(); + } + + commandQueue->commandQueuePerThreadScratchSize = 4096; + + auto usedSpaceBefore = commandQueue->commandStream->getUsed(); + + ze_command_list_handle_t commandLists[] = { + CommandList::create(productFamily, device, false)->toHandle()}; + uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]); + + auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + auto usedSpaceAfter = commandQueue->commandStream->getUsed(); + ASSERT_GT(usedSpaceAfter, usedSpaceBefore); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter)); + + auto sbaItor = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), sbaItor); + auto cmdSba = genCmdCast(*sbaItor); + + auto sdiItor = find(sbaItor, cmdList.end()); + ASSERT_NE(cmdList.end(), sdiItor); + auto cmdSdi = genCmdCast(*sdiItor); + + uint64_t gsbaGpuVa = cmdSba->getGeneralStateBaseAddress(); + EXPECT_EQ(static_cast(gsbaGpuVa & 0x0000FFFFFFFFULL), cmdSdi->getDataDword0()); + EXPECT_EQ(static_cast(gsbaGpuVa >> 32), cmdSdi->getDataDword1()); + + auto expectedGpuVa = GmmHelper::decanonize(device->getL0Debugger()->getSbaTrackingGpuVa()) + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress); + EXPECT_EQ(expectedGpuVa, cmdSdi->getAddress()); + + for (auto i = 0u; i < numCommandLists; i++) { + auto commandList = CommandList::fromHandle(commandLists[i]); + commandList->destroy(); + } + commandQueue->destroy(); +} + +HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledWhenNonCopyCommandListIsInititalizedOrResetThenSSHAddressIsTracked, NotGen8Or11) { + using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + + size_t usedSpaceBefore = 0; + ze_command_list_handle_t commandListHandle = CommandList::create(productFamily, device, false)->toHandle(); + auto commandList = CommandList::fromHandle(commandListHandle); + + auto usedSpaceAfter = commandList->commandContainer.getCommandStream()->getUsed(); + ASSERT_GT(usedSpaceAfter, usedSpaceBefore); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandList->commandContainer.getCommandStream()->getCpuBase(), usedSpaceAfter)); + + auto sbaItor = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), sbaItor); + auto cmdSba = genCmdCast(*sbaItor); + + uint64_t sshGpuVa = cmdSba->getSurfaceStateBaseAddress(); + auto expectedGpuVa = commandList->commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE)->getHeapGpuBase(); + EXPECT_EQ(expectedGpuVa, sshGpuVa); + EXPECT_EQ(1u, getMockDebuggerL0Hw()->captureStateBaseAddressCount); + + commandList->reset(); + EXPECT_EQ(2u, getMockDebuggerL0Hw()->captureStateBaseAddressCount); + + commandList->destroy(); +} + HWTEST_F(L0DebuggerTest, givenDebuggerWhenAppendingKernelToCommandListThenBindlessSurfaceStateForDebugSurfaceIsProgrammedAtOffsetZero) { using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; @@ -257,5 +345,86 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenAppendingKernelToCommandListThenBindle EXPECT_EQ(RENDER_SURFACE_STATE::COHERENCY_TYPE_IA_COHERENT, debugSurfaceState->getCoherencyType()); } +using L0DebuggerSimpleTest = Test; + +HWTEST_F(L0DebuggerSimpleTest, givenNonZeroGpuVasWhenProgrammingSbaTrackingThenCorrectCmdsAreAddedToStream) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + auto debugger = std::make_unique>(neoDevice); + + debugger->sbaTrackingGpuVa.address = 0x45670000; + auto expectedGpuVa = debugger->sbaTrackingGpuVa.address + offsetof(SbaTrackedAddresses, GeneralStateBaseAddress); + + StackVec buffer(4096); + NEO::LinearStream cmdStream(buffer.begin(), buffer.size()); + uint64_t gsba = 0x60000; + uint64_t ssba = 0x1234567000; + + debugger->programSbaTrackingCommands(cmdStream, gsba, ssba); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, cmdStream.getCpuBase(), cmdStream.getUsed())); + + EXPECT_EQ(2 * sizeof(MI_STORE_DATA_IMM), cmdStream.getUsed()); + + auto sdiItor = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), sdiItor); + auto cmdSdi = genCmdCast(*sdiItor); + + EXPECT_EQ(static_cast(gsba & 0x0000FFFFFFFFULL), cmdSdi->getDataDword0()); + EXPECT_EQ(static_cast(gsba >> 32), cmdSdi->getDataDword1()); + EXPECT_EQ(expectedGpuVa, cmdSdi->getAddress()); + EXPECT_TRUE(cmdSdi->getStoreQword()); + + sdiItor++; + cmdSdi = genCmdCast(*sdiItor); + + expectedGpuVa = debugger->sbaTrackingGpuVa.address + offsetof(SbaTrackedAddresses, SurfaceStateBaseAddress); + EXPECT_EQ(static_cast(ssba & 0x0000FFFFFFFFULL), cmdSdi->getDataDword0()); + EXPECT_EQ(static_cast(ssba >> 32), cmdSdi->getDataDword1()); + EXPECT_EQ(expectedGpuVa, cmdSdi->getAddress()); + EXPECT_TRUE(cmdSdi->getStoreQword()); +} + +HWTEST_F(L0DebuggerSimpleTest, givenZeroGpuVasWhenProgrammingSbaTrackingThenStreamIsNotUsed) { + using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; + auto debugger = std::make_unique>(neoDevice); + + debugger->sbaTrackingGpuVa.address = 0x45670000; + + StackVec buffer(4096); + NEO::LinearStream cmdStream(buffer.begin(), buffer.size()); + uint64_t gsba = 0; + uint64_t ssba = 0; + + debugger->programSbaTrackingCommands(cmdStream, gsba, ssba); + + EXPECT_EQ(0u, cmdStream.getUsed()); +} + +HWTEST_F(L0DebuggerSimpleTest, whenAllocateCalledThenDebuggerIsCreated) { + auto debugger = DebuggerL0Hw::allocate(neoDevice); + EXPECT_NE(nullptr, debugger); + delete debugger; +} + +HWTEST_F(L0DebuggerSimpleTest, givenNotDirtySSHWhenCapturingSBAThenNoTrackingCmdsAreAdded) { + auto debugger = std::make_unique>(neoDevice); + + debugger->sbaTrackingGpuVa.address = 0x45670000; + + NEO::CommandContainer container; + container.initialize(neoDevice); + + debugger->captureStateBaseAddress(container); + auto sizeUsed = container.getCommandStream()->getUsed(); + + EXPECT_NE(0u, sizeUsed); + container.setDirtyStateForAllHeaps(false); + + debugger->captureStateBaseAddress(container); + auto sizeUsed2 = container.getCommandStream()->getUsed(); + + EXPECT_EQ(sizeUsed, sizeUsed2); +} } // namespace ult } // namespace L0 diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp index 42777e5aef..546c252dd1 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/command_container/cmdcontainer.h" #include "shared/source/device/device.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/source_level_debugger/source_level_debugger.h" @@ -601,3 +602,15 @@ TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyUseDedic EXPECT_NE(sourceLevelDebugger, device2->getDebugger()); } } + +TEST(SourceLevelDebugger, whenCaptureSBACalledThenNoCommandsAreAddedToStream) { + ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); + auto device = std::unique_ptr(Device::create(executionEnvironment, 0u)); + MockSourceLevelDebugger debugger; + + CommandContainer container; + container.initialize(device.get()); + + debugger.captureStateBaseAddress(container); + EXPECT_EQ(0u, container.getCommandStream()->getUsed()); +} \ No newline at end of file diff --git a/shared/source/debugger/debugger.h b/shared/source/debugger/debugger.h index e3830a2dfa..cbfcc13dcb 100644 --- a/shared/source/debugger/debugger.h +++ b/shared/source/debugger/debugger.h @@ -9,13 +9,16 @@ #include namespace NEO { struct HardwareInfo; +class CommandContainer; class IndirectHeap; + class Debugger { public: static std::unique_ptr create(HardwareInfo *hwInfo); virtual ~Debugger() = default; virtual bool isDebuggerActive() = 0; bool isLegacy() const { return isLegacyMode; } + virtual void captureStateBaseAddress(CommandContainer &container) = 0; void *getDebugSurfaceReservedSurfaceState(IndirectHeap &ssh); diff --git a/shared/source/source_level_debugger/source_level_debugger.h b/shared/source/source_level_debugger/source_level_debugger.h index 58105e0292..352302e257 100644 --- a/shared/source/source_level_debugger/source_level_debugger.h +++ b/shared/source/source_level_debugger/source_level_debugger.h @@ -31,6 +31,8 @@ class SourceLevelDebugger : public Debugger { MOCKABLE_VIRTUAL bool notifyKernelDebugData(const DebugData *debugData, const std::string &name, const void *isa, size_t isaSize) const; MOCKABLE_VIRTUAL bool initialize(bool useLocalMemory); + void captureStateBaseAddress(CommandContainer &container) override{}; + protected: class SourceLevelDebuggerInterface; SourceLevelDebuggerInterface *sourceLevelDebuggerInterface = nullptr; diff --git a/shared/test/unit_test/test_macros/header/test.h b/shared/test/unit_test/test_macros/header/test.h index 8adc889492..ec08d7688d 100644 --- a/shared/test/unit_test/test_macros/header/test.h +++ b/shared/test/unit_test/test_macros/header/test.h @@ -997,6 +997,14 @@ struct IsGfxCore { } }; +template +struct AreNotGfxCores { + template + static constexpr bool isMatched() { + return NEO::ToGfxCoreFamily::get() != gfxCoreFamily && NEO::ToGfxCoreFamily::get() != gfxCoreFamily2; + } +}; + template struct IsAtMostGfxCore { template