perf(perception): borrow contiguous image buffers for local IPC
This commit is contained in:
@@ -114,6 +114,43 @@ def test_ipc_preserves_binary_and_rejects_oversized_header(pilot):
|
||||
ipc.receive(io.BytesIO((65537).to_bytes(4, "little")))
|
||||
|
||||
|
||||
def test_ipc_borrows_payload_without_concatenation_and_handles_partial_writes(pilot):
|
||||
ipc = pilot("pilot_ipc")
|
||||
payload = np.arange(24, dtype=np.uint8).reshape(2, 4, 3)
|
||||
calls, written = [], bytearray()
|
||||
|
||||
class Writer:
|
||||
def write(self, value):
|
||||
calls.append(value)
|
||||
size = min(7, len(value))
|
||||
written.extend(value[:size])
|
||||
return size
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
||||
ipc.send(Writer(), {"op": "infer"}, memoryview(payload))
|
||||
body = payload.tobytes()
|
||||
header = json.dumps({"op": "infer", "payload_bytes": len(body)}).encode()
|
||||
assert written == len(header).to_bytes(4, "little") + header + body
|
||||
assert any(value.obj is payload for value in calls)
|
||||
assert all(isinstance(value, memoryview) for value in calls)
|
||||
assert ipc.receive(io.BytesIO(written)) == ({"op": "infer"}, body)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("result", [0, None, -1, True, 100000])
|
||||
def test_ipc_rejects_invalid_write_progress(pilot, result):
|
||||
with pytest.raises(EOFError, match="progress"):
|
||||
pilot("pilot_ipc").send(SimpleNamespace(write=lambda _: result), {}, b"x")
|
||||
|
||||
|
||||
def test_ipc_rejects_noncontiguous_payload_before_writing(pilot):
|
||||
stream = io.BytesIO()
|
||||
with pytest.raises(TypeError):
|
||||
pilot("pilot_ipc").send(stream, {}, memoryview(np.arange(8, dtype=np.uint8)[::2]))
|
||||
assert stream.getvalue() == b""
|
||||
|
||||
|
||||
def test_nearest_rank_tail_metrics_keep_outlier(pilot):
|
||||
metrics = pilot("run_joint_pilot").distribution([1] * 99 + [200])
|
||||
assert metrics["p99"] == 1
|
||||
|
||||
Reference in New Issue
Block a user