Skip to content
Open
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
12 changes: 10 additions & 2 deletions legate/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,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, 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 +405,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