Event Query Kernel Timestamps Extension

Event Query Kernel Timestamps Extension

API

Event Query Kernel Timestamps

This extension enables the querying of synchronized event timestamps.

  • Synchronized event timestamps are device timestamps synchronized to the host time domain.

Notes

ze_device_properties_t devProps;
ze_event_query_kernel_timestamps_ext_properties_t tsProps;

devProps.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
devProps.pNext = &tsProps;

tsProps.stype = ZE_STRUCTURE_TYPE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_PROPERTIES;
tsProps.pNext = nullptr;

// Determine the level of support by getting the module properties
zeDeviceGetProperties(hDevice, &devProps);

const bool supportsKernelTimestamps = (0 != (tsProps.flags & ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_FLAG_KERNEL));
const bool supportsSynchronizedTimestamps = (0 != (tsProps.flags & ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_FLAG_SYNCHRONIZED));

// Assumption: hEvent was created with ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP

// ...
// launch kernel
// synchronize host
// ...

if (supportsKernelTimestamps || supportsSynchronizedTimestamps) {
    // Number of event timestamps
    uint32_t count = 0;

    // Get the number of timestamps associated with the event.
    zeEventQueryKernelTimestampsExt(hEvent, hDevice, &count, nullptr);

    // Allocate storage for kernel timestamp results
    std::vector<ze_kernel_timestamp_result_t> kernelTimestamps(count);

    // Allocate storage for synchronized timestamp results
    std::vector<ze_synchronized_timestamp_result_ext_t> synchronizedTimestamps(count);

    // Build event query kernel timestamps descriptors
    ze_event_query_kernel_timestamps_results_ext_properties_t resultsProps;

    resultsProps.stype = ZE_STRUCTURE_TYPE_EVENT_QUERY_KERNEL_TIMESTAMPS_RESULTS_EXT_PROPERTIES;
    resultsProps.pNext = nullptr;
    resultsProps.pKernelTimestampsBuffer = supportsKernelTimestamps ? kernelTimestamps.data() : nullptr;
    resultsProps.pSynchronizedTimestampsBuffer = supportsSynchronizedTimestamps ? synchronizedTimestamps.data() : nullptr;

    // Query the event timestamps
    zeEventQueryKernelTimestampsExt(hEvent, hDevice, &count, &resultsProps);
}