Skip to content

Commit 060a508

Browse files
committed
CUDA backend: add a PTE device-id remap tool under backends/cuda/scripts
A CUDA program records the devices it was exported for in its planned memory table, in tensor placement info, and in each delegate's target_device compile spec. All three must agree, so a program exported on a shared multi-GPU box for whichever GPU was free (cuda:3, say) does not load on a single-GPU robot as cuda:0, and the loader has no way to move it. scripts/remap_pte_devices.py rewrites all three places in the file with one mapping, dense by default (3, 5, 7 become 0, 1, 2, keeping their order) or explicit (--mapping 3=0,5=0 collapses everything onto one device). The output is an ordinary PTE that loads as if it had been exported for the new devices, so the runtime needs no remapping support of its own. The companion .ptd is untouched: tensor data carries no device ids. A mapping that does not cover a recorded device is refused, so a file is never rewritten only in part. The tool lives in a new backends/cuda/scripts directory next to merge_ptes.py, which moves there with it; a forwarding module stays at the old merge_ptes path so existing imports and the documented command keep working. Callers (CI, the CUDA examples README, tests, BUCK targets) point at the new module paths.
1 parent 679e49e commit 060a508

9 files changed

Lines changed: 1396 additions & 745 deletions

File tree

‎.github/workflows/cuda.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ jobs:
365365
366366
merged_dir="${RUNNER_ARTIFACT_DIR}/merged"
367367
mkdir -p "${merged_dir}"
368-
python -m executorch.backends.cuda.merge_ptes \
368+
python -m executorch.backends.cuda.scripts.merge_ptes \
369369
--input-pte "${RUNNER_ARTIFACT_DIR}/native-sm80/linear/linear.pte" \
370370
--input-pte "${RUNNER_ARTIFACT_DIR}/native-sm86/linear/linear.pte" \
371371
--input-ptd "${sm80_ptd}" \

‎backends/cuda/BUCK‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fbcode_target(
152152
_kind = runtime.python_library,
153153
name = "merge_ptes",
154154
srcs = [
155-
"merge_ptes.py",
155+
"scripts/merge_ptes.py",
156156
],
157157
visibility = ["PUBLIC"],
158158
deps = [
@@ -164,6 +164,32 @@ fbcode_target(
164164
],
165165
)
166166

167+
fbcode_target(
168+
_kind = runtime.python_library,
169+
name = "merge_ptes_shim",
170+
srcs = [
171+
"merge_ptes.py",
172+
],
173+
visibility = ["PUBLIC"],
174+
deps = [
175+
":merge_ptes",
176+
],
177+
)
178+
179+
fbcode_target(
180+
_kind = runtime.python_library,
181+
name = "remap_pte_devices",
182+
srcs = [
183+
"scripts/remap_pte_devices.py",
184+
],
185+
visibility = ["PUBLIC"],
186+
deps = [
187+
"//executorch/exir/_serialize:lib",
188+
"//executorch/exir/passes:propagate_device_pass",
189+
"//executorch/exir:schema",
190+
],
191+
)
192+
167193
fbcode_target(
168194
_kind = runtime.python_library,
169195
name = "cuda_partitioner",

0 commit comments

Comments
 (0)