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

[TKW] Avoid nested multiprocessing.Pool usage #333

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 7 additions & 2 deletions iree/turbine/kernel/wave/scheduling/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from functools import partial
from ..utils import safe_subs
import multiprocessing as mp
from typing import Optional

T = index_symbol("$INITIATION_INTERVAL")

Expand Down Expand Up @@ -203,7 +204,7 @@ def all_pairs_longest_paths_symbolic(


def all_pairs_longest_paths(
graph: fx.Graph, edges: list[Edge], T: int, pool: mp.Pool
graph: fx.Graph, edges: list[Edge], T: int, pool: Optional[mp.Pool]
) -> dict[tuple[fx.Node, fx.Node], IndexExpr]:
"""
For each node in the graph, compute the longest path to all other nodes.
Expand All @@ -229,7 +230,11 @@ def all_pairs_longest_paths(
# Parallel implementation
for k in range(N):
func = partial(all_pairs_longest_path_parallel, N, D, k)
results = pool.map(func, range(N))
if pool is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining what would be the right way to do this?

results = pool.map(func, range(N))
else:
results = map(func, range(N))

for result in results:
D[result[0]] = result[1]

Expand Down
12 changes: 9 additions & 3 deletions iree/turbine/kernel/wave/scheduling/modulo_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ def schedule_graph(self) -> tuple[dict[fx.Node, int], bool]:
# TODO: Come up with a better heuristic on an upper bound for the initiation interval.
T_max_range = 3 * T0
success = False
pool = mp.get_context("fork").Pool(processes=mp.cpu_count())
if mp.current_process().daemon:
pool = None
else:
pool = mp.get_context("fork").Pool(processes=mp.cpu_count())

for T in range(T0, T0 + T_max_range):
logger.debug(f"Trying initiation interval: {T}.")
self.RT = np.zeros((T, len(self.resources)))
Expand Down Expand Up @@ -150,8 +154,10 @@ def schedule_graph(self) -> tuple[dict[fx.Node, int], bool]:
break
else:
raise Exception("Failed to schedule the graph.")
pool.close()
pool.join()

if pool is not None:
pool.close()
pool.join()

self._initiation_interval = T
return self.schedule, success
Expand Down
Loading