diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index ad1a862aca..3b242e6ca0 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -392,7 +392,7 @@ 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().outProfilingTimerResolution; + pDeviceProperties->timerResolution = this->neoDevice->getDeviceInfo().outProfilingTimerClock; pDeviceProperties->timestampValidBits = hardwareInfo.capabilityTable.timestampValidBits; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 51adba8914..95b8ebe178 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -75,7 +75,7 @@ NEO::SVMAllocsManager *DriverHandleImp::getSvmAllocsManager() { } ze_result_t DriverHandleImp::getApiVersion(ze_api_version_t *version) { - *version = ZE_API_VERSION_1_0; + *version = ZE_API_VERSION_1_1; return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/black_box_tests/zello_timestamp.cpp b/level_zero/core/test/black_box_tests/zello_timestamp.cpp index 0b32bfd11c..0ab6912b94 100644 --- a/level_zero/core/test/black_box_tests/zello_timestamp.cpp +++ b/level_zero/core/test/black_box_tests/zello_timestamp.cpp @@ -236,7 +236,8 @@ bool testKernelTimestampHostQuery(ze_context_handle_t &context, << " Kernel start: " << std::dec << kernelTsResults.context.kernelStart << " cycles\n" << " Kernel end: " << std::dec << kernelTsResults.context.kernelEnd << " cycles\n" << " Global end: " << std::dec << kernelTsResults.global.kernelEnd << " cycles\n" - << " Kernel duration : " << std::dec << kernelDuration << " cycles, " << kernelDuration * timerResolution << " ns\n"; + << " timerResolution clock: " << std::dec << timerResolution << " cycles/s\n" + << " Kernel duration : " << std::dec << kernelDuration << " cycles, " << kernelDuration * (1000000000.0 / static_cast(timerResolution)) << " ns\n"; // Cleanup SUCCESS_OR_TERMINATE(zeMemFree(context, dstBuffer)); @@ -342,7 +343,8 @@ bool testKernelTimestampApendQuery(ze_context_handle_t &context, << " Kernel start: " << std::dec << kernelTsResults->context.kernelStart << " cycles\n" << " Kernel end: " << std::dec << kernelTsResults->context.kernelEnd << " cycles\n" << " Global end: " << std::dec << kernelTsResults->global.kernelEnd << " cycles\n" - << " Kernel duration : " << std::dec << kernelDuration << " cycles, " << kernelDuration * timerResolution << " ns\n"; + << " timerResolution clock: " << std::dec << timerResolution << " cycles/s\n" + << " Kernel duration : " << std::dec << kernelDuration << " cycles, " << kernelDuration * (1000000000.0 / static_cast(timerResolution)) << " ns\n"; // Cleanup SUCCESS_OR_TERMINATE(zeMemFree(context, dstBuffer)); 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 144c0da802..e88e20ec5b 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 @@ -401,6 +401,9 @@ class FalseCpuGpuTime : public NEO::OSTime { double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { return NEO::OSTime::getDeviceTimerResolution(hwInfo); } + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override { + return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); + } uint64_t getCpuRawTimestamp() override { return 0; } @@ -438,6 +441,20 @@ TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuGpuTimeIsFalseR EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); } +TEST_F(GlobalTimestampTest, whenGetProfilingTimerClockandProfilingTimerResolutionThenVerifyRelation) { + neoDevice->setOSTime(new FalseCpuGpuTime()); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique>(); + driverHandle->initialize(std::move(devices)); + + uint64_t timerClock = neoDevice->getProfilingTimerClock(); + EXPECT_NE(timerClock, 0u); + double timerResolution = neoDevice->getProfilingTimerResolution(); + EXPECT_NE(timerResolution, 0.0); + EXPECT_EQ(timerClock, static_cast(1000000000.0 / timerResolution)); +} + class FalseCpuTime : public NEO::OSTime { public: bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { @@ -452,6 +469,9 @@ class FalseCpuTime : public NEO::OSTime { double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { return NEO::OSTime::getDeviceTimerResolution(hwInfo); } + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override { + return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); + } uint64_t getCpuRawTimestamp() override { return 0; } diff --git a/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl b/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl index 22f443575f..61b2edb83e 100644 --- a/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl +++ b/opencl/test/unit_test/gen12lp/profiling_tests_gen12lp.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -91,6 +91,10 @@ class MyOSTime : public OSTime { EXPECT_FALSE(true); return 1.0; } + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override { + EXPECT_FALSE(true); + return 0; + } bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { EXPECT_FALSE(true); return false; diff --git a/opencl/test/unit_test/mocks/mock_ostime.h b/opencl/test/unit_test/mocks/mock_ostime.h index 23d72efdfd..6fb775b505 100644 --- a/opencl/test/unit_test/mocks/mock_ostime.h +++ b/opencl/test/unit_test/mocks/mock_ostime.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,6 +27,9 @@ class MockOSTime : public OSTime { double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { return OSTime::getDeviceTimerResolution(hwInfo); } + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override { + return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); + } uint64_t getCpuRawTimestamp() override { return 0; } diff --git a/opencl/test/unit_test/os_interface/linux/os_time_test.cpp b/opencl/test/unit_test/os_interface/linux/os_time_test.cpp index a92678e240..b322dbadbb 100644 --- a/opencl/test/unit_test/os_interface/linux/os_time_test.cpp +++ b/opencl/test/unit_test/os_interface/linux/os_time_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -195,6 +195,31 @@ TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenIoctlFailsThenDefaultRes EXPECT_DOUBLE_EQ(result, defaultResolution); } +TEST_F(DrmTimeTest, givenGetDynamicDeviceTimerClockWhenIoctlFailsThenDefaultClockIsReturned) { + auto defaultResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution; + + auto drm = new DrmMockCustom(); + osTime->updateDrm(drm); + + drm->getParamRetValue = 0; + drm->ioctl_res = -1; + + auto result = osTime->getDynamicDeviceTimerClock(*defaultHwInfo); + auto expectedResult = static_cast(1000000000.0 / defaultResolution); + EXPECT_DOUBLE_EQ(result, expectedResult); +} + +TEST_F(DrmTimeTest, givenGetDynamicDeviceTimerClockWhenIoctlSucceedsThenNonDefaultClockIsReturned) { + auto drm = new DrmMockCustom(); + osTime->updateDrm(drm); + + uint64_t frequency = 1500; + drm->getParamRetValue = static_cast(frequency); + + auto result = osTime->getDynamicDeviceTimerClock(*defaultHwInfo); + EXPECT_EQ(result, frequency); +} + TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenNoDrmThenDefaultResolutionIsReturned) { osTime->updateDrm(nullptr); diff --git a/opencl/test/unit_test/profiling/profiling_tests.cpp b/opencl/test/unit_test/profiling/profiling_tests.cpp index 6e506b320e..43fd65f5f0 100644 --- a/opencl/test/unit_test/profiling/profiling_tests.cpp +++ b/opencl/test/unit_test/profiling/profiling_tests.cpp @@ -436,6 +436,10 @@ class MyOSTime : public OSTime { EXPECT_FALSE(true); return 1.0; } + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override { + EXPECT_FALSE(true); + return 0; + } bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { EXPECT_FALSE(true); return false; diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 9d219cfe86..9735c8d155 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -208,6 +208,10 @@ double Device::getProfilingTimerResolution() { return osTime->getDynamicDeviceTimerResolution(getHardwareInfo()); } +uint64_t Device::getProfilingTimerClock() { + return osTime->getDynamicDeviceTimerClock(getHardwareInfo()); +} + bool Device::isSimulation() const { auto &hwInfo = getHardwareInfo(); diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 586429ea75..d41c6c1c19 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -64,6 +64,7 @@ class Device : public ReferenceTrackedObject { GmmClientContext *getGmmClientContext() const; OSTime *getOSTime() const { return osTime.get(); }; double getProfilingTimerResolution(); + uint64_t getProfilingTimerClock(); double getPlatformHostTimerResolution() const; bool isSimulation() const; GFXCORE_FAMILY getRenderCoreFamily() const; diff --git a/shared/source/device/device_caps.cpp b/shared/source/device/device_caps.cpp index aec1c6cb93..eb699a92bd 100644 --- a/shared/source/device/device_caps.cpp +++ b/shared/source/device/device_caps.cpp @@ -71,6 +71,9 @@ void Device::initializeCaps() { deviceInfo.profilingTimerResolution = getProfilingTimerResolution(); if (DebugManager.flags.OverrideProfilingTimerResolution.get() != -1) { deviceInfo.profilingTimerResolution = static_cast(DebugManager.flags.OverrideProfilingTimerResolution.get()); + deviceInfo.outProfilingTimerClock = static_cast(1000000000.0 / deviceInfo.profilingTimerResolution); + } else { + deviceInfo.outProfilingTimerClock = static_cast(getProfilingTimerClock()); } deviceInfo.outProfilingTimerResolution = static_cast(deviceInfo.profilingTimerResolution); diff --git a/shared/source/device/device_info.h b/shared/source/device/device_info.h index c979fb20a8..63b1398068 100644 --- a/shared/source/device/device_info.h +++ b/shared/source/device/device_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,6 +30,7 @@ struct DeviceInfo { size_t maxWorkGroupSize; size_t maxWorkItemSizes[3]; size_t outProfilingTimerResolution; + size_t outProfilingTimerClock; size_t printfBufferSize; uint32_t addressBits; uint32_t computeUnitsUsedForScratch; diff --git a/shared/source/os_interface/linux/os_time_linux.cpp b/shared/source/os_interface/linux/os_time_linux.cpp index 9e5954b3c2..8cda24548a 100644 --- a/shared/source/os_interface/linux/os_time_linux.cpp +++ b/shared/source/os_interface/linux/os_time_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -155,6 +155,22 @@ double OSTimeLinux::getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) return OSTime::getDeviceTimerResolution(hwInfo); } +uint64_t OSTimeLinux::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const { + if (pDrm) { + drm_i915_getparam_t getParam = {}; + int frequency = 0; + + getParam.param = I915_PARAM_CS_TIMESTAMP_FREQUENCY; + getParam.value = &frequency; + auto error = pDrm->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam); + + if (!error) { + return static_cast(frequency); + } + } + return static_cast(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo)); +} + uint64_t OSTimeLinux::getCpuRawTimestamp() { uint64_t timesInNsec = 0; uint64_t ticksInNsec = 0; diff --git a/shared/source/os_interface/linux/os_time_linux.h b/shared/source/os_interface/linux/os_time_linux.h index 42fa068b9a..ff6f7e21b1 100644 --- a/shared/source/os_interface/linux/os_time_linux.h +++ b/shared/source/os_interface/linux/os_time_linux.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,6 +30,7 @@ class OSTimeLinux : public OSTime { bool getGpuTimeSplitted(uint64_t *timestamp); double getHostTimerResolution() const override; double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override; + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override; uint64_t getCpuRawTimestamp() override; protected: diff --git a/shared/source/os_interface/os_time.h b/shared/source/os_interface/os_time.h index 1a92273587..93081e8835 100644 --- a/shared/source/os_interface/os_time.h +++ b/shared/source/os_interface/os_time.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,6 +29,7 @@ class OSTime { virtual bool getCpuGpuTime(TimeStampData *pGpuCpuTime) = 0; virtual double getHostTimerResolution() const = 0; virtual double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const = 0; + virtual uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const = 0; virtual uint64_t getCpuRawTimestamp() = 0; OSInterface *getOSInterface() const { return osInterface; diff --git a/shared/source/os_interface/windows/os_time_win.cpp b/shared/source/os_interface/windows/os_time_win.cpp index fc1f524f57..b88d4a593b 100644 --- a/shared/source/os_interface/windows/os_time_win.cpp +++ b/shared/source/os_interface/windows/os_time_win.cpp @@ -107,6 +107,15 @@ double OSTimeWin::getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) co return retVal; } +uint64_t OSTimeWin::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const { + uint64_t retVal = 0u; + if (wddm) { + retVal = static_cast(wddm->getTimestampFrequency()); + } + + return retVal; +} + uint64_t OSTimeWin::getCpuRawTimestamp() { LARGE_INTEGER cpuRawTimestamp = {}; this->QueryPerfomanceCounterFnc(&cpuRawTimestamp); diff --git a/shared/source/os_interface/windows/os_time_win.h b/shared/source/os_interface/windows/os_time_win.h index 45d0c8fd2b..514ad77c99 100644 --- a/shared/source/os_interface/windows/os_time_win.h +++ b/shared/source/os_interface/windows/os_time_win.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,6 +22,7 @@ class OSTimeWin : public OSTime { bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override; double getHostTimerResolution() const override; double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override; + uint64_t getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) const override; uint64_t getCpuRawTimestamp() override; protected: