@@ -48,21 +48,21 @@ struct EnqueueResultT {
48
48
cl_int MErrCode;
49
49
};
50
50
51
-
52
51
// DepDesc represents dependency between two commands
53
52
struct DepDesc {
54
- DepDesc (Command *DepCommand, Requirement *Req, AllocaCommandBase *AllocaCmd)
55
- : MDepCommand(DepCommand), MReq(Req), MAllocaCmd(AllocaCmd) {}
53
+ DepDesc (Command *DepCommand, const Requirement *Req,
54
+ AllocaCommandBase *AllocaCmd)
55
+ : MDepCommand(DepCommand), MDepRequirement(Req), MAllocaCmd(AllocaCmd) {}
56
56
57
57
friend bool operator <(const DepDesc &Lhs, const DepDesc &Rhs) {
58
- return std::tie (Lhs.MReq , Lhs.MDepCommand ) <
59
- std::tie (Rhs.MReq , Rhs.MDepCommand );
58
+ return std::tie (Lhs.MDepRequirement , Lhs.MDepCommand ) <
59
+ std::tie (Rhs.MDepRequirement , Rhs.MDepCommand );
60
60
}
61
61
62
62
// The actual dependency command.
63
63
Command *MDepCommand = nullptr ;
64
64
// Requirement for the dependency.
65
- Requirement *MReq = nullptr ;
65
+ const Requirement *MDepRequirement = nullptr ;
66
66
// Allocation command for the memory object we have requirement for.
67
67
// Used to simplify searching for memory handle.
68
68
AllocaCommandBase *MAllocaCmd = nullptr ;
@@ -116,10 +116,15 @@ class Command {
116
116
117
117
std::shared_ptr<event_impl> getEvent () const { return MEvent; }
118
118
119
- virtual ~Command () = default ;
120
-
121
119
virtual void printDot (std::ostream &Stream) const = 0;
122
120
121
+ virtual const Requirement *getRequirement () const {
122
+ assert (!" Internal Error. The command has no stored requirement" );
123
+ return nullptr ;
124
+ }
125
+
126
+ virtual ~Command () = default ;
127
+
123
128
protected:
124
129
EventImplPtr MEvent;
125
130
QueueImplPtr MQueue;
@@ -129,22 +134,23 @@ class Command {
129
134
RT::PiEvent &Event);
130
135
std::vector<RT::PiEvent> prepareEvents (ContextImplPtr Context);
131
136
132
- bool MUseExclusiveQueue = false ;
133
-
134
137
// Private interface. Derived classes should implement this method.
135
138
virtual cl_int enqueueImp () = 0;
136
139
137
- public:
140
+ bool MUseExclusiveQueue = false ;
141
+
138
142
// The type of the command
139
143
CommandType MType;
140
144
// Indicates whether the command is enqueued or not
141
145
std::atomic<bool > MEnqueued;
146
+ // Mutex used to protect enqueueing from race conditions
147
+ std::mutex MEnqueueMtx;
148
+
149
+ public:
142
150
// Contains list of dependencies(edges)
143
151
std::vector<DepDesc> MDeps;
144
152
// Contains list of commands that depend on the command
145
153
std::vector<Command *> MUsers;
146
- // Mutex used to protect enqueueing from race conditions
147
- std::mutex MEnqueueMtx;
148
154
// Indicates whether the command can be blocked from enqueueing
149
155
bool MIsBlockable = false ;
150
156
// Indicates whether the command is blocked from enqueueing
@@ -155,17 +161,17 @@ class Command {
155
161
// lock in the graph, or to merge several nodes into one.
156
162
class EmptyCommand : public Command {
157
163
public:
158
- EmptyCommand (QueueImplPtr Queue, Requirement * Req)
164
+ EmptyCommand (QueueImplPtr Queue, Requirement Req)
159
165
: Command(CommandType::EMPTY_TASK, std::move(Queue)),
160
- MStoredRequirement (* Req) {}
166
+ MRequirement (std::move( Req) ) {}
161
167
162
- Requirement *getStoredRequirement () { return &MStoredRequirement; }
168
+ void printDot (std::ostream &Stream) const final ;
169
+ const Requirement *getRequirement () const final { return &MRequirement; }
163
170
164
171
private:
165
- cl_int enqueueImp () override { return CL_SUCCESS; }
166
- void printDot (std::ostream &Stream) const override ;
172
+ cl_int enqueueImp () final { return CL_SUCCESS; }
167
173
168
- Requirement MStoredRequirement ;
174
+ Requirement MRequirement ;
169
175
};
170
176
171
177
// The command enqueues release instance of memory allocated on Host or
@@ -176,32 +182,34 @@ class ReleaseCommand : public Command {
176
182
: Command(CommandType::RELEASE, std::move(Queue)), MAllocaCmd(AllocaCmd) {
177
183
}
178
184
179
- void printDot (std::ostream &Stream) const override ;
185
+ void printDot (std::ostream &Stream) const final ;
180
186
181
187
private:
182
- cl_int enqueueImp () override ;
188
+ cl_int enqueueImp () final ;
183
189
190
+ // Command which allocates memory release command should dealocate
184
191
AllocaCommandBase *MAllocaCmd = nullptr ;
185
192
};
186
193
187
194
class AllocaCommandBase : public Command {
188
195
public:
189
196
AllocaCommandBase (CommandType Type, QueueImplPtr Queue, Requirement Req)
190
- : Command(Type, Queue), MReleaseCmd(Queue, this ), MReq(std::move(Req)) {
191
- MReq.MAccessMode = access::mode::read_write;
197
+ : Command(Type, Queue), MReleaseCmd(Queue, this ),
198
+ MRequirement (std::move(Req)) {
199
+ MRequirement.MAccessMode = access::mode::read_write;
192
200
}
193
201
194
202
ReleaseCommand *getReleaseCmd () { return &MReleaseCmd; }
195
203
196
- SYCLMemObjI *getSYCLMemObj () const { return MReq .MSYCLMemObj ; }
204
+ SYCLMemObjI *getSYCLMemObj () const { return MRequirement .MSYCLMemObj ; }
197
205
198
206
void *getMemAllocation () const { return MMemAllocation; }
199
207
200
- Requirement *getAllocationReq () { return &MReq ; }
208
+ const Requirement *getRequirement () const final { return &MRequirement ; }
201
209
202
210
protected:
203
211
ReleaseCommand MReleaseCmd;
204
- Requirement MReq ;
212
+ Requirement MRequirement ;
205
213
void *MMemAllocation = nullptr ;
206
214
};
207
215
@@ -211,16 +219,19 @@ class AllocaCommand : public AllocaCommandBase {
211
219
public:
212
220
AllocaCommand (QueueImplPtr Queue, Requirement Req,
213
221
bool InitFromUserData = true )
214
- : AllocaCommandBase(CommandType::ALLOCA, std::move(Queue), Req),
222
+ : AllocaCommandBase(CommandType::ALLOCA, std::move(Queue),
223
+ std::move (Req)),
215
224
MInitFromUserData(InitFromUserData) {
216
- addDep (DepDesc (nullptr , &MReq , this ));
225
+ addDep (DepDesc (nullptr , getRequirement () , this ));
217
226
}
218
227
219
- void printDot (std::ostream &Stream) const override ;
228
+ void printDot (std::ostream &Stream) const final ;
220
229
221
230
private:
222
- cl_int enqueueImp () override final ;
231
+ cl_int enqueueImp () final ;
223
232
233
+ // The flag indicates that alloca should try to reuse pointer provided by the
234
+ // user during memory object construction
224
235
bool MInitFromUserData = false ;
225
236
};
226
237
@@ -231,90 +242,95 @@ class AllocaSubBufCommand : public AllocaCommandBase {
231
242
: AllocaCommandBase(CommandType::ALLOCA_SUB_BUF, std::move(Queue),
232
243
std::move (Req)),
233
244
MParentAlloca(ParentAlloca) {
234
- addDep (DepDesc (MParentAlloca, &MReq , MParentAlloca));
245
+ addDep (DepDesc (MParentAlloca, getRequirement () , MParentAlloca));
235
246
}
236
247
237
- void printDot (std::ostream &Stream) const override ;
248
+ void printDot (std::ostream &Stream) const final ;
238
249
AllocaCommandBase *getParentAlloca () { return MParentAlloca; }
239
250
240
251
private:
241
- cl_int enqueueImp () override final ;
252
+ cl_int enqueueImp () final ;
242
253
243
254
AllocaCommandBase *MParentAlloca;
244
255
};
245
256
246
257
class MapMemObject : public Command {
247
258
public:
248
- MapMemObject (AllocaCommandBase *SrcAlloca , Requirement * Req, void **DstPtr,
259
+ MapMemObject (AllocaCommandBase *SrcAllocaCmd , Requirement Req, void **DstPtr,
249
260
QueueImplPtr Queue);
250
261
251
- AllocaCommandBase *MSrcAlloca = nullptr ;
252
- void **MDstPtr = nullptr ;
253
- Requirement MReq;
254
-
255
- void printDot (std::ostream &Stream) const override ;
262
+ void printDot (std::ostream &Stream) const final ;
263
+ const Requirement *getRequirement () const final { return &MSrcReq; }
256
264
257
265
private:
258
- cl_int enqueueImp () override ;
266
+ cl_int enqueueImp () final ;
267
+
268
+ AllocaCommandBase *MSrcAllocaCmd = nullptr ;
269
+ Requirement MSrcReq;
270
+ void **MDstPtr = nullptr ;
259
271
};
260
272
261
273
class UnMapMemObject : public Command {
262
274
public:
263
- UnMapMemObject (AllocaCommandBase *DstAlloca, Requirement *Req, void **SrcPtr,
264
- QueueImplPtr Queue, bool UseExclusiveQueue = false );
275
+ UnMapMemObject (AllocaCommandBase *DstAllocaCmd, Requirement Req,
276
+ void **SrcPtr, QueueImplPtr Queue,
277
+ bool UseExclusiveQueue = false );
265
278
266
- void printDot (std::ostream &Stream) const override ;
279
+ void printDot (std::ostream &Stream) const final ;
280
+ const Requirement *getRequirement () const final { return &MDstReq; }
267
281
268
282
private:
269
- cl_int enqueueImp () override ;
283
+ cl_int enqueueImp () final ;
270
284
271
- AllocaCommandBase *MDstAlloca = nullptr ;
272
- Requirement MReq ;
285
+ AllocaCommandBase *MDstAllocaCmd = nullptr ;
286
+ Requirement MDstReq ;
273
287
void **MSrcPtr = nullptr ;
274
288
};
275
289
276
290
// The command enqueues memory copy between two instances of memory object.
277
291
class MemCpyCommand : public Command {
278
292
public:
279
- MemCpyCommand (Requirement SrcReq, AllocaCommandBase *SrcAlloca ,
280
- Requirement DstReq, AllocaCommandBase *DstAlloca ,
293
+ MemCpyCommand (Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd ,
294
+ Requirement DstReq, AllocaCommandBase *DstAllocaCmd ,
281
295
QueueImplPtr SrcQueue, QueueImplPtr DstQueue,
282
296
bool UseExclusiveQueue = false );
283
297
284
- QueueImplPtr MSrcQueue;
285
- Requirement MSrcReq;
286
- AllocaCommandBase *MSrcAlloca = nullptr ;
287
- Requirement MDstReq;
288
- AllocaCommandBase *MDstAlloca = nullptr ;
289
- Requirement *MAccToUpdate = nullptr ;
290
-
291
298
void setAccessorToUpdate (Requirement *AccToUpdate) {
292
299
MAccToUpdate = AccToUpdate;
293
300
}
294
301
295
- void printDot (std::ostream &Stream) const override ;
302
+ void printDot (std::ostream &Stream) const final ;
303
+ const Requirement *getRequirement () const final { return &MDstReq; }
296
304
297
305
private:
298
- cl_int enqueueImp () override ;
306
+ cl_int enqueueImp () final ;
307
+
308
+ QueueImplPtr MSrcQueue;
309
+ Requirement MSrcReq;
310
+ AllocaCommandBase *MSrcAllocaCmd = nullptr ;
311
+ Requirement MDstReq;
312
+ AllocaCommandBase *MDstAllocaCmd = nullptr ;
313
+ Requirement *MAccToUpdate = nullptr ;
299
314
};
300
315
301
316
// The command enqueues memory copy between two instances of memory object.
302
317
class MemCpyCommandHost : public Command {
303
318
public:
304
- MemCpyCommandHost (Requirement SrcReq, AllocaCommandBase *SrcAlloca ,
319
+ MemCpyCommandHost (Requirement SrcReq, AllocaCommandBase *SrcAllocaCmd ,
305
320
Requirement DstReq, void **DstPtr, QueueImplPtr SrcQueue,
306
321
QueueImplPtr DstQueue);
307
322
323
+ void printDot (std::ostream &Stream) const final ;
324
+ const Requirement *getRequirement () const final { return &MDstReq; }
325
+
326
+ private:
327
+ cl_int enqueueImp () final ;
328
+
308
329
QueueImplPtr MSrcQueue;
309
330
Requirement MSrcReq;
310
- AllocaCommandBase *MSrcAlloca = nullptr ;
331
+ AllocaCommandBase *MSrcAllocaCmd = nullptr ;
311
332
Requirement MDstReq;
312
333
void **MDstPtr = nullptr ;
313
-
314
- void printDot (std::ostream &Stream) const override ;
315
-
316
- private:
317
- cl_int enqueueImp () override ;
318
334
};
319
335
320
336
// The command enqueues execution of kernel or explicit memory operation.
@@ -326,11 +342,10 @@ class ExecCGCommand : public Command {
326
342
327
343
void flushStreams ();
328
344
329
- void printDot (std::ostream &Stream) const override ;
345
+ void printDot (std::ostream &Stream) const final ;
330
346
331
347
private:
332
- // Implementation of enqueueing of ExecCGCommand.
333
- cl_int enqueueImp () override ;
348
+ cl_int enqueueImp () final ;
334
349
335
350
AllocaCommandBase *getAllocaForReq (Requirement *Req);
336
351
@@ -339,20 +354,20 @@ class ExecCGCommand : public Command {
339
354
340
355
class UpdateHostRequirementCommand : public Command {
341
356
public:
342
- UpdateHostRequirementCommand (QueueImplPtr Queue, AllocaCommandBase *AllocaCmd ,
343
- Requirement *Req , void **DstPtr)
357
+ UpdateHostRequirementCommand (QueueImplPtr Queue, Requirement Req ,
358
+ AllocaCommandBase *SrcAllocaCmd , void **DstPtr)
344
359
: Command(CommandType::UPDATE_REQUIREMENT, std::move(Queue)),
345
- MDstPtr (DstPtr ), MAllocaCmd(AllocaCmd), MReq(*Req ) {}
360
+ MSrcAllocaCmd (SrcAllocaCmd ), MDstReq(std::move(Req)), MDstPtr(DstPtr ) {}
346
361
347
- Requirement *getStoredRequirement () { return &MReq; }
362
+ void printDot (std::ostream &Stream) const final ;
363
+ const Requirement *getRequirement () const final { return &MDstReq; }
348
364
349
365
private:
350
- cl_int enqueueImp () override ;
351
- void printDot (std::ostream &Stream) const override ;
366
+ cl_int enqueueImp () final ;
352
367
368
+ AllocaCommandBase *MSrcAllocaCmd = nullptr ;
369
+ Requirement MDstReq;
353
370
void **MDstPtr = nullptr ;
354
- AllocaCommandBase *MAllocaCmd = nullptr ;
355
- Requirement MReq;
356
371
};
357
372
358
373
} // namespace detail
0 commit comments