Loading...
Searching...
No Matches
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
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16
17#include "pxr/base/tf/hashmap.h"
18
19#include <atomic>
20#include <utility>
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class VdfMaskedOutput;
26using VdfMaskedOutputVector = std::vector<VdfMaskedOutput>;
27class VdfNetwork;
28class VdfNode;
29class VdfRequest;
30class VdfSchedule;
31class VdfScheduleNode;
32class VdfScheduleOutput;
33
41{
42public:
43 // Vector of priorities for pool outputs.
44 typedef std::vector<
45 std::pair<VdfPoolChainIndex, const VdfOutput *>
46 > PoolPriorityVector;
47
50 TfHashMap<const VdfNode *, VdfMaskedOutputVector, TfHash>;
51
60 VDF_API
61 VdfScheduler(const std::atomic_bool *interruptionFlag);
62
65 VDF_API
66 static void Schedule(const VdfRequest &request, VdfSchedule *schedule,
67 bool topologicallySort);
68
75 VDF_API
76 bool CreateSchedule(const VdfRequest &request, VdfSchedule *schedule,
77 bool topologicallySort);
78
81 VDF_API
83 VdfSchedule *schedule,
84 const VdfOutput &output);
85
86protected:
93 bool _HasBeenInterrupted() const {
94 return _interruptionFlag &&
95 _interruptionFlag->load(std::memory_order_relaxed);
96 }
97
101 VDF_API
102 static void _SetScheduleValid(
103 VdfSchedule *schedule,
104 const VdfNetwork *network);
105
117 VDF_API
119 const VdfRequest &request,
120 VdfSchedule *schedule,
121 PoolPriorityVector *poolOutputs);
122
124 VDF_API
125 static void _MarkSmallSchedule(VdfSchedule *schedule);
126
135 VDF_API
137 const VdfRequest &request,
138 VdfSchedule *schedule);
139
151 VDF_API
153 const VdfRequest &request,
154 VdfSchedule *schedule,
155 const PoolPriorityVector &sortedPoolOutputs);
156
162 VDF_API
164 VdfSchedule *schedule,
165 const PoolPriorityVector &sortedPoolOutputs);
166
172 VDF_API
174 VdfSchedule *schedule,
175 const PoolPriorityVector &sortedPoolOutputs);
176
185 VDF_API
186 static void _ComputeLockMasks(
187 const VdfRequest &request,
188 VdfSchedule *schedule,
189 const PoolPriorityVector &sortedPoolOutputs);
190
195 VDF_API
197
206 VDF_API
208
211 VDF_API
213 VdfSchedule *schedule,
214 VdfScheduleNode *node);
215
218 VDF_API
220 VdfSchedule *schedule,
221 VdfScheduleNode *node);
222
225 VDF_API
227 VdfSchedule *schedule,
228 VdfScheduleNode *node);
229
230private:
231
232 // Used to optionally support scheduling interruption.
233 const std::atomic_bool *_interruptionFlag = nullptr;
234};
235
237
238PXR_NAMESPACE_CLOSE_SCOPE
239
240#endif
Class to hold on to an externally owned output and a mask.
A VdfNetwork is a collection of VdfNodes and their connections.
Definition network.h:60
This is the base class for all nodes in a VdfNetwork.
Definition node.h:53
A VdfOutput represents an output on a node.
Definition output.h:32
Contains a specification of how to execute a particular VdfNetwork.
Definition schedule.h:42
This class contains scheduling information necessary to run a single VdfNode.
Used to make a VdfSchedule.
Definition scheduler.h:41
static VDF_API void _MarkSmallSchedule(VdfSchedule *schedule)
Marks the schedule as small if it is indeed small.
VDF_API bool _ScheduleForPassThroughs(const VdfRequest &request, VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
Schedule the outputs from which buffers should be passed.
static VDF_API void _SetScheduleValid(VdfSchedule *schedule, const VdfNetwork *network)
Method to signal that a schedule is done being built and that it is now valid for the given network.
VDF_API bool _ScheduleBufferPasses(const VdfRequest &request, VdfSchedule *schedule)
Method to schedule the buffer passes and the "keep" masks for the scheduled nodes.
static VDF_API void Schedule(const VdfRequest &request, VdfSchedule *schedule, bool topologicallySort)
Generates a schedule.
static VDF_API void _UpdateLockMaskForNode(VdfSchedule *schedule, VdfScheduleNode *node)
Updates schedule for node if the lock mask changed.
static VDF_API void _ComputeLockMasks(const VdfRequest &request, VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
Setup the lock masks require for sparse mung buffer locking for all the outputs in the pool chain.
bool _HasBeenInterrupted() const
Returns true if the scheduler has been interrupted, if the scheduler supports interruption.
Definition scheduler.h:93
static VDF_API bool _ApplyAffectsMasksForNode(VdfScheduleNode *node)
Applies the affects masks to the scheduled node.
VDF_API bool _ScheduleTaskGraph(VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
Schedule the task graph for multi-threaded munging.
VDF_API void _GenerateTasks(VdfSchedule *schedule, const PoolPriorityVector &sortedPoolOutputs)
Generate tasks for the scheduled task graph.
static VDF_API void _UpdateAffectsMaskForInvocation(VdfSchedule *schedule, VdfScheduleNode *node)
Updates the affects mask on an existing scheduled node invocation.
static VDF_API bool _UpdateAffectsMasksForNode(VdfSchedule *schedule, VdfScheduleNode *node)
Updates schedule for node if affects mask changed.
TfHashMap< const VdfNode *, VdfMaskedOutputVector, TfHash > NodeToRequestMap
A map from VdfNode * to VdfMaskedOutputVector.
Definition scheduler.h:49
VDF_API bool CreateSchedule(const VdfRequest &request, VdfSchedule *schedule, bool topologicallySort)
Generates a schedule.
VDF_API bool _ApplyAffectsMasks(VdfSchedule *schedule)
Applies the affects mask to the schedule.
VDF_API VdfScheduler(const std::atomic_bool *interruptionFlag)
Constructs a scheduler.
static VDF_API bool UpdateAffectsMaskForOutput(VdfSchedule *schedule, const VdfOutput &output)
Update schedule after the affects mask changed on output.
VDF_API bool _InitializeRequestMasks(const VdfRequest &request, VdfSchedule *schedule, PoolPriorityVector *poolOutputs)
Initializes the request masks for all the outputs that will be computed as a result of request.