Loading...
Searching...
No Matches
speculationNode.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_SPECULATION_NODE_H
8#define PXR_EXEC_VDF_SPECULATION_NODE_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
17#include "pxr/exec/vdf/node.h"
19
20#include <tbb/concurrent_hash_map.h>
21
22#include <memory>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class VdfSchedule;
27
35class VDF_API_TYPE VdfSpeculationNode final : public VdfNode
36{
37public:
40 VDF_API
42 VdfNetwork *network,
43 const VdfInputSpecs &inputSpecs,
44 const VdfOutputSpecs &outputSpecs);
45
48 virtual bool IsSpeculationNode() const { return true; }
49
57 const VdfContext &context) const {
58 return VdfRequiredInputsPredicate::NoReads(*this);
59 }
60
63 VDF_API
64 virtual void Compute(const VdfContext &context) const;
65
69 VDF_API
70 const VdfSchedule &GetSchedule(const VdfSchedule *requestingSched) const;
71
72private:
73
74 // Only a network is allowed to delete nodes.
75 VDF_API
76 virtual ~VdfSpeculationNode();
77
80 const VdfExecutorInterface &_GetContextExecutor(
81 const VdfContext &context) const {
82 return context._GetExecutor();
83 }
84
90 VdfRequest _GetInputRequest(const VdfSchedule &requestingSched) const;
91
95 const VdfSchedule *_GetSchedule(const VdfRequest &request) const;
96
102 const VdfConnection &inputConnection,
103 const VdfMask &inputDependencyMask,
104 const VdfOutput &output) const;
105
111 const VdfMaskedOutput &maskedOutput,
112 const VdfConnection &inputConnection) const;
113
114private:
115
116 // A hash functor for VdfRequest.
117 struct _HashRequest {
118 bool equal(const VdfRequest &lhs, const VdfRequest &rhs) const {
119 return lhs == rhs;
120 }
121
122 size_t hash(const VdfRequest &request) const {
123 return VdfRequest::Hash()(request);
124 }
125 };
126
127 // This is a schedule map that holds the schedules that we will use to
128 // compute the node. Invalidation is automatic from the
129 // network for which they are scheduled.
130 using _ScheduleMap = tbb::concurrent_hash_map<
131 VdfRequest, std::unique_ptr<VdfSchedule>, _HashRequest>;
132 mutable _ScheduleMap _scheduleMap;
133};
134
135PXR_NAMESPACE_CLOSE_SCOPE
136
137#endif
Fast, compressed bit array which is capable of performing logical operations without first decompress...
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
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values.
VdfInputSpecs is a container for VdfInputSpec objects.
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:37
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:32
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
virtual VDF_API VdfMask::Bits _ComputeInputDependencyMask(const VdfMaskedOutput &maskedOutput, const VdfConnection &inputConnection) const
Returns a mask that indicates which elements of the data that flows along inputConnection are needed ...
virtual VDF_API VdfMask _ComputeOutputDependencyMask(const VdfConnection &inputConnection, const VdfMask &inputDependencyMask, const VdfOutput &output) const
Returns a mask that indicates which elements of the data that flows along output depend on the elemen...
A VdfOutput represents an output on a node.
Definition: output.h:32
VdfOutputSpecs is a container for VdfOutputSpec objects.
This predicate determines whether a given input value is needed to fulfill the input dependencies req...
Contains a specification of how to execute a particular VdfNetwork.
Definition: schedule.h:41
A node that pulls on a vector of value that are downstream of the current execution position.
virtual VdfRequiredInputsPredicate GetRequiredInputsPredicate(const VdfContext &context) const
Returns a predicate to determine the required read inputs.
virtual bool IsSpeculationNode() const
Returns true, indicating that this node performs speculation.
VDF_API VdfSpeculationNode(VdfNetwork *network, const VdfInputSpecs &inputSpecs, const VdfOutputSpecs &outputSpecs)
Construct a new speculation node.
VDF_API const VdfSchedule & GetSchedule(const VdfSchedule *requestingSched) const
Returns the schedule for this speculation node.
virtual VDF_API void Compute(const VdfContext &context) const
Executes the speculation node.