Download code/tt_laya/device.py from changh95/laya: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/changh95/laya/resolve/main/code/tt_laya/device.py
- Command line
-
hf download hf://changh95/laya/code/tt_laya/device.py
-
curl -L -o device.py https://huggingface.co/changh95/laya/resolve/main/code/tt_laya/device.py
1.53 kB
| # 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() | |
| 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) | |