-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathnative-host.rst
More file actions
364 lines (260 loc) · 10.1 KB
/
Copy pathnative-host.rst
File metadata and controls
364 lines (260 loc) · 10.1 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
Native-Host Deployment
=====================
Deploy Spur across physical or virtual machines.
Install
-------
Get Spur binaries onto all nodes.
.. code-block:: bash
curl -fsSL https://raw.githubusercontent.com/ROCm/spur/main/install.sh | bash
export PATH="$HOME/.local/bin:$PATH"
To build from source instead, see :doc:`/developer/building`.
Setting Up the Controller
-------------------------
Initialize the network for encrypted node-to-node communication:
.. code-block:: bash
sudo spur net init --cidr 10.44.0.0/16 --port 51820
This sets up a WireGuard mesh, prints the server public key, and outputs a join command template for workers.
Create ``/etc/spur/spur.conf``. The repository includes ``examples/spur.conf``. A minimal example:
.. code-block:: toml
cluster_name = "gpu-cluster"
[controller]
listen_addr = "[::]:6817"
hosts = ["10.44.0.1"]
state_dir = "/var/spool/spur"
[scheduler]
plugin = "backfill"
interval_secs = 1
[network]
wg_enabled = true
wg_interface = "spur0"
agent_port = 6818
# reject_loopback_comm_addr = true # optional: refuse agent registrations whose comm address is loopback or link-local
[[partitions]]
name = "gpu"
default = true
nodes = "gpu-node-[1-2]"
max_time = "72:00:00"
[[nodes]]
names = "gpu-node-[1-2]"
cpus = 128
memory_mb = 512000
gres = ["gpu:mi300x:8"]
# address = "10.44.0.2" # optional default comm address before the agent registers
Start the controller:
.. code-block:: bash
sudo mkdir -p /var/spool/spur
spurctld -D -f /etc/spur/spur.conf
.. tip::
For production, run as a systemd service, e.g.:
.. code-block:: ini
# /etc/systemd/system/spurctld.service
[Unit]
Description=Spur Controller
After=network.target
[Service]
ExecStart=/usr/local/bin/spurctld -f /etc/spur/spur.conf
StateDirectory=spur
Restart=on-failure
Adjust ``ExecStart`` to match your install path. Then ``systemctl enable --now spurctld``.
High Availability
^^^^^^^^^^^^^^^^^
For HA, run ``spurctld`` on 3 (or 5) nodes with Raft consensus. Add all controller addresses to the ``peers`` list in the config:
.. code-block:: toml
[controller]
peers = [
"10.44.0.1:6821",
"10.44.0.4:6821",
"10.44.0.5:6821",
]
Raft automatically elects a leader. Workers connect to any controller and are redirected to the current leader.
Joining Worker Nodes
--------------------
On each worker, join the WireGuard mesh:
.. code-block:: bash
sudo spur net join \
--endpoint 192.168.1.100:51820 \
--server-key <controller-pubkey> \
--address 10.44.0.2
Then register the worker on the controller:
.. code-block:: bash
sudo spur net add-peer \
--key <node-pubkey> \
--allowed-ip 10.44.0.2/32 \
--endpoint 192.168.1.101:51820
Start the agent:
.. code-block:: bash
spurd -D \
--controller http://10.44.0.1:6817 \
--hostname gpu-node-1 \
--address 10.44.0.2 \
--listen [::]:6818
``--address`` sets the advertised comm address. Alternatively, set the
``SPUR_NODE_ADDRESS`` environment variable. Pass a routable IP or FQDN,
not the short hostname alone when ``/etc/hosts`` maps it to loopback.
The agent auto-detects CPUs, memory, and GPUs, then registers with the controller over the mesh.
For an HA quorum, pass every controller as a comma-separated list so the agent
and CLI fail over to a surviving node if one is unreachable. The same format
works for the ``SPUR_CONTROLLER_ADDR`` environment variable:
.. code-block:: bash
--controller http://10.44.0.1:6817,http://10.44.0.2:6817,http://10.44.0.3:6817
Repeat for each worker, incrementing the WireGuard address.
Verify:
.. code-block:: bash
spur net status # WireGuard peers and handshake times
spur nodes # All registered nodes
Resource Limits (rlimits)
-------------------------
By default, ``spurd`` raises ``RLIMIT_MEMLOCK`` to unlimited for every job step
before dropping to the submitting user. This is required for InfiniBand/RDMA
verbs (``ibv_reg_mr``, ``ibv_create_cq``) and NCCL collective communication.
Without it, jobs fail with ``Cannot allocate memory`` from libibverbs.
The default can be changed in ``spur.conf``:
.. code-block:: toml
[rlimits]
memlock = "unlimited" # default: RDMA/NCCL just works
# memlock = "inherit" # keep whatever spurd inherited
# memlock = "1073741824" # fixed cap in bytes
.. note::
With the default ``"unlimited"`` setting, a ``LimitMEMLOCK=infinity`` line on
the ``spurd`` systemd unit is no longer required. The agent raises the limit
itself while still privileged.
MPI (PMIx)
----------
Spur supports **single-node** Open MPI jobs via ``--mpi=pmix``. The controller and
CLI do not link libpmix; each compute node loads ``spur_mpi_pmix.so`` from
``[mpi].plugin_dir`` when a PMIx job starts.
Architecture
~~~~~~~~~~~~
1. **``spurd``** loads ``spur_mpi_pmix.so`` and calls ``PMIx_server_init`` when a
job with ``mpi = pmix`` is launched.
2. The plugin registers a namespace (``spur.<job_id>``), job size, and local
client ranks, then serves PMIx to application processes.
3. For ``-n > 1`` on one node, ``spurd`` wraps the user command in a bash script
that runs **``mpirun -np N``** once (not ``N`` independent forks). Open MPI
4.x otherwise creates a singleton ``MPI_COMM_WORLD`` (``size=1`` per rank).
4. The wrapper exports ``PMIX_SERVER_URI4`` from ``PMIX_SERVER_URI``, unsets
``SLURM_*`` twins (so Open MPI does not assume Slurm PMI), and resolves
``mpirun`` from ``PATH`` or ``OPAL_PREFIX``.
The embedded PMIx server must **not** override ``fence_nb`` / ``fence`` with a
no-op: modex exchange is handled internally by OpenPMIx GDS on single-node jobs.
Build and install the plugin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On each **agent**, with libpmix development files (``pkg-config pmix`` or vendor
headers + ``libpmix.so``):
.. code-block:: bash
cargo build --release -p spur-mpi-pmix
sudo install -D target/release/spur_mpi_pmix.so /usr/lib/spur/spur_mpi_pmix.so
.. important::
Build on the **same OS/glibc** as the agent, or compile ``pmix_server.c``
directly on the node. Copying a plugin from a mismatched dev environment can
crash ``spurd`` at ``dlopen`` time.
If ``pkg-config pmix`` is unavailable on the agent but system headers exist (e.g.
``/usr/lib/x86_64-linux-gnu/pmix2/include``), compile the C plugin manually on the
node:
.. code-block:: bash
gcc -fPIC -Wall -O2 -shared -o spur_mpi_pmix.so pmix_server.c \
-Iinclude \
-I/usr/lib/x86_64-linux-gnu/pmix2/include \
-L/usr/lib/x86_64-linux-gnu/pmix2/lib \
-Wl,-rpath,/usr/lib/x86_64-linux-gnu/pmix2/lib \
-lpmix -pthread
sudo install -D spur_mpi_pmix.so /usr/lib/spur/spur_mpi_pmix.so
Runtime requirements
~~~~~~~~~~~~~~~~~~~~
- **OpenPMIx** on the agent (plugin links ``libpmix``).
- **Open MPI** with ``mpirun`` on the agent ``PATH`` (or set ``OPAL_PREFIX`` so
the wrapper finds ``$OPAL_PREFIX/bin/mpirun``).
- Application binaries built against the **same** Open MPI install you use at
runtime (consistent ``LD_LIBRARY_PATH`` / ``OPAL_PREFIX``).
``spur.conf`` on agents (match ``plugin_dir`` to the install path):
.. code-block:: toml
[mpi]
plugin_dir = "/usr/lib/spur"
pmix_tmpdir = "/tmp/spur-pmix"
pmix_min_version = "4.1.0"
Submit PMIx jobs
~~~~~~~~~~~~~~~~
.. code-block:: bash
srun --mpi=pmix -n4 ./hello_mpi
sbatch --mpi=pmix -n4 batch.sh
Inside an interactive allocation (``salloc``), enable PMIx per step:
.. code-block:: bash
srun --mpi=pmix -n4 ./hello_mpi
Minimal ``hello_mpi`` (build on the agent with ``mpicc``):
.. code-block:: c
#include <mpi.h>
#include <stdio.h>
int main(int argc, char **argv) {
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("rank=%d size=%d\n", rank, size);
MPI_Finalize();
return 0;
}
Expected result for ``-n4``: four lines with ``rank=0`` … ``rank=3`` and
``size=4`` on each.
Application scripts should **avoid**:
- ``OMPI_MCA_ess=env`` when ``spurd`` already uses ``mpirun``.
- Forcing ``OMPI_MCA_pmix=ext3x`` on Open MPI 4.1 (use the default ``pmix3x``
component, or omit the variable).
- Mixing library paths from different Open MPI installations.
Operational notes
~~~~~~~~~~~~~~~~~
- Set ``SPUR_MPI_DEBUG=1`` in ``spurd`` environment for plugin debug logs.
- Each agent holds at most 64 active PMIx namespaces; additional concurrent
``--mpi=pmix`` jobs on the same node fail until a job finishes.
- Multi-node PMIx coordination is not yet supported.
- Multi-rank ``--mpi=pmix`` steps launch via a single ``mpirun -np N`` wrapper.
That path does not apply Spur's per-task CPU bind (``--cpu-bind``) or per-rank
GPU partitioning (``SPUR_JOB_GPUS``) the way the non-MPI fork wrapper does.
Use Open MPI binding options or set rank-local GPU env in the application script
until Spur adds MPI-aware bind support.
Submitting Jobs
---------------
.. code-block:: bash
cat > train.sh << 'EOF'
#!/bin/bash
#SBATCH --job-name=distributed-training
#SBATCH -N 2
#SBATCH --ntasks-per-node=8
#SBATCH --gres=gpu:mi300x:8
#SBATCH --time=4:00:00
torchrun \
--nnodes=$SPUR_NNODES \
--node_rank=$SPUR_TASK_OFFSET \
--master_addr=$(echo $SPUR_PEER_NODES | cut -d: -f1) \
--master_port=29500 \
--nproc_per_node=8 \
train.py
EOF
spur submit train.sh
Environment Variables
---------------------
Each node in a multi-node job receives:
.. list-table::
:header-rows: 1
* - Variable
- Example
- Description
* - ``SPUR_JOB_ID``
- ``42``
- Job ID
* - ``SPUR_NNODES``
- ``2``
- Total nodes in allocation
* - ``SPUR_TASK_OFFSET``
- ``0`` or ``8``
- This node's starting task index
* - ``SPUR_PEER_NODES``
- ``10.44.0.2:6818,10.44.0.3:6818``
- All nodes in the allocation
* - ``SPUR_CPUS_ON_NODE``
- ``128``
- CPUs allocated on this node
GPU Isolation
-------------
Spur automatically restricts GPU visibility per job:
- **AMD (ROCm):** Sets ``ROCR_VISIBLE_DEVICES``
- **NVIDIA (CUDA):** Sets ``CUDA_VISIBLE_DEVICES``