From 40ecee57334decfc2efff7fee26ac0bcd9e193aa Mon Sep 17 00:00:00 2001 From: Jaime Arteaga Date: Mon, 29 Mar 2021 16:54:52 -0700 Subject: [PATCH] Add environment variable to select L0 timer resolution Signed-off-by: Jaime Arteaga --- level_zero/core/source/device/device_imp.cpp | 6 +++- .../unit_tests/sources/device/test_device.cpp | 36 +++++++++++++++++++ .../test/unit_test/test_files/igdrcl.config | 1 + .../debug_settings/debug_variables_base.inl | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 3b242e6ca0..185636faf4 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -392,7 +392,11 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) pDeviceProperties->numSlices = hardwareInfo.gtSystemInfo.SliceCount * ((this->numSubDevices > 0) ? this->numSubDevices : 1); - pDeviceProperties->timerResolution = this->neoDevice->getDeviceInfo().outProfilingTimerClock; + if (NEO::DebugManager.flags.UseCyclesPerSecondTimer.get() == 0) { + pDeviceProperties->timerResolution = this->neoDevice->getDeviceInfo().outProfilingTimerResolution; + } else { + pDeviceProperties->timerResolution = this->neoDevice->getDeviceInfo().outProfilingTimerClock; + } pDeviceProperties->timestampValidBits = hardwareInfo.capabilityTable.timestampValidBits; diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index e88e20ec5b..f69725743f 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -17,6 +17,7 @@ #include "test.h" #include "level_zero/core/source/cmdqueue/cmdqueue_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/host_pointer_manager.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" @@ -455,6 +456,41 @@ TEST_F(GlobalTimestampTest, whenGetProfilingTimerClockandProfilingTimerResolutio EXPECT_EQ(timerClock, static_cast(1000000000.0 / timerResolution)); } +TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionThenDefaultTimerResolutionInNanoSecondsIsReturned) { + neoDevice->setOSTime(new FalseCpuGpuTime()); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + std::unique_ptr driverHandle = std::make_unique(); + driverHandle->initialize(std::move(devices)); + + double timerResolution = neoDevice->getProfilingTimerResolution(); + EXPECT_NE(timerResolution, 0.0); + + ze_device_properties_t deviceProps = {}; + ze_result_t res = driverHandle.get()->devices[0]->getProperties(&deviceProps); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(deviceProps.timerResolution, static_cast(timerResolution)); +} + +TEST_F(GlobalTimestampTest, whenQueryingForTimerResolutionWithUseCyclesPerSecondTimerSetThenTimerResolutionInCyclesPerSecondsIsReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.UseCyclesPerSecondTimer.set(1u); + + neoDevice->setOSTime(new FalseCpuGpuTime()); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + std::unique_ptr driverHandle = std::make_unique(); + driverHandle->initialize(std::move(devices)); + + uint64_t timerClock = neoDevice->getProfilingTimerClock(); + EXPECT_NE(timerClock, 0u); + + ze_device_properties_t deviceProps = {}; + ze_result_t res = driverHandle.get()->devices[0]->getProperties(&deviceProps); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(deviceProps.timerResolution, timerClock); +} + class FalseCpuTime : public NEO::OSTime { public: bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 24ba82e1ae..eedb89d74f 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -225,3 +225,4 @@ GpuScratchRegWriteRegisterOffset = 0 UseBindlessDebugSip = 0 OverrideSlmAllocationSize = -1 OverrideSlmSize = -1 +UseCyclesPerSecondTimer = 0 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index fe23f126d4..565c6c27ac 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -212,6 +212,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, ForcePipeSupport, -1, "-1: default, 0: disabled, DECLARE_DEBUG_VARIABLE(int32_t, UseAsyncDrmExec, -1, "-1: default, 0: Disabled 1: Enabled. If enabled, pass EXEC_OBJECT_ASYNC to exec ioctl.") DECLARE_DEBUG_VARIABLE(int32_t, UseBindlessMode, -1, "Use precompiled builtins in bindless mode, -1: api dependent, 0: disabled, 1: enabled") DECLARE_DEBUG_VARIABLE(int32_t, OverrideSlmSize, -1, "Force different slm size than default in kB") +DECLARE_DEBUG_VARIABLE(int32_t, UseCyclesPerSecondTimer, 0, "0: default behavior, 0: disabled: Report L0 timer in nanosecond units, 1: enabled: Report L0 timer in cycles per second") /*DRIVER TOGGLES*/ DECLARE_DEBUG_VARIABLE(int32_t, ForceOCLVersion, 0, "Force specific OpenCL API version")