HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_Partitioner.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __PDG_PARTITIONER_H__
10 #define __PDG_PARTITIONER_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeMerge.h"
15 #include "PDG_Node.h"
16 #include "PDG_WorkItemTypes.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_ArrayMap.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_WorkBuffer.h>
22 
23 class PDG_FeedbackBegin;
25 
26 /**
27  * PDG_Node subclass that partitions incoming work items, e.g. it groups
28  * items together into a single unit that can be used for mapping or further
29  * work item generation.
30  */
32 {
33 public:
35  PDG_GraphContext* context,
36  const UT_StringHolder& name,
37  const PDG_NodeCallbackType* type_object,
38  int custom_id = -1);
39 
40  ~PDG_Partitioner() override {}
41 
42  /// Returns the total memory usage of the node, including any work items
43  /// owned by it.
44  void memoryInfo(
45  PDG_MemoryInfo& memory_info,
46  bool inclusive) const override;
47 
48  /// Deserialized the specified work item into this node. Most of the
49  /// work is handled by the parent class, but partitioner nodes need to
50  /// update the myPartitionMap
52  PDG_WorkItem* work_item) override;
53 
54  /// Called after deserializing a work item and adding its dependencies
55  void commitWorkItem(
56  PDG_WorkItem* work_item) override;
57 
58  /// Adds special handling for feedback blocks, when a specific work item
59  /// in a node is cooked with upstraem dependencies on an end block work
60  /// item
61  void queueWorkItemDeps(
62  PDGE_Evaluator& evaluator,
63  PDG_NodeSet& visited_nodes,
64  PDG_WorkItemIDSet& visited_items,
65  PDG_Filter& filter) override;
66 
67 protected:
68  /// Returns true if this partitioner generates when the target node is
69  /// generated rather than the input nodes
70  inline bool isTargetedPartitioner() const
71  { return (myPartitionWhen > eAllInputsCooked); }
72 
73  /// Sets the loop depth and loop block reference on the node
74  int preCookLoop(
75  const UT_Array<LoopInfo>& begin_info) override;
76 
77  /// Called when this node should clear all work items. Management of the
78  /// main work item array is handled by the parent class, but partitioners
79  /// need to clear their myPartitionMap contents.
80  void clearAllWorkItems() override;
81 
82  /// Called when this node should clear a specific work item. Partitioner
83  /// nodes need to update the myPartitionMap accordingly.
84  void clearWorkItem(
85  const PDG_WorkItem* work_item) override;
86 
87  /// Called when a work item in this node is building depenendcies
88  bool queueWorkItem(
89  PDG_WorkItem* work_item) override;
90 
91  /// Called when a work in this node cook. The partitioner uses this to
92  /// control the data merging process
93  bool cookWorkItem(
94  PDGE_Resolutions& resolutions,
95  PDG_WorkItem* work_item,
96  bool did_cook) override;
97 
98  /// Resets any dependencies owned by this node
99  void resetOwner() override;
100 
101  /// Called when a dependency on this node is resolved
103  evalResolve(
104  PDGE_Resolutions& resolutions,
105  const PDGE_Evaluator& evaluator,
106  PDGE_Dependency* dependency) override;
107 
108  /// Called when a dependency on this node is partially resolved
110  evalPartial(
111  PDGE_Resolutions& resolutions,
112  const PDGE_Evaluator& evaluator,
113  PDGE_Dependency* dependency,
114  const PDGE_DependencyOwner::Array& owners)
115  override;
116 
117  /// Caches any built in parm state for the current cook
118  bool cacheBuiltinParms(
119  PDG_NodeSet& dirty,
120  bool dynamic_inputs) override;
121 
122  /// Adds node dependencies based on the current partitioner settings
123  void addInputDeps(PDG_Node* input_node) override;
124 
125  /// Adds depenencies are that not input specific
126  void addCommonDeps() override;
127 
128 
129  /// Returns true if this node needs to cook its inputs
130  bool requiresCookedInputs(bool cook) const override;
131 
132 private:
133  /// Enumeration of conditions for partitioning work item with missing
134  /// split attributes
135  enum SplitMissing
136  {
137  /// Work items missing the split attribute are ignored
138  eSplitIgnore,
139 
140  /// Work items missing the split attribute are added to the holder
141  /// and the node itself figures out what to do with them.
142  eSplitDefer,
143 
144  /// Work items missing the attribute are added to all partitions.
145  eSplitAll,
146 
147  /// Work items missing the attribute will use a default value
148  eSplitDefault
149  };
150 
151  /// Enumeration of partitioning conditions
152  enum PartitionWhen
153  {
154  /// Partition when all input work items are generated
155  eAllInputsGenerated,
156 
157  /// Partition when all input work items are cooked
158  eAllInputsCooked,
159 
160  /// Partition when all target items are generated
161  eAllTargetsGenerated,
162 
163  /// Partition when each target item group is generated
164  eEachTargetGenerated,
165  };
166 
167  /// Enumeration of frame configuration options
168  enum PartitionFrame
169  {
170  /// The partition will not have its frame set
171  eFrameNone,
172 
173  /// The partition will set its frame from the first work item with
174  /// a frame value
175  eFrameFirst,
176 
177  /// The partition will set its frame from the last work item with
178  /// a frame value
179  eFrameLast,
180 
181  /// The partition will set its frame to the largest frame value
182  /// from all work items
183  eFrameLargest,
184 
185  /// The partition will set its frame to the smallest frame value
186  /// from all work items
187  eFrameSmallest
188  };
189 
190 private:
191 
192  /// Validates and configures targeted nodes
193  bool cacheTargets();
194 
195  /// Loads merge options from pattern parms into our merge pattern object.
196  /// Returns true if the pattern has changed.
197  bool cacheMergePatterns();
198 
199  /// Merges partition data on a specified work item
200  void mergePartitionData(
201  PDG_WorkItem* work_item,
202  bool update);
203 
204  /// Constructs a new partition work item
205  PDG_WorkItem* createPartition(
206  int index,
207  int priority,
208  PDG_OptionalFrame frame);
209 
210  /// Partitions a list of work items that came from a target node
211  bool partitionFromTarget(
212  PDG_WorkItemArray& partitions,
213  PDG_WorkItemArray& new_partitions,
214  PDGE_Resolutions& resolutions,
215  const PDG_WorkItemArray& work_items);
216 
217  /// Constructs partitions from the input work items and target item, and
218  /// returns them back in the output array
219  bool partitionWorkItems(
220  PDG_WorkItemArray& partitions,
221  PDG_WorkItemArray& new_partitions,
222  const PDG_WorkItemArray& work_items,
223  const PDG_WorkItem* target);
224 
225  /// Standard parh for creating partitions
226  bool partitionStandard(
227  PDG_WorkItemArray& partitions,
228  PDG_WorkItemArray& new_partitions,
229  const PDG_WorkItemArray& work_items,
230  const PDG_WorkItem* target,
231  const PDG_PartitionHolder& holder);
232 
233  /// Optimized path for creating a single partition with all work items.
234  bool partitionAll(
235  PDG_WorkItemArray& partitions,
236  PDG_WorkItemArray& new_partitions,
237  const PDG_WorkItemArray& work_items,
238  const PDG_WorkItem* target,
239  const PDG_PartitionHolder& holder,
240  bool add_all);
241 
242  /// Adds a loop dependency for a specified work item
243  void addLoopDependency(
244  PDG_WorkItem* work_item,
245  bool full_cook);
246 
247  /// Adds loop dependencies for the specified partitions and input work
248  /// items
249  void addLoopDependencies(
250  const PDG_WorkItemArray& work_items,
251  bool full_cook);
252 
253  /// Removes stale partitions from the node.
254  void removeStalePartitions();
255 
256 
257 private:
258  using PartitionMap = UT_ArrayMap<int, PDG_WorkItem*>;
259  using LoopDependencies = UT_Array<UT_UniquePtr<PDGE_Dependency>>;
260 
263 
264  PartitionMap myPartitionMap;
265  PDG_NodeSet myPartitionTargets;
266  PDG_FeedbackBegin* myFeedbackBegin;
267 
268  LoopDependencies myLoopDependencies;
269  TargetMap myTargetPartitions;
270  TargetMapInv myTargetPartitionsInv;
271  PDG_AttributeMerge::Pattern myMergePattern;
272  PDG_AttributeMergeOp myOutputMergeOp;
273 
274  UT_StringHolder myWorkItemIDAttribute;
275 
276  UT_StringHolder mySplitAttribute;
277  UT_StringHolder mySplitDefault;
278  SplitMissing mySplitMissing;
279 
280  PartitionWhen myPartitionWhen;
281  PartitionFrame myPartitionFrame;
282 
283  bool mySplitEnabled;
284  bool mySplitPartial;
285  bool myHasCustomFrame;
286  bool myMergeAttributes;
287  bool myStoreWorkItemIDs;
288  bool myIgnoreFailedItems;
289 };
290 
291 #endif /* __PDG_PARTITIONER_H__ */
virtual bool cookWorkItem(PDGE_Resolutions &resolutions, PDG_WorkItem *work_item, bool did_cook)
virtual bool queueWorkItem(PDG_WorkItem *work_item)
Definition: PDG_Node.h:650
virtual PDGE_Dependency::State evalPartial(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *, const Array &)
friend class PDG_Partitioner
Definition: PDG_Node.h:620
#define PDG_API
Definition: PDG_API.h:23
virtual bool deserializeWorkItem(PDG_WorkItem *work_item)
virtual void clearAllWorkItems()
virtual void addCommonDeps()
UT_Optional< fpreal > PDG_OptionalFrame
Optional frame value, used when constructing work items and partitions.
~PDG_Partitioner() override
virtual void queueWorkItemDeps(PDGE_Evaluator &evaluator, PDG_NodeSet &visited_nodes, PDG_WorkItemIDSet &visited_items, PDG_Filter &filter)
Builds evaluation dependencies to cook a specific set of work items.
virtual void clearWorkItem(const PDG_WorkItem *work_item)
bool isTargetedPartitioner() const
int preCookLoop()
Sets the loop depth and loop block reference on the node.
GLenum target
Definition: glcorearb.h:1667
GLuint const GLchar * name
Definition: glcorearb.h:786
PDG_AttributeMergeOp
Enumeration of different ways that attributes can be combined.
virtual void addInputDeps(PDG_Node *input_node)
virtual void commitWorkItem(PDG_WorkItem *work_item)
Called after a work item is completely deserialized.
GLuint index
Definition: glcorearb.h:786
virtual PDGE_Dependency::State evalResolve(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *)
Called when a dependency owned by this object is resolved.
virtual bool cacheBuiltinParms(PDG_NodeSet &dirty, bool dynamic_inputs)
void resetOwner() override
Resets the owner.
virtual void memoryInfo(PDG_MemoryInfo &memory_info, bool inclusive) const
Returns the memory usage as a PDG_MemoryInfo struct.
virtual bool requiresCookedInputs(bool cook) const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297