Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / auto_parallel / hyper_offload / ir / schedule.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
1# Copyright 2026 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15"""Scheduler output model for residency actions."""
17from __future__ import annotations
19from dataclasses import dataclass, field
20from enum import Enum, auto
23class ResidencyActionType(Enum):
24 """Runtime action emitted by the planner."""
26 COPY_D2H = auto()
27 COPY_H2D = auto()
28 RELEASE_DEVICE = auto()
29 RELEASE_HOST = auto()
30 TRY_RELEASE_DEVICE = auto()
33@dataclass(frozen=True)
34class ResidencyAction:
35 """A scheduled runtime residency action."""
37 op_id: int
38 storage_id: int
39 kind: ResidencyActionType
42@dataclass
43class ResidencySchedule:
44 """Scheduler output indexed by op id."""
46 pre: dict[int, list[ResidencyAction]] = field(default_factory=dict)
47 post: dict[int, list[ResidencyAction]] = field(default_factory=dict)
49 def add_pre(self, op_id: int, kind: ResidencyActionType, storage_id: int) -> None:
50 """Add pre."""
51 self.pre.setdefault(op_id, []).append(ResidencyAction(op_id, storage_id, kind))
53 def add_post(self, op_id: int, kind: ResidencyActionType, storage_id: int) -> None:
54 """Add post."""
55 self.post.setdefault(op_id, []).append(ResidencyAction(op_id, storage_id, kind))
57 def pre_actions(self, op_id: int) -> list[ResidencyAction]:
58 """Pre actions."""
59 return self.pre.get(op_id, [])
61 def post_actions(self, op_id: int) -> list[ResidencyAction]:
62 """Post actions."""
63 return self.post.get(op_id, [])