-
Notifications
You must be signed in to change notification settings - Fork 157
/
parameters.py
130 lines (94 loc) · 4.12 KB
/
parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""The parameters dictionary contains global parameter settings."""
from __future__ import absolute_import
from ffc import default_parameters
from pyop2.configuration import configuration
from firedrake.citations import Citations
__all__ = ['Parameters', 'parameters', 'disable_performance_optimisations']
class Parameters(dict):
def __init__(self, name=None, **kwargs):
self._name = name
self._update_function = None
for key, value in kwargs.iteritems():
self.add(key, value)
def add(self, key, value=None):
if isinstance(key, Parameters):
self[key.name()] = key
else:
self[key] = value
def __setitem__(self, key, value):
super(Parameters, self).__setitem__(key, value)
if self._update_function:
self._update_function(key, value)
def name(self):
return self._name
def rename(self, name):
self._name = name
def __getstate__(self):
# Remove non-picklable update function slot
d = self.__dict__.copy()
del d["_update_function"]
return d
def set_update_function(self, callable):
"""Set a function to be called whenever a dictionary entry is changed.
:arg callable: the function.
The function receives two arguments, the key-value pair of
updated entries."""
self._update_function = callable
parameters = Parameters()
"""A nested dictionary of parameters used by Firedrake"""
parameters.add(Parameters("assembly_cache",
enabled=True,
eviction=True,
max_bytes=float("Inf"),
max_factor=0.6,
max_misses=3))
parameters.add(Parameters("coffee",
O2=True))
# Spew citation for coffee paper if user modifies coffee options.
parameters["coffee"].set_update_function(lambda k, v: Citations().register("Luporini2015"))
# Default to the values of PyOP2 configuration dictionary
pyop2_opts = Parameters("pyop2_options",
**configuration)
pyop2_opts.set_update_function(lambda k, v: configuration.unsafe_reconfigure(**{k: v}))
# Override values
pyop2_opts["type_check"] = True
pyop2_opts["log_level"] = "INFO"
parameters.add(pyop2_opts)
ffc_parameters = default_parameters()
ffc_parameters['write_file'] = False
ffc_parameters['format'] = 'pyop2'
ffc_parameters['representation'] = 'quadrature'
ffc_parameters['pyop2-ir'] = True
parameters.add(Parameters("form_compiler", **ffc_parameters))
parameters["reorder_meshes"] = True
parameters["matnest"] = True
parameters["type_check_safe_par_loops"] = False
def disable_performance_optimisations():
"""Switches off performance optimisations in Firedrake.
This is mostly useful for debugging purposes.
This switches off all of COFFEE's kernel compilation optimisations
and enables PyOP2's runtime checking of par_loop arguments in all
cases (even those where they are claimed safe). Additionally, it
switches to compiling generated code in debug mode.
Returns a function that can be called with no arguments, to
restore the state of the parameters dict."""
check = parameters["pyop2_options"]["type_check"]
debug = parameters["pyop2_options"]["debug"]
lazy = parameters["pyop2_options"]["lazy_evaluation"]
safe_check = parameters["type_check_safe_par_loops"]
coffee = parameters["coffee"]
cache = parameters["assembly_cache"]["enabled"]
def restore():
parameters["pyop2_options"]["type_check"] = check
parameters["pyop2_options"]["debug"] = debug
parameters["pyop2_options"]["lazy_evaluation"] = lazy
parameters["type_check_safe_par_loops"] = safe_check
parameters["coffee"] = coffee
parameters["assembly_cache"]["enabled"] = cache
parameters["pyop2_options"]["type_check"] = True
parameters["pyop2_options"]["debug"] = True
parameters["pyop2_options"]["lazy_evaluation"] = False
parameters["type_check_safe_par_loops"] = True
parameters["coffee"] = {}
parameters["assembly_cache"]["enabled"] = False
return restore