Debian Codegraph @

test/uflacs/unit/test_ssa_manipulations.py

raw
1 # -*- coding: utf-8 -*-
2 """
3 Tests of manipulations of the ssa form of expressions.
4 """
5 from ufl_legacy import *
6 from ufl_legacy import product
7 from ufl_legacy.permutation import compute_indices
8
9 from ffc.uflacs.analysis.graph import build_graph
10
11 # Tests need this but it has been removed. Rewrite tests!
12 # from ffc.uflacs.analysis.graph_rebuild import rebuild_scalar_e2i
13
14 # from ffc.uflacs.analysis.graph_rebuild import rebuild_expression_from_graph
15
16 # from ffc.uflacs.analysis.indexing import (map_indexed_arg_components,
17 # map_indexed_arg_components2,
18 # map_component_tensor_arg_components)
19 # from ffc.uflacs.analysis.graph_symbols import (map_list_tensor_symbols,
20 # map_transposed_symbols, get_node_symbols)
21 # from ffc.uflacs.analysis.dependencies import (compute_dependencies,
22 # mark_active,
23 # mark_image)
24 # from ffc.uflacs.analysis.graph_ssa import (mark_partitions,
25 # compute_dependency_count,
26 # invert_dependencies,
27 # default_cache_score_policy,
28 # compute_cache_scores,
29 # allocate_registers)
30
31
32 def xtest_dependency_construction():
33 cell = triangle
34 d = cell.geometric_dimension()
35 x = SpatialCoordinate(cell)
36 n = FacetNormal(cell)
37
38 U = FiniteElement("CG", cell, 1)
39 V = VectorElement("CG", cell, 1)
40 W = TensorElement("CG", cell, 1)
41 u = Coefficient(U)
42 v = Coefficient(V)
43 w = Coefficient(W)
44
45 i, = indices(1)
46
47 expressions = [as_ufl(1),
48 as_ufl(3.14),
49 as_ufl(0),
50 x[0],
51 n[0],
52 u,
53 v[0],
54 v[1],
55 w[0, 1],
56 w[0, 0] + w[1, 1],
57 (2 * v + w[1, :])[i] * v[i],
58 ]
59
60 for expr in expressions:
61 G = build_graph([expr])
62 ne2i, NV, W, terminals, nvs = rebuild_scalar_e2i(G)
63
64 e2i = ne2i
65 V = NV
66
67 dependencies = compute_dependencies(e2i, V)
68
69 max_symbol = len(V)
70 targets = (max_symbol - 1,)
71 active, num_active = mark_active(max_symbol, dependencies, targets)
72
73 partitions = mark_partitions(V, active, dependencies, {})
74
75 depcount = compute_dependency_count(dependencies)
76
77 inverse_dependencies = invert_dependencies(dependencies, depcount)
78
79 scores = compute_cache_scores(V,
80 active,
81 dependencies,
82 inverse_dependencies,
83 partitions,
84 cache_score_policy=default_cache_score_policy)
85
86 max_registers = 4
87 score_threshold = 1
88 allocations = allocate_registers(active, partitions, targets,
89 scores, max_registers, score_threshold)
90
91 if 0:
92 print()
93 print("====== expr \n", expr)
94 print("====== V \n", '\n'.join(map(str, V)))
95 print("====== dependencies \n", dependencies)
96 print("====== active \n", active)
97 print("====== partitions \n", partitions)
98 print("====== depcount \n", depcount)
99 print("====== inverse_dependencies\n", inverse_dependencies)
100 print("====== scores \n", scores)
101 print("====== allocations \n", allocations)
102 print()