Skip to content

Commit 7d1c88f

Browse files
committed
docs(ib): switch perftest example from mpirun to srun
Signed-off-by: chang-ning <spiderpower02@gmail.com>
1 parent 98bb0cb commit 7d1c88f

2 files changed

Lines changed: 57 additions & 57 deletions

File tree

examples/ib/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@ suite of micro-benchmarks for RDMA verbs — `ib_write_bw`, `ib_read_bw`,
66
program: one rank acts as a server, the other connects as a client.
77

88
`examples/ib/ib.sh` is a thin wrapper that launches both ranks across
9-
two hosts with `mpirun`, so you can benchmark inter-node RDMA with a
9+
two hosts with `srun`, so you can benchmark inter-node RDMA with a
1010
single command and observe the traffic in `rdmatop` from another shell.
1111

1212
## Prerequisites
1313

14-
- `perftest` and an MPI launcher installed on both hosts:
14+
- A working Slurm cluster with both hosts as compute nodes, and
15+
`perftest` installed on both:
1516
```bash
16-
sudo apt install -y perftest openmpi-bin
17-
```
18-
- Passwordless SSH from the launcher host to both hosts (mpirun shells
19-
in to spawn each rank):
20-
```bash
21-
ssh-keygen -t ed25519 -N "" -f ~/.ssh/id_ed25519
22-
ssh-copy-id user@host1
23-
ssh-copy-id user@host2
17+
sudo apt install -y perftest
2418
```
19+
- `srun` reachable from where you launch the script (any login or
20+
compute node in the cluster).
2521
- An RDMA device that is ACTIVE on both ends (`rdma link`) and a netdev
2622
with an IPv4 address reachable between the two hosts.
2723

@@ -31,6 +27,7 @@ single command and observe the traffic in `rdmatop` from another shell.
3127
./examples/ib/ib.sh <host1> <host2> [perftest_binary]
3228
# host1 -> rank 0 -> server
3329
# host2 -> rank 1 -> client (dials host1)
30+
# host1/host2 must be Slurm NodeNames (see `sinfo -N -h -o %N`)
3431
```
3532

3633
`perftest_binary` defaults to `ib_write_bw`. Any perftest tool that
@@ -40,22 +37,25 @@ follows the `<tool> [opts] [server_ip]` convention works.
4037

4138
```bash
4239
# RDMA write bandwidth, 30s, 1 QP, mlx5_1
43-
./examples/ib/ib.sh amd0 amd1
40+
./examples/ib/ib.sh host1 host2
4441

4542
# RDMA read bandwidth
46-
./examples/ib/ib.sh amd0 amd1 ib_read_bw
43+
./examples/ib/ib.sh host1 host2 ib_read_bw
4744

4845
# Send latency
49-
./examples/ib/ib.sh amd0 amd1 ib_send_lat
46+
./examples/ib/ib.sh host1 host2 ib_send_lat
5047

5148
# Longer run with 4 queue pairs (closer to line rate)
52-
IB_DURATION=30 IB_QPS=4 ./examples/ib/ib.sh amd0 amd1
49+
IB_DURATION=30 IB_QPS=4 ./examples/ib/ib.sh host1 host2
5350

5451
# Sweep all message sizes
55-
IB_EXTRA="-a" ./examples/ib/ib.sh amd0 amd1
52+
IB_EXTRA="-a" ./examples/ib/ib.sh host1 host2
5653

5754
# Use a different RDMA device + matching netdev
58-
IB_DEV=mlx5_0 IB_NETDEV=enp49s0f0np0 ./examples/ib/ib.sh amd0 amd1
55+
IB_DEV=mlx5_0 IB_NETDEV=enp49s0f0np0 ./examples/ib/ib.sh host1 host2
56+
57+
# Pin to a specific Slurm partition
58+
SRUN_EXTRA="-p all" ./examples/ib/ib.sh host1 host2
5959
```
6060

6161
## Environment Variables
@@ -67,13 +67,13 @@ IB_DEV=mlx5_0 IB_NETDEV=enp49s0f0np0 ./examples/ib/ib.sh amd0 amd1
6767
| `IB_DURATION` | `30` | Seconds, passed as `-D` |
6868
| `IB_QPS` | `1` | Queue pairs, passed as `-q` |
6969
| `IB_EXTRA` | (empty) | Extra args appended verbatim to the perftest binary |
70-
| `MPI_EXTRA` | (empty) | Extra args passed to `mpirun` |
70+
| `SRUN_EXTRA` | (empty) | Extra args passed to `srun` (e.g. `-p <partition>`) |
7171

7272
## Related Links
7373

7474
- [perftest](https://github.com/linux-rdma/perftest)
7575
— upstream RDMA verbs benchmarks
76-
- [Open MPI](https://www.open-mpi.org/)
77-
`mpirun` launcher
76+
- [Slurm](https://slurm.schedmd.com/)
77+
`srun` launcher
7878
- [rdma-core](https://github.com/linux-rdma/rdma-core)
7979
— userspace RDMA libraries and drivers

examples/ib/ib.sh

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env bash
2-
# ib.sh - launch a perftest benchmark between two hosts via mpirun.
2+
# ib.sh - launch a perftest benchmark between two hosts via Slurm (srun).
33
#
44
# Usage:
55
# ./ib.sh <host1> <host2> [perftest_binary]
66
# host1 -> rank 0 -> perftest server
77
# host2 -> rank 1 -> perftest client (connects to host1)
88
# perftest_binary defaults to ib_write_bw
9+
# host1/host2 must be Slurm NodeNames (e.g. `sinfo -N -h -o %N`)
910
#
1011
# Env overrides:
1112
# IB_DEV RDMA device (default: mlx5_1)
@@ -14,13 +15,7 @@
1415
# IB_DURATION perftest -D seconds (default: 30)
1516
# IB_QPS perftest -q queue pairs (default: 1)
1617
# IB_EXTRA extra args appended verbatim (default: empty)
17-
# MPI_EXTRA extra args passed to mpirun (default: empty)
18-
#
19-
# Examples:
20-
# ./ib.sh amd0 amd1
21-
# ./ib.sh amd0 amd1 ib_read_bw
22-
# IB_DURATION=30 IB_QPS=4 ./ib.sh amd0 amd1 ib_write_bw
23-
# IB_DEV=mlx5_0 IB_NETDEV=enp49s0f0np0 ./ib.sh amd0 amd1
18+
# SRUN_EXTRA extra args passed to srun (default: empty)
2419

2520
set -euo pipefail
2621

@@ -29,28 +24,10 @@ IB_NETDEV=${IB_NETDEV:-enp49s0f1np1}
2924
IB_DURATION=${IB_DURATION:-30}
3025
IB_QPS=${IB_QPS:-1}
3126
IB_EXTRA=${IB_EXTRA:-}
32-
MPI_EXTRA=${MPI_EXTRA:-}
33-
34-
# Worker mode: mpirun re-invokes this script on each host with a rank set.
35-
rank=${OMPI_COMM_WORLD_RANK:-${PMI_RANK:-${PMIX_RANK:-}}}
36-
if [[ -n "${rank}" ]]; then
37-
test_bin=$1
38-
peer_ip=$2
39-
common=(-d "$IB_DEV" -F -D "$IB_DURATION" -q "$IB_QPS" $IB_EXTRA)
40-
if [[ "$rank" == "0" ]]; then
41-
echo "[$(hostname)] rank 0: $test_bin ${common[*]} (server)"
42-
exec "$test_bin" "${common[@]}"
43-
else
44-
# Tiny delay so the server's TCP listener is up before we dial.
45-
sleep 1
46-
echo "[$(hostname)] rank 1: $test_bin ${common[*]} $peer_ip (client)"
47-
exec "$test_bin" "${common[@]}" "$peer_ip"
48-
fi
49-
fi
27+
SRUN_EXTRA=${SRUN_EXTRA:-}
5028

51-
# Launcher mode
5229
if [[ $# -lt 2 ]]; then
53-
sed -n '2,25p' "$0"
30+
sed -n '2,19p' "$0"
5431
exit 2
5532
fi
5633

@@ -59,26 +36,49 @@ host2=$2
5936
test_bin=${3:-ib_write_bw}
6037

6138
# Resolve host1's IP on the RDMA-adjacent netdev so host2 can connect to it.
62-
peer_ip=$(ssh -o BatchMode=yes "$host1" \
63-
"ip -br -4 addr show $IB_NETDEV 2>/dev/null | awk '{print \$3}' | cut -d/ -f1")
39+
peer_ip=$(srun --nodelist="$host1" --nodes=1 --ntasks=1 \
40+
bash -c "ip -br -4 addr show $IB_NETDEV 2>/dev/null | awk '{print \$3}' | cut -d/ -f1" \
41+
2>/dev/null | tr -d '[:space:]')
6442
if [[ -z "$peer_ip" ]]; then
6543
echo "ERROR: could not resolve IPv4 on $IB_NETDEV at $host1" >&2
6644
echo " set IB_NETDEV to a netdev that has an IP on both hosts." >&2
6745
exit 1
6846
fi
6947

70-
script=$(readlink -f "$0")
71-
echo "=== ib.sh ==="
48+
echo "=== ib.sh (slurm) ==="
7249
echo " test : $test_bin"
7350
echo " hosts : $host1 (server) -> $host2 (client)"
7451
echo " device : $IB_DEV via netdev $IB_NETDEV"
7552
echo " peer ip : $peer_ip"
7653
echo " duration : ${IB_DURATION}s qps=${IB_QPS}"
77-
[[ -n "$IB_EXTRA" ]] && echo " extra : $IB_EXTRA"
78-
[[ -n "$MPI_EXTRA" ]] && echo " mpi extra: $MPI_EXTRA"
54+
[[ -n "$IB_EXTRA" ]] && echo " extra : $IB_EXTRA"
55+
[[ -n "$SRUN_EXTRA" ]] && echo " srun extra: $SRUN_EXTRA"
7956
echo
8057

81-
exec mpirun --host "$host1,$host2" -np 2 \
82-
--tag-output \
83-
$MPI_EXTRA \
84-
"$script" "$test_bin" "$peer_ip"
58+
# Pin rank 0 -> host1, rank 1 -> host2 via SLURM_HOSTFILE + arbitrary distribution.
59+
hostfile=$(mktemp)
60+
trap 'rm -f "$hostfile"' EXIT
61+
printf '%s\n%s\n' "$host1" "$host2" > "$hostfile"
62+
export SLURM_HOSTFILE="$hostfile"
63+
64+
export PERF_BIN="$test_bin"
65+
export PEER_IP="$peer_ip"
66+
export IB_DEV IB_DURATION IB_QPS IB_EXTRA
67+
68+
exec srun \
69+
--ntasks=2 \
70+
--distribution=arbitrary \
71+
--label \
72+
$SRUN_EXTRA \
73+
bash -c '
74+
common=(-d "$IB_DEV" -F -D "$IB_DURATION" -q "$IB_QPS" $IB_EXTRA)
75+
if [[ "$SLURM_PROCID" == "0" ]]; then
76+
echo "[$(hostname)] rank 0 server: $PERF_BIN ${common[*]}"
77+
exec "$PERF_BIN" "${common[@]}"
78+
else
79+
# Tiny delay so the server'\''s listener is up before we dial.
80+
sleep 1
81+
echo "[$(hostname)] rank 1 client: $PERF_BIN ${common[*]} $PEER_IP"
82+
exec "$PERF_BIN" "${common[@]}" "$PEER_IP"
83+
fi
84+
'

0 commit comments

Comments
 (0)