Skip to content

Commit

Permalink
Move the device timer conversion in cvk_device instead of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr committed Oct 30, 2023
1 parent b65b365 commit 1d00885
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
14 changes: 9 additions & 5 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions src/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<cvk_device_properties> m_clvk_properties;
Expand Down
23 changes: 7 additions & 16 deletions src/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -876,7 +868,6 @@ struct cvk_command_batch : public cvk_command {
private:
std::vector<std::unique_ptr<cvk_command_batchable>> m_commands;
std::unique_ptr<cvk_command_buffer> m_command_buffer;
cl_ulong m_sync_dev, m_sync_host;
};

struct cvk_command_map_buffer final : public cvk_command_buffer_base_region {
Expand Down

0 comments on commit 1d00885

Please sign in to comment.