From 9d8994e244f9451af90de4d56d230b4d02ec3f7a Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Tue, 14 May 2024 09:29:41 +0200 Subject: [PATCH] handle error in device_timer_to_host --- src/device.cpp | 12 +++++++----- src/device.hpp | 2 +- src/queue.hpp | 19 +++++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/device.cpp b/src/device.cpp index 10a81948..78e9502e 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1249,15 +1249,17 @@ cl_int cvk_device::get_device_host_timer(cl_ulong* device_timestamp, return CL_SUCCESS; } -cl_ulong cvk_device::device_timer_to_host(cl_ulong dev) { +cl_int cvk_device::device_timer_to_host(cl_ulong dev, cl_ulong& host) { if (dev > m_sync_dev) { - if (get_device_host_timer(&m_sync_dev, &m_sync_host) != CL_SUCCESS) { - return dev; + cl_int err = get_device_host_timer(&m_sync_dev, &m_sync_host); + if (err != CL_SUCCESS) { + return err; } } if (m_sync_host > m_sync_dev) { - return (m_sync_host - m_sync_dev) + dev; + host = (m_sync_host - m_sync_dev) + dev; } else { - return dev - (m_sync_dev - m_sync_host); + host = dev - (m_sync_dev - m_sync_host); } + return CL_SUCCESS; } diff --git a/src/device.hpp b/src/device.hpp index ce3806a7..425d780d 100644 --- a/src/device.hpp +++ b/src/device.hpp @@ -542,7 +542,7 @@ struct cvk_device : public _cl_device_id, CHECK_RETURN cl_int get_device_host_timer(cl_ulong* dev_ts, cl_ulong* host_ts) const; - cl_ulong device_timer_to_host(cl_ulong dev); + cl_int device_timer_to_host(cl_ulong dev, cl_ulong& host); uint64_t timestamp_to_ns(uint64_t ts) const { double ns_per_tick = vulkan_limits().timestampPeriod; diff --git a/src/queue.hpp b/src/queue.hpp index 846e5b2e..cc0ed58a 100644 --- a/src/queue.hpp +++ b/src/queue.hpp @@ -696,15 +696,22 @@ struct cvk_command_batchable : public cvk_command { if (m_event->get_profiling_info(CL_PROFILING_COMMAND_END) != 0) { return CL_SUCCESS; } - cl_ulong start, end; - auto perr = get_timestamp_query_results(&start, &end); + cl_ulong start_dev, end_dev; + cl_int perr = get_timestamp_query_results(&start_dev, &end_dev); if (perr != CL_COMPLETE) { return perr; } - start = m_queue->device()->device_timer_to_host(start); - end = m_queue->device()->device_timer_to_host(end); - m_event->set_profiling_info(CL_PROFILING_COMMAND_START, start); - m_event->set_profiling_info(CL_PROFILING_COMMAND_END, end); + cl_ulong start_host, end_host; + perr = m_queue->device()->device_timer_to_host(start_dev, start_host); + if (perr != CL_SUCCESS) { + return perr; + } + perr = m_queue->device()->device_timer_to_host(end_dev, end_host); + if (perr != CL_SUCCESS) { + return perr; + } + m_event->set_profiling_info(CL_PROFILING_COMMAND_START, start_host); + m_event->set_profiling_info(CL_PROFILING_COMMAND_END, end_host); return CL_SUCCESS; }