High level optimization of stacked Blockwise layers For operations that have multiple Blockwise operations one after the other, like ``x.T + 123`` we can fuse these into a single Blockwise operation. This happens before any actual tasks are generated, and so can reduce overhead. T
(graph, keys=())
| 1075 | |
| 1076 | |
| 1077 | def optimize_blockwise(graph, keys=()): |
| 1078 | """High level optimization of stacked Blockwise layers |
| 1079 | |
| 1080 | For operations that have multiple Blockwise operations one after the other, like |
| 1081 | ``x.T + 123`` we can fuse these into a single Blockwise operation. This happens |
| 1082 | before any actual tasks are generated, and so can reduce overhead. |
| 1083 | |
| 1084 | This finds groups of Blockwise operations that can be safely fused, and then |
| 1085 | passes them to ``rewrite_blockwise`` for rewriting. |
| 1086 | |
| 1087 | Parameters |
| 1088 | ---------- |
| 1089 | graph : HighLevelGraph |
| 1090 | keys : Iterable |
| 1091 | The keys of all outputs of all collections. |
| 1092 | Used to make sure that we don't fuse a layer needed by an output |
| 1093 | |
| 1094 | Returns |
| 1095 | ------- |
| 1096 | HighLevelGraph |
| 1097 | |
| 1098 | See Also |
| 1099 | -------- |
| 1100 | rewrite_blockwise |
| 1101 | """ |
| 1102 | out = _optimize_blockwise(graph, keys=keys) |
| 1103 | while out.dependencies != graph.dependencies: |
| 1104 | graph = out |
| 1105 | out = _optimize_blockwise(graph, keys=keys) |
| 1106 | return out |
| 1107 | |
| 1108 | |
| 1109 | def _optimize_blockwise(full_graph, keys=()): |
searching dependent graphs…