Skip to content
Merged
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
19 changes: 17 additions & 2 deletions python/simpler/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
read_args_from_blob,
)

from .comm_endpoints import RegionAccessReasonCode

__all__ = [
"AccessMode",
"AddressSpace",
Expand Down Expand Up @@ -545,6 +547,17 @@ class ImportContext:
the endpoint x address_space matrix is enforced at submit time by the
``(target_worker_id, ptr)`` check in ``orchestrator.py``; this is a backstop for a path that
reaches ``materialize`` without going through it, not a replacement for that check.

``materialize()``'s DEVICE-backing rejections are tagged with
``RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION`` (``comm_endpoints.py``) — the same
reason code the domain-scoped ``EndpointRegistry``/``RegionAccessService`` capability engine
reports for the same question at region-planning time. The two mechanisms share only this
rejection vocabulary, not a live registry object: this context is built inside forked child
processes (and at L2's same-process lazy-materialize point), both of which run before
``EndpointRegistry.from_snapshot()``'s ``_require_ready_for_region_planning()`` precondition
can be assumed to hold. ``EndpointRegistry``'s topology snapshot also carries no per-chip
identity (only per-Worker), so it could not close this class's own Worker-grained-not-chip-
grained limit even where it is reachable.
"""

is_host_endpoint: bool
Expand Down Expand Up @@ -605,11 +618,13 @@ def materialize(self, desc: BufferDescriptor) -> ImportedBuffer:
if desc.address_space == AddressSpace.DEVICE:
if self._context is None or self._context.is_host_endpoint:
raise ValueError(
f"ImportRegistry: refusing to materialize a DEVICE backing ({desc.identity}) on a host endpoint"
f"ImportRegistry: [{RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION.value}] "
f"refusing to materialize a DEVICE backing ({desc.identity}) on a host endpoint"
)
if bytes(desc.identity.owner_instance_id) != self._context.owning_chip_instance_id:
raise ValueError(
f"ImportRegistry: refusing to materialize a DEVICE backing ({desc.identity}) "
f"ImportRegistry: [{RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION.value}] "
f"refusing to materialize a DEVICE backing ({desc.identity}) "
f"minted for a different chip's owner"
)
if desc.backend_kind in (
Expand Down
19 changes: 19 additions & 0 deletions tests/ut/py/test_worker/test_endpoint_capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""

import ctypes
import re

import pytest
from simpler.buffer import (
Expand All @@ -24,6 +25,7 @@
mint_owner_instance_id,
wrap_device_malloc,
)
from simpler.comm_endpoints import RegionAccessReasonCode
from simpler.task_interface import DataType, TaskArgs, TensorArgType
from simpler.worker import Worker

Expand Down Expand Up @@ -116,3 +118,20 @@ def test_chip_materialization_refuses_a_foreign_chips_device_tensor():
reg = ImportRegistry(ImportContext(is_host_endpoint=False, owning_chip_instance_id=foreign_chip_owner))
with pytest.raises(ValueError, match="different chip's owner"):
reg.materialize(dev.to_descriptor())


def test_device_backing_rejections_carry_the_endpoint_relation_reason_code():
# Both materialize() rejections above are instances of the same capability-judgment question
# the domain-scoped EndpointRegistry/RegionAccessService engine answers with
# RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION -- pinned here so the two mechanisms'
# rejection vocabulary stays in sync rather than drifting back into two freeform strings.
dev = _device_handle()

host_reg = ImportRegistry(ImportContext(is_host_endpoint=True))
with pytest.raises(ValueError, match=re.escape(RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION.value)):
host_reg.materialize(dev.to_descriptor())

foreign_chip_owner = mint_owner_instance_id()
chip_reg = ImportRegistry(ImportContext(is_host_endpoint=False, owning_chip_instance_id=foreign_chip_owner))
with pytest.raises(ValueError, match=re.escape(RegionAccessReasonCode.UNSUPPORTED_ENDPOINT_RELATION.value)):
chip_reg.materialize(dev.to_descriptor())
Loading