From 31250b343f3f2bb3094d0515c737035b5a257128 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Thu, 22 Jul 2021 15:27:05 +0000 Subject: [PATCH] TSP: Move packetsUsed member out of GraphicsAllocation Signed-off-by: Bartosz Dunajski --- level_zero/core/source/event/event.h | 13 ++++++++++++- level_zero/core/source/event/event_impl.inl | 2 +- .../helpers/timestamp_packet_1_tests.cpp | 9 ++++----- .../unit_test/profiling/profiling_tests.cpp | 4 ++-- .../utilities/tag_allocator_tests.cpp | 6 ------ shared/source/helpers/timestamp_packet.h | 7 +------ shared/source/utilities/tag_allocator.h | 9 ++++----- shared/source/utilities/tag_allocator.inl | 19 ------------------- 8 files changed, 24 insertions(+), 45 deletions(-) diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 1af0e9da10..15cb031a2b 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -92,8 +92,19 @@ struct Event : _ze_event_handle_t { bool isTimestampEvent = false; }; +template +class KernelTimestampsData : public NEO::TimestampPackets { + public: + uint32_t getPacketsUsed() const { return packetsUsed; } + void setPacketsUsed(uint32_t value) { packetsUsed = value; } + + protected: + uint32_t packetsUsed = 1; +}; + template struct EventImp : public Event { + EventImp(EventPool *eventPool, int index, Device *device) : device(device), index(index), eventPool(eventPool) {} @@ -124,7 +135,7 @@ struct EventImp : public Event { size_t getGlobalEndOffset() const override { return NEO::TimestampPackets::getGlobalEndOffset(); } size_t getSinglePacketSize() const override { return NEO::TimestampPackets::getSinglePacketSize(); }; - std::unique_ptr[]> kernelTimestampsData; + std::unique_ptr[]> kernelTimestampsData; Device *device; int index; diff --git a/level_zero/core/source/event/event_impl.inl b/level_zero/core/source/event/event_impl.inl index dab9cc30c6..80266c2b20 100644 --- a/level_zero/core/source/event/event_impl.inl +++ b/level_zero/core/source/event/event_impl.inl @@ -15,7 +15,7 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device * if (eventPool->isEventPoolTimestampFlagSet()) { event->setEventTimestampFlag(true); - event->kernelTimestampsData = std::make_unique[]>(EventPacketsCount::maxKernelSplit); + event->kernelTimestampsData = std::make_unique[]>(EventPacketsCount::maxKernelSplit); } auto alloc = eventPool->getAllocation().getGraphicsAllocation(device->getNEODevice()->getRootDeviceIndex()); diff --git a/opencl/test/unit_test/helpers/timestamp_packet_1_tests.cpp b/opencl/test/unit_test/helpers/timestamp_packet_1_tests.cpp index bfd38db3be..7e2b09f8e5 100644 --- a/opencl/test/unit_test/helpers/timestamp_packet_1_tests.cpp +++ b/opencl/test/unit_test/helpers/timestamp_packet_1_tests.cpp @@ -48,10 +48,10 @@ HWTEST_F(TimestampPacketTests, givenTagNodeWithPacketsUsed2WhenSemaphoreIsProgra using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; TimestampPackets tag; - tag.setPacketsUsed(2); MockTagNode mockNode; mockNode.tagForCpuAccess = &tag; mockNode.gpuAddress = 0x1230000; + mockNode.setPacketsUsed(2); auto &cmdStream = mockCmdQ->getCS(0); TimestampPacketHelper::programSemaphore(cmdStream, mockNode); @@ -59,7 +59,7 @@ HWTEST_F(TimestampPacketTests, givenTagNodeWithPacketsUsed2WhenSemaphoreIsProgra HardwareParse hwParser; hwParser.parseCommands(cmdStream, 0); auto it = hwParser.cmdList.begin(); - for (uint32_t packetId = 0; packetId < tag.getPacketsUsed(); packetId++) { + for (uint32_t packetId = 0; packetId < mockNode.getPacketsUsed(); packetId++) { verifySemaphore(genCmdCast(*it++), &mockNode, packetId); } } @@ -137,7 +137,7 @@ TEST_F(TimestampPacketSimpleTests, whenNewTagIsTakenThenReinitialize) { EXPECT_EQ(1u, packet.contextEnd); EXPECT_EQ(1u, packet.globalEnd); } - EXPECT_EQ(1u, firstNode->tagForCpuAccess->getPacketsUsed()); + EXPECT_EQ(1u, firstNode->getPacketsUsed()); } TEST_F(TimestampPacketSimpleTests, whenObjectIsCreatedThenInitializeAllStamps) { @@ -150,7 +150,6 @@ TEST_F(TimestampPacketSimpleTests, whenObjectIsCreatedThenInitializeAllStamps) { EXPECT_EQ(1u, packet.contextEnd); EXPECT_EQ(1u, packet.globalEnd); } - EXPECT_EQ(1u, timestampPacketStorage.getPacketsUsed()); } HWTEST_F(TimestampPacketTests, givenCommandStreamReceiverHwWhenObtainingPreferredTagPoolSizeThenReturnCorrectValue) { @@ -421,7 +420,7 @@ HWTEST_F(TimestampPacketTests, whenEstimatingSizeForNodeDependencyThenReturnCorr size_t sizeForNodeDependency = 0; sizeForNodeDependency += TimestampPacketHelper::getRequiredCmdStreamSizeForNodeDependency(mockNode); - size_t expectedSize = mockNode.tagForCpuAccess->getPacketsUsed() * sizeof(typename FamilyType::MI_SEMAPHORE_WAIT); + size_t expectedSize = mockNode.getPacketsUsed() * sizeof(typename FamilyType::MI_SEMAPHORE_WAIT); EXPECT_EQ(expectedSize, sizeForNodeDependency); } diff --git a/opencl/test/unit_test/profiling/profiling_tests.cpp b/opencl/test/unit_test/profiling/profiling_tests.cpp index 89c793a9e7..0578ec1200 100644 --- a/opencl/test/unit_test/profiling/profiling_tests.cpp +++ b/opencl/test/unit_test/profiling/profiling_tests.cpp @@ -1142,9 +1142,9 @@ struct ProfilingTimestampPacketsTest : public ::testing::Test { void addTimestampNodeMultiOsContext(uint32_t globalStart[16], uint32_t globalEnd[16], uint32_t contextStart[16], uint32_t contextEnd[16], uint32_t size) { auto node = new MockTagNode>(); auto timestampPacketStorage = new TimestampPackets(); - timestampPacketStorage->setPacketsUsed(size); + node->setPacketsUsed(size); - for (uint32_t i = 0u; i < timestampPacketStorage->getPacketsUsed(); ++i) { + for (uint32_t i = 0u; i < node->getPacketsUsed(); ++i) { uint32_t values[4] = {contextStart[i], globalStart[i], contextEnd[i], globalEnd[i]}; timestampPacketStorage->assignDataToAllTimestamps(i, values); diff --git a/opencl/test/unit_test/utilities/tag_allocator_tests.cpp b/opencl/test/unit_test/utilities/tag_allocator_tests.cpp index ce1226c254..d3fdce16ee 100644 --- a/opencl/test/unit_test/utilities/tag_allocator_tests.cpp +++ b/opencl/test/unit_test/utilities/tag_allocator_tests.cpp @@ -25,7 +25,6 @@ struct TagAllocatorTest : public Test { class MockTimestampPackets32 : public TimestampPackets { public: void setTagToReadyState() { - auto packetsUsed = getPacketsUsed(); initialize(); uint32_t zeros[4] = {}; @@ -33,7 +32,6 @@ struct TagAllocatorTest : public Test { for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) { assignDataToAllTimestamps(i, zeros); } - setPacketsUsed(packetsUsed); } void setToNonReadyState() { @@ -553,8 +551,6 @@ TEST_F(TagAllocatorTest, givenNotSupportedTagTypeWhenCallingMethodThenAbortOrRet EXPECT_ANY_THROW(perfCounterNode.getGlobalEndValue(0)); EXPECT_ANY_THROW(perfCounterNode.getContextCompleteRef()); EXPECT_ANY_THROW(perfCounterNode.getGlobalEndRef()); - EXPECT_ANY_THROW(perfCounterNode.setPacketsUsed(0)); - EXPECT_ANY_THROW(perfCounterNode.getPacketsUsed()); EXPECT_ANY_THROW(perfCounterNode.getSinglePacketSize()); EXPECT_ANY_THROW(perfCounterNode.assignDataToAllTimestamps(0, nullptr)); } @@ -566,8 +562,6 @@ TEST_F(TagAllocatorTest, givenNotSupportedTagTypeWhenCallingMethodThenAbortOrRet EXPECT_ANY_THROW(hwTimestampNode.getContextStartOffset()); EXPECT_ANY_THROW(hwTimestampNode.getContextEndOffset()); EXPECT_ANY_THROW(hwTimestampNode.getGlobalEndOffset()); - EXPECT_ANY_THROW(hwTimestampNode.setPacketsUsed(0)); - EXPECT_ANY_THROW(hwTimestampNode.getPacketsUsed()); EXPECT_ANY_THROW(hwTimestampNode.getSinglePacketSize()); EXPECT_ANY_THROW(hwTimestampNode.assignDataToAllTimestamps(0, nullptr)); EXPECT_ANY_THROW(hwTimestampNode.getQueryHandleRef()); diff --git a/shared/source/helpers/timestamp_packet.h b/shared/source/helpers/timestamp_packet.h index 11710a0bb7..954c4abb1d 100644 --- a/shared/source/helpers/timestamp_packet.h +++ b/shared/source/helpers/timestamp_packet.h @@ -55,7 +55,6 @@ class TimestampPackets : public TagTypeBase { packet.contextEnd = 1u; packet.globalEnd = 1u; } - packetsUsed = 1; } void assignDataToAllTimestamps(uint32_t packetIndex, void *source) { @@ -72,16 +71,12 @@ class TimestampPackets : public TagTypeBase { uint64_t getContextEndValue(uint32_t packetIndex) const { return static_cast(packets[packetIndex].contextEnd); } uint64_t getGlobalEndValue(uint32_t packetIndex) const { return static_cast(packets[packetIndex].globalEnd); } - void setPacketsUsed(uint32_t used) { packetsUsed = used; } - uint32_t getPacketsUsed() const { return packetsUsed; } - protected: Packet packets[TimestampPacketSizeControl::preferredPacketCount]; - uint32_t packetsUsed = 1; }; #pragma pack() -static_assert(((4 * TimestampPacketSizeControl::preferredPacketCount + 1) * sizeof(uint32_t)) == sizeof(TimestampPackets), +static_assert(((4 * TimestampPacketSizeControl::preferredPacketCount) * sizeof(uint32_t)) == sizeof(TimestampPackets), "This structure is consumed by GPU and has to follow specific restrictions for padding and size"); class TimestampPacketContainer : public NonCopyableClass { diff --git a/shared/source/utilities/tag_allocator.h b/shared/source/utilities/tag_allocator.h index 46174199aa..26f59336e0 100644 --- a/shared/source/utilities/tag_allocator.h +++ b/shared/source/utilities/tag_allocator.h @@ -72,8 +72,8 @@ class TagNodeBase : public NonCopyableOrMovableClass { virtual uint64_t &getGlobalEndRef() const = 0; virtual uint64_t &getContextCompleteRef() const = 0; - virtual void setPacketsUsed(uint32_t used) = 0; - virtual uint32_t getPacketsUsed() const = 0; + void setPacketsUsed(uint32_t used) { packetsUsed = used; }; + uint32_t getPacketsUsed() const { return packetsUsed; }; virtual size_t getSinglePacketSize() const = 0; @@ -87,6 +87,7 @@ class TagNodeBase : public NonCopyableOrMovableClass { MultiGraphicsAllocation *gfxAllocation = nullptr; uint64_t gpuAddress = 0; std::atomic refCount{0}; + uint32_t packetsUsed = 1; bool doNotReleaseNodes = false; bool profilingCapable = true; @@ -104,6 +105,7 @@ class TagNode : public TagNodeBase, public IDNode> { void initialize() override { tagForCpuAccess->initialize(); + packetsUsed = 1; setProfilingCapable(true); } @@ -124,9 +126,6 @@ class TagNode : public TagNodeBase, public IDNode> { uint64_t &getGlobalEndRef() const override; uint64_t &getContextCompleteRef() const override; - void setPacketsUsed(uint32_t used) override; - uint32_t getPacketsUsed() const override; - size_t getSinglePacketSize() const override; MetricsLibraryApi::QueryHandle_1_0 &getQueryHandleRef() const override; diff --git a/shared/source/utilities/tag_allocator.inl b/shared/source/utilities/tag_allocator.inl index 8f2839d138..0eb8666e59 100644 --- a/shared/source/utilities/tag_allocator.inl +++ b/shared/source/utilities/tag_allocator.inl @@ -222,25 +222,6 @@ uint64_t &TagNode::getGlobalEndRef() const { } } -template -void TagNode::setPacketsUsed(uint32_t used) { - if constexpr (TagType::getTagNodeType() == TagNodeType::TimestampPacket) { - return tagForCpuAccess->setPacketsUsed(used); - } else { - UNUSED_VARIABLE(used); - UNRECOVERABLE_IF(true); - } -} - -template -uint32_t TagNode::getPacketsUsed() const { - if constexpr (TagType::getTagNodeType() == TagNodeType::TimestampPacket) { - return tagForCpuAccess->getPacketsUsed(); - } else { - UNRECOVERABLE_IF(true); - } -} - template size_t TagNode::getSinglePacketSize() const { if constexpr (TagType::getTagNodeType() == TagNodeType::TimestampPacket) {