Repository navigation
feat(snapshot): add shared CUDA CustomStorage operation layer #12488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hhzhang16
merged 11 commits into
main
from
hannahz/dyn-3691-extract-shared-target-pid-cuda-customstorage-operation-layer
Aug 7, 2026
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
321836b
feat: roundtrip test for cuda-checkpoint with customstorage
hhzhang16 e4b0aa6
fix: address Linux warnings in CustomStorage harness
hhzhang16 f7d046d
Merge branch 'main' of https://github.com/ai-dynamo/dynamo into hanna…
hhzhang16 143138e
refactor(snapshot): share CustomStorage operation handling
hhzhang16 6cec1b9
refactor: move things around within benchmark for customstorage
hhzhang16 731eba8
feat: add new benchmark to codeowners and areas for gms codeowners
hhzhang16 3ac6bd3
Merge branch 'main' of https://github.com/ai-dynamo/dynamo into hanna…
hhzhang16 088daf3
fix: address MR comments
hhzhang16 614e1c1
Merge branch 'main' of https://github.com/ai-dynamo/dynamo into hanna…
hhzhang16 dd0b602
Merge branch 'main' into hannahz/dyn-3691-extract-shared-target-pid-c…
hhzhang16 c296a30
Merge branch 'main' into hannahz/dyn-3691-extract-shared-target-pid-c…
hhzhang16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| CUDA_HOME ?= /usr/local/cuda | ||
| CXX ?= g++ | ||
| CXXFLAGS ?= -O2 -g | ||
|
|
||
| BENCHMARK_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) | ||
| TARGET := $(BENCHMARK_DIR)/cuda-custom-storage-roundtrip | ||
| SOURCES := $(addprefix $(BENCHMARK_DIR)/, \ | ||
| custom_storage_operation.cpp \ | ||
| roundtrip.cpp \ | ||
| roundtrip_common.cpp \ | ||
| storage.cpp \ | ||
| workload.cpp) | ||
| HEADERS := $(wildcard $(BENCHMARK_DIR)/*.hpp) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: $(TARGET) | ||
|
|
||
| $(TARGET): $(SOURCES) $(HEADERS) | ||
| $(CXX) -std=c++20 $(CXXFLAGS) -Wall -Wextra -Werror \ | ||
| -I$(CUDA_HOME)/include \ | ||
| -I$(BENCHMARK_DIR) \ | ||
| -L$(CUDA_HOME)/lib64/stubs \ | ||
| -Wl,-rpath,$(CUDA_HOME)/lib64 \ | ||
| -o $@ $(SOURCES) -lcuda | ||
|
|
||
| clean: | ||
| $(RM) $(TARGET) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
|
|
||
| # CUDA CustomStorage standalone round-trip | ||
|
|
||
| This single-GPU harness validates the CUDA 13.4 CustomStorage checkpoint contract without | ||
| Snapshot, CRIU, GMS, HVBM, NIXL, or Kubernetes. | ||
|
|
||
| The target-PID CustomStorage operation and capability handling are benchmark-local. The | ||
| harness deliberately supplies its own single-buffer POSIX transfer instead of depending | ||
| on Snapshot's daemon, NIXL engine, or artifact format. Production integration belongs in | ||
| Snapshot only when the snapshot helper consumes this C++ path. | ||
|
|
||
| It forks a standalone CUDA workload that allocates a deterministic local device | ||
| buffer. The controller process then: | ||
|
|
||
| 1. locks the workload; | ||
| 2. requests a CustomStorage checkpoint; | ||
| 3. requires one driver-provided device extent and reports its requested device ordinal, | ||
| UUID, pointer, size, and stream; | ||
| 4. copies that extent to one POSIX file through one bounded pinned buffer; | ||
| 5. completes the checkpoint operation; | ||
| 6. validates the file size before mutating restore state; | ||
| 7. restores the extent and unlocks the workload; | ||
| 8. asserts the documented RUNNING → LOCKED → CHECKPOINTED → LOCKED → RUNNING states; and | ||
| 9. asks the workload to verify its original bytes and execute another CUDA operation. | ||
|
|
||
| An internal 120-second watchdog kills the child workload and exits the controller if a | ||
| driver call, pipe operation, or workload exit hangs. Multi-GPU restore is an explicit | ||
| non-goal of this proof. | ||
|
|
||
| The driver-provided CustomStorage pointer is checkpoint storage, not necessarily an | ||
| application allocation address. Correctness is therefore established by application | ||
| byte verification after a complete checkpoint/restore cycle, not by matching the | ||
| application pointer against the returned extent pointer. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Linux on x86-64 | ||
| - CUDA driver exposing the CUDA 13.4 CustomStorage API | ||
| - CUDA 13.4 or newer toolkit headers and driver stubs under `CUDA_HOME` | ||
| - Permission to checkpoint the child process | ||
|
|
||
| The benchmark intentionally does not recreate CUDA 13.4 declarations when compiling | ||
| against older toolkit headers. | ||
|
|
||
| ## Source layout | ||
|
|
||
| - `roundtrip.cpp` owns argument parsing and controller orchestration. | ||
| - `workload.cpp` owns the child CUDA workload and its typed result protocol. | ||
| - `storage.cpp` owns POSIX extent transfer and checkpoint/restore sequencing. | ||
| - `custom_storage_operation.cpp` owns the benchmark-local CUDA operation state. | ||
| - `roundtrip_common.cpp` owns process, pipe, watchdog, and CUDA utility code. | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| make -C benchmarks/cuda_custom_storage | ||
| ``` | ||
|
|
||
| ## Verify a normal round-trip | ||
|
|
||
| The artifact directory must not already exist: | ||
|
|
||
| ```bash | ||
| artifact_dir="$(mktemp -d)/artifact" | ||
| timeout 130s benchmarks/cuda_custom_storage/cuda-custom-storage-roundtrip \ | ||
| --artifact-dir "${artifact_dir}" \ | ||
| --bytes 67108864 | ||
| ``` | ||
|
|
||
| Expected output reports the CUDA-provided extent and ends with `roundtrip=passed`. | ||
| The output directory contains one `checkpoint.bin` file. Its metadata remains in | ||
| memory for the duration of the test; the harness does not define a persistent artifact | ||
| format. | ||
|
|
||
| ## Verify truncated-artifact rejection | ||
|
|
||
| Use a new artifact directory: | ||
|
|
||
| ```bash | ||
| artifact_dir="$(mktemp -d)/artifact" | ||
| timeout 130s benchmarks/cuda_custom_storage/cuda-custom-storage-roundtrip \ | ||
| --artifact-dir "${artifact_dir}" \ | ||
| --bytes 67108864 \ | ||
| --truncate-before-restore | ||
| ``` | ||
|
|
||
| The harness intentionally truncates the checkpoint file, rejects it before invoking CUDA | ||
| restore, terminates the now-checkpointed test workload, and reports | ||
| `corruption_check=passed`. | ||
|
|
||
| ## Verify that restored state depends on artifact bytes | ||
|
|
||
| Use another new artifact directory: | ||
|
|
||
| ```bash | ||
| artifact_dir="$(mktemp -d)/artifact" | ||
| timeout 130s benchmarks/cuda_custom_storage/cuda-custom-storage-roundtrip \ | ||
| --artifact-dir "${artifact_dir}" \ | ||
| --bytes 67108864 \ | ||
| --corrupt-before-restore | ||
| ``` | ||
|
|
||
| This preserves the extent's declared size but overwrites its contents. The test passes | ||
| only if CUDA restore/completion rejects the bytes or the workload explicitly rejects | ||
| the restored application state. | ||
|
|
||
| ## Explicit non-goals | ||
|
|
||
| - Snapshot or CRIU orchestration | ||
| - GMS/HVBM allocation ownership or metadata | ||
| - NIXL and transfer-performance optimization | ||
| - daemonization or multi-tenant policy | ||
| - portable GPU remapping | ||
| - multi-GPU checkpoint or restore | ||
| - production artifact compatibility | ||
|
|
||
| Those layers should consume or extend the verified CUDA contract only after this | ||
| standalone behavior is reproduced on the target CUDA 13.4 environment. |
71 changes: 71 additions & 0 deletions
71
benchmarks/cuda_custom_storage/custom_storage_operation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include "custom_storage_operation.hpp" | ||
|
|
||
| namespace cuda_custom_storage_benchmark { | ||
| namespace { | ||
|
|
||
| bool | ||
| HasValidStorageShape(const CUcheckpointCustomStorageInfo* info) | ||
| { | ||
| return info != nullptr && info->handle != nullptr && (info->deviceCount == 0 || info->perDeviceData != nullptr); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| CUresult | ||
| CustomStorageOperation::Adopt(CUresult status, CUcheckpointCustomStorageInfo* storage_info) | ||
| { | ||
| if (status != CUDA_SUCCESS) { | ||
| return status; | ||
| } | ||
| has_started_ = true; | ||
| storage_info_ = storage_info; | ||
| has_valid_storage_shape_ = HasValidStorageShape(storage_info); | ||
| return has_valid_storage_shape_ ? CUDA_SUCCESS : CUDA_ERROR_INVALID_VALUE; | ||
| } | ||
|
|
||
| CUresult | ||
| CustomStorageOperation::BeginCheckpoint(pid_t pid) | ||
| { | ||
| if (pid <= 0 || has_started_ || has_attempted_completion_) { | ||
| return CUDA_ERROR_INVALID_VALUE; | ||
| } | ||
| CUcheckpointCustomStorageInfo* storage_info = nullptr; | ||
| CUcheckpointCheckpointArgs args{}; | ||
| args.customStorageInfo_out = &storage_info; | ||
| const CUresult status = cuCheckpointProcessCheckpoint(pid, &args); | ||
| return Adopt(status, storage_info); | ||
| } | ||
|
|
||
| CUresult | ||
| CustomStorageOperation::BeginRestore(pid_t pid, CUcheckpointGpuPair* gpu_pairs, unsigned int gpu_pair_count) | ||
| { | ||
| if (pid <= 0 || has_started_ || has_attempted_completion_ || (gpu_pair_count != 0 && gpu_pairs == nullptr)) { | ||
| return CUDA_ERROR_INVALID_VALUE; | ||
| } | ||
| CUcheckpointCustomStorageInfo* storage_info = nullptr; | ||
| CUcheckpointRestoreArgs args{}; | ||
| args.gpuPairs = gpu_pairs; | ||
| args.gpuPairsCount = gpu_pair_count; | ||
| args.customStorageInfo_out = &storage_info; | ||
| const CUresult status = cuCheckpointProcessRestore(pid, &args); | ||
| return Adopt(status, storage_info); | ||
| } | ||
|
|
||
| CUresult | ||
| CustomStorageOperation::Complete() | ||
| { | ||
| if (!has_started_ || !has_valid_storage_shape_ || has_attempted_completion_) { | ||
| return CUDA_ERROR_INVALID_VALUE; | ||
| } | ||
| has_attempted_completion_ = true; | ||
| const auto handle = storage_info_->handle; | ||
| storage_info_ = nullptr; | ||
| return cuCheckpointOperationComplete(handle); | ||
| } | ||
|
|
||
| } // namespace cuda_custom_storage_benchmark |
41 changes: 41 additions & 0 deletions
41
benchmarks/cuda_custom_storage/custom_storage_operation.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cuda.h> | ||
| #include <sys/types.h> | ||
|
|
||
| #if !defined(CUDA_VERSION) || CUDA_VERSION < 13040 | ||
| #error "CUDA CustomStorage benchmark requires CUDA 13.4 or newer headers" | ||
| #endif | ||
|
|
||
| namespace cuda_custom_storage_benchmark { | ||
|
|
||
| // Owns one benchmark checkpoint or restore operation. Storage transfer and | ||
| // persistence remain the caller's responsibility. | ||
| class CustomStorageOperation { | ||
| public: | ||
| CustomStorageOperation() = default; | ||
| CustomStorageOperation(const CustomStorageOperation&) = delete; | ||
| CustomStorageOperation& operator=(const CustomStorageOperation&) = delete; | ||
|
|
||
| [[nodiscard]] CUresult BeginCheckpoint(pid_t pid); | ||
| [[nodiscard]] CUresult BeginRestore( | ||
| pid_t pid, CUcheckpointGpuPair* gpu_pairs = nullptr, unsigned int gpu_pair_count = 0); | ||
| [[nodiscard]] CUresult Complete(); | ||
|
|
||
| [[nodiscard]] const CUcheckpointCustomStorageInfo* storage_info() const { return storage_info_; } | ||
|
|
||
| private: | ||
| CUresult Adopt(CUresult status, CUcheckpointCustomStorageInfo* storage_info); | ||
|
|
||
| CUcheckpointCustomStorageInfo* storage_info_ = nullptr; | ||
| bool has_started_ = false; | ||
| bool has_valid_storage_shape_ = false; | ||
| bool has_attempted_completion_ = false; | ||
| }; | ||
|
|
||
| } // namespace cuda_custom_storage_benchmark |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.