提交 80209cb4 authored 作者: Frederic Bastien's avatar Frederic Bastien

add a STABILIZE mode and a stabilize optimizer. They allow to test that…

add a STABILIZE mode and a stabilize optimizer. They allow to test that stabilization optimization happen in the stabilize phase. Not always the case now.
上级 e14b6ac3
......@@ -72,13 +72,16 @@ def register_linker(name, linker):
OPT_FAST_RUN = gof.Query(include = ['fast_run'])
OPT_FAST_RUN_STABLE = OPT_FAST_RUN.requiring('stable')
OPT_FAST_COMPILE = gof.Query(include = ['fast_compile'])
OPT_STABILIZE = gof.Query(include = ['fast_run'])
OPT_STABILIZE.position_cutoff = 1.5000001
predefined_optimizers = {
None : lambda env: None,
'merge' : gof.MergeOptimizer(),
'fast_run' : OPT_FAST_RUN,
'fast_run_stable' : OPT_FAST_RUN_STABLE,
'fast_compile' : OPT_FAST_COMPILE
'fast_compile' : OPT_FAST_COMPILE,
'stabilize': OPT_STABILIZE
}
def register_optimizer(name, opt):
......@@ -258,10 +261,13 @@ FAST_RUN = Mode('c|py', 'fast_run')
FAST_RUN_NOGC = Mode("c|py_nogc", 'fast_run')
SANITY_CHECK = [Mode('c|py', None),
Mode('c|py', 'fast_run')]
STABILIZE = Mode("c|py", OPT_STABILIZE)
predefined_modes = {'FAST_COMPILE': FAST_COMPILE,
'FAST_RUN': FAST_RUN,
'FAST_RUN_NOGC':FAST_RUN_NOGC,
'SANITY_CHECK': SANITY_CHECK}
'SANITY_CHECK': SANITY_CHECK,
'STABILIZE': STABILIZE}
instanciated_default_mode=None
def get_mode(orig_string):
......
......@@ -108,30 +108,39 @@ class DB(object):
class Query(object):
def __init__(self, include, require = None, exclude = None, subquery = None):
def __init__(self, include, require = None, exclude = None, subquery = None, position_cutoff = None):
"""
:type position_cutoff: float
:param position_cutoff: Used by SequenceDB to keep only optimizer that
are positioned before the cut_off point.
"""
self.include = set(include)
self.require = require or set()
self.exclude = exclude or set()
self.subquery = subquery or {}
self.position_cutoff = position_cutoff
#add all opt with this tag
def including(self, *tags):
return Query(self.include.union(tags),
self.require,
self.exclude,
self.subquery)
self.subquery,
self.position_cutoff)
#remove all opt with this tag
def excluding(self, *tags):
return Query(self.include,
self.require,
self.exclude.union(tags),
self.subquery)
self.subquery,
self.position_cutoff)
#keep only opt with this tag.
def requiring(self, *tags):
return Query(self.include,
self.require.union(tags),
self.exclude,
self.subquery)
self.subquery,
self.position_cutoff)
......@@ -184,8 +193,15 @@ class SequenceDB(DB):
:type position_cutoff: float or int
:param position_cutoff: only optimizations with position less than the cutoff are returned.
"""
position_cutoff = kwtags.pop('position_cutoff', config.optdb.position_cutoff)
opts = super(SequenceDB, self).query(*tags, **kwtags)
position_cutoff = kwtags.pop('position_cutoff', config.optdb.position_cutoff)
if len(tags)>=1 and isinstance(tags[0],Query):
#the call to super should have raise an error with a good message
assert len(tags)==1
if getattr(tags[0],'position_cutoff', None):
position_cutoff = tags[0].position_cutoff
opts = [o for o in opts if self.__position__[o.name] < position_cutoff]
opts.sort(key = lambda obj: self.__position__[obj.name])
return opt.SeqOptimizer(opts, failure_callback = self.failure_callback)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论