提交 f8f49690 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Remove unnecessary implicit COp.python_constant_folding function

上级 c058326d
...@@ -414,9 +414,11 @@ class GpuElemwise(_NoPythonOp, HideC, Elemwise): ...@@ -414,9 +414,11 @@ class GpuElemwise(_NoPythonOp, HideC, Elemwise):
return str(code) return str(code)
# Since we don't have a perform ... def prepare_node(self, node, storage_map, compute_map, no_recycling, impl=None):
def python_constant_folding(self, node): # Since we don't have a Python implementation, ignore `impl` and use C.
return False return super().prepare_node(
node, storage_map, compute_map, no_recycling, impl="c"
)
def c_code_cache_version(self): def c_code_cache_version(self):
ver = self.scalar_op.c_code_cache_version() ver = self.scalar_op.c_code_cache_version()
......
...@@ -4347,18 +4347,12 @@ def constant_folding(fgraph, node): ...@@ -4347,18 +4347,12 @@ def constant_folding(fgraph, node):
for o in node.outputs: for o in node.outputs:
storage_map[o] = [None] storage_map[o] = [None]
compute_map[o] = [False] compute_map[o] = [False]
impl = None
if hasattr(node.op, "python_constant_folding") and node.op.python_constant_folding(
node
):
impl = "py"
thunk = node.op.make_thunk(
node, storage_map, compute_map, no_recycling=[], impl=impl
)
thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
required = thunk() required = thunk()
assert not required # a node whose inputs are all provided should always # A node whose inputs are all provided should always return successfully
# return successfully assert not required
rval = [] rval = []
for output in node.outputs: for output in node.outputs:
assert compute_map[output][0], (output, storage_map[output][0]) assert compute_map[output][0], (output, storage_map[output][0])
......
...@@ -665,6 +665,9 @@ second dimension ...@@ -665,6 +665,9 @@ second dimension
# - NumPy ufunc support only up to 31 inputs. # - NumPy ufunc support only up to 31 inputs.
# But our c code support more. # But our c code support more.
# - nfunc is reused for scipy and scipy is optional # - nfunc is reused for scipy and scipy is optional
if len(node.inputs) > 32 and self.ufunc and impl == "py":
impl = "c"
if getattr(self, "nfunc_spec", None) and impl != "c": if getattr(self, "nfunc_spec", None) and impl != "c":
self.nfunc = getattr(np, self.nfunc_spec[0], None) self.nfunc = getattr(np, self.nfunc_spec[0], None)
if self.nfunc is None: if self.nfunc is None:
...@@ -1255,14 +1258,6 @@ second dimension ...@@ -1255,14 +1258,6 @@ second dimension
else: else:
return () return ()
def python_constant_folding(self, node):
"""
Return True if we do not want to compile c code
when doing constant folding of this node.
"""
# The python code don't support 32 inputs or more.
return node.outputs[0].ndim == 0 and len(node.inputs) < 32
class CAReduce(COp): class CAReduce(COp):
""" """
......
...@@ -209,20 +209,6 @@ There are less methods to define for a `COp` than for a `Type`: ...@@ -209,20 +209,6 @@ There are less methods to define for a `COp` than for a `Type`:
Overrides :meth:`c_code_cache_version` if defined, but Overrides :meth:`c_code_cache_version` if defined, but
otherwise has the same contract. otherwise has the same contract.
.. method:: python_constant_folding(node)
Optional. If present this method will be called before doing
constant folding of a node, with that node as a parameter. If
it return True, we will not generate C code when doing constant
folding of this node. This is useful when the compilation of
the C code will be longer then the computation in python
(e.g. Elemwise of scalars).
In addition, this allow to lower the number of compiled module
and disk access. Particularly useful when the file system load
is high or when aesara compilation directory is shared by many
process (like on a network file server on a cluster).
.. method:: get_params(node) .. method:: get_params(node)
(optional) If defined, should return the runtime params the op (optional) If defined, should return the runtime params the op
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论