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

Don't include hidden arrays when counting max_total_source_arrays #463

Merged
merged 1 commit into from
May 16, 2024
Merged
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
17 changes: 14 additions & 3 deletions cubed/core/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def is_fusable(node_dict):
return is_primitive_op(node_dict) and node_dict["primitive_op"].fusable


def num_source_arrays(dag, name):
"""Return the number of (non-hidden) arrays that are inputs to an op.

Hidden arrays are used for internal bookkeeping, are very small virtual arrays
(empty, or offsets for example), and are not shown on the plan visualization.
For these reasons they shouldn't count towards ``max_total_source_arrays``.
"""
nodes = dict(dag.nodes(data=True))
return sum(
not nodes[array]["hidden"] for array in predecessors_unordered(dag, name)
)


def can_fuse_predecessors(
dag,
name,
Expand Down Expand Up @@ -145,9 +158,7 @@ def can_fuse_predecessors(
# the fused function would be more than an allowed maximum, then don't fuse
if len(list(predecessor_ops(dag, name))) > 1:
total_source_arrays = sum(
len(list(predecessors_unordered(dag, pre)))
if is_primitive_op(nodes[pre])
else 1
num_source_arrays(dag, pre) if is_primitive_op(nodes[pre]) else 1
for pre in predecessor_ops(dag, name)
)
if total_source_arrays > max_total_source_arrays:
Expand Down
Loading