14
14
#include < detail/queue_impl.hpp>
15
15
16
16
#include < cstring>
17
+ #include < utility>
17
18
18
19
#ifdef XPTI_ENABLE_INSTRUMENTATION
19
20
#include " xpti_trace_framework.hpp"
@@ -27,7 +28,7 @@ template <> cl_uint queue_impl::get_info<info::queue::reference_count>() const {
27
28
RT::PiResult result = PI_SUCCESS;
28
29
if (!is_host ())
29
30
getPlugin ().call <PiApiKind::piQueueGetInfo>(
30
- MCommandQueue , PI_QUEUE_INFO_REFERENCE_COUNT, sizeof (result), &result,
31
+ MQueues[ 0 ] , PI_QUEUE_INFO_REFERENCE_COUNT, sizeof (result), &result,
31
32
nullptr );
32
33
return result;
33
34
}
@@ -40,78 +41,80 @@ template <> device queue_impl::get_info<info::queue::device>() const {
40
41
return get_device ();
41
42
}
42
43
43
- static event prepareUSMEvent (shared_ptr_class<detail::queue_impl> QueueImpl,
44
- RT::PiEvent NativeEvent) {
44
+ static event
45
+ prepareUSMEvent (const shared_ptr_class<detail::queue_impl> &QueueImpl,
46
+ RT::PiEvent NativeEvent) {
45
47
auto EventImpl = std::make_shared<detail::event_impl>(QueueImpl);
46
48
EventImpl->getHandleRef () = NativeEvent;
47
49
EventImpl->setContextImpl (detail::getSyclObjImpl (QueueImpl->get_context ()));
48
50
return detail::createSyclObjFromImpl<event>(EventImpl);
49
51
}
50
52
51
- event queue_impl::memset (shared_ptr_class<detail::queue_impl> Impl, void *Ptr,
52
- int Value, size_t Count) {
53
- context Context = get_context ();
54
- RT::PiEvent NativeEvent = nullptr ;
55
- MemoryManager::fill_usm (Ptr, Impl, Count, Value, /* DepEvents*/ {},
53
+ event queue_impl::memset (const shared_ptr_class<detail::queue_impl> &Self,
54
+ void *Ptr, int Value, size_t Count) {
55
+ RT::PiEvent NativeEvent{};
56
+ MemoryManager::fill_usm (Ptr, Self, Count, Value, /* DepEvents*/ {},
56
57
NativeEvent);
57
58
58
- if (Context. is_host ())
59
+ if (MContext-> is_host ())
59
60
return event ();
60
61
61
- event ResEvent = prepareUSMEvent (Impl , NativeEvent);
62
+ event ResEvent = prepareUSMEvent (Self , NativeEvent);
62
63
addUSMEvent (ResEvent);
63
64
return ResEvent;
64
65
}
65
66
66
- event queue_impl::memcpy (shared_ptr_class<detail::queue_impl> Impl, void *Dest,
67
- const void *Src, size_t Count) {
68
- context Context = get_context ();
69
- RT::PiEvent NativeEvent = nullptr ;
70
- MemoryManager::copy_usm (Src, Impl, Count, Dest, /* DepEvents*/ {},
67
+ event queue_impl::memcpy (const shared_ptr_class<detail::queue_impl> &Self,
68
+ void *Dest, const void *Src, size_t Count) {
69
+ RT::PiEvent NativeEvent{};
70
+ MemoryManager::copy_usm (Src, Self, Count, Dest, /* DepEvents*/ {},
71
71
NativeEvent);
72
72
73
- if (Context. is_host ())
73
+ if (MContext-> is_host ())
74
74
return event ();
75
75
76
- event ResEvent = prepareUSMEvent (Impl , NativeEvent);
76
+ event ResEvent = prepareUSMEvent (Self , NativeEvent);
77
77
addUSMEvent (ResEvent);
78
78
return ResEvent;
79
79
}
80
80
81
- event queue_impl::mem_advise (shared_ptr_class<detail::queue_impl> Impl ,
81
+ event queue_impl::mem_advise (const shared_ptr_class<detail::queue_impl> &Self ,
82
82
const void *Ptr, size_t Length,
83
83
pi_mem_advice Advice) {
84
- context Context = get_context ();
85
- if (Context.is_host ()) {
84
+ if (MContext->is_host ()) {
86
85
return event ();
87
86
}
88
87
89
88
// non-Host device
90
- RT::PiEvent NativeEvent = nullptr ;
89
+ RT::PiEvent NativeEvent{} ;
91
90
const detail::plugin &Plugin = getPlugin ();
92
91
Plugin.call <PiApiKind::piextUSMEnqueueMemAdvise>(getHandleRef (), Ptr, Length,
93
92
Advice, &NativeEvent);
94
93
95
- event ResEvent = prepareUSMEvent (Impl , NativeEvent);
94
+ event ResEvent = prepareUSMEvent (Self , NativeEvent);
96
95
addUSMEvent (ResEvent);
97
96
return ResEvent;
98
97
}
99
98
100
- void queue_impl::addEvent (event Event) {
99
+ void queue_impl::addEvent (const event & Event) {
101
100
std::weak_ptr<event_impl> EventWeakPtr{getSyclObjImpl (Event)};
102
- std::lock_guard<mutex_class> Guard (MMutex);
101
+ std::lock_guard<mutex_class> Lock (MMutex);
103
102
MEvents.push_back (std::move (EventWeakPtr));
104
103
}
105
104
106
- void queue_impl::addUSMEvent (event Event) {
107
- std::lock_guard<mutex_class> Guard (MMutex);
108
- MUSMEvents.push_back (std::move ( Event) );
105
+ void queue_impl::addUSMEvent (const event & Event) {
106
+ std::lock_guard<mutex_class> Lock (MMutex);
107
+ MUSMEvents.push_back (Event);
109
108
}
110
109
111
110
void *queue_impl::instrumentationProlog (const detail::code_location &CodeLoc,
112
111
string_class &Name, int32_t StreamID,
113
112
uint64_t &IId) {
114
113
void *TraceEvent = nullptr ;
114
+ (void )CodeLoc;
115
+ (void )Name;
116
+ (void )StreamID;
117
+ (void )IId;
115
118
#ifdef XPTI_ENABLE_INSTRUMENTATION
116
119
xpti::trace_event_data_t *WaitEvent = nullptr ;
117
120
if (!xptiTraceEnabled ())
@@ -172,6 +175,10 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
172
175
173
176
void queue_impl::instrumentationEpilog (void *TelemetryEvent, string_class &Name,
174
177
int32_t StreamID, uint64_t IId) {
178
+ (void )TelemetryEvent;
179
+ (void )Name;
180
+ (void )StreamID;
181
+ (void )IId;
175
182
#ifdef XPTI_ENABLE_INSTRUMENTATION
176
183
if (!(xptiTraceEnabled () && TelemetryEvent))
177
184
return ;
@@ -184,6 +191,7 @@ void queue_impl::instrumentationEpilog(void *TelemetryEvent, string_class &Name,
184
191
}
185
192
186
193
void queue_impl::wait (const detail::code_location &CodeLoc) {
194
+ (void )CodeLoc;
187
195
#ifdef XPTI_ENABLE_INSTRUMENTATION
188
196
void *TelemetryEvent = nullptr ;
189
197
uint64_t IId;
@@ -192,24 +200,20 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
192
200
TelemetryEvent = instrumentationProlog (CodeLoc, Name, StreamID, IId);
193
201
#endif
194
202
195
- std::vector<std::shared_ptr<event_impl>> Events;
203
+ vector_class<std::weak_ptr<event_impl>> Events;
204
+ vector_class<event> USMEvents;
196
205
{
197
- std::lock_guard<mutex_class> Guard (MMutex);
198
- for (std::weak_ptr<event_impl> &EventImplWeakPtr : MEvents)
199
- if (std::shared_ptr<event_impl> EventImplPtr = EventImplWeakPtr.lock ())
200
- Events.push_back (EventImplPtr);
206
+ std::lock_guard<mutex_class> Lock (MMutex);
207
+ Events = std::move (MEvents);
208
+ USMEvents = std::move (MUSMEvents);
201
209
}
202
210
203
- for (std::shared_ptr <event_impl> &Event : Events) {
204
- Event-> wait (Event);
205
- }
211
+ for (std::weak_ptr <event_impl> &EventImplWeakPtr : Events)
212
+ if (std::shared_ptr<event_impl> EventImplPtr = EventImplWeakPtr. lock ())
213
+ EventImplPtr-> wait (EventImplPtr);
206
214
207
- for (event &Event : MUSMEvents) {
215
+ for (event &Event : USMEvents)
208
216
Event.wait ();
209
- }
210
-
211
- MEvents.clear ();
212
- MUSMEvents.clear ();
213
217
214
218
#ifdef XPTI_ENABLE_INSTRUMENTATION
215
219
instrumentationEpilog (TelemetryEvent, Name, StreamID, IId);
@@ -222,9 +226,9 @@ void queue_impl::initHostTaskAndEventCallbackThreadPool() {
222
226
223
227
int Size = 1 ;
224
228
225
- if (const char *val = std::getenv (" SYCL_QUEUE_THREAD_POOL_SIZE" ))
229
+ if (const char *Val = std::getenv (" SYCL_QUEUE_THREAD_POOL_SIZE" ))
226
230
try {
227
- Size = std::stoi (val );
231
+ Size = std::stoi (Val );
228
232
} catch (...) {
229
233
throw invalid_parameter_error (
230
234
" Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment variable" ,
@@ -241,9 +245,9 @@ void queue_impl::initHostTaskAndEventCallbackThreadPool() {
241
245
}
242
246
243
247
pi_native_handle queue_impl::getNative () const {
244
- auto Plugin = getPlugin ();
245
- pi_native_handle Handle;
246
- Plugin.call <PiApiKind::piextQueueGetNativeHandle>(MCommandQueue , &Handle);
248
+ const detail::plugin & Plugin = getPlugin ();
249
+ pi_native_handle Handle{} ;
250
+ Plugin.call <PiApiKind::piextQueueGetNativeHandle>(MQueues[ 0 ] , &Handle);
247
251
return Handle;
248
252
}
249
253
0 commit comments