Update zello_timestamp test

This patch updates zello_timestamp for
1. add parameter to choose test
2. Fix testKernelTimestampMapToHostTimescale test to use timestamp
with lower range for calculations

Related-To: LOCI-3360

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2022-10-10 14:57:47 +00:00
committed by Compute-Runtime-Automation
parent 809abb005f
commit fc0f600fd2
3 changed files with 77 additions and 28 deletions

View File

@@ -42,6 +42,23 @@ int getParamValue(int argc, char *argv[], const char *shortName, const char *lon
return defaultValue; return defaultValue;
} }
const char *getParamValue(int argc, char *argv[], const char *shortName, const char *longName, const char *defaultString) {
char **arg = &argv[1];
char **argE = &argv[argc];
for (; arg != argE; ++arg) {
if ((0 == strcmp(*arg, shortName)) || (0 == strcmp(*arg, longName))) {
arg++;
if (arg == argE) {
break;
}
return *arg;
}
}
return defaultString;
}
bool isCircularDepTest(int argc, char *argv[]) { bool isCircularDepTest(int argc, char *argv[]) {
bool enabled = isParamEnabled(argc, argv, "-c", "--circular"); bool enabled = isParamEnabled(argc, argv, "-c", "--circular");
if (enabled == false) { if (enabled == false) {

View File

@@ -50,6 +50,8 @@ bool isParamEnabled(int argc, char *argv[], const char *shortName, const char *l
int getParamValue(int argc, char *argv[], const char *shortName, const char *longName, int defaultValue); int getParamValue(int argc, char *argv[], const char *shortName, const char *longName, int defaultValue);
const char *getParamValue(int argc, char *argv[], const char *shortName, const char *longName, const char *defaultString);
bool isCircularDepTest(int argc, char *argv[]); bool isCircularDepTest(int argc, char *argv[]);
bool isVerbose(int argc, char *argv[]); bool isVerbose(int argc, char *argv[]);

View File

@@ -7,6 +7,9 @@
#include "zello_common.h" #include "zello_common.h"
#include <functional>
#include <map>
inline std::vector<uint8_t> loadBinaryFile(const std::string &filePath) { inline std::vector<uint8_t> loadBinaryFile(const std::string &filePath) {
std::ifstream stream(filePath, std::ios::binary); std::ifstream stream(filePath, std::ios::binary);
if (!stream.good()) { if (!stream.good()) {
@@ -55,7 +58,8 @@ void createCmdQueueAndCmdList(ze_context_handle_t &context,
SUCCESS_OR_TERMINATE(zeCommandListCreate(context, device, &cmdListDesc, &cmdList)); SUCCESS_OR_TERMINATE(zeCommandListCreate(context, device, &cmdListDesc, &cmdList));
} }
bool testWriteGlobalTimestamp(ze_context_handle_t &context, bool testWriteGlobalTimestamp(int argc, char *argv[],
ze_context_handle_t &context,
ze_driver_handle_t &driver, ze_driver_handle_t &driver,
ze_device_handle_t &device) { ze_device_handle_t &device) {
constexpr size_t allocSize = 4096; constexpr size_t allocSize = 4096;
@@ -124,7 +128,8 @@ bool testWriteGlobalTimestamp(ze_context_handle_t &context,
return true; return true;
} }
bool testKernelTimestampHostQuery(ze_context_handle_t &context, bool testKernelTimestampHostQuery(int argc, char *argv[],
ze_context_handle_t &context,
ze_driver_handle_t &driver, ze_driver_handle_t &driver,
ze_device_handle_t &device) { ze_device_handle_t &device) {
@@ -228,9 +233,9 @@ bool testKernelTimestampHostQuery(ze_context_handle_t &context,
return true; return true;
} }
bool testKernelTimestampApendQuery(ze_context_handle_t &context, bool testKernelTimestampAppendQuery(ze_context_handle_t &context,
ze_device_handle_t &device, ze_device_handle_t &device,
ze_device_properties_t devProperties) { ze_device_properties_t devProperties) {
ze_command_queue_handle_t cmdQueue; ze_command_queue_handle_t cmdQueue;
ze_command_list_handle_t cmdList; ze_command_list_handle_t cmdList;
@@ -348,8 +353,34 @@ bool testKernelTimestampApendQuery(ze_context_handle_t &context,
return true; return true;
} }
bool testKernelTimestampAppendQueryWithDeviceProperties(int argc, char *argv[],
ze_context_handle_t &context,
ze_driver_handle_t &driver,
ze_device_handle_t &device) {
bool result;
std::string currentTest;
bool aubMode = isAubMode(argc, argv);
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
SUCCESS_OR_TERMINATE(zeDeviceGetProperties(device, &deviceProperties));
printDeviceProperties(deviceProperties);
currentTest = "Test Append Write of Global Timestamp: Default Device Properties Structure";
deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
result = testKernelTimestampAppendQuery(context, device, deviceProperties);
if (result || aubMode) {
currentTest = "Test Append Write of Global Timestamp: V1.2 (and later) Device Properties Structure";
deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2};
result = testKernelTimestampAppendQuery(context, device, deviceProperties);
}
return result;
}
bool testKernelTimestampMapToHostTimescale(int argc, char *argv[], bool testKernelTimestampMapToHostTimescale(int argc, char *argv[],
ze_context_handle_t &context, ze_context_handle_t &context,
ze_driver_handle_t &driver,
ze_device_handle_t &device) { ze_device_handle_t &device) {
ze_command_queue_handle_t cmdQueue; ze_command_queue_handle_t cmdQueue;
@@ -442,8 +473,8 @@ bool testKernelTimestampMapToHostTimescale(int argc, char *argv[],
std::cout << "TimestampMaxValueInCycles: " << timestampMaxValueInCycles << " | validBits : " << devProperties.timestampValidBits << "\n"; std::cout << "TimestampMaxValueInCycles: " << timestampMaxValueInCycles << " | validBits : " << devProperties.timestampValidBits << "\n";
std::cout << "timerResolution: " << devProperties.timerResolution << "\n"; std::cout << "timerResolution: " << devProperties.timerResolution << "\n";
auto convertDeviceTsToNanoseconds = [&devProperties](uint64_t deviceTs) { auto convertDeviceTsToNanoseconds = [&devProperties, &kernelTimestampMaxValueInCycles](uint64_t deviceTs) {
return static_cast<uint64_t>(deviceTs * devProperties.timerResolution); return static_cast<uint64_t>((deviceTs & kernelTimestampMaxValueInCycles) * devProperties.timerResolution);
}; };
auto getDuration = [](uint64_t startTs, uint64_t endTs, uint32_t timestampValidBits) { auto getDuration = [](uint64_t startTs, uint64_t endTs, uint32_t timestampValidBits) {
@@ -521,31 +552,30 @@ int main(int argc, char *argv[]) {
const std::string blackBoxName("Zello Timestamp"); const std::string blackBoxName("Zello Timestamp");
verbose = isVerbose(argc, argv); verbose = isVerbose(argc, argv);
bool aubMode = isAubMode(argc, argv); bool aubMode = isAubMode(argc, argv);
using testFunction = std::function<bool(int, char *[],
ze_context_handle_t &,
ze_driver_handle_t &,
ze_device_handle_t &)>;
ze_context_handle_t context = nullptr; std::map<std::string, testFunction> supportedTests{};
auto devices = zelloInitContextAndGetDevices(context); supportedTests["testKernelTimestampMapToHostTimescale"] = testKernelTimestampMapToHostTimescale;
auto device = devices[0]; supportedTests["testKernelTimestampAppendQueryWithDeviceProperties"] = testKernelTimestampAppendQueryWithDeviceProperties;
supportedTests["testWriteGlobalTimestamp"] = testWriteGlobalTimestamp;
supportedTests["testKernelTimestampHostQuery"] = testKernelTimestampHostQuery;
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; const char *defaultString = "testKernelTimestampAppendQueryWithDeviceProperties";
SUCCESS_OR_TERMINATE(zeDeviceGetProperties(device, &deviceProperties)); const char *test = getParamValue(argc, argv, "-t", "--test", defaultString);
printDeviceProperties(deviceProperties); bool result = false;
if (supportedTests.find(test) != supportedTests.end()) {
ze_context_handle_t context = nullptr;
ze_driver_handle_t driverHandle = nullptr;
auto devices = zelloInitContextAndGetDevices(context, driverHandle);
auto device = devices[0];
bool result; result = supportedTests[test](argc, argv, context, driverHandle, device);
std::string currentTest; SUCCESS_OR_TERMINATE(zeContextDestroy(context));
printResult(aubMode, result, blackBoxName, test);
currentTest = "Test Append Write of Global Timestamp: Default Device Properties Structure";
deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
result = testKernelTimestampApendQuery(context, device, deviceProperties);
printResult(aubMode, result, blackBoxName, currentTest);
if (result || aubMode) {
currentTest = "Test Append Write of Global Timestamp: V1.2 (and later) Device Properties Structure";
deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2};
result = testKernelTimestampApendQuery(context, device, deviceProperties);
printResult(aubMode, result, blackBoxName, currentTest);
} }
SUCCESS_OR_TERMINATE(zeContextDestroy(context));
result = aubMode ? true : result; result = aubMode ? true : result;
return result ? 0 : 1; return result ? 0 : 1;
} }