From 830bcd69878ecbbf748815cb091bc20c5e288cd9 Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Mon, 7 Dec 2020 15:38:12 +0000 Subject: [PATCH] Scratch using bindless heaps Signed-off-by: Maciej Plewka --- .../core/source/cmdqueue/CMakeLists.txt | 7 ++ .../test/unit_tests/mocks/mock_cmdqueue.h | 1 + .../sources/cmdqueue/test_cmdqueue.cpp | 2 +- ...and_stream_receiver_flush_task_2_tests.cpp | 9 +- .../command_stream/scratch_space_controller.h | 9 ++ .../scratch_space_controller_base.cpp | 9 ++ .../scratch_space_controller_base.h | 8 ++ .../scratch_space_controler/CMakeLists.txt | 12 +++ .../scratch_space_controler_tests.cpp | 83 +++++++++++++++++++ 9 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 level_zero/core/source/cmdqueue/CMakeLists.txt create mode 100644 shared/test/unit_test/scratch_space_controler/CMakeLists.txt create mode 100644 shared/test/unit_test/scratch_space_controler/scratch_space_controler_tests.cpp diff --git a/level_zero/core/source/cmdqueue/CMakeLists.txt b/level_zero/core/source/cmdqueue/CMakeLists.txt new file mode 100644 index 0000000000..1e8ca6b45a --- /dev/null +++ b/level_zero/core/source/cmdqueue/CMakeLists.txt @@ -0,0 +1,7 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +add_subdirectories() 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 5edd20c8c5..5a9b797215 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h +++ b/level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h @@ -78,6 +78,7 @@ struct MockCommandQueueHw : public L0::CommandQueueHw { using BaseClass = ::L0::CommandQueueHw; using BaseClass::commandStream; using BaseClass::printfFunctionContainer; + using L0::CommandQueue::commandQueuePerThreadScratchSize; using L0::CommandQueue::internalUsage; MockCommandQueueHw(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc) : L0::CommandQueueHw(device, csr, desc) { diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp index e9c019c771..4a1cdf111c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/command_stream/scratch_space_controller_base.h" #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/state_base_address.h" @@ -656,6 +657,5 @@ TEST_F(CommandQueueInitTests, givenMultipleSubDevicesWhenInitializingThenAllocat commandQueue->destroy(); } - } // namespace ult } // namespace L0 diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_2_tests.cpp index 76a6e1131d..83b2b02f5f 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -497,7 +497,14 @@ struct MockScratchController : public ScratchSpaceController { bool &stateBaseAddressDirty, bool &vfeStateDirty) override { } - + void programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) override { + } void reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) override{}; }; diff --git a/shared/source/command_stream/scratch_space_controller.h b/shared/source/command_stream/scratch_space_controller.h index 19c3b609b0..60642e2df9 100644 --- a/shared/source/command_stream/scratch_space_controller.h +++ b/shared/source/command_stream/scratch_space_controller.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/helpers/bindless_heaps_helper.h" #include "shared/source/indirect_heap/indirect_heap.h" #include @@ -43,6 +44,7 @@ class ScratchSpaceController { OsContext &osContext, bool &stateBaseAddressDirty, bool &vfeStateDirty) = 0; + virtual uint64_t calculateNewGSH() = 0; virtual uint64_t getScratchPatchAddress() = 0; @@ -55,6 +57,13 @@ class ScratchSpaceController { OsContext &osContext, bool &stateBaseAddressDirty, bool &vfeStateDirty) = 0; + virtual void programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) = 0; protected: MemoryManager *getMemoryManager() const; diff --git a/shared/source/command_stream/scratch_space_controller_base.cpp b/shared/source/command_stream/scratch_space_controller_base.cpp index d9362b5408..574781048e 100644 --- a/shared/source/command_stream/scratch_space_controller_base.cpp +++ b/shared/source/command_stream/scratch_space_controller_base.cpp @@ -90,4 +90,13 @@ void ScratchSpaceControllerBase::programHeaps(HeapContainer &heapContainer, bool &stateBaseAddressDirty, bool &vfeStateDirty) { } + +void ScratchSpaceControllerBase::programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) { +} } // namespace NEO diff --git a/shared/source/command_stream/scratch_space_controller_base.h b/shared/source/command_stream/scratch_space_controller_base.h index d6d6dcb5f7..c3c5ce710b 100644 --- a/shared/source/command_stream/scratch_space_controller_base.h +++ b/shared/source/command_stream/scratch_space_controller_base.h @@ -22,6 +22,7 @@ class ScratchSpaceControllerBase : public ScratchSpaceController { OsContext &osContext, bool &stateBaseAddressDirty, bool &vfeStateDirty) override; + uint64_t calculateNewGSH() override; uint64_t getScratchPatchAddress() override; @@ -34,6 +35,13 @@ class ScratchSpaceControllerBase : public ScratchSpaceController { OsContext &osContext, bool &stateBaseAddressDirty, bool &vfeStateDirty) override; + void programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) override; protected: void createScratchSpaceAllocation(); diff --git a/shared/test/unit_test/scratch_space_controler/CMakeLists.txt b/shared/test/unit_test/scratch_space_controler/CMakeLists.txt new file mode 100644 index 0000000000..7a6e07222b --- /dev/null +++ b/shared/test/unit_test/scratch_space_controler/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/scratch_space_controler_tests.cpp +) + +add_subdirectories() diff --git a/shared/test/unit_test/scratch_space_controler/scratch_space_controler_tests.cpp b/shared/test/unit_test/scratch_space_controler/scratch_space_controler_tests.cpp new file mode 100644 index 0000000000..e0041fe8f1 --- /dev/null +++ b/shared/test/unit_test/scratch_space_controler/scratch_space_controler_tests.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_stream/scratch_space_controller_base.h" +#include "shared/test/unit_test/fixtures/device_fixture.h" +#include "shared/test/unit_test/mocks/mock_command_stream_receiver.h" + +#include "test.h" + +using namespace NEO; + +class MockScratchSpaceControllerBase : public ScratchSpaceControllerBase { + public: + MockScratchSpaceControllerBase(uint32_t rootDeviceIndex, + ExecutionEnvironment &environment, + InternalAllocationStorage &allocationStorage) : ScratchSpaceControllerBase(rootDeviceIndex, environment, allocationStorage) {} + + void programHeaps(HeapContainer &heapContainer, + uint32_t offset, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) override { + ScratchSpaceControllerBase::programHeaps(heapContainer, offset, requiredPerThreadScratchSize, requiredPerThreadPrivateScratchSize, currentTaskCount, osContext, stateBaseAddressDirty, vfeStateDirty); + programHeapsCalled = true; + } + void programBindlessSurfaceStateForScratch(BindlessHeapsHelper *heapsHelper, + uint32_t requiredPerThreadScratchSize, + uint32_t requiredPerThreadPrivateScratchSize, + uint32_t currentTaskCount, + OsContext &osContext, + bool &stateBaseAddressDirty, + bool &vfeStateDirty) override { + ScratchSpaceControllerBase::programBindlessSurfaceStateForScratch(heapsHelper, requiredPerThreadScratchSize, requiredPerThreadPrivateScratchSize, currentTaskCount, osContext, stateBaseAddressDirty, vfeStateDirty); + programBindlessSurfaceStateForScratchCalled = true; + } + bool programHeapsCalled = false; + bool programBindlessSurfaceStateForScratchCalled = false; +}; + +using ScratchComtrolerTests = Test; + +HWTEST_F(ScratchComtrolerTests, givenCommandQueueWhenProgramHeapsCalledThenThenProgramHeapsCalled) { + MockCsrHw2 csr(*pDevice->getExecutionEnvironment(), 0, pDevice->getDeviceBitfield()); + csr.initializeTagAllocation(); + csr.setupContext(*pDevice->getDefaultEngine().osContext); + + ExecutionEnvironment *execEnv = static_cast(pDevice->getExecutionEnvironment()); + std::unique_ptr scratchController = std::make_unique(pDevice->getRootDeviceIndex(), + *execEnv, + *csr.getInternalAllocationStorage()); + + bool gsbaStateDirty = false; + bool frontEndStateDirty = false; + HeapContainer heapContainer; + scratchController->programHeaps(heapContainer, 0, 0, 0, 0, *pDevice->getDefaultEngine().osContext, gsbaStateDirty, frontEndStateDirty); + + EXPECT_TRUE(static_cast(scratchController.get())->programHeapsCalled); +} + +HWTEST_F(ScratchComtrolerTests, givenCommandQueueWhenProgramHeapBindlessCalledThenThenProgramBindlessSurfaceStateForScratchCalled) { + MockCsrHw2 csr(*pDevice->getExecutionEnvironment(), 0, pDevice->getDeviceBitfield()); + csr.initializeTagAllocation(); + csr.setupContext(*pDevice->getDefaultEngine().osContext); + + ExecutionEnvironment *execEnv = static_cast(pDevice->getExecutionEnvironment()); + std::unique_ptr scratchController = std::make_unique(pDevice->getRootDeviceIndex(), + *execEnv, + *csr.getInternalAllocationStorage()); + + bool gsbaStateDirty = false; + bool frontEndStateDirty = false; + HeapContainer heapContainer; + scratchController->programBindlessSurfaceStateForScratch(nullptr, 0, 0, 0, *pDevice->getDefaultEngine().osContext, gsbaStateDirty, frontEndStateDirty); + + EXPECT_TRUE(static_cast(scratchController.get())->programBindlessSurfaceStateForScratchCalled); +} \ No newline at end of file