@@ -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 (×tamp->global , timestamp_freq,
158+ device_properties.kernelTimestampValidBits ,
159+ property_type);
151160}
152161
153162double
154163get_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 (×tamp->context , timestamp_freq,
173+ device_properties.kernelTimestampValidBits ,
174+ property_type);
183175}
184176
185177#ifdef ZE_EVENT_QUERY_TIMESTAMPS_EXP_NAME
0 commit comments