Skip to content

Commit 488aa04

Browse files
committed
refactor: enhance docker mirrored deployment
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent f11f3b6 commit 488aa04

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

gpustack_runtime/deployer/docker.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ def _prepare_create(self):
10131013
for d in mirrored_devices
10141014
if d.get("PathInContainer") not in igs
10151015
]
1016+
## - Container customized device requests
1017+
mirrored_device_requests: list[dict[str, Any]] = (
1018+
self_container.attrs["HostConfig"].get("DeviceRequests", []) or []
1019+
)
10161020

10171021
# Construct mutation function.
10181022
def mutate_create_options(create_options: dict[str, Any]) -> dict[str, Any]:
@@ -1078,6 +1082,36 @@ def mutate_create_options(create_options: dict[str, Any]) -> dict[str, Any]:
10781082
for d in c_devices
10791083
]
10801084

1085+
if mirrored_device_requests:
1086+
c_device_requests: list[dict[str, Any]] = create_options.get(
1087+
"device_requests",
1088+
[],
1089+
)
1090+
c_device_requests_ids = {
1091+
f"{r.get('Driver')}:{did}"
1092+
for r in c_device_requests
1093+
for did in r.get("DeviceIDs", [])
1094+
}
1095+
for r in mirrored_device_requests:
1096+
dri: str = r.get("Driver")
1097+
dids: list[str] = []
1098+
for did in r.get("DeviceIDs", []):
1099+
if f"{dri}:{did}" in c_device_requests_ids:
1100+
continue
1101+
dids.append(did)
1102+
if not dids:
1103+
continue
1104+
c_device_requests.append(
1105+
docker.types.DeviceRequest(
1106+
driver=dri,
1107+
count=r.get("Count"),
1108+
device_ids=dids,
1109+
capabilities=r.get("Capabilities", None),
1110+
options=r.get("Options", None),
1111+
),
1112+
)
1113+
create_options["device_requests"] = c_device_requests
1114+
10811115
return create_options
10821116

10831117
self._mutate_create_options = mutate_create_options

0 commit comments

Comments
 (0)