-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_nixl.sh
More file actions
executable file
·145 lines (129 loc) · 5.46 KB
/
Copy pathpatch_nixl.sh
File metadata and controls
executable file
·145 lines (129 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Patch a NIXL source tree so it can build the DOCA_DMA_PROXY backend plugin.
#
# Usage:
# ./scripts/patch_nixl.sh /path/to/nixl/source
#
# The script is idempotent: running it multiple times on the same tree is safe.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
NIXL_SRC="${1:-}"
if [ -z "$NIXL_SRC" ]; then
echo "Usage: $0 <NIXL_SOURCE_DIR>" >&2
exit 1
fi
if [ ! -d "$NIXL_SRC/src/plugins" ] || [ ! -f "$NIXL_SRC/meson.build" ]; then
echo "Error: $NIXL_SRC does not look like a NIXL source tree." >&2
exit 1
fi
NIXL_SRC="$(cd "$NIXL_SRC" && pwd)"
PLUGIN_DIR="$NIXL_SRC/src/plugins/doca_dma_proxy"
echo "============================================================"
echo "Patching NIXL source tree: $NIXL_SRC"
echo "Project source: $PROJECT_DIR"
echo "============================================================"
# 1. Install plugin source files (resolve symlinks so the NIXL tree is self-contained).
mkdir -p "$PLUGIN_DIR"
cp -L "$PROJECT_DIR/nixl-plugin/src/"*.cpp "$PLUGIN_DIR/"
cp -L "$PROJECT_DIR/nixl-plugin/src/"*.h "$PLUGIN_DIR/"
cp -L "$PROJECT_DIR/nixl-plugin/src/meson.build" "$PLUGIN_DIR/"
cp -L "$PROJECT_DIR/common/include/dma_transfer.h" "$PLUGIN_DIR/"
echo "[OK] Copied plugin source files to $PLUGIN_DIR"
# 2. Patch root meson.build to include DOCA_DMA_PROXY in all_plugins.
python3 - "$NIXL_SRC/meson.build" <<'PY'
import sys
path = sys.argv[1]
with open(path, 'r') as f:
text = f.read()
marker = "'DOCA_DMA_PROXY'"
if marker not in text:
# Insert into the all_plugins list before the closing bracket.
old = "all_plugins = ['UCX', 'LIBFABRIC', 'POSIX', 'OBJ', 'GDS', 'GDS_MT', 'MOONCAKE', 'HF3FS', 'GUSLI', 'GPUNETIO', 'UCCL', 'AZURE_BLOB'"
new = "all_plugins = ['UCX', 'LIBFABRIC', 'POSIX', 'OBJ', 'GDS', 'GDS_MT', 'MOONCAKE', 'HF3FS', 'GUSLI', 'GPUNETIO', 'UCCL', 'AZURE_BLOB', 'DOCA_DMA_PROXY'"
if old in text:
text = text.replace(old, new, 1)
with open(path, 'w') as f:
f.write(text)
print("[OK] Patched root meson.build: added DOCA_DMA_PROXY to all_plugins")
else:
print("[WARN] Could not locate all_plugins list in root meson.build; manual check needed")
else:
print("[OK] Root meson.build already contains DOCA_DMA_PROXY")
PY
# 3. Patch src/plugins/meson.build to probe DOCA deps and conditionally build the plugin.
python3 - "$NIXL_SRC/src/plugins/meson.build" <<'PY'
import sys
path = sys.argv[1]
with open(path, 'r') as f:
text = f.read()
# Ensure DOCA dependency probes exist.
probe_block = """
doca_common_dep = dependency('doca-common', required: false)
doca_comch_dep = dependency('doca-comch', required: false)
doca_dma_dep = dependency('doca-dma', required: false)
"""
if "doca_common_dep = dependency('doca-common'" not in text:
# Insert before the conditional plugin block we add below, or at end if already present.
text = text.rstrip() + "\n" + probe_block
print("[OK] Added DOCA dependency probes to src/plugins/meson.build")
else:
print("[OK] DOCA dependency probes already present in src/plugins/meson.build")
plugin_block = """
# DOCA DMA Proxy plugin for GPU <-> DPU transfers via DOCA Comch + DMA
if enabled_plugins.get('DOCA_DMA_PROXY')
if (not cuda_dep.found() or not doca_common_dep.found()
or not doca_comch_dep.found() or not doca_dma_dep.found()) and is_explicit_enable
if not cuda_dep.found()
error('DOCA_DMA_PROXY plugin requested but CUDA dependency not found')
else
error('DOCA_DMA_PROXY plugin requested but DOCA dependency not found')
endif
elif cuda_dep.found() and doca_common_dep.found() and doca_comch_dep.found() and doca_dma_dep.found()
subdir('doca_dma_proxy')
endif
endif
"""
if "DOCA DMA Proxy plugin for GPU <-> DPU transfers" not in text:
text = text.rstrip() + "\n" + plugin_block
with open(path, 'w') as f:
f.write(text)
print("[OK] Added DOCA_DMA_PROXY conditional build to src/plugins/meson.build")
else:
print("[OK] DOCA_DMA_PROXY conditional build already present in src/plugins/meson.build")
PY
# 4. Patch src/core/nixl_plugin_manager.cpp for static plugin registration.
python3 - "$NIXL_SRC/src/core/nixl_plugin_manager.cpp" <<'PY'
import sys
path = sys.argv[1]
with open(path, 'r') as f:
text = f.read()
marker = "STATIC_PLUGIN_DOCA_DMA_PROXY"
if marker in text:
print("[OK] Static plugin registration already present in nixl_plugin_manager.cpp")
else:
# Insert before the telemetry buffer registration line.
old = " NIXL_REGISTER_STATIC_PLUGIN(Telemetry, BUFFER)"
new = """#ifdef STATIC_PLUGIN_DOCA_DMA_PROXY
NIXL_REGISTER_STATIC_PLUGIN(Backend, DOCA_DMA_PROXY)
#endif
NIXL_REGISTER_STATIC_PLUGIN(Telemetry, BUFFER)"""
if old in text:
text = text.replace(old, new, 1)
with open(path, 'w') as f:
f.write(text)
print("[OK] Patched nixl_plugin_manager.cpp: added DOCA_DMA_PROXY static registration")
else:
print("[WARN] Could not locate static plugin registration block; manual check needed")
PY
echo ""
echo "============================================================"
echo "Patch complete."
echo "Next steps:"
echo " cd $NIXL_SRC"
echo " meson setup build -Denable_plugins=DOCA_DMA_PROXY"
echo " ninja -C build"
echo "============================================================"