File size: 1,529 Bytes
f882f26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # SPDX-License-Identifier: Apache-2.0
"""Opening the p150 the way every published number of this port was measured (vendored ``ttaw.device``): ETH
dispatch (12 x 10 compute grid; WORKER 11 x 10 is the A/B switch), the sizes below; ``LAYA_DISPATCH`` /
``LAYA_NUM_CQS`` / ``LAYA_L1_SMALL`` / ``LAYA_TRACE_REGION`` / ``LAYA_WORKER_L1_SIZE`` and ``TT_DEVICE_ID`` override
per process. Never hard-code the grid. Importing has no side effects."""
from __future__ import annotations
import contextlib
import dataclasses
from typing import Any, Dict, Iterator, Optional
from .ttaw.device import DeviceConfig, close_device, compute_grid, describe_device # noqa: F401
ENV_PREFIX = "LAYA"
DEVICE_DEFAULTS: Dict[str, Any] = {
"num_command_queues": 1,
"l1_small_size": 0,
"trace_region_size": 256 << 20, # ttnn engine: one trace per (batch, length) bucket; mk: one per bucket
}
def device_config(**overrides: Any) -> DeviceConfig:
config = DeviceConfig.from_env(ENV_PREFIX, **DEVICE_DEFAULTS)
return dataclasses.replace(config, **{k: v for k, v in overrides.items() if v is not None})
def open_device(device_id: Optional[int] = None, *, dispatch: Optional[str] = None, **overrides: Any):
return device_config(device_id=device_id, dispatch=dispatch, **overrides).open()
@contextlib.contextmanager
def device_session(device_id: Optional[int] = None, **overrides: Any) -> Iterator[Any]:
device = open_device(device_id, **overrides)
try:
yield device
finally:
close_device(device)
|