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
207 VDF_API
208 void ClearData();
209
212 VDF_API
213 void ClearDataForOutput(const VdfId outputId, const VdfId nodeId);
214
217 virtual bool IsEmpty() const = 0;
218
220
221
224
229 ++_executorInvalidationTimestamp;
230 }
231
235 _executorInvalidationTimestamp =
237 }
238
242 return _executorInvalidationTimestamp;
243 }
244
250 const VdfOutput &source,
251 const VdfOutput &dest) const = 0;
252
254
255
258
261 void SetInterruptionFlag(const std::atomic_bool *interruptionFlag) {
262 _interruptionFlag = interruptionFlag;
263 }
264
267 const std::atomic_bool *GetInterruptionFlag() const {
268 return _interruptionFlag;
269 }
270
275 bool HasBeenInterrupted() const {
276 return _interruptionFlag && _interruptionFlag->load();
277 }
278
280
281
284
291 _stats = stats;
292 }
293
297 return _stats;
298 }
299
301
302
303protected:
304
307 VDF_API
309
312 VDF_API
313 explicit VdfExecutorInterface(const VdfExecutorInterface *parentExecutor);
314
317 virtual void _Run(
318 const VdfSchedule &schedule,
319 const VdfRequest &computeRequest,
320 VdfExecutorErrorLogger *errorLogger) = 0;
321
324 virtual const VdfVector *_GetInputValue(
325 const VdfConnection &connection,
326 const VdfMask &mask) const = 0;
327
331 const VdfOutput &output,
332 const VdfMask &mask) const = 0;
333
337 const VdfOutput &output) const = 0;
338
342 virtual bool _IsOutputInvalid(
343 const VdfId outputId,
344 const VdfMask &invalidationMask) const = 0;
345
352 virtual bool _InvalidateOutput(
353 const VdfOutput &output,
354 const VdfMask &invalidationMask) = 0;
355
362 const VdfMaskedOutputVector &invalidationRequest,
363 VdfMaskedOutputVector *processedRequest) {
364 return false;
365 }
366
372
376 VDF_API
377 virtual void _ClearData();
378
382 VDF_API
383 virtual void _ClearDataForOutput(const VdfId outputId, const VdfId nodeId);
384
389 const VdfOutput &destOutput,
390 const VdfOutput &sourceOutput,
391 const VdfMask &sourceMask) const = 0;
392
397 virtual void _TouchOutput(const VdfOutput &output) const = 0;
398
399private:
400
401 // VdfContext needs access to _SetReferenceOutputValue,
402 // _GetOutputValueForReading, _GetOutputValueForWriting and _LogWarning.
403 friend class VdfContext;
404
405 // VdfIterator needs friend access to _GetInputValue,
406 // _GetOutputValueForReading and _GetOutputValueForWriting.
407 friend class VdfIterator;
408
409 // VdfSpeculationNode needs friend access to _GetOutputValueForWriting.
410 friend class VdfSpeculationNode;
411
412 // These classes need access to _TouchOutput.
413 template<template <typename> class E, class D>
414 friend class VdfSpeculationExecutor;
415 template<class T> friend class VdfSpeculationExecutorEngine;
416 template<class T> friend class VdfPullBasedExecutorEngine;
417 template<class T> friend class VdfParallelSpeculationExecutorEngine;
418
419 // VdfExecutorInvalidator needs access to _InvalidateOutput.
420 friend class VdfExecutorInvalidator;
421
422 // The optional invalidator, responsible for invalidating output state
423 // and temporary buffers for outputs and their dependent outputs.
424 std::unique_ptr<VdfExecutorInvalidator> _invalidator;
425
426 // Optional, externally provided (i.e. not owned by the executor) object
427 // to keep track of execution statistics.
428 VdfExecutionStats *_stats;
429
430 // Keeps track of the VdfExecutorObservers registered with this executor
431 typedef TfHashSet<const VdfExecutorObserver *, TfHash> _Observers;
432 mutable _Observers _observers;
433
434 // Access to the _observers set can happen from multiple threads. The
435 // scenario where this happens is when background execution is interrupted
436 // with sharing enabled. Interuption iterates over the _observers lists in
437 // order to notify. That notification causes sharing node to release
438 // sub-executors via a worker thread. That also does unregister from the
439 // _observers set while the main thread is still using the set to interrupt.
440 mutable std::recursive_mutex _observersLock;
441
442 // The executor stores its own invalidation timestamp.
443 // This timestamp will be applied to the data manager upon
444 // invalidating values.
445 VdfInvalidationTimestamp _executorInvalidationTimestamp;
446
447 // Optional parent executor.
448 const VdfExecutorInterface *_parentExecutor;
449
450 // Interruption flag
451 const std::atomic_bool *_interruptionFlag;
452
453};
454
456
457PXR_NAMESPACE_CLOSE_SCOPE
458
459#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 executors 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 the ClearDataForOutput call.
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 the ClearData call.
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:56
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