Loading...
Searching...
No Matches
executorInterface.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_EXECUTOR_API_H
8#define PXR_EXEC_VDF_EXECUTOR_API_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16#include "pxr/exec/vdf/types.h"
17
18#include "pxr/base/tf/hashset.h"
19
20#include <atomic>
21#include <memory>
22#include <mutex>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class VdfMask;
27class VdfNetwork;
28class VdfOutput;
29class VdfRequest;
30class VdfSchedule;
31class VdfVector;
34class VdfExecutorFactoryBase;
37
43
44class VDF_API_TYPE VdfExecutorInterface
45{
46public:
50 VdfExecutorInterface &operator=(const VdfExecutorInterface &) = delete;
51
54 VDF_API
56
59
62 VDF_API
63 void Run(
64 const VdfSchedule &schedule,
65 VdfExecutorErrorLogger *errorLogger = NULL);
66
73 VDF_API
74 void Run(
75 const VdfSchedule &schedule,
76 const VdfRequest &computeRequest,
77 VdfExecutorErrorLogger *errorLogger = NULL);
78
80
81
84
88 virtual const VdfExecutorFactoryBase &GetFactory() const = 0;
89
91
92
95
99 VDF_API
100 void RegisterObserver(const VdfExecutorObserver *observer) const;
101
106 VDF_API
107 void UnregisterObserver(const VdfExecutorObserver *observer) const;
108
110
111
114
117 virtual void Resize(const VdfNetwork &network) {}
118
121 virtual void SetOutputValue(
122 const VdfOutput &output,
123 const VdfVector &value,
124 const VdfMask &mask) = 0;
125
132 virtual bool TakeOutputValue(
133 const VdfOutput &output,
134 VdfVector *value,
135 const VdfMask &mask) = 0;
136
142 const VdfOutput &output,
143 const VdfMask &mask) const {
144 return _GetOutputValueForReading(output, mask);
145 }
146
151 const VdfOutput &sourceOutput,
152 const VdfOutput &destOutput) = 0;
153
155
156
159
163 return _parentExecutor;
164 }
165
174 VDF_API
175 void SetParentExecutor(const VdfExecutorInterface *parentExecutor);
176
178
179
182
188 VDF_API
190 const VdfMaskedOutputVector &invalidationRequest);
191
202 VDF_API
204
210 VDF_API
211 void ClearData();
212
215 VDF_API
216 void ClearDataForOutput(const VdfId outputId, const VdfId nodeId);
217
220 virtual bool IsEmpty() const = 0;
221
223
224
227
232 ++_executorInvalidationTimestamp;
233 }
234
238 _executorInvalidationTimestamp =
240 }
241
245 return _executorInvalidationTimestamp;
246 }
247
253 const VdfOutput &source,
254 const VdfOutput &dest) const = 0;
255
257
258
261
264 void SetInterruptionFlag(const std::atomic_bool *interruptionFlag) {
265 _interruptionFlag = interruptionFlag;
266 }
267
270 const std::atomic_bool *GetInterruptionFlag() const {
271 return _interruptionFlag;
272 }
273
278 bool HasBeenInterrupted() const {
279 return _interruptionFlag && _interruptionFlag->load();
280 }
281
283
284
287
294 _stats = stats;
295 }
296
300 return _stats;
301 }
302
304
305
306protected:
307
310 VDF_API
312
315 VDF_API
316 explicit VdfExecutorInterface(const VdfExecutorInterface *parentExecutor);
317
320 virtual void _Run(
321 const VdfSchedule &schedule,
322 const VdfRequest &computeRequest,
323 VdfExecutorErrorLogger *errorLogger) = 0;
324
327 virtual const VdfVector *_GetInputValue(
328 const VdfConnection &connection,
329 const VdfMask &mask) const = 0;
330
334 const VdfOutput &output,
335 const VdfMask &mask) const = 0;
336
340 const VdfOutput &output) const = 0;
341
345 virtual bool _IsOutputInvalid(
346 const VdfId outputId,
347 const VdfMask &invalidationMask) const = 0;
348
355 virtual bool _InvalidateOutput(
356 const VdfOutput &output,
357 const VdfMask &invalidationMask) = 0;
358
365 const VdfMaskedOutputVector &invalidationRequest,
366 VdfMaskedOutputVector *processedRequest) {
367 return false;
368 }
369
375
381 VDF_API
382 virtual void _ClearData();
383
389 VDF_API
390 virtual void _ClearDataForOutput(const VdfId outputId, const VdfId nodeId);
391
396 const VdfOutput &destOutput,
397 const VdfOutput &sourceOutput,
398 const VdfMask &sourceMask) const = 0;
399
404 virtual void _TouchOutput(const VdfOutput &output) const = 0;
405
406private:
407
408 // VdfContext needs access to _SetReferenceOutputValue,
409 // _GetOutputValueForReading, _GetOutputValueForWriting and _LogWarning.
410 friend class VdfContext;
411
412 // VdfIterator needs friend access to _GetInputValue,
413 // _GetOutputValueForReading and _GetOutputValueForWriting.
414 friend class VdfIterator;
415
416 // VdfSpeculationNode needs friend access to _GetOutputValueForWriting.
417 friend class VdfSpeculationNode;
418
419 // These classes need access to _TouchOutput.
420 template<template <typename> class E, class D>
421 friend class VdfSpeculationExecutor;
422 template<class T> friend class VdfSpeculationExecutorEngine;
423 template<class T> friend class VdfPullBasedExecutorEngine;
424 template<class T> friend class VdfParallelSpeculationExecutorEngine;
425
426 // VdfExecutorInvalidator needs access to _InvalidateOutput.
427 friend class VdfExecutorInvalidator;
428
429 // The optional invalidator, responsible for invalidating output state
430 // and temporary buffers for outputs and their dependent outputs.
431 std::unique_ptr<VdfExecutorInvalidator> _invalidator;
432
433 // Optional, externally provided (i.e. not owned by the executor) object
434 // to keep track of execution statistics.
435 VdfExecutionStats *_stats;
436
437 // Keeps track of the VdfExecutorObservers registered with this executor
438 typedef TfHashSet<const VdfExecutorObserver *, TfHash> _Observers;
439 mutable _Observers _observers;
440
441 // Access to the _observers set can happen from multiple threads. The
442 // scenario where this happens is when background execution is interrupted
443 // with sharing enabled. Interuption iterates over the _observers lists in
444 // order to notify. That notification causes sharing node to release
445 // sub-executors via a worker thread. That also does unregister from the
446 // _observers set while the main thread is still using the set to interrupt.
447 mutable std::recursive_mutex _observersLock;
448
449 // The executor stores its own invalidation timestamp.
450 // This timestamp will be applied to the data manager upon
451 // invalidating values.
452 VdfInvalidationTimestamp _executorInvalidationTimestamp;
453
454 // Optional parent executor.
455 const VdfExecutorInterface *_parentExecutor;
456
457 // Interruption flag
458 const std::atomic_bool *_interruptionFlag;
459
460};
461
463
464PXR_NAMESPACE_CLOSE_SCOPE
465
466#endif
A class that fully represents a connection between two VdfNodes.
Definition connection.h:30
A context is the parameter bundle passed to callbacks of computations.
Definition context.h:40
Execution stats profiling event logger.
A client may instantiate an object of this class and set it in an executor, to collect errors that ma...
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values.
void IncrementExecutorInvalidationTimestamp()
Increment this executor's invalidation timestamp for mung buffer locking.
VDF_API void Run(const VdfSchedule &schedule, VdfExecutorErrorLogger *errorLogger=NULL)
Executes the schedule.
VDF_API void ClearDataForOutput(const VdfId outputId, const VdfId nodeId)
Clears the executor buffers for a specific output.
virtual bool IsEmpty() const =0
Returns true if the executor buffers are empty.
virtual bool _InvalidateOutput(const VdfOutput &output, const VdfMask &invalidationMask)=0
Called during invalidation to mark outputs as invalid and determine when the traversal can terminate ...
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const =0
Returns true, if the invalidation timestamps between the source and dest outputs do not match,...
virtual void _Run(const VdfSchedule &schedule, const VdfRequest &computeRequest, VdfExecutorErrorLogger *errorLogger)=0
Run this executor with the given schedule and request.
bool HasBeenInterrupted() const
Returns whether or not the executor has been interrupted, if the executor supports interruption.
void SetInterruptionFlag(const std::atomic_bool *interruptionFlag)
Set the interruption flag.
const VdfVector * GetOutputValue(const VdfOutput &output, const VdfMask &mask) const
Returns the cached value for a given output if it has a cache that contains all values specified by m...
VDF_API VdfExecutorInterface()
Protected default constructor.
VDF_API void ClearData()
Clears the executor buffers.
const std::atomic_bool * GetInterruptionFlag() const
Returns the interruption flag.
void SetExecutionStats(VdfExecutionStats *stats)
Sets an execution stats object.
virtual void _TouchOutput(const VdfOutput &output) const =0
Mark the output as having been visited.
virtual void Resize(const VdfNetwork &network)
Resize the executor to accomodate data for the given network.
VdfExecutorInterface(const VdfExecutorInterface &)=delete
Noncopyable.
VDF_API void SetParentExecutor(const VdfExecutorInterface *parentExecutor)
Sets the parent executor.
virtual VDF_API void _ClearDataForOutput(const VdfId outputId, const VdfId nodeId)
Virtual implementation of ClearDataForOutput, which can optionally be overridden by derived classes.
VDF_API void InvalidateValues(const VdfMaskedOutputVector &invalidationRequest)
Invalidates the network, starting from the masked outputs in request.
VDF_API void InvalidateTopologicalState()
Invalidate all state depending on network topology.
const VdfExecutorInterface * GetParentExecutor() const
Returns the parent executor, if any.
virtual const VdfExecutorFactoryBase & GetFactory() const =0
Returns a factory class facilitating the construction of new executors that share traits with this ex...
VDF_API void RegisterObserver(const VdfExecutorObserver *observer) const
Can be called by clients to register a VdfExecutorObserver with this executor.
virtual VDF_API ~VdfExecutorInterface()
Destructor.
virtual void DuplicateOutputData(const VdfOutput &sourceOutput, const VdfOutput &destOutput)=0
Duplicates the output data associated with sourceOutput and copies it to destOutput.
virtual void _SetReferenceOutputValue(const VdfOutput &destOutput, const VdfOutput &sourceOutput, const VdfMask &sourceMask) const =0
Called to set destOutput's buffer output to be a reference to the buffer output of sourceOutput.
VDF_API void Run(const VdfSchedule &schedule, const VdfRequest &computeRequest, VdfExecutorErrorLogger *errorLogger=NULL)
Executes the schedule.
VDF_API VdfExecutorInterface(const VdfExecutorInterface *parentExecutor)
Construct with a parent executor.
virtual void _UpdateInvalidationTimestamp()=0
Called before invalidation begins to update the timestamp that will be written for every VdfOutput vi...
VdfExecutionStats * GetExecutionStats() const
Returns the Execution Stats object, if any.
virtual VDF_API void _ClearData()
Virtual implementation of ClearData, which can optionally be overridden by derived classes.
virtual bool TakeOutputValue(const VdfOutput &output, VdfVector *value, const VdfMask &mask)=0
Transfers ownership of the value to the given output.
virtual bool _IsOutputInvalid(const VdfId outputId, const VdfMask &invalidationMask) const =0
Returns true if the output is already invalid for the given invalidationMask.
virtual const VdfVector * _GetInputValue(const VdfConnection &connection, const VdfMask &mask) const =0
Returns a value for the cache that flows across connection.
void InheritExecutorInvalidationTimestamp(const VdfExecutorInterface &executor)
Inherit the invalidation timestamp from another executor.
virtual VdfVector * _GetOutputValueForWriting(const VdfOutput &output) const =0
Returns an output value for writing.
virtual bool _PreProcessInvalidation(const VdfMaskedOutputVector &invalidationRequest, VdfMaskedOutputVector *processedRequest)
This method is called as a pre-processing step before an InvalidateValues() call.
VdfInvalidationTimestamp GetExecutorInvalidationTimestamp() const
Returns this executor's invalidation timestamp.
virtual const VdfVector * _GetOutputValueForReading(const VdfOutput &output, const VdfMask &mask) const =0
Returns an output value for reading.
VDF_API void UnregisterObserver(const VdfExecutorObserver *observer) const
Must be called by clients to unregister a VdfExecutorObserver, which has been previously registered w...
virtual void SetOutputValue(const VdfOutput &output, const VdfVector &value, const VdfMask &mask)=0
Sets the cached value for a given output.
Invalidates state and temporary buffers of all outputs dependent on the outputs supplied in the inval...
This is an interface for any class that wants to listen to specific executor events,...
Base class for libVdf iterators.
Definition iterator.h:36
A VdfMask is placed on connections to specify the data flowing through them.
Definition mask.h:37
A VdfNetwork is a collection of VdfNodes and their connections.
Definition network.h:60
A VdfOutput represents an output on a node.
Definition output.h:32
An executor engine used for parallel speculation node evaluation, deriving from VdfParallelExecutorEn...
This class is a collection of common functions used by pulled based executors.
Contains a specification of how to execute a particular VdfNetwork.
Definition schedule.h:41
This class provides an executor engine to the speculation executor.
Executor used in speculation.
A node that pulls on a vector of value that are downstream of the current execution position.
This class is used to abstract away knowledge of the cache data used for each node.
Definition vector.h:59
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition types.h:107
unsigned int VdfInvalidationTimestamp
Type of the timestamp that identifies the most recent round of invalidation.
Definition types.h:74