HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scheduler.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_VDF_SCHEDULER_H
8 #define PXR_EXEC_VDF_SCHEDULER_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
16 
18 
19 class VdfMaskedOutput;
20 using VdfMaskedOutputVector = std::vector<VdfMaskedOutput>;
21 class VdfNetwork;
22 class VdfNode;
23 class VdfRequest;
24 class VdfSchedule;
25 class VdfScheduleNode;
26 class VdfScheduleOutput;
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 ///
30 /// \class VdfScheduler
31 ///
32 /// \brief Used to make a VdfSchedule.
33 ///
35 {
36 public:
37  // Vector of priorities for pool outputs.
38  typedef std::vector<
39  std::pair<VdfPoolChainIndex, const VdfOutput *>
41 
42  /// A map from VdfNode * to VdfMaskedOutputVector.
43  typedef
45 
46  /// Generates a schedule.
47  ///
48  VDF_API
49  static void Schedule(const VdfRequest &request, VdfSchedule *schedule,
50  bool topologicallySort);
51 
52  /// Update \p schedule after the affects mask changed on \p output.
53  ///
54  VDF_API
55  static bool UpdateAffectsMaskForOutput(
56  VdfSchedule *schedule,
57  const VdfOutput &output);
58 
59 protected:
60  /// Method to signal that a \p schedule is done being built and that it is
61  /// now valid for the given \p network.
62  ///
63  VDF_API
64  static void _SetScheduleValid(
65  VdfSchedule *schedule,
66  const VdfNetwork *network);
67 
68  /// Initializes the request masks for all the outputs that will be computed
69  /// as a result of \p request.
70  ///
71  /// \p poolOutputs is an output parameter. The vector will contain
72  /// all the pool outputs scheduled with request masks, sorted in reverse
73  /// order of pool chain index, i.e. the pool output furthest downstream
74  /// will be at the front of the vector.
75  ///
76  VDF_API
77  static void _InitializeRequestMasks(
78  const VdfRequest &request,
79  VdfSchedule *schedule,
80  PoolPriorityVector *poolOutputs);
81 
82  /// Marks the schedule as small if it is indeed small.
83  VDF_API
84  static void _MarkSmallSchedule(VdfSchedule *schedule);
85 
86  /// Method to schedule the buffer passes and the "keep" masks for the
87  /// scheduled nodes.
88  ///
89  /// Schedulers that care about performance will want to call this after
90  /// all the outputs have gone through the _ScheduleOutput method above.
91  ///
92  VDF_API
93  static void _ScheduleBufferPasses(
94  const VdfRequest &request,
95  VdfSchedule *schedule);
96 
97  /// Schedule the outputs from which buffers should be passed. This helps
98  /// ensure that potentially large portions of the network that won't have
99  /// any effect in this schedule are skipped when passing buffers.
100  ///
101  /// \p sortedPoolOutputs contains all the pool outputs in the schedule.
102  /// Callers are responsible for ensuring that \p sortedPoolOutputs are in
103  /// descending order of their respective pool chain index, i.e. the pool
104  /// output furthest downstream will be at the front of the vector.
105  ///
106  VDF_API
107  static void _ScheduleForPassThroughs(
108  const VdfRequest &request,
109  VdfSchedule *schedule,
110  const PoolPriorityVector &sortedPoolOutputs);
111 
112  /// Generate tasks for the scheduled task graph. The task graph is used
113  /// by the parallel evaluation engine.
114  ///
115  VDF_API
116  static void _GenerateTasks(
117  VdfSchedule *schedule,
118  const PoolPriorityVector &sortedPoolOutputs);
119 
120  /// Schedule the task graph for multi-threaded munging. This will generate
121  /// tasks and invocations, as well as dependencies between them.
122  ///
123  VDF_API
124  static void _ScheduleTaskGraph(
125  VdfSchedule *schedule,
126  const PoolPriorityVector &sortedPoolOutputs);
127 
128  /// Setup the lock masks require for sparse mung buffer locking for all the
129  /// outputs in the pool chain.
130  ///
131  /// \p sortedPoolOutputs contains all the pool outputs in the schedule.
132  /// Callers are responsible for ensuring that \p sortedPoolOutputs are in
133  /// descending order of their respective pool chain index, i.e. the pool
134  /// output furthest downstream will be at the front of the vector.
135  ///
136  VDF_API
137  static void _ComputeLockMasks(
138  const VdfRequest &request,
139  VdfSchedule *schedule,
140  const PoolPriorityVector &sortedPoolOutputs);
141 
142  /// Applies the affects mask to the schedule.
143  ///
144  VDF_API
145  static void _ApplyAffectsMasks(VdfSchedule *schedule);
146 
147  /// Applies the affects masks to the scheduled node.
148  ///
149  /// This mask is the ANDing of the request mask and the affects mask (if
150  /// any). It is used by iterators to quickly skip only to the elements
151  /// that are affected by the node. It is an optional mask, and if it
152  /// doesn't exist, the scheduled affects mask will simply be request mask
153  /// (a super set of the truly affected elements).
154  ///
155  VDF_API
156  static bool _ApplyAffectsMasksForNode(VdfScheduleNode *node);
157 
158  /// Updates the affects mask on an existing scheduled node invocation.
159  ///
160  VDF_API
162  VdfSchedule *schedule,
163  VdfScheduleNode *node);
164 
165  /// Updates schedule for \p node if affects mask changed.
166  ///
167  VDF_API
168  static bool _UpdateAffectsMasksForNode(
169  VdfSchedule *schedule,
170  VdfScheduleNode *node);
171 
172  /// Updates schedule for \p node if the lock mask changed.
173  ///
174  VDF_API
175  static void _UpdateLockMaskForNode(
176  VdfSchedule *schedule,
177  VdfScheduleNode *node);
178 
179 };
180 
181 ///////////////////////////////////////////////////////////////////////////////
182 
184 
185 #endif
static VDF_API void _UpdateLockMaskForNode(VdfSchedule *schedule, VdfScheduleNode *node)
static VDF_API bool _UpdateAffectsMasksForNode(VdfSchedule *schedule, VdfScheduleNode *node)
static VDF_API void _SetScheduleValid(VdfSchedule *schedule, const VdfNetwork *network)
static VDF_API bool UpdateAffectsMaskForOutput(VdfSchedule *schedule, const VdfOutput &output)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
static VDF_API void _ComputeLockMasks(const VdfRequest &request, VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
Definition: node.h:52
#define VDF_API
Definition: api.h:25
static VDF_API void _ApplyAffectsMasks(VdfSchedule *schedule)
std::vector< std::pair< VdfPoolChainIndex, const VdfOutput * > > PoolPriorityVector
Definition: scheduler.h:40
static VDF_API void _ScheduleBufferPasses(const VdfRequest &request, VdfSchedule *schedule)
static VDF_API void Schedule(const VdfRequest &request, VdfSchedule *schedule, bool topologicallySort)
Contains a specification of how to execute a particular VdfNetwork.
Definition: schedule.h:40
static VDF_API void _ScheduleForPassThroughs(const VdfRequest &request, VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
static VDF_API void _UpdateAffectsMaskForInvocation(VdfSchedule *schedule, VdfScheduleNode *node)
static VDF_API void _InitializeRequestMasks(const VdfRequest &request, VdfSchedule *schedule, PoolPriorityVector *poolOutputs)
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
Used to make a VdfSchedule.
Definition: scheduler.h:34
TfHashMap< const VdfNode *, VdfMaskedOutputVector, TfHash > NodeToRequestMap
A map from VdfNode * to VdfMaskedOutputVector.
Definition: scheduler.h:44
static VDF_API void _ScheduleTaskGraph(VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
static VDF_API bool _ApplyAffectsMasksForNode(VdfScheduleNode *node)
static VDF_API void _MarkSmallSchedule(VdfSchedule *schedule)
Marks the schedule as small if it is indeed small.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static VDF_API void _GenerateTasks(VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
std::vector< VdfMaskedOutput > VdfMaskedOutputVector