Skip to content

Commit 2d86b7f

Browse files
authored
refactor: expose timestamp calculation to common function (#298)
Signed-off-by: Kozlowski, Marek <[email protected]>
1 parent f11bee5 commit 2d86b7f

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

utils/test_harness/include/test_harness/test_harness_event.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void destroy_event(ze_event_handle_t event);
8383
void destroy_event_pool(ze_event_pool_handle_t event_pool);
8484
ze_kernel_timestamp_result_t
8585
get_event_kernel_timestamp(ze_event_handle_t event);
86+
double get_timestamp_time(const ze_kernel_timestamp_data_t *timestamp,
87+
uint64_t timer_resolution,
88+
uint64_t kernel_timestamp_valid_bits,
89+
const ze_structure_type_t property_type =
90+
ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES);
8691
double
8792
get_timestamp_global_duration(const ze_kernel_timestamp_result_t *timestamp,
8893
const ze_device_handle_t &device,

utils/test_harness/src/test_harness_event.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,12 @@ void get_event_kernel_timestamps_from_mapped_timestamp_event(
118118
zeEventQueryKernelTimestampsExt(event, device, &count, &properties));
119119
}
120120

121-
double
122-
get_timestamp_global_duration(const ze_kernel_timestamp_result_t *timestamp,
123-
const ze_device_handle_t &device,
124-
const ze_driver_handle_t driver,
125-
const ze_structure_type_t property_type) {
126-
127-
double global_time_ns;
128-
auto device_properties = lzt::get_device_properties(device, property_type);
129-
uint64_t timestamp_freq = device_properties.timerResolution;
130-
uint64_t timestamp_max_val =
131-
~(-1L << device_properties.kernelTimestampValidBits);
121+
double get_timestamp_time(const ze_kernel_timestamp_data_t *timestamp,
122+
uint64_t timer_resolution,
123+
uint64_t kernel_timestamp_valid_bits,
124+
const ze_structure_type_t property_type) {
125+
uint64_t timestamp_freq = timer_resolution;
126+
uint64_t timestamp_max_val = ~(-1L << kernel_timestamp_valid_bits);
132127

133128
double timer_period = 0;
134129
if (property_type == ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES) {
@@ -138,48 +133,45 @@ get_timestamp_global_duration(const ze_kernel_timestamp_result_t *timestamp,
138133
} else {
139134
LOG_ERROR << "INVALID DEVICE_PROPERTY_TYPE";
140135
}
141-
142-
global_time_ns =
143-
(timestamp->global.kernelEnd >= timestamp->global.kernelStart)
144-
? (timestamp->global.kernelEnd - timestamp->global.kernelStart) *
145-
timer_period
146-
: ((timestamp_max_val - timestamp->global.kernelStart) +
147-
timestamp->global.kernelEnd + 1) *
136+
const auto time_ns =
137+
(timestamp->kernelEnd >= timestamp->kernelStart)
138+
? (timestamp->kernelEnd - timestamp->kernelStart) * timer_period
139+
: ((timestamp_max_val - timestamp->kernelStart) +
140+
timestamp->kernelEnd + 1) *
148141
timer_period;
149142

150-
return global_time_ns;
143+
return time_ns;
144+
}
145+
146+
double
147+
get_timestamp_global_duration(const ze_kernel_timestamp_result_t *timestamp,
148+
const ze_device_handle_t &device,
149+
const ze_driver_handle_t driver,
150+
const ze_structure_type_t property_type) {
151+
152+
auto device_properties = lzt::get_device_properties(device, property_type);
153+
uint64_t timestamp_freq = device_properties.timerResolution;
154+
uint64_t timestamp_max_val =
155+
~(-1L << device_properties.kernelTimestampValidBits);
156+
157+
return lzt::get_timestamp_time(&timestamp->global, timestamp_freq,
158+
device_properties.kernelTimestampValidBits,
159+
property_type);
151160
}
152161

153162
double
154163
get_timestamp_context_duration(const ze_kernel_timestamp_result_t *timestamp,
155164
const ze_device_handle_t &device,
156165
const ze_driver_handle_t driver,
157166
const ze_structure_type_t property_type) {
158-
159-
double context_time_ns;
160167
auto device_properties = lzt::get_device_properties(device, property_type);
161168
uint64_t timestamp_freq = device_properties.timerResolution;
162169
uint64_t timestamp_max_val =
163170
~(-1L << device_properties.kernelTimestampValidBits);
164171

165-
double timer_period = 0;
166-
if (property_type == ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES) {
167-
timer_period = (1000000000.0 / static_cast<double>(timestamp_freq));
168-
} else if (property_type == ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2) {
169-
timer_period = static_cast<double>(timestamp_freq);
170-
} else {
171-
LOG_ERROR << "INVALID DEVICE_PROPERTY_TYPE";
172-
}
173-
174-
context_time_ns =
175-
(timestamp->context.kernelEnd >= timestamp->context.kernelStart)
176-
? (timestamp->context.kernelEnd - timestamp->context.kernelStart) *
177-
timer_period
178-
: ((timestamp_max_val - timestamp->context.kernelStart) +
179-
timestamp->context.kernelEnd + 1) *
180-
timer_period;
181-
182-
return context_time_ns;
172+
return lzt::get_timestamp_time(&timestamp->context, timestamp_freq,
173+
device_properties.kernelTimestampValidBits,
174+
property_type);
183175
}
184176

185177
#ifdef ZE_EVENT_QUERY_TIMESTAMPS_EXP_NAME

0 commit comments

Comments
 (0)