Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fusion rewrite for CAReduces with Elemwise inputs #1285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions aesara/compile/function/pfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"""

import logging
from copy import copy
from typing import Optional

Expand All @@ -16,11 +15,6 @@
from aesara.graph.fg import FunctionGraph


_logger = logging.getLogger("aesara.compile.function.pfunc")

__docformat__ = "restructuredtext en"


def rebuild_collect_shared(
outputs,
inputs=None,
Expand Down
21 changes: 14 additions & 7 deletions aesara/compile/function/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


if TYPE_CHECKING:
from aesara.compile.mode import Mode
from aesara.link.vm import VM


Expand Down Expand Up @@ -1391,16 +1392,24 @@ def check_unused_inputs(inputs, outputs, on_unused_input):

@staticmethod
def prepare_fgraph(
inputs, outputs, additional_outputs, fgraph, rewriter, linker, profile
inputs,
outputs,
additional_outputs,
fgraph: FunctionGraph,
mode: "Mode",
profile,
):

rewriter = mode.optimizer

try:
start_rewriter = time.perf_counter()

rewriter_profile = None
rewrite_time = None

with config.change_flags(
mode=mode,
compute_test_value=config.compute_test_value_opt,
traceback__limit=config.traceback__compile_limit,
):
Expand Down Expand Up @@ -1440,7 +1449,7 @@ def prepare_fgraph(
stacklevel=3,
)

if not hasattr(linker, "accept"):
if not hasattr(mode.linker, "accept"):
raise ValueError(
"'linker' parameter of FunctionMaker should be "
f"a Linker with an accept method or one of {list(aesara.compile.mode.predefined_linkers.keys())}"
Expand Down Expand Up @@ -1511,12 +1520,8 @@ def __init__(

self.fgraph = fgraph

rewriter, linker = mode.optimizer, copy.copy(mode.linker)

if not no_fgraph_prep:
self.prepare_fgraph(
inputs, outputs, found_updates, fgraph, rewriter, linker, profile
)
self.prepare_fgraph(inputs, outputs, found_updates, fgraph, mode, profile)

assert len(fgraph.outputs) == len(outputs + found_updates)

Expand All @@ -1528,6 +1533,8 @@ def __init__(
if not spec.borrow
]

linker = copy.copy(mode.linker)

if no_borrow:
self.linker = linker.accept(
fgraph,
Expand Down
25 changes: 25 additions & 0 deletions aesara/compile/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import warnings
from typing import Optional, Tuple, Union

from typing_extensions import Literal

from aesara.compile.function.types import Supervisor
from aesara.configdefaults import config
from aesara.graph.destroyhandler import DestroyHandler
Expand Down Expand Up @@ -530,3 +532,26 @@ def register_mode(name, mode):
if name in predefined_modes:
raise ValueError(f"Mode name already taken: {name}")
predefined_modes[name] = mode


def get_target_language(mode=None) -> Tuple[Literal["py", "c", "numba", "jax"], ...]:
"""Get the compilation target language."""

if mode is None:
mode = get_default_mode()

linker = mode.linker

if isinstance(linker, NumbaLinker):
return ("numba",)
if isinstance(linker, JAXLinker):
return ("jax",)
if isinstance(linker, PerformLinker):
return ("py",)
if isinstance(linker, CLinker):
return ("c",)

if isinstance(linker, (VMLinker, OpWiseCLinker)):
return ("c", "py") if config.cxx else ("py",)

raise Exception(f"Unsupported Linker: {linker}")
Loading