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  PDG_NodeSet& visited,
76  const UT_Array<LoopInfo>& begin_info)
77  override;
78 
79  /// Called when this node should clear all work items. Management of the
80  /// main work item array is handled by the parent class, but partitioners
81  /// need to clear their myPartitionMap contents.
82  void clearAllWorkItems() override;
83 
84  /// Called when this node should clear a specific work item. Partitioner
85  /// nodes need to update the myPartitionMap accordingly.
86  void clearWorkItem(
87  const PDG_WorkItem* work_item) override;
88 
89  /// Called when a work item in this node is building depenendcies
90  bool queueWorkItem(
91  PDG_WorkItem* work_item) override;
92 
93  /// Called when a work in this node cook. The partitioner uses this to
94  /// control the data merging process
95  bool cookWorkItem(
96  PDGE_Resolutions& resolutions,
97  PDG_WorkItem* work_item,
98  bool did_cook) override;
99 
100  /// Resets any dependencies owned by this node
101  void resetOwner() override;
102 
103  /// Called when a dependency on this node is resolved
105  evalResolve(
106  PDGE_Resolutions& resolutions,
107  const PDGE_Evaluator& evaluator,
108  PDGE_Dependency* dependency) override;
109 
110  /// Called when a dependency on this node is partially resolved
112  evalPartial(
113  PDGE_Resolutions& resolutions,
114  const PDGE_Evaluator& evaluator,
115  PDGE_Dependency* dependency,
116  const PDGE_DependencyOwner::Array& owners)
117  override;
118 
119  /// Caches any built in parm state for the current cook
120  bool cacheBuiltinParms(
121  PDG_NodeSet& dirty,
122  int num_inputs,
123  bool dynamic_inputs) override;
124 
125  /// Adds node dependencies based on the current partitioner settings
126  void addInputDeps(PDG_Node* input_node) override;
127 
128  /// Adds depenencies are that not input specific
129  void addCommonDeps() override;
130 
131 
132  /// Returns true if this node needs to cook its inputs
133  bool requiresCookedInputs(bool cook) const override;
134 
135 private:
136  /// Enumeration of conditions for partitioning work item with missing
137  /// split attributes
138  enum SplitMissing
139  {
140  /// Work items missing the split attribute are ignored
141  eSplitIgnore,
142 
143  /// Work items missing the split attribute are added to the holder
144  /// and the node itself figures out what to do with them.
145  eSplitDefer,
146 
147  /// Work items missing the attribute are added to all partitions.
148  eSplitAll,
149 
150  /// Work items missing the attribute will use a default value
151  eSplitDefault
152  };
153 
154  /// Enumeration of partitioning conditions
155  enum PartitionWhen
156  {
157  /// Partition when all input work items are generated
158  eAllInputsGenerated,
159 
160  /// Partition when all input work items are cooked
161  eAllInputsCooked,
162 
163  /// Partition when all target items are generated
164  eAllTargetsGenerated,
165 
166  /// Partition when each target item group is generated
167  eEachTargetGenerated,
168  };
169 
170  /// Enumeration of frame configuration options
171  enum PartitionFrame
172  {
173  /// The partition will not have its frame set
174  eFrameNone,
175 
176  /// The partition will set its frame from the first work item with
177  /// a frame value
178  eFrameFirst,
179 
180  /// The partition will set its frame from the last work item with
181  /// a frame value
182  eFrameLast,
183 
184  /// The partition will set its frame to the largest frame value
185  /// from all work items
186  eFrameLargest,
187 
188  /// The partition will set its frame to the smallest frame value
189  /// from all work items
190  eFrameSmallest
191  };
192 
193  /// Result of syncing partition attribute data
194  enum SyncResult
195  {
196  /// Sync failed
197  eSyncFail,
198 
199  /// Synced successfully without any user-defined changes
200  eSyncSuccess,
201  };
202 
203 private:
204 
205  /// Validates and configures targeted nodes
206  bool cacheTargets();
207 
208  /// Loads merge options from pattern parms into our merge pattern object.
209  /// Returns true if the pattern has changed.
210  bool cacheMergePatterns();
211 
212  /// Merges partition data on a specified work item
213  SyncResult syncPartitionAttributes(
214  PDG_WorkItem* work_item,
215  bool update);
216 
217  /// Constructs a new partition work item
218  PDG_WorkItem* createPartition(
219  int index,
220  int priority,
221  PDG_OptionalFrame frame);
222 
223  /// Partitions a list of work items that came from a target node
224  bool partitionFromTarget(
225  PDG_WorkItemArray& partitions,
226  PDG_WorkItemArray& new_partitions,
227  PDGE_Resolutions& resolutions,
228  const PDG_WorkItemArray& work_items);
229 
230  /// Constructs partitions from the input work items and target item, and
231  /// returns them back in the output array
232  bool partitionWorkItems(
233  PDG_WorkItemArray& partitions,
234  PDG_WorkItemArray& new_partitions,
235  const PDG_WorkItemArray& work_items,
236  const PDG_WorkItem* target);
237 
238  /// Standard parh for creating partitions
239  bool partitionStandard(
240  PDG_WorkItemArray& partitions,
241  PDG_WorkItemArray& new_partitions,
242  const PDG_WorkItemArray& work_items,
243  const PDG_WorkItem* target,
244  const PDG_PartitionHolder& holder);
245 
246  /// Optimized path for creating a single partition with all work items.
247  bool partitionAll(
248  PDG_WorkItemArray& partitions,
249  PDG_WorkItemArray& new_partitions,
250  const PDG_WorkItemArray& work_items,
251  const PDG_WorkItem* target,
252  const PDG_PartitionHolder& holder,
253  bool add_all);
254 
255  /// Adds a loop dependency for a specified work item
256  void addLoopDependency(
257  PDG_WorkItem* work_item,
258  bool full_cook);
259 
260  /// Adds loop dependencies for the specified partitions and input work
261  /// items
262  void addLoopDependencies(
263  const PDG_WorkItemArray& work_items,
264  bool full_cook);
265 
266  /// Removes stale partitions from the node.
267  void removeStalePartitions();
268 
269 
270 private:
271  using PartitionMap = UT_ArrayMap<int, PDG_WorkItem*>;
272  using LoopDependencies = UT_Array<UT_UniquePtr<PDGE_Dependency>>;
273 
276 
277  PartitionMap myPartitionMap;
278  PDG_NodeSet myPartitionTargets;
279  PDG_FeedbackBegin* myFeedbackBegin;
280 
281  LoopDependencies myLoopDependencies;
282  TargetMap myTargetPartitions;
283  TargetMapInv myTargetPartitionsInv;
284  PDG_AttributeMerge::Pattern myMergePattern;
285  PDG_AttributeMergeOp myOutputMergeOp;
286 
287  UT_StringHolder myWorkItemIDAttribute;
288 
289  UT_StringHolder mySplitAttribute;
290  UT_StringHolder mySplitDefault;
291  SplitMissing mySplitMissing;
292 
293  PartitionWhen myPartitionWhen;
294  PartitionFrame myPartitionFrame;
295 
296  bool mySplitEnabled;
297  bool mySplitPartial;
298  bool myHasCustomFrame;
299  bool myMergeAttributes;
300  bool myStoreWorkItemIDs;
301  bool myIgnoreFailedItems;
302 };
303 
304 #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:651
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
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.
int preCookLoop(PDG_NodeSet &visited)
Sets the loop depth and loop block reference on the node.
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.
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
virtual bool cacheBuiltinParms(PDG_NodeSet &dirty, int num_inputs, bool dynamic_inputs)