Skip to content

Commit

Permalink
Add barrier_on_logical_device for synchoronizations
Browse files Browse the repository at this point in the history
Operation is used to handle adjacent to transfers to prevent unwanted
fusions.
  • Loading branch information
rsuderman committed Jan 15, 2025
1 parent 11b6126 commit d85a8aa
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions iree/turbine/ops/iree.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ def generate(self, ksel: KernelSelection, kb: KernelBuilder):
kb.yield_results(result)


@CustomOp.register(library=IREE_LIBRARY)
class barrier_on_logical_device(CustomOp):
signature = "barrier_on_logical_device(str moniker, Tensor tensor) -> Tensor"

def select(self, ksel: KernelSelection):
ksel.attr_str(0)
ta = ksel.arg_tensor(1)
spec = [i for i, s in enumerate(ta.t.shape) if isinstance(s, int)]

ta.specialize_dims(*spec)
ksel.return_tensor(ta.t).specialize_dims(*spec)

def eager_execute(self, device_moniker, tensor):
return tensor

def generate(self, ksel: KernelSelection, kb: KernelBuilder):
moniker = cast(AttrArg, ksel.arg_descs[0]).v
t = kb.arg_bindings[1]
dynamic_dims: list[Value] = []
_append_dynamic_dims(kb, dynamic_dims, t)
target = Attribute.parse(f'#hal.device.promise<@"__device_{moniker}">')
result = flow_d.TensorBarrierOp(t, dynamic_dims, target).result
kb.yield_results(result)


################################################################################
# Emission utilities
################################################################################
Expand Down

0 comments on commit d85a8aa

Please sign in to comment.