diff --git a/level_zero/api/core/ze_device_api_entrypoints.h b/level_zero/api/core/ze_device_api_entrypoints.h index a7261f2a9e..512a4bdfa6 100644 --- a/level_zero/api/core/ze_device_api_entrypoints.h +++ b/level_zero/api/core/ze_device_api_entrypoints.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -108,7 +108,7 @@ ze_result_t zeDeviceGetGlobalTimestamps( ze_device_handle_t hDevice, uint64_t *hostTimestamp, uint64_t *deviceTimestamp) { - return L0::Device::fromHandle(hDevice)->getGlobalTimestamps(hostTimestamp, deviceTimestamp); + return L0::Device::fromHandle(hDevice)->getGlobalTimestamps(hostTimestamp, deviceTimestamp, true); } ze_result_t zeDeviceReserveCacheExt( diff --git a/level_zero/core/source/device/device.h b/level_zero/core/source/device/device.h index 09f1bad4af..39f54f9d2f 100644 --- a/level_zero/core/source/device/device.h +++ b/level_zero/core/source/device/device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -87,7 +87,7 @@ struct Device : _ze_device_handle_t { virtual ze_result_t imageGetProperties(const ze_image_desc_t *desc, ze_image_properties_t *pImageProperties) = 0; virtual ze_result_t getDeviceImageProperties(ze_device_image_properties_t *pDeviceImageProperties) = 0; virtual ze_result_t getExternalMemoryProperties(ze_device_external_memory_properties_t *pExternalMemoryProperties) = 0; - virtual ze_result_t getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp) = 0; + virtual ze_result_t getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp, const bool useSubmissionMethod) = 0; virtual ze_result_t getCommandQueueGroupProperties(uint32_t *pCount, ze_command_queue_group_properties_t *pCommandQueueGroupProperties) = 0; diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 54ce4c4f7b..b869d5e0ef 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1092,14 +1092,18 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) return ZE_RESULT_SUCCESS; } -ze_result_t DeviceImp::getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp) { +ze_result_t DeviceImp::getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp, const bool useSubmissionMethod) { - bool method = 0; - if (NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get() != -1) { - method = NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get(); + bool getGlobalTimestampUsingSubmissionMethod = true; + + if (!useSubmissionMethod) { + // It needs to be set as false because if `useSubmissionMethod` is false then it takes precedence to the debug variable `EnableGlobalTimestampViaSubmission`. + getGlobalTimestampUsingSubmissionMethod = false; + } else if (NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get() != -1) { + getGlobalTimestampUsingSubmissionMethod = !!NEO::debugManager.flags.EnableGlobalTimestampViaSubmission.get(); } - if (method == 0) { + if (!getGlobalTimestampUsingSubmissionMethod) { auto ret = getGlobalTimestampsUsingOsInterface(hostTimestamp, deviceTimestamp); if (ret != ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) { return ret; diff --git a/level_zero/core/source/device/device_imp.h b/level_zero/core/source/device/device_imp.h index 3758b22c81..0674d086f5 100644 --- a/level_zero/core/source/device/device_imp.h +++ b/level_zero/core/source/device/device_imp.h @@ -71,7 +71,7 @@ struct DeviceImp : public Device, NEO::NonCopyableOrMovableClass { ze_result_t getCommandQueueGroupProperties(uint32_t *pCount, ze_command_queue_group_properties_t *pCommandQueueGroupProperties) override; ze_result_t getExternalMemoryProperties(ze_device_external_memory_properties_t *pExternalMemoryProperties) override; - ze_result_t getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp) override; + ze_result_t getGlobalTimestamps(uint64_t *hostTimestamp, uint64_t *deviceTimestamp, const bool useSubmissionMethod) override; ze_result_t getDebugProperties(zet_device_debug_properties_t *pDebugProperties) override; ze_result_t systemBarrier() override; diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index 6f9530f631..29d474fa1f 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -569,7 +569,7 @@ NEO::GraphicsAllocation *Event::getAllocation(Device *device) const { void Event::setGpuStartTimestamp() { if (isEventTimestampFlagSet()) { - this->device->getGlobalTimestamps(&cpuStartTimestamp, &gpuStartTimestamp); + this->device->getGlobalTimestamps(&cpuStartTimestamp, &gpuStartTimestamp, false); cpuStartTimestamp = cpuStartTimestamp / this->device->getNEODevice()->getDeviceInfo().outProfilingTimerResolution; } } diff --git a/level_zero/core/test/unit_tests/mocks/mock_device.h b/level_zero/core/test/unit_tests/mocks/mock_device.h index 279f8d0758..aa8fa147a3 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_device.h +++ b/level_zero/core/test/unit_tests/mocks/mock_device.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -48,7 +48,7 @@ struct MockDevice : public Device { ADDMETHOD_NOBASE(getCommandQueueGroupProperties, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCount, ze_command_queue_group_properties_t *pCommandQueueGroupProperties)); ADDMETHOD_NOBASE(getDeviceImageProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_image_properties_t * pDeviceImageProperties)); ADDMETHOD_NOBASE(getExternalMemoryProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_external_memory_properties_t * pExternalMemoryProperties)); - ADDMETHOD_NOBASE(getGlobalTimestamps, ze_result_t, ZE_RESULT_SUCCESS, (uint64_t * hostTimestamp, uint64_t *deviceTimestamp)); + ADDMETHOD_NOBASE(getGlobalTimestamps, ze_result_t, ZE_RESULT_SUCCESS, (uint64_t * hostTimestamp, uint64_t *deviceTimestamp, const bool useSubmissionMethod)); ADDMETHOD_NOBASE(systemBarrier, ze_result_t, ZE_RESULT_SUCCESS, ()); ADDMETHOD_NOBASE(getRootDevice, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_handle_t * phRootDevice)); // Runtime internal methods diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp index 5d4542ea57..7a15178107 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1244,6 +1244,10 @@ HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndCpuMemcpyWitho } HWTEST2_F(AppendMemoryLockedCopyTest, givenImmediateCommandListAndTimestampFlagSetWhenCpuMemcpyThenSetCorrectGpuTimestamps, MatchAny) { + + // This test is design for testing timestamp when using the Os Interface + debugManager.flags.EnableGlobalTimestampViaSubmission.set(0); + ze_command_queue_desc_t queueDesc = {}; auto queue = std::make_unique>(device, device->getNEODevice()->getDefaultEngine().commandStreamReceiver, &queueDesc); MockAppendMemoryLockedCopyTestImmediateCmdList cmdList; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp index 515b8b09e4..99ae5002a9 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_1.cpp @@ -5037,6 +5037,7 @@ HWTEST2_F(InOrderCmdListTests, givenAubModeWhenSyncCalledAlwaysPollForCompletion } HWTEST2_F(InOrderCmdListTests, givenProfilingEventWhenDoingCpuCopyThenSetProfilingData, IsAtLeastXeHpCore) { + auto immCmdList = createImmCmdList(); immCmdList->copyThroughLockedPtrEnabled = true; diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index eb89b20083..ed480c9cb3 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -1692,20 +1692,20 @@ TEST_F(DeviceTest, givenInvalidPciBusInfoWhenPciPropertiesIsCalledThenUninitiali } } -TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithOsInterfaceThenSuccessIsReturnedAndValuesSetCorrectly) { +TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithOsInterfaceViaDebugVariableThenSuccessIsReturnedAndValuesSetCorrectly) { uint64_t hostTs = 0u; uint64_t deviceTs = 0u; debugManager.flags.EnableGlobalTimestampViaSubmission.set(0); - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(0u, hostTs); EXPECT_NE(0u, deviceTs); } -TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithSubmissionThenSuccessIsReturned) { +TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithSubmissionViaDebugVariableThenSuccessIsReturned) { debugManager.flags.EnableGlobalTimestampViaSubmission.set(1); @@ -1713,12 +1713,28 @@ TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithSubmissionThenSuccessIsRetu uint64_t deviceTs = 0u; // First time to hit the if case of initialization of internal structures. - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(0u, hostTs); // Second time to hit the false case for initialization of internal structures as they are already initialized. - result = device->getGlobalTimestamps(&hostTs, &deviceTs); + result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_NE(0u, hostTs); +} + +TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledWithUseSubmissionAsTrueThenSuccessIsReturned) { + + uint64_t hostTs = 0u; + uint64_t deviceTs = 0u; + + // First time to hit the if case of initialization of internal structures. + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_NE(0u, hostTs); + + // Second time to hit the false case for initialization of internal structures as they are already initialized. + result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(0u, hostTs); } @@ -1736,7 +1752,7 @@ TEST_F(DeviceTest, givenAppendWriteGlobalTimestampFailsWhenGetGlobalTimestampsUs uint64_t deviceTs = 0u; // First time to hit the if case of initialization of internal structures. - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(0u, hostTs); @@ -1750,7 +1766,7 @@ TEST_F(DeviceTest, givenAppendWriteGlobalTimestampFailsWhenGetGlobalTimestampsUs L0::CommandList::fromHandle(deviceImp->globalTimestampCommandList)->appendWriteGlobalTimestamp(nullptr, nullptr, 0, nullptr); - result = device->getGlobalTimestamps(&hostTs, &deviceTs); + result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); // Swap back the command list. @@ -1789,7 +1805,7 @@ TEST_F(DeviceTest, givenCreateHostUnifiedMemoryAllocationFailsWhenGetGlobalTimes uint64_t hostTs = 0u; uint64_t deviceTs = 0u; - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); mockDriverHandleImp->setSVMAllocsManager(nullptr); @@ -1820,6 +1836,7 @@ struct GlobalTimestampTest : public ::testing::Test { }; TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetGpuCpuTimeIsDeviceLostReturnError) { + uint64_t hostTs = 0u; uint64_t deviceTs = 0u; @@ -1830,7 +1847,7 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetGpuCpuTimeIsDevice driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, false); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); } @@ -1846,7 +1863,7 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetGpuCpuTimeIsUnsupp uint64_t hostTs = 0u; uint64_t deviceTs = 0u; - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); } @@ -1972,11 +1989,12 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampsUsingSubmissionAndGetCpuTimeH uint64_t hostTs = 0u; uint64_t deviceTs = 0u; - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, true); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); } TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuTimeIsFalseReturnArbitraryValues) { + uint64_t hostTs = 0u; uint64_t deviceTs = 0u; @@ -1987,14 +2005,14 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuTimeIsFalseRetu driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(0u, hostTs); EXPECT_NE(0u, deviceTs); } TEST_F(DeviceTest, givenPrintGlobalTimestampIsSetWhenGetGlobalTimestampIsCalledThenOutputStringIsAsExpected) { - DebugManagerStateRestore restorer; + debugManager.flags.PrintGlobalTimestampInNs.set(true); uint64_t hostTs = 0u; uint64_t deviceTs = 0u; @@ -2011,7 +2029,7 @@ TEST_F(DeviceTest, givenPrintGlobalTimestampIsSetWhenGetGlobalTimestampIsCalledT capabilityTable.kernelTimestampValidBits = 32; testing::internal::CaptureStdout(); - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); std::string output = testing::internal::GetCapturedStdout(); // Considering kernelTimestampValidBits(32) @@ -2042,7 +2060,7 @@ TEST_F(DeviceTest, givenPrintGlobalTimestampIsSetAnd64bitTimestampWhenGetGlobalT uint64_t deviceTs = 0u; testing::internal::CaptureStdout(); - ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); std::string output = testing::internal::GetCapturedStdout(); const std::string expectedString("Host timestamp in ns : 0 | Device timestamp in ns : " + diff --git a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp index 9862c52216..ea4258ab10 100644 --- a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp +++ b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -348,7 +348,7 @@ ze_result_t getDeviceTimestamps(DeviceImp *deviceImp, const ze_bool_t synchroniz uint64_t hostTimestamp; uint64_t deviceTimestamp; - result = deviceImp->getGlobalTimestamps(&hostTimestamp, &deviceTimestamp); + result = deviceImp->getGlobalTimestamps(&hostTimestamp, &deviceTimestamp, false); if (result != ZE_RESULT_SUCCESS) { *globalTimestamp = 0; *metricTimestamp = 0; diff --git a/level_zero/tools/source/metrics/metric_oa_enumeration_imp.cpp b/level_zero/tools/source/metrics/metric_oa_enumeration_imp.cpp index 8be0a1dac2..a96b20e2c1 100644 --- a/level_zero/tools/source/metrics/metric_oa_enumeration_imp.cpp +++ b/level_zero/tools/source/metrics/metric_oa_enumeration_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1001,7 +1001,7 @@ ze_result_t OaMetricGroupImp::getMetricTimestampsExp(const ze_bool_t synchronize uint64_t hostTimestamp; uint64_t deviceTimestamp; - result = deviceImp->getGlobalTimestamps(&hostTimestamp, &deviceTimestamp); + result = deviceImp->getGlobalTimestamps(&hostTimestamp, &deviceTimestamp, false); if (result != ZE_RESULT_SUCCESS) { *globalTimestamp = 0; *metricTimestamp = 0; diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 232ab6b0f5..fe91c7d5c3 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -672,7 +672,7 @@ DECLARE_DEBUG_VARIABLE(int64_t, ReadOnlyAllocationsTypeMask, 0, "0: default, >0 DECLARE_DEBUG_VARIABLE(bool, IgnoreZebinUnknownAttributes, false, "enable to treat unknown zebin attributes as warning instead of error"); DECLARE_DEBUG_VARIABLE(int64_t, FinalizerInputType, 0, "0: default (N/A), input type for finalizer") DECLARE_DEBUG_VARIABLE(std::string, FinalizerLibraryName, std::string("unk"), "Library name for finalizer") -DECLARE_DEBUG_VARIABLE(int32_t, EnableGlobalTimestampViaSubmission, -1, "-1: OS Interface, 0: OS Interface, 1: Submission. This flag sets the type of method to get timestamp for getGlobalTimestamps"); +DECLARE_DEBUG_VARIABLE(int32_t, EnableGlobalTimestampViaSubmission, -1, "-1: default (submission method), 0: os interface method, 1: submission method. This flag sets the type of method to get timestamp for getGlobalTimestamps"); /* Binary Cache */ DECLARE_DEBUG_VARIABLE(bool, BinaryCacheTrace, false, "enable cl_cache to produce .trace files with information about hash computation")