Apply timerResolution mod for L0 V1.1

Signed-off-by: John Falkowski <john.falkowski@intel.com>
This commit is contained in:
John Falkowski
2021-03-24 13:57:46 -04:00
committed by Compute-Runtime-Automation
parent 85f93cd51b
commit 218387dd47
17 changed files with 107 additions and 12 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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<double>(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<double>(timerResolution)) << " ns\n";
// Cleanup
SUCCESS_OR_TERMINATE(zeMemFree(context, dstBuffer));

View File

@ -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<uint64_t>(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<NEO::Device>(neoDevice));
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
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<uint64_t>(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<uint64_t>(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo));
}
uint64_t getCpuRawTimestamp() override {
return 0;
}

View File

@ -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;

View File

@ -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<uint64_t>(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo));
}
uint64_t getCpuRawTimestamp() override {
return 0;
}

View File

@ -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<uint64_t>(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<int>(frequency);
auto result = osTime->getDynamicDeviceTimerClock(*defaultHwInfo);
EXPECT_EQ(result, frequency);
}
TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenNoDrmThenDefaultResolutionIsReturned) {
osTime->updateDrm(nullptr);

View File

@ -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;

View File

@ -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();

View File

@ -64,6 +64,7 @@ class Device : public ReferenceTrackedObject<Device> {
GmmClientContext *getGmmClientContext() const;
OSTime *getOSTime() const { return osTime.get(); };
double getProfilingTimerResolution();
uint64_t getProfilingTimerClock();
double getPlatformHostTimerResolution() const;
bool isSimulation() const;
GFXCORE_FAMILY getRenderCoreFamily() const;

View File

@ -71,6 +71,9 @@ void Device::initializeCaps() {
deviceInfo.profilingTimerResolution = getProfilingTimerResolution();
if (DebugManager.flags.OverrideProfilingTimerResolution.get() != -1) {
deviceInfo.profilingTimerResolution = static_cast<double>(DebugManager.flags.OverrideProfilingTimerResolution.get());
deviceInfo.outProfilingTimerClock = static_cast<size_t>(1000000000.0 / deviceInfo.profilingTimerResolution);
} else {
deviceInfo.outProfilingTimerClock = static_cast<size_t>(getProfilingTimerClock());
}
deviceInfo.outProfilingTimerResolution = static_cast<size_t>(deviceInfo.profilingTimerResolution);

View File

@ -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;

View File

@ -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<uint64_t>(frequency);
}
}
return static_cast<uint64_t>(1000000000.0 / OSTime::getDeviceTimerResolution(hwInfo));
}
uint64_t OSTimeLinux::getCpuRawTimestamp() {
uint64_t timesInNsec = 0;
uint64_t ticksInNsec = 0;

View File

@ -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:

View File

@ -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;

View File

@ -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<uint64_t>(wddm->getTimestampFrequency());
}
return retVal;
}
uint64_t OSTimeWin::getCpuRawTimestamp() {
LARGE_INTEGER cpuRawTimestamp = {};
this->QueryPerfomanceCounterFnc(&cpuRawTimestamp);

View File

@ -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: