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

Add device queues to device affinities #327

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
13 changes: 10 additions & 3 deletions iree/turbine/aot/support/ir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,16 @@ def create_tensor_global(
if attrs.mutable:
ir_attrs["is_mutable"] = UnitAttr.get()
if device:
ir_attrs["iree.abi.affinity"] = Attribute.parse(
f"#hal.device.promise<@__device_{device.ordinal}>"
)
if device.queues is None:
ir_attrs["stream.affinity"] = Attribute.parse(
f"#hal.device.promise<@__device_{device.ordinal}>"
)
else:
queues = ", ".join(device.queues)
ir_attrs["stream.affinity"] = Attribute.parse(
f"#hal.device.promise<@__device_{device.ordinal}, [{queues}]>"
)

if external:
# Emit named external reference.
external_scope_attr = StringAttr.get(external_scope or "model")
Expand Down
10 changes: 7 additions & 3 deletions iree/turbine/aot/tensor_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
class DeviceAffinity:
"""This is used to provide device affinities to exported function arguments."""

def __init__(self, ordinal: int):
def __init__(self, ordinal: int, queues: Optional[list] = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful to know what type is to be expected for a queue.

self.ordinal = ordinal
self.queues = queues

def __eq__(self, other) -> bool:
if not isinstance(other, DeviceAffinity):
return False
return self.ordinal == other.ordinal
return self.ordinal == other.ordinal and self.queues == other.queues

def __repr__(self) -> str:
return f"DeviceAffinity({self.ordinal})"
if self.queues is None:
return f"DeviceAffinity({self.ordinal})"
return f"DeviceAffinity({self.ordinal}, [{', '.join(self.queues)}])"


@dataclass
Expand All @@ -39,6 +42,7 @@ class DeviceTensorTrait:
"""

ordinal: int
queues: Optional[list] = None

@staticmethod
def get(from_tensor: torch.Tensor) -> Optional["DeviceTensorTrait"]:
Expand Down
Loading