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

Simple addition enabling the passing of scalar arguments to Reduce #942

Open
wants to merge 2 commits into
base: branch-24.03
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions legate/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import numpy as np

import legate.core.types as ty
JosephGuman marked this conversation as resolved.
Show resolved Hide resolved

from . import Future, legion
from ._legion.util import Logger
from ._lib.context import ( # type: ignore[import-not-found]
Expand Down Expand Up @@ -370,7 +372,13 @@ def issue_execution_fence(self, block: bool = False) -> None:
"""
self._runtime.issue_execution_fence(block=block)

def tree_reduce(self, task_id: int, store: Store, radix: int = 4) -> Store:
def tree_reduce(
self,
task_id: int,
store: Store,
radix: int = 4,
scalar_args: list[tuple[Any, ty.Dtype]] = [],
) -> Store:
"""
Performs a user-defined reduction by building a tree of reduction
tasks. At each step, the reducer task gets up to ``radix`` input stores
Expand Down Expand Up @@ -399,4 +407,6 @@ def tree_reduce(self, task_id: int, store: Store, radix: int = 4) -> Store:
Store
Store that contains reduction results
"""
return self._runtime.tree_reduce(self, task_id, store, radix)
return self._runtime.tree_reduce(
self, task_id, store, radix, scalar_args
)
7 changes: 7 additions & 0 deletions legate/core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ def __init__(
)
self._radix = radix
self._task_id = task_id
self._scalar_args: list[tuple[Any, ty.Dtype]] = []

def add_input(self, store: Store) -> None:
self._check_store(store)
Expand All @@ -1508,6 +1509,9 @@ def add_output(self, store: Store) -> None:
self._outputs.append(store)
self._output_parts.append(partition)

def add_scalar_arg(self, value: Any, dtype: ty.Dtype) -> None:
self._scalar_args.append((value, dtype))

def launch(self, strategy: Strategy) -> None:
assert len(self._inputs) == 1 and len(self._outputs) == 1

Expand Down Expand Up @@ -1537,6 +1541,9 @@ def launch(self, strategy: Strategy) -> None:
provenance=self.provenance,
)

for scalar, dtype in self._scalar_args:
launcher.add_scalar_arg(scalar, dtype)

if num_tasks > 1:
for proj_fn in proj_fns:
launcher.add_input(
Expand Down
9 changes: 8 additions & 1 deletion legate/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,12 @@ def issue_fill(
fill.execute()

def tree_reduce(
self, context: Context, task_id: int, store: Store, radix: int = 4
self,
context: Context,
task_id: int,
store: Store,
radix: int = 4,
scalar_args: list[tuple[Any, ty.Dtype]] = [],
) -> Store:
"""
Performs a user-defined reduction by building a tree of reduction
Expand Down Expand Up @@ -1780,6 +1785,8 @@ def tree_reduce(
)
task.add_input(store)
task.add_output(result)
for scalar_arg in scalar_args:
task.add_scalar_arg(scalar_arg[0], scalar_arg[1])
task.execute()
return result

Expand Down