diff --git a/opencl/test/unit_test/device/windows/device_windows_tests.cpp b/opencl/test/unit_test/device/windows/device_windows_tests.cpp index c38365e402..18977bb7d3 100644 --- a/opencl/test/unit_test/device/windows/device_windows_tests.cpp +++ b/opencl/test/unit_test/device/windows/device_windows_tests.cpp @@ -6,9 +6,6 @@ */ #include "shared/source/execution_environment/root_device_environment.h" -#include "shared/test/common/mocks/mock_execution_environment.h" -#include "shared/test/common/mocks/mock_ostime.h" -#include "shared/test/common/mocks/mock_ostime_win.h" #include "shared/test/common/mocks/mock_wddm.h" #include "shared/test/common/test_macros/test.h" @@ -18,25 +15,6 @@ using namespace NEO; namespace ULT { -typedef ::testing::Test MockOSTimeWinTest; - -TEST_F(MockOSTimeWinTest, whenCreatingTimerThenResolutionIsSetCorrectly) { - MockExecutionEnvironment executionEnvironment; - RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); - auto wddmMock = new WddmMock(rootDeviceEnvironment); - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - - wddmMock->init(); - - wddmMock->timestampFrequency = 1000; - - std::unique_ptr timeWin(new MockOSTimeWin(wddmMock)); - - double res = 0.0; - res = timeWin->getDynamicDeviceTimerResolution(device->getHardwareInfo()); - EXPECT_EQ(res, 1e+06); -} - TEST(GetDeviceInfo, givenClDeviceWhenGettingDeviceInfoThenCorrectAdapterLuidIsReturned) { auto clDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index b1210f9654..a00c8044e9 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -162,6 +162,7 @@ class HwHelper { virtual uint32_t getAmountOfAllocationsToFill() const = 0; virtual bool isChipsetUniqueUUIDSupported() const = 0; virtual bool isSurfaceFormatSupportedForMediaBlockOperation(NEO::GFX3DSTATE_SURFACEFORMAT format) const = 0; + virtual bool isTimestampShiftRequired() const = 0; protected: HwHelper() = default; @@ -406,6 +407,7 @@ class HwHelperHw : public HwHelper { uint32_t getAmountOfAllocationsToFill() const override; bool isChipsetUniqueUUIDSupported() const override; bool isSurfaceFormatSupportedForMediaBlockOperation(NEO::GFX3DSTATE_SURFACEFORMAT format) const override; + bool isTimestampShiftRequired() const override; protected: static const AuxTranslationMode defaultAuxTranslationMode; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 8a9d10a40a..3dfccff367 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -737,4 +737,9 @@ template bool HwHelperHw::isSurfaceFormatSupportedForMediaBlockOperation(NEO::GFX3DSTATE_SURFACEFORMAT format) const { return true; } + +template +bool HwHelperHw::isTimestampShiftRequired() const { + return true; +} } // namespace NEO diff --git a/shared/source/os_interface/hw_info_config.h b/shared/source/os_interface/hw_info_config.h index 6ec2021d58..ecc2d57959 100644 --- a/shared/source/os_interface/hw_info_config.h +++ b/shared/source/os_interface/hw_info_config.h @@ -60,7 +60,6 @@ class HwInfoConfig { virtual uint64_t getSharedSystemMemCapabilities(const HardwareInfo *hwInfo) = 0; virtual void getKernelExtendedProperties(uint32_t *fp16, uint32_t *fp32, uint32_t *fp64) = 0; virtual std::vector getKernelSupportedThreadArbitrationPolicies() = 0; - virtual void convertTimestampsFromOaToCsDomain(uint64_t ×tampData) = 0; virtual uint32_t getDeviceMemoryMaxClkRate(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) = 0; virtual uint64_t getDeviceMemoryPhysicalSizeInBytes(const OSInterface *osIface, uint32_t subDeviceIndex) = 0; virtual uint64_t getDeviceMemoryMaxBandWidthInBytesPerSecond(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) = 0; @@ -196,7 +195,6 @@ class HwInfoConfigHw : public HwInfoConfig { uint64_t getSharedSystemMemCapabilities(const HardwareInfo *hwInfo) override; void getKernelExtendedProperties(uint32_t *fp16, uint32_t *fp32, uint32_t *fp64) override; std::vector getKernelSupportedThreadArbitrationPolicies() override; - void convertTimestampsFromOaToCsDomain(uint64_t ×tampData) override; uint32_t getDeviceMemoryMaxClkRate(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) override; uint64_t getDeviceMemoryPhysicalSizeInBytes(const OSInterface *osIface, uint32_t subDeviceIndex) override; uint64_t getDeviceMemoryMaxBandWidthInBytesPerSecond(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) override; diff --git a/shared/source/os_interface/hw_info_config.inl b/shared/source/os_interface/hw_info_config.inl index 4248c45aa4..9984e25249 100644 --- a/shared/source/os_interface/hw_info_config.inl +++ b/shared/source/os_interface/hw_info_config.inl @@ -42,9 +42,6 @@ std::vector HwInfoConfigHw::getKernelSupportedThreadArbitra return PreambleHelper::getSupportedThreadArbitrationPolicies(); } -template -void HwInfoConfigHw::convertTimestampsFromOaToCsDomain(uint64_t ×tampData){}; - template void HwInfoConfigHw::adjustPlatformForProductFamily(HardwareInfo *hwInfo) {} diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp index c0b00b424e..00380c4875 100644 --- a/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_drm_or_wddm.cpp @@ -21,9 +21,8 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { TimeStampDataHeader escapeInfo = {}; if (runEscape(wddm, escapeInfo)) { - auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily; - auto *hwInfoConfig = HwInfoConfig::get(productFamily); - hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks); + auto hwInfo = wddm->getRootDeviceEnvironment().getHardwareInfo(); + convertTimestampsFromOaToCsDomain(*hwInfo, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); osTime->getCpuTime(&pGpuCpuTime->CPUTimeinNS); pGpuCpuTime->GPUTimeStamp = (unsigned long long)escapeInfo.m_Data.m_Out.gpuPerfTicks; diff --git a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp index bf8db852b2..2924a1d7c5 100644 --- a/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_gpu_cpu_wddm.cpp @@ -21,9 +21,8 @@ bool DeviceTimeWddm::getCpuGpuTime(TimeStampData *pGpuCpuTime, OSTime *osTime) { TimeStampDataHeader escapeInfo = {}; if (runEscape(wddm, escapeInfo)) { - auto productFamily = wddm->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily; - auto *hwInfoConfig = HwInfoConfig::get(productFamily); - hwInfoConfig->convertTimestampsFromOaToCsDomain(escapeInfo.m_Data.m_Out.gpuPerfTicks); + auto hwInfo = wddm->getRootDeviceEnvironment().getHardwareInfo(); + convertTimestampsFromOaToCsDomain(*hwInfo, escapeInfo.m_Data.m_Out.gpuPerfTicks, escapeInfo.m_Data.m_Out.gpuPerfFreq, static_cast(wddm->getTimestampFrequency())); double cpuNanoseconds = escapeInfo.m_Data.m_Out.cpuPerfTicks * (1000000000.0 / escapeInfo.m_Data.m_Out.cpuPerfFreq); diff --git a/shared/source/os_interface/windows/device_time_wddm.cpp b/shared/source/os_interface/windows/device_time_wddm.cpp index 13f2b3c20f..35faa1ec86 100644 --- a/shared/source/os_interface/windows/device_time_wddm.cpp +++ b/shared/source/os_interface/windows/device_time_wddm.cpp @@ -8,6 +8,7 @@ #include "shared/source/os_interface/windows/device_time_wddm.h" #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/hw_helper.h" #include "shared/source/os_interface/hw_info_config.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/windows/wddm/wddm.h" @@ -70,4 +71,12 @@ uint64_t DeviceTimeWddm::getDynamicDeviceTimerClock(HardwareInfo const &hwInfo) return retVal; } +void DeviceTimeWddm::convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { + auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + + if (hwHelper.isTimestampShiftRequired() && freqCS > 0) { + auto freqRatio = freqOA / freqCS; + timestampData /= freqRatio; + } +}; } // namespace NEO diff --git a/shared/source/os_interface/windows/device_time_wddm.h b/shared/source/os_interface/windows/device_time_wddm.h index cb5f02b00f..af916c9ae2 100644 --- a/shared/source/os_interface/windows/device_time_wddm.h +++ b/shared/source/os_interface/windows/device_time_wddm.h @@ -24,6 +24,7 @@ class DeviceTimeWddm : public DeviceTime { protected: MOCKABLE_VIRTUAL bool runEscape(Wddm *wddm, TimeStampDataHeader &escapeInfo); + void convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS); Wddm *wddm = nullptr; }; diff --git a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl index f3d567b11b..6308a8201e 100644 --- a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl +++ b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl @@ -168,11 +168,6 @@ uint32_t HwInfoConfigHw::computeMaxNeededSubSliceSpace(const Hardwar return maxSubSlice; } -template <> -void HwInfoConfigHw::convertTimestampsFromOaToCsDomain(uint64_t ×tampData) { - timestampData >>= 1; -} - template <> bool HwInfoConfigHw::isFlushTaskAllowed() const { return true; diff --git a/shared/test/common/mocks/mock_hw_info_config.cpp b/shared/test/common/mocks/mock_hw_info_config.cpp index 3752baa5c8..ab04511289 100644 --- a/shared/test/common/mocks/mock_hw_info_config.cpp +++ b/shared/test/common/mocks/mock_hw_info_config.cpp @@ -18,10 +18,6 @@ template <> void HwInfoConfigHw::adjustSamplerState(void *sampler, const HardwareInfo &hwInfo) { } -template <> -void HwInfoConfigHw::convertTimestampsFromOaToCsDomain(uint64_t ×tampData) { -} - template <> uint32_t HwInfoConfigHw::getMaxThreadsForWorkgroupInDSSOrSS(const HardwareInfo &hwInfo, uint32_t maxNumEUsPerSubSlice, uint32_t maxNumEUsPerDualSubSlice) const { return 0; diff --git a/shared/test/common/mocks/mock_ostime_win.h b/shared/test/common/mocks/mock_ostime_win.h index 5e83589eaa..916bcb6242 100644 --- a/shared/test/common/mocks/mock_ostime_win.h +++ b/shared/test/common/mocks/mock_ostime_win.h @@ -10,10 +10,16 @@ #include "shared/source/os_interface/windows/os_time_win.h" namespace NEO { +struct MockDeviceTimeWddm : DeviceTimeWddm { + using DeviceTimeWddm::convertTimestampsFromOaToCsDomain; +}; class MockOSTimeWin : public OSTimeWin { public: MockOSTimeWin(Wddm *wddm) { this->deviceTime = std::make_unique(wddm); } + void convertTimestampsFromOaToCsDomain(HardwareInfo const &hwInfo, uint64_t ×tampData, uint64_t freqOA, uint64_t freqCS) { + static_cast(this->deviceTime.get())->convertTimestampsFromOaToCsDomain(hwInfo, timestampData, freqOA, freqCS); + } }; } // namespace NEO diff --git a/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp b/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp index c4a3044c1e..29910c5193 100644 --- a/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp +++ b/shared/test/unit_test/device/windows/neo_device_windows_tests.cpp @@ -9,8 +9,11 @@ #include "shared/source/os_interface/windows/wddm/wddm.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/raii_hw_helper.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_ostime_win.h" #include "shared/test/common/mocks/mock_wddm.h" -#include "shared/test/common/test_macros/test.h" +#include "shared/test/common/test_macros/hw_test.h" using DeviceTest = Test; @@ -55,3 +58,69 @@ TEST_F(DeviceTest, GivenDeviceWhenGetAdapterMaskThenMaskIsSet) { EXPECT_EQ(nodeMask, 1u); } + +typedef ::testing::Test MockOSTimeWinTest; + +TEST_F(MockOSTimeWinTest, whenCreatingTimerThenResolutionIsSetCorrectly) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddmMock = new WddmMock(rootDeviceEnvironment); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + wddmMock->init(); + + wddmMock->timestampFrequency = 1000; + + std::unique_ptr timeWin(new MockOSTimeWin(wddmMock)); + + double res = 0.0; + res = timeWin->getDynamicDeviceTimerResolution(device->getHardwareInfo()); + EXPECT_EQ(res, 1e+06); +} + +template +class TestMockHwHelper : public HwHelperHw { + public: + bool isTimestampShiftRequired() const override { + return shiftRequired; + } + uint32_t shiftRequired = true; +}; + +HWTEST_F(MockOSTimeWinTest, whenConvertingTimestampsToCsDomainThenTimestampDataAreSetCorrectly) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); + auto wddmMock = new WddmMock(rootDeviceEnvironment); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + wddmMock->init(); + auto hwInfo = wddmMock->getRootDeviceEnvironment().getHardwareInfo(); + RAIIHwHelperFactory> hwHelperBackup{hwInfo->platform.eRenderCoreFamily}; + std::unique_ptr timeWin(new MockOSTimeWin(wddmMock)); + uint64_t timestampData = 0x1234; + uint64_t freqOA = 1; + uint64_t freqCS = 0; + auto expectedGpuTicksWhenNotChange = timestampData; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); + freqCS = 1; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); + freqOA = 2; + uint64_t ratio = freqOA / freqCS; + auto expectedGpuTicksWhenRatioBiggerThanOne = timestampData / ratio; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenRatioBiggerThanOne, timestampData); + + hwHelperBackup.mockHwHelper.shiftRequired = false; + freqOA = 1; + freqCS = 0; + expectedGpuTicksWhenNotChange = timestampData; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); + freqCS = 1; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); + freqOA = 2; + timeWin->convertTimestampsFromOaToCsDomain(*hwInfo, timestampData, freqOA, freqCS); + EXPECT_EQ(expectedGpuTicksWhenNotChange, timestampData); +} \ No newline at end of file diff --git a/shared/test/unit_test/os_interface/hw_info_config_tests.cpp b/shared/test/unit_test/os_interface/hw_info_config_tests.cpp index 6d9f57700d..788878dac3 100644 --- a/shared/test/unit_test/os_interface/hw_info_config_tests.cpp +++ b/shared/test/unit_test/os_interface/hw_info_config_tests.cpp @@ -196,14 +196,6 @@ TEST_F(HwInfoConfigTest, givenInvalidHwInfoWhenParsingHwInfoConfigThenErrorIsRet EXPECT_FALSE(success); } -HWTEST_F(HwInfoConfigTest, whenConvertingTimestampsToCsDomainThenNothingIsChanged) { - auto hwInfoConfig = HwInfoConfig::get(pInHwInfo.platform.eProductFamily); - uint64_t timestampData = 0x1234; - uint64_t initialData = timestampData; - hwInfoConfig->convertTimestampsFromOaToCsDomain(timestampData); - EXPECT_EQ(initialData, timestampData); -} - HWTEST_F(HwInfoConfigTest, whenOverrideGfxPartitionLayoutForWslThenReturnFalse) { auto hwInfoConfig = HwInfoConfig::get(pInHwInfo.platform.eProductFamily); EXPECT_FALSE(hwInfoConfig->overrideGfxPartitionLayoutForWsl()); diff --git a/shared/test/unit_test/xe_hpg_core/dg2/hw_info_config_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/hw_info_config_tests_dg2.cpp index 9ac9435477..982b70009c 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/hw_info_config_tests_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/hw_info_config_tests_dg2.cpp @@ -19,16 +19,6 @@ using namespace NEO; using HwInfoConfigTestDg2 = ::testing::Test; -DG2TEST_F(HwInfoConfigTestDg2, whenConvertingTimestampsToCsDomainThenGpuTicksAreShifted) { - auto hwInfoConfig = HwInfoConfig::get(defaultHwInfo->platform.eProductFamily); - uint64_t gpuTicks = 0x12345u; - - auto expectedGpuTicks = gpuTicks >> 1; - - hwInfoConfig->convertTimestampsFromOaToCsDomain(gpuTicks); - EXPECT_EQ(expectedGpuTicks, gpuTicks); -} - DG2TEST_F(HwInfoConfigTestDg2, givenDg2ConfigWhenSetupHardwareInfoBaseThenGtSystemInfoIsCorrect) { HardwareInfo hwInfo = *defaultHwInfo; GT_SYSTEM_INFO >SystemInfo = hwInfo.gtSystemInfo;