Skip to content

Commit f9e6934

Browse files
author
Alexander Batashev
committed
Address more comments
Signed-off-by: Alexander Batashev <[email protected]>
1 parent 0032e53 commit f9e6934

File tree

2 files changed

+84
-90
lines changed

2 files changed

+84
-90
lines changed

sycl/source/detail/scheduler/commands.hpp

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct EnqueueResultT {
4949
EnqueueResultT(ResultT Result = SyclEnqueueSuccess, Command *Cmd = nullptr,
5050
cl_int ErrCode = CL_SUCCESS)
5151
: MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {}
52-
/// Indicates result of enqueueing.
52+
/// Indicates the result of enqueueing.
5353
ResultT MResult;
5454
/// Pointer to the command which failed to enqueue.
5555
Command *MCmd;
@@ -77,11 +77,11 @@ struct DepDesc {
7777
AllocaCommandBase *MAllocaCmd = nullptr;
7878
};
7979

80-
/// The Command represents some action that needs to be performed on one or
81-
/// more memory objects. The Command has a vector of DepDesc objects that
82-
/// represent dependencies of the command. It has a vector of pointers to commands
83-
/// that depend on the command. It has a pointer to \ref queue object and an
84-
/// event that is associated with the command.
80+
/// The Command class represents some action that needs to be performed on one
81+
/// or more memory objects. The Command has a vector of DepDesc objects that
82+
/// represent dependencies of the command. It has a vector of pointers to
83+
/// commands that depend on the command. It has a pointer to a \ref queue object
84+
/// and an event that is associated with the command.
8585
///
8686
/// \ingroup sycl_graph
8787
class Command {
@@ -112,8 +112,8 @@ class Command {
112112
/// Checks if the command is enqueued, and calls enqueueImp.
113113
///
114114
/// \param EnqueueResult is set to the specific status if enqueue failed.
115-
/// \param Blocking if this argument is true, function will wait for command
116-
/// to be unblocked before calling enqueueImp.
115+
/// \param Blocking if this argument is true, function will wait for the
116+
/// command to be unblocked before calling enqueueImp.
117117
/// \return true if the command is enqueued.
118118
bool enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking);
119119

@@ -136,23 +136,23 @@ class Command {
136136
/// Looks at all the dependencies for the release command and enables
137137
/// instrumentation to report these dependencies as edges.
138138
void resolveReleaseDependencies(std::set<Command *> &list);
139-
/// Creates an edge event when the dependency is a command
139+
/// Creates an edge event when the dependency is a command.
140140
void emitEdgeEventForCommandDependence(Command *Cmd, void *ObjAddr,
141141
const string_class &Prefix,
142142
bool IsCommand);
143-
/// Creates an edge event when the dependency is an event
143+
/// Creates an edge event when the dependency is an event.
144144
void emitEdgeEventForEventDependence(Command *Cmd, RT::PiEvent &EventAddr);
145-
/// Creates a signal event with the enqueued kernel event handle
145+
/// Creates a signal event with the enqueued kernel event handle.
146146
void emitEnqueuedEventSignal(RT::PiEvent &PiEventAddr);
147147
/// Create a trace event of node_create type; this must be guarded by a
148-
/// check for xptiTraceEnabled()
149-
/// Post Condition: MTraceEvent will be set to the event created
150-
/// \param MAddress The address to use to create the payload
148+
/// check for xptiTraceEnabled().
149+
/// Post Condition: MTraceEvent will be set to the event created.
150+
/// \param MAddress The address to use to create the payload.
151151
uint64_t makeTraceEventProlog(void *MAddress);
152152
/// If prolog has been run, run epilog; this must be guarded by a check for
153-
/// xptiTraceEnabled()
153+
/// xptiTraceEnabled().
154154
void makeTraceEventEpilog();
155-
/// Emits an event of Type
155+
/// Emits an event of Type.
156156
void emitInstrumentation(uint16_t Type, const char *Txt = nullptr);
157157

158158
// End Methods needed to support SYCL instrumentation
@@ -178,50 +178,51 @@ class Command {
178178
/// Private interface. Derived classes should implement this method.
179179
virtual cl_int enqueueImp() = 0;
180180

181-
/// The type of the command
181+
/// The type of the command.
182182
CommandType MType;
183183
/// Mutex used to protect enqueueing from race conditions
184184
std::mutex MEnqueueMtx;
185185

186186
public:
187187
/// Contains list of dependencies(edges)
188188
std::vector<DepDesc> MDeps;
189-
/// Contains list of commands that depend on the command
189+
/// Contains list of commands that depend on the command.
190190
std::unordered_set<Command *> MUsers;
191-
/// Indicates whether the command can be blocked from enqueueing
191+
/// Indicates whether the command can be blocked from enqueueing.
192192
bool MIsBlockable = false;
193-
/// Counts the number of memory objects this command is a leaf for
193+
/// Counts the number of memory objects this command is a leaf for.
194194
unsigned MLeafCounter = 0;
195195

196196
const char *MBlockReason = "Unknown";
197197

198-
/// Describes the status of a command
198+
/// Describes the status of the command.
199199
std::atomic<EnqueueResultT::ResultT> MEnqueueStatus;
200200

201201
// All member variable defined here are needed for the SYCL instrumentation
202202
// layer. Do not guard these variables below with XPTI_ENABLE_INSTRUMENTATION
203203
// to ensure we have the same object layout when the macro in the library and
204204
// SYCL app are not the same.
205205

206-
/// The event for node_create and task_begin
206+
/// The event for node_create and task_begin.
207207
void *MTraceEvent = nullptr;
208-
/// The stream under which the traces are emitted; stream ids are
209-
/// positive integers and we set it to an invalid value
208+
/// The stream under which the traces are emitted.
209+
///
210+
/// Stream ids are positive integers and we set it to an invalid value.
210211
int32_t MStreamID = -1;
211212
/// Reserved for storing the object address such as SPIRV or memory object
212-
/// address
213+
/// address.
213214
void *MAddress = nullptr;
214-
/// Buffer to build the address string
215+
/// Buffer to build the address string.
215216
string_class MAddressString;
216-
/// Buffer to build the command node type
217+
/// Buffer to build the command node type.
217218
string_class MCommandNodeType;
218-
/// Buffer to build the command end-user understandable name
219+
/// Buffer to build the command end-user understandable name.
219220
string_class MCommandName;
220-
/// Flag to indicate if makeTraceEventProlog() has been run
221+
/// Flag to indicate if makeTraceEventProlog() has been run.
221222
bool MTraceEventPrologComplete = false;
222-
/// Flag to indicate if this is the first time we are seeing this payload
223+
/// Flag to indicate if this is the first time we are seeing this payload.
223224
bool MFirstInstance = false;
224-
/// Instance ID tracked for the command
225+
/// Instance ID tracked for the command.
225226
uint64_t MInstanceID = 0;
226227
};
227228

@@ -242,8 +243,8 @@ class EmptyCommand : public Command {
242243
Requirement MRequirement;
243244
};
244245

245-
/// The release command enqueues release of a memory object instance allocated on Host or
246-
/// underlying framework.
246+
/// The release command enqueues release of a memory object instance allocated
247+
/// on Host or underlying framework.
247248
class ReleaseCommand : public Command {
248249
public:
249250
ReleaseCommand(QueueImplPtr Queue, AllocaCommandBase *AllocaCmd);
@@ -286,7 +287,7 @@ class AllocaCommandBase : public Command {
286287
bool MIsActive = true;
287288

288289
/// Indicates that the command owns memory allocation in case of connected
289-
/// alloca command
290+
/// alloca command.
290291
bool MIsLeaderAlloca = true;
291292

292293
protected:
@@ -309,7 +310,7 @@ class AllocaCommand : public AllocaCommandBase {
309310
cl_int enqueueImp() final;
310311

311312
/// The flag indicates that alloca should try to reuse pointer provided by
312-
/// the user during memory object construction
313+
/// the user during memory object construction.
313314
bool MInitFromUserData = false;
314315
};
315316

@@ -329,7 +330,7 @@ class AllocaSubBufCommand : public AllocaCommandBase {
329330
AllocaCommandBase *MParentAlloca = nullptr;
330331
};
331332

332-
/// The map command enqueues mapping of host memory onto device memory.
333+
/// The map command enqueues mapping of device memory onto host memory.
333334
class MapMemObject : public Command {
334335
public:
335336
MapMemObject(AllocaCommandBase *SrcAllocaCmd, Requirement Req, void **DstPtr,

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
///
3434
/// The SYCL framework defines command group (\ref CG) as an entity that
3535
/// represents minimal execution block. The command group is submitted to SYCL
36-
/// queue and consists of a kernel and its requirements. The SYCL queue defines
37-
/// the device and context using which the kernel should be executed.
36+
/// queue and consists of a kernel or an explicit memory operation, and their
37+
/// requirements. The SYCL queue defines the device and context using which the
38+
/// kernel should be executed.
3839
///
39-
/// There are also command groups that consist of memory requirements and
40-
/// an explicit memory operation, such as copy, fill, update_host. In this case
41-
/// it's up to an implementation how to implement these operations.
40+
/// The commands that contain explicit memory operations include copy, fill,
41+
/// update_host and other operations. It's up to implementation how to define
42+
/// these operations.
4243
///
4344
/// The relative order of command groups submission defines the order in which
4445
/// kernels must be executed if their memory requirements intersect. For
@@ -93,17 +94,17 @@
9394
///
9495
/// // "Host accessor creation" section
9596
/// // Request the latest data of BufferC for the moment
96-
/// // This is a synchronization point, which means that the DPC++ RT blocks on creation of
97-
/// // the accessor until requested data is available.
97+
/// // This is a synchronization point, which means that the DPC++ RT blocks
98+
/// // on creation of the accessor until requested data is available.
9899
/// auto C = BufferC.get_access<read>();
99100
/// }
100101
/// \endcode
101102
///
102103
/// In the example above the DPC++ RT does the following:
103104
///
104105
/// 1. **Copy command group**.
105-
/// The DPC++ RT allocates memory for BufferA and BufferB on CPU then executes
106-
/// an explicit copy operation on CPU.
106+
/// The DPC++ RT allocates memory for BufferA and BufferB on CPU then
107+
/// executes an explicit copy operation on CPU.
107108
///
108109
/// 2. **Multi command group**
109110
/// DPC++ RT allocates memory for BufferC and BufferB on GPU and copy
@@ -266,8 +267,8 @@ struct MemObjRecord {
266267
/// executing the first command group memory allocation must be performed.
267268
///
268269
/// At some point Scheduler enqueues commands to the underlying devices. To do
269-
/// this, Scheduler performs topological sort to get the order in which commands should
270-
/// be enqueued. For example, the following graph (D depends on B and C,
270+
/// this, Scheduler performs topological sort to get the order in which commands
271+
/// should be enqueued. For example, the following graph (D depends on B and C,
271272
/// B and C depends on A) will be enqueued in the following order:
272273
/// \code{.cpp}
273274
/// EventA = Enqueue(A, /*Deps=*/{});
@@ -308,8 +309,7 @@ struct MemObjRecord {
308309
///
309310
/// \section sched_impl Implementation details
310311
///
311-
/// The Scheduler is split up into two parts: graph builder and graph
312-
/// processor.
312+
/// The Scheduler is split up into two parts: graph builder and graph processor.
313313
///
314314
/// To build dependencies, Scheduler needs to memorize memory objects and
315315
/// commands that modify them.
@@ -338,9 +338,9 @@ struct MemObjRecord {
338338
/// 1. errors that happen during command enqueue process
339339
/// 2. the error that happend during command execution.
340340
///
341-
/// If an error occurs during command enqueue process, the Command::enqueue method
342-
/// returns the faulty command. Scheduler then reschedules the command and all
343-
/// dependent commands (if any).
341+
/// If an error occurs during command enqueue process, the Command::enqueue
342+
/// method returns the faulty command. Scheduler then reschedules the command
343+
/// and all dependent commands (if any).
344344
///
345345
/// An error with command processing can happen in underlying runtime, in this
346346
/// case Scheduler is notified asynchronously (using callback mechanism) what
@@ -378,26 +378,23 @@ class Scheduler {
378378

379379
/// Removes buffer from the graph.
380380
///
381-
/// The lifetime of memory object descriptor begins when the first command group
382-
/// that uses the memory object is submitted and ends when "removeMemoryObject(...)"
383-
/// method is called which means there will be no command group that uses the
384-
/// memory object. When removeMemoryObject is called Scheduler will enqueue
385-
/// and wait on all release commands associated with the memory object, which
386-
/// effectively guarantees that all commands accessing the memory object are
387-
/// complete and then the resources allocated for the memory object are freed. Then all the
388-
/// commands affecting the memory object are removed.
389-
///
390-
/// On destruction Scheduler triggers destruction of all memory object
391-
/// descriptors in order to wait on all commands not yet executed and all
392-
/// memory it manages.
381+
/// The lifetime of memory object descriptor begins when the first command
382+
/// group that uses the memory object is submitted and ends when
383+
/// "removeMemoryObject(...)" method is called which means there will be no
384+
/// command group that uses the memory object. When removeMemoryObject is
385+
/// called Scheduler will enqueue and wait on all release commands associated
386+
/// with the memory object, which effectively guarantees that all commands
387+
/// accessing the memory object are complete and then the resources allocated
388+
/// for the memory object are freed. Then all the commands affecting the
389+
/// memory object are removed.
393390
///
394391
/// This member function is used by \ref buffer and \ref image.
395392
///
396393
/// \param MemObj is a memory object that points to the buffer being removed.
397394
void removeMemoryObject(detail::SYCLMemObjI *MemObj);
398395

399-
/// Removes finished non-leaf non-alloca commands from the subgraph
400-
/// (assuming that all its commands have been waited for).
396+
/// Removes finished non-leaf non-alloca commands from the subgraph (assuming
397+
/// that all its commands have been waited for).
401398
/// \sa GraphBuilder::cleanupFinishedCommands
402399
///
403400
/// \param FinishedEvent is a cleanup candidate event.
@@ -458,13 +455,12 @@ class Scheduler {
458455
Command *addCGUpdateHost(std::unique_ptr<detail::CG> CommandGroup,
459456
QueueImplPtr HostQueue);
460457

461-
/// Registers a \ref CG "command group" to update memory to the latest
462-
/// state.
458+
/// Enqueues a command to update memory to the latest state.
463459
///
464460
/// \param Req is a requirement, that describes memory object.
465461
Command *addCopyBack(Requirement *Req);
466462

467-
/// Registers a \ref CG "command group" to create a host accessor.
463+
/// Enqueues a command to create a host accessor.
468464
///
469465
/// \param Req points to memory being accessed.
470466
Command *addHostAccessor(Requirement *Req, const bool destructor = false);
@@ -483,8 +479,9 @@ class Scheduler {
483479
/// Reschedules the command passed using Queue provided.
484480
///
485481
/// This can lead to rescheduling of all dependent commands. This can be
486-
/// used when the user provides a "secondary" queue to the submit method which may
487-
/// be used when the command fails to enqueue/execute in the primary queue.
482+
/// used when the user provides a "secondary" queue to the submit method
483+
/// which may be used when the command fails to enqueue/execute in the
484+
/// primary queue.
488485
void rescheduleCommand(Command *Cmd, QueueImplPtr Queue);
489486

490487
/// \return a pointer to the corresponding memory object record for the
@@ -516,7 +513,8 @@ class Scheduler {
516513
std::vector<SYCLMemObjI *> MMemObjs;
517514

518515
private:
519-
/// Inserts the command required to update the memory object state in the context.
516+
/// Inserts the command required to update the memory object state in the
517+
/// context.
520518
///
521519
/// Copy/map/unmap operations can be inserted depending on the source and
522520
/// destination.
@@ -579,26 +577,21 @@ class Scheduler {
579577
/// Member functions of this class do not modify the graph.
580578
///
581579
/// \section sched_enqueue Command enqueueing
582-
/// \todo lazy mode is not implemented.
583-
///
584-
/// The Scheduler can work in two modes of enqueueing commands: eager (default)
585-
/// and lazy. In eager mode commands are enqueued whenever they come to the
586-
/// Scheduler. In lazy mode they are not enqueued until the content of the buffer
587-
/// they are accessing is requested by user.
588580
///
589-
/// Each command has enqueue method which takes vector of events that
590-
/// represents dependencies and returns event which represents the command.
591-
/// GraphProcessor performs topological sort to get the order in which commands have to
592-
/// be enqueued. Then it enqueues each command, passing a vector of events
593-
/// that this command needs to wait on. If an error happens during command
594-
/// enqueue, the whole process is stopped, the faulty command is propagated back
595-
/// to the Scheduler.
581+
/// Commands are enqueued whenever they come to the Scheduler. Each command
582+
/// has enqueue method which takes vector of events that represents
583+
/// dependencies and returns event which represents the command.
584+
/// GraphProcessor performs topological sort to get the order in which
585+
/// commands have to be enqueued. Then it enqueues each command, passing a
586+
/// vector of events that this command needs to wait on. If an error happens
587+
/// during command enqueue, the whole process is stopped, the faulty command
588+
/// is propagated back to the Scheduler.
596589
///
597-
/// The command with dependencies that belong to a context different from its own
598-
/// can't be enqueued directly (limitation of OpenCL runtime).
599-
/// Instead, for each dependency, a proxy event is created in the target context
600-
/// and linked using OpenCL callback mechanism with original one. For example,
601-
/// the following SYCL code:
590+
/// The command with dependencies that belong to a context different from its
591+
/// own can't be enqueued directly (limitation of OpenCL runtime).
592+
/// Instead, for each dependency, a proxy event is created in the target
593+
/// context and linked using OpenCL callback mechanism with original one.
594+
/// For example, the following SYCL code:
602595
///
603596
/// \code{.cpp}
604597
/// // The ContextA and ContextB are different OpenCL contexts

0 commit comments

Comments
 (0)