Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/codeowners/areas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ areas:
- label: gms
github_team: '@ai-dynamo/dynamo-gms-codeowners'
path_globs:
- benchmarks/cuda_custom_storage/
- components/src/dynamo/common/snapshot/
- deploy/helm/charts/snapshot/
- deploy/operator/internal/checkpoint/
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
/lib/gpu_memory_service/client/ @ai-dynamo/dynamo-gms-codeowners
/lib/gpu_memory_service/common/ @ai-dynamo/dynamo-gms-codeowners
/lib/gpu_memory_service/server/ @ai-dynamo/dynamo-gms-codeowners
/benchmarks/cuda_custom_storage/ @ai-dynamo/dynamo-gms-codeowners
/deploy/snapshot/internal/types/ @ai-dynamo/dynamo-gms-codeowners
/deploy/snapshot/cmd/snapshotctl/ @ai-dynamo/dynamo-gms-codeowners
/lib/gpu_memory_service/snapshot/ @ai-dynamo/dynamo-gms-codeowners
Expand Down
31 changes: 31 additions & 0 deletions benchmarks/cuda_custom_storage/Makefile
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
Comment thread
hhzhang16 marked this conversation as resolved.
Resolved

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)
122 changes: 122 additions & 0 deletions benchmarks/cuda_custom_storage/README.md
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 benchmarks/cuda_custom_storage/custom_storage_operation.cpp
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 benchmarks/cuda_custom_storage/custom_storage_operation.hpp
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
Loading
Loading