You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And an additional list of dimensions sizes sorted by the numerical id of the dimension:
30
+
31
+
.. code-block::
32
+
33
+
60,60,20,20,8,8,8,8,8,8
34
+
35
+
36
+
To achieve this goal, we implemented a struct called ``EinsumNode`` to parse the string representation of a tree and the numerically sorted dimension sizes.
16
37
This structure holds one node of the tree, its possible children, dimension sizes, and a tensor representing an intermediate or final
17
38
(root node) result.
18
39
@@ -105,6 +126,65 @@ To ensure the success of all tensor operations, the methods return an ``ErrorExe
105
126
106
127
**Task**: Benchmark the performance of your implementation for the above examples. Report the measured performance in GFLOPS.
Performing a benchmark on both Einsum Trees, we get the following performance:
187
+
108
188
.. code-block:: bash
109
189
:emphasize-lines: 4, 8
110
190
@@ -132,18 +212,25 @@ Optimization
132
212
133
213
**Task**: Develop an optimization pass for einsum trees that applies the three transformations.
134
214
215
+
Three transformation that can be performed on the einsum tree are reorder, swap and permutation insert.
216
+
217
+
- **Reorder**: Operates on individual tensor to reorder its dimensions such that next involved tensor operation has a better performance.
218
+
- **Swap**: Swap the two children of a contraction to mitigate the usage of permutation inserts.
219
+
- **Permutation Insert**: Inserts an additional node in the tree to perform a reordering for the next tensor operation.
220
+
135
221
Reorder Node
136
222
""""""""""""
137
223
138
-
For the reorder node we divided into an different optimization pass for the left and the right node.
224
+
For the reorder node we divided the optimization into an different pass for the left and the right node.
139
225
140
226
For the reorder pass, we divided the transformation into two methods. The first is ``reorder_left_node``, which reorders the left child node
141
227
of a node. The second method is ``reorder_right_node``, which is designed to reorder the right child node of a node.
142
-
This division is due to the fact that the left node requires the M dimension as the unit stride, while the right node requires the K1 dimension.
228
+
This division is due to the fact that the left node requires the M dimension as the unit-stride, while the right node requires the K1 dimension
229
+
as unit-stride.
143
230
144
231
*Left Node:*
145
232
146
-
The method ``reorder_left_node`` checks if the last dimensions of the left child node are ``KM``. If not, it permutes the dimensions to
233
+
The method ``reorder_left_node`` checks if the last dimensions of the left child node are ``KM`` dimensions. If not, it permutes the dimensions to
147
234
move ``KM`` to the rightmost location. First, we determine the index of the first occurrence of the ``M`` and ``K`` dimension in the left
148
235
child node of the node from right to left. If they are already in order, we return. Otherwise, we place them at the desired index location.
149
236
@@ -221,7 +308,7 @@ child node of the node from right to left. If they are already in order, we retu
221
308
222
309
*Right Node:*
223
310
224
-
The method ``reorder_right_node`` checks if the last dimensions of the right child node are ``NK``. If not, it permutes the dimensions to
311
+
The method ``reorder_right_node`` checks if the last dimensions of the right child node are ``NK`` dimensions. If not, it permutes the dimensions to
225
312
move ``NK`` to the rightmost location. First, we determine the index of the first occurrence of the ``N`` and ``K`` dimension in the right
226
313
child node of the node from right to left. If they are already in order, we return. Otherwise, we place them at the desired index location.
227
314
@@ -256,8 +343,9 @@ The right node reordering is very similar to the left node reordering, but it or
256
343
Insert Permutation Node
257
344
"""""""""""""""""""""""
258
345
259
-
If the ``reorder_left_node`` or ``reorder_right_node`` method reorders a leaf node, an additional permutation node is inserted. Here the
260
-
fragment in the ``reorder_left_node`` method:
346
+
The permutation node is only added if the ``reorder_left_node`` or ``reorder_right_node`` method reorders a leaf node i.e. a node that is provided by the user.
347
+
348
+
The code fragment of a permutation node in the ``reorder_left_node`` method:
261
349
262
350
.. code-block:: cpp
263
351
@@ -301,9 +389,10 @@ And for the ``reorder_right_node`` method:
301
389
Swap Contraction Nodes
302
390
""""""""""""""""""""""
303
391
304
-
For our current needs, a conditional swap is sufficient. The idea behind the method is to check if a node's unit stride dimension is of type
305
-
``N``. If this is the case, we swap its children to later obtain a unit stride dimension in the first input tensor (left child node). We use
306
-
the C++ ``swap`` method to swap the child nodes of a node, swapping the left child node pointer with the right child node pointer.
392
+
The swap method allows optimization so that the order of the input tensor does not affect the performance of the contraction.
393
+
Therefore, the idea behind the swap method is to check if a node's unit-stride dimension is of type ``N``.
394
+
If this is the case, we swap its children to obtain a unit-stride dimension in the first input tensor (left child node).
395
+
We use the C++ ``swap`` method to swap the child nodes of a node, swapping the left child node pointer with the right child node pointer.
307
396
308
397
.. code-block:: cpp
309
398
@@ -314,66 +403,131 @@ the C++ ``swap`` method to swap the child nodes of a node, swapping the left chi
0 commit comments