@@ -183,23 +183,9 @@ event_impl::event_impl(queue_impl &Queue, private_tag)
183183}
184184
185185event_impl::event_impl (HostEventState State, private_tag) : MState(State) {
186- switch (State) {
187- case HES_Discarded:
188- case HES_Complete: {
186+ MIsHostEvent = true ;
187+ if (State == HES_Discarded || State == HES_Complete)
189188 MIsFlushed = true ;
190- MIsHostEvent = true ;
191- break ;
192- }
193- case HES_NotComplete: {
194- MIsProfilingEnabled = true ;
195- MHostProfilingInfo.reset (new HostProfilingInfo ());
196- if (!MHostProfilingInfo)
197- throw sycl::exception (
198- sycl::make_error_code (sycl::errc::runtime),
199- " Out of host memory " +
200- codeToString (UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
201- }
202- }
203189}
204190
205191void event_impl::setQueue (queue_impl &Queue) {
@@ -214,8 +200,22 @@ void event_impl::setQueue(queue_impl &Queue) {
214200
215201void event_impl::setSubmittedQueue (std::weak_ptr<queue_impl> SubmittedQueue) {
216202 MSubmittedQueue = std::move (SubmittedQueue);
217- if (MHostProfilingInfo ) {
203+ if (isHost () ) {
218204 if (auto QueuePtr = MSubmittedQueue.lock ()) {
205+ // Enable profiling for host events only if the queue where host task was
206+ // submitted has profiling enabled.
207+ MIsProfilingEnabled = QueuePtr->MIsProfilingEnabled ;
208+ if (!MIsProfilingEnabled || MState == HES_Discarded ||
209+ MState == HES_Complete)
210+ return ;
211+
212+ MHostProfilingInfo.reset (new HostProfilingInfo ());
213+ if (!MHostProfilingInfo)
214+ throw sycl::exception (
215+ sycl::make_error_code (sycl::errc::runtime),
216+ " Out of host memory " +
217+ codeToString (UR_RESULT_ERROR_OUT_OF_HOST_MEMORY));
218+
219219 device_impl &Device = QueuePtr->getDeviceImpl ();
220220 MHostProfilingInfo->setDevice (&Device);
221221 }
0 commit comments