From 8b267fd949172f84984def63319b7fd3ff52034e Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Fri, 31 Jul 2020 10:34:29 +0200 Subject: [PATCH] Use global timestamps for TimestampPacket profiling calculations Change-Id: I53ffe566b78c1b86cf430c23e0c0bb9000532b0c Signed-off-by: Bartosz Dunajski --- opencl/source/event/event.cpp | 40 +++++-------------- .../unit_test/profiling/profiling_tests.cpp | 20 +++++----- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/opencl/source/event/event.cpp b/opencl/source/event/event.cpp index ab9709e77f..6f2c4e0771 100644 --- a/opencl/source/event/event.cpp +++ b/opencl/source/event/event.cpp @@ -253,7 +253,6 @@ bool Event::calcProfilingData() { if (!dataCalculated && !profilingCpuPath) { if (timestampPacketContainer && timestampPacketContainer->peekNodes().size() > 0) { const auto timestamps = timestampPacketContainer->peekNodes(); - auto isMultiOsContextCapable = this->getCommandQueue()->getGpgpuCommandStreamReceiver().isMultiOsContextCapable(); if (DebugManager.flags.PrintTimestampPacketContents.get()) { for (auto i = 0u; i < timestamps.size(); i++) { @@ -268,41 +267,22 @@ bool Event::calcProfilingData() { } } - if (isMultiOsContextCapable) { - auto globalStartTS = timestamps[0]->tagForCpuAccess->packets[0].globalStart; - uint64_t globalEndTS = timestamps[0]->tagForCpuAccess->packets[0].globalEnd; + uint64_t globalStartTS = timestamps[0]->tagForCpuAccess->packets[0].globalStart; + uint64_t globalEndTS = timestamps[0]->tagForCpuAccess->packets[0].globalEnd; - for (const auto ×tamp : timestamps) { - for (auto i = 0u; i < timestamp->tagForCpuAccess->packetsUsed; ++i) { - const auto &packet = timestamp->tagForCpuAccess->packets[i]; - if (globalStartTS > packet.globalStart) { - globalStartTS = packet.globalStart; - } - if (globalEndTS < packet.globalEnd) { - globalEndTS = packet.globalEnd; - } - } - } - calculateProfilingDataInternal(globalStartTS, globalEndTS, &globalEndTS, globalStartTS); - } else { - auto contextStartTS = timestamps[0]->tagForCpuAccess->packets[0].contextStart; - uint64_t contextEndTS = timestamps[0]->tagForCpuAccess->packets[0].contextEnd; - auto globalStartTS = timestamps[0]->tagForCpuAccess->packets[0].globalStart; - - for (const auto ×tamp : timestamps) { - const auto &packet = timestamp->tagForCpuAccess->packets[0]; - if (contextStartTS > packet.contextStart) { - contextStartTS = packet.contextStart; - } - if (contextEndTS < packet.contextEnd) { - contextEndTS = packet.contextEnd; - } + for (const auto ×tamp : timestamps) { + for (auto i = 0u; i < timestamp->tagForCpuAccess->packetsUsed; ++i) { + const auto &packet = timestamp->tagForCpuAccess->packets[i]; if (globalStartTS > packet.globalStart) { globalStartTS = packet.globalStart; } + if (globalEndTS < packet.globalEnd) { + globalEndTS = packet.globalEnd; + } } - calculateProfilingDataInternal(contextStartTS, contextEndTS, &contextEndTS, globalStartTS); } + calculateProfilingDataInternal(globalStartTS, globalEndTS, &globalEndTS, globalStartTS); + } else if (timeStampNode) { calculateProfilingDataInternal( timeStampNode->tagForCpuAccess->ContextStartTS, diff --git a/opencl/test/unit_test/profiling/profiling_tests.cpp b/opencl/test/unit_test/profiling/profiling_tests.cpp index d43535c7c8..efbfdec1c2 100644 --- a/opencl/test/unit_test/profiling/profiling_tests.cpp +++ b/opencl/test/unit_test/profiling/profiling_tests.cpp @@ -1033,7 +1033,7 @@ struct ProfilingTimestampPacketsTest : public ::testing::Test { ev->timestampPacketContainer = std::make_unique(); } - void addTimestampNode(int contextStart, int contextEnd, int globalStart) { + void addTimestampNode(int contextStart, int contextEnd, int globalStart, int globalEnd) { auto node = new MockTagNode(); auto timestampPacketStorage = new TimestampPacketStorage(); node->tagForCpuAccess = timestampPacketStorage; @@ -1041,6 +1041,7 @@ struct ProfilingTimestampPacketsTest : public ::testing::Test { timestampPacketStorage->packets[0].contextStart = contextStart; timestampPacketStorage->packets[0].contextEnd = contextEnd; timestampPacketStorage->packets[0].globalStart = globalStart; + timestampPacketStorage->packets[0].globalEnd = globalEnd; ev->timestampPacketContainer->add(node); } @@ -1082,20 +1083,21 @@ struct ProfilingTimestampPacketsTest : public ::testing::Test { }; TEST_F(ProfilingTimestampPacketsTest, givenTimestampsPacketContainerWithOneElementAndTimestampNodeWhenCalculatingProfilingThenTimesAreTakenFromPacket) { - addTimestampNode(10, 11, 12); + addTimestampNode(10, 11, 12, 13); HwTimeStamps hwTimestamps; hwTimestamps.ContextStartTS = 100; hwTimestamps.ContextEndTS = 110; hwTimestamps.GlobalStartTS = 120; + MockTagNode hwTimestampsNode; hwTimestampsNode.tagForCpuAccess = &hwTimestamps; ev->timeStampNode = &hwTimestampsNode; ev->calcProfilingData(); - EXPECT_EQ(10u, ev->getStartTimeStamp()); - EXPECT_EQ(11u, ev->getEndTimeStamp()); + EXPECT_EQ(12u, ev->getStartTimeStamp()); + EXPECT_EQ(13u, ev->getEndTimeStamp()); EXPECT_EQ(12u, ev->getGlobalStartTimestamp()); ev->timeStampNode = nullptr; @@ -1153,14 +1155,14 @@ TEST_F(ProfilingTimestampPacketsTest, givenPrintTimestampPacketContentsSetWhenCa } TEST_F(ProfilingTimestampPacketsTest, givenTimestampsPacketContainerWithThreeElementsWhenCalculatingProfilingThenTimesAreTakenFromProperPacket) { - addTimestampNode(10, 11, 12); - addTimestampNode(1, 21, 22); - addTimestampNode(5, 31, 2); + addTimestampNode(10, 11, 12, 13); + addTimestampNode(1, 21, 22, 13); + addTimestampNode(5, 31, 2, 13); ev->calcProfilingData(); - EXPECT_EQ(1u, ev->getStartTimeStamp()); - EXPECT_EQ(31u, ev->getEndTimeStamp()); + EXPECT_EQ(2u, ev->getStartTimeStamp()); + EXPECT_EQ(13u, ev->getEndTimeStamp()); EXPECT_EQ(2u, ev->getGlobalStartTimestamp()); }