1111#include < CL/sycl/detail/queue_impl.hpp>
1212#include < CL/sycl/detail/scheduler/scheduler.hpp>
1313
14+ #include < chrono>
15+
1416namespace cl {
1517namespace sycl {
1618namespace detail {
@@ -81,6 +83,15 @@ event_impl::event_impl(cl_event CLEvent, const context &SyclContext)
8183 PI_CALL (RT::piEventRetain (m_Event));
8284}
8385
86+ event_impl::event_impl (std::shared_ptr<cl::sycl::detail::queue_impl> Queue) {
87+ if (Queue->is_host () &&
88+ Queue->has_property <property::queue::enable_profiling>()) {
89+ m_HostProfilingInfo.reset (new HostProfilingInfo ());
90+ if (!m_HostProfilingInfo)
91+ throw runtime_error (" Out of host memory" );
92+ }
93+ }
94+
8495void event_impl::wait (
8596 std::shared_ptr<cl::sycl::detail::event_impl> Self) const {
8697
@@ -110,8 +121,9 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
110121 return get_event_profiling_info<
111122 info::event_profiling::command_submit>::_ (this ->getHandleRef ());
112123 }
113- assert (!" Not implemented for host device." );
114- return (cl_ulong)0 ;
124+ if (!m_HostProfilingInfo)
125+ throw invalid_object_error (" Profiling info is not available." );
126+ return m_HostProfilingInfo->getStartTime ();
115127}
116128
117129template <>
@@ -121,8 +133,9 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() const {
121133 return get_event_profiling_info<info::event_profiling::command_start>::_ (
122134 this ->getHandleRef ());
123135 }
124- assert (!" Not implemented for host device." );
125- return (cl_ulong)0 ;
136+ if (!m_HostProfilingInfo)
137+ throw invalid_object_error (" Profiling info is not available." );
138+ return m_HostProfilingInfo->getStartTime ();
126139}
127140
128141template <>
@@ -132,17 +145,17 @@ event_impl::get_profiling_info<info::event_profiling::command_end>() const {
132145 return get_event_profiling_info<info::event_profiling::command_end>::_ (
133146 this ->getHandleRef ());
134147 }
135- assert (!" Not implemented for host device." );
136- return (cl_ulong)0 ;
148+ if (!m_HostProfilingInfo)
149+ throw invalid_object_error (" Profiling info is not available." );
150+ return m_HostProfilingInfo->getEndTime ();
137151}
138152
139153template <> cl_uint event_impl::get_info<info::event::reference_count>() const {
140154 if (!m_HostEvent) {
141155 return get_event_info<info::event::reference_count>::_ (
142156 this ->getHandleRef ());
143157 }
144- assert (!" Not implemented for host device." );
145- return (cl_ulong)0 ;
158+ return 0 ;
146159}
147160
148161template <>
@@ -152,10 +165,18 @@ event_impl::get_info<info::event::command_execution_status>() const {
152165 return get_event_info<info::event::command_execution_status>::_ (
153166 this ->getHandleRef ());
154167 }
155- assert (!" Not implemented for host device." );
156168 return info::event_command_status::complete;
157169}
158170
171+ static uint64_t getTimestamp () {
172+ auto ts = std::chrono::high_resolution_clock::now ().time_since_epoch ();
173+ return std::chrono::duration_cast<std::chrono::nanoseconds>(ts).count ();
174+ }
175+
176+ void HostProfilingInfo::start () { StartTime = getTimestamp (); }
177+
178+ void HostProfilingInfo::end () { EndTime = getTimestamp (); }
179+
159180} // namespace detail
160181} // namespace sycl
161182} // namespace cl
0 commit comments