From 1d00885239dfc5d8a86e620ae20ce41e82cf540e Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Mon, 30 Oct 2023 22:19:56 +0100 Subject: [PATCH] Move the device timer conversion in cvk_device instead of commands --- src/device.cpp | 14 +++++++++----- src/device.hpp | 6 ++++-- src/queue.hpp | 23 +++++++---------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/device.cpp b/src/device.cpp index 03b528b7..24d64390 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1171,11 +1171,15 @@ 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_ulong sync_dev, - cl_ulong sync_host) const { - if (sync_host > sync_dev) { - return (sync_host - sync_dev) + dev; +cl_ulong cvk_device::device_timer_to_host(cl_ulong dev) { + if (dev > m_sync_dev) { + if (get_device_host_timer(&m_sync_dev, &m_sync_host) != CL_SUCCESS) { + return dev; + } + } + if (m_sync_host > m_sync_dev) { + return (m_sync_host - m_sync_dev) + dev; } else { - return dev - (sync_dev - sync_host); + return dev - (m_sync_dev - m_sync_host); } } diff --git a/src/device.hpp b/src/device.hpp index 91ed7bc3..e9f495fe 100644 --- a/src/device.hpp +++ b/src/device.hpp @@ -473,8 +473,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_ulong sync_dev, - cl_ulong sync_host) const; + cl_ulong device_timer_to_host(cl_ulong dev); uint64_t timestamp_to_ns(uint64_t ts) const { double ns_per_tick = vulkan_limits().timestampPeriod; @@ -650,6 +649,9 @@ struct cvk_device : public _cl_device_id, std::string m_spirv_arch; bool m_physical_addressing; + cl_ulong m_sync_host{}; + cl_ulong m_sync_dev{}; + spv_target_env m_vulkan_spirv_env; std::unique_ptr m_clvk_properties; diff --git a/src/queue.hpp b/src/queue.hpp index 329fed32..6b225278 100644 --- a/src/queue.hpp +++ b/src/queue.hpp @@ -669,16 +669,14 @@ struct cvk_command_batchable : public cvk_command { CHECK_RETURN cl_int do_action() override; CHECK_RETURN virtual cl_int do_post_action() { return CL_SUCCESS; } - CHECK_RETURN cl_int set_profiling_info_end(cl_ulong sync_dev, - cl_ulong sync_host) { + CHECK_RETURN cl_int set_profiling_info_end() { cl_ulong start, end; auto perr = get_timestamp_query_results(&start, &end); if (perr != CL_COMPLETE) { return perr; } - start = - m_queue->device()->device_timer_to_host(start, sync_dev, sync_host); - end = m_queue->device()->device_timer_to_host(end, sync_dev, sync_host); + 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); return CL_SUCCESS; @@ -694,12 +692,10 @@ struct cvk_command_batchable : public cvk_command { pinfo == CL_PROFILING_COMMAND_SUBMIT) { return cvk_command::set_profiling_info(pinfo); } else if (pinfo == CL_PROFILING_COMMAND_START) { - return m_queue->device()->get_device_host_timer(&m_sync_dev, - &m_sync_host); + return CL_SUCCESS; } else { CVK_ASSERT(pinfo == CL_PROFILING_COMMAND_END); - CVK_ASSERT(m_sync_dev != 0 && m_sync_host != 0); - return set_profiling_info_end(m_sync_dev, m_sync_host); + return set_profiling_info_end(); } } @@ -710,8 +706,6 @@ struct cvk_command_batchable : public cvk_command { static const int NUM_POOL_QUERIES_PER_COMMAND = 2; static const int POOL_QUERY_CMD_START = 0; static const int POOL_QUERY_CMD_END = 1; - - cl_ulong m_sync_dev{}, m_sync_host{}; }; struct cvk_ndrange { @@ -841,14 +835,12 @@ struct cvk_command_batch : public cvk_command { cl_int status = cvk_command::set_profiling_info(pinfo); if (m_queue->profiling_on_device()) { if (pinfo == CL_PROFILING_COMMAND_START) { - return m_queue->device()->get_device_host_timer(&m_sync_dev, - &m_sync_host); + return status; } else { for (auto& cmd : m_commands) { cl_int err; if (pinfo == CL_PROFILING_COMMAND_END) { - err = cmd->set_profiling_info_end(m_sync_dev, - m_sync_host); + err = cmd->set_profiling_info_end(); } else { err = cmd->set_profiling_info(pinfo); } @@ -876,7 +868,6 @@ struct cvk_command_batch : public cvk_command { private: std::vector> m_commands; std::unique_ptr m_command_buffer; - cl_ulong m_sync_dev, m_sync_host; }; struct cvk_command_map_buffer final : public cvk_command_buffer_base_region {