11
11
#include < CL/sycl/detail/queue_impl.hpp>
12
12
#include < CL/sycl/detail/scheduler/scheduler.hpp>
13
13
14
+ #include < chrono>
15
+
14
16
namespace cl {
15
17
namespace sycl {
16
18
namespace detail {
@@ -81,6 +83,15 @@ event_impl::event_impl(cl_event CLEvent, const context &SyclContext)
81
83
PI_CALL (RT::piEventRetain (m_Event));
82
84
}
83
85
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
+
84
95
void event_impl::wait (
85
96
std::shared_ptr<cl::sycl::detail::event_impl> Self) const {
86
97
@@ -110,8 +121,9 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
110
121
return get_event_profiling_info<
111
122
info::event_profiling::command_submit>::_ (this ->getHandleRef ());
112
123
}
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 ();
115
127
}
116
128
117
129
template <>
@@ -121,8 +133,9 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() const {
121
133
return get_event_profiling_info<info::event_profiling::command_start>::_ (
122
134
this ->getHandleRef ());
123
135
}
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 ();
126
139
}
127
140
128
141
template <>
@@ -132,17 +145,17 @@ event_impl::get_profiling_info<info::event_profiling::command_end>() const {
132
145
return get_event_profiling_info<info::event_profiling::command_end>::_ (
133
146
this ->getHandleRef ());
134
147
}
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 ();
137
151
}
138
152
139
153
template <> cl_uint event_impl::get_info<info::event::reference_count>() const {
140
154
if (!m_HostEvent) {
141
155
return get_event_info<info::event::reference_count>::_ (
142
156
this ->getHandleRef ());
143
157
}
144
- assert (!" Not implemented for host device." );
145
- return (cl_ulong)0 ;
158
+ return 0 ;
146
159
}
147
160
148
161
template <>
@@ -152,10 +165,18 @@ event_impl::get_info<info::event::command_execution_status>() const {
152
165
return get_event_info<info::event::command_execution_status>::_ (
153
166
this ->getHandleRef ());
154
167
}
155
- assert (!" Not implemented for host device." );
156
168
return info::event_command_status::complete;
157
169
}
158
170
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
+
159
180
} // namespace detail
160
181
} // namespace sycl
161
182
} // namespace cl
0 commit comments