From 8ffdddf860562fcfe6c2e68729399c1335794efa Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 3 Oct 2021 15:31:04 -0700 Subject: [PATCH] ircd::cl: Improve queue profiling wrapper related. --- include/ircd/cl.h | 25 +++++++++++++++++++++- ircd/cl.cc | 53 +++++++++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/include/ircd/cl.h b/include/ircd/cl.h index 28d3020d0..cf244ed70 100644 --- a/include/ircd/cl.h +++ b/include/ircd/cl.h @@ -52,6 +52,8 @@ namespace ircd::cl struct ircd::cl::work :instance_list { + struct prof; + void *handle {nullptr}; ctx::ctx *context {ctx::current}; void *object {nullptr}; @@ -61,7 +63,6 @@ struct ircd::cl::work public: int type() const; const char *name() const; - std::array profile() const; void wait(const uint = 0); @@ -74,6 +75,28 @@ struct ircd::cl::work ~work() noexcept; }; +/// Queue profiling convenience +struct ircd::cl::work::prof +:std::array +{ + enum phase :int; + + prof(const cl::work &); + prof() = default; +}; + +/// cl_profiling_info wrapper +enum ircd::cl::work::prof::phase +:int +{ + QUEUE, + SUBMIT, + START, + END, + COMPLETE, + _NUM_ +}; + /// cl_mem wrapping struct ircd::cl::data { diff --git a/ircd/cl.cc b/ircd/cl.cc index bbb9181f3..77835a927 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -2007,28 +2007,6 @@ catch(const std::exception &e) throw; } -std::array -ircd::cl::work::profile() -const -{ - const auto handle - { - cl_event(this->handle) - }; - - if(!profile_queue || !handle) - return {0}; - - char buf[4][8]; - return std::array - { - info(clGetEventProfilingInfo, handle, CL_PROFILING_COMMAND_QUEUED, buf[0]), - info(clGetEventProfilingInfo, handle, CL_PROFILING_COMMAND_SUBMIT, buf[1]), - info(clGetEventProfilingInfo, handle, CL_PROFILING_COMMAND_START, buf[2]), - info(clGetEventProfilingInfo, handle, CL_PROFILING_COMMAND_END, buf[3]), - }; -} - const char * ircd::cl::work::name() const @@ -2080,6 +2058,37 @@ const return info(clGetEventInfo, handle, CL_EVENT_COMMAND_TYPE, buf); } +// +// cl::work::prof +// + +ircd::cl::work::prof::prof(const cl::work &w) +{ + const auto h + { + cl_event(w.handle) + }; + + if(!profile_queue || !h) + { + for(uint i(0); i < this->size(); ++i) + (*this)[i] = 0ns; + + return; + } + + char b[5][8]; + (*this)[0] = info(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_QUEUED, b[0]); + (*this)[1] = info(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_SUBMIT, b[1]); + (*this)[2] = info(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_START, b[2]); + (*this)[3] = info(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_END, b[3]); + (*this)[4] = info(clGetEventProfilingInfo, h, CL_PROFILING_COMMAND_COMPLETE, b[4]); +} + +// +// cl::work (internal) +// + int ircd::cl::wait_event(work &work, const int status,