#!/bin/bash
set +e
if [ "${NNODES:-1}" -lt 2 ]; then
BASEDIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$BASEDIR/generate_comm_microbench.py"
OUTPUT_DIR="${1:-./hccl_bench_data}"
mkdir -p "$OUTPUT_DIR" || { echo "ERROR: cannot create output dir '$OUTPUT_DIR'" >&2; exit 2; }
echo "=== HCCL Communication Microbenchmark ==="
echo "Script: $SCRIPT"
echo "Output: $OUTPUT_DIR"
echo "Mode: kernel (profiler -> kernel_details.csv hcom_* Duration, no inter-iter sync)"
echo ""
echo "Start time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
MSG_BYTES="128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912"
run_session() {
local port=$1 ndev=$2 ops=$3 bytes=$4 outdir=$5
local desc=$6
echo ""
echo "--- [$desc] $(date '+%H:%M:%S') ---"
echo " port=$port ndev=$ndev ops=$ops"
echo " bytes_count=$(echo $bytes | wc -w | tr -d ' ')"
MASTER_PORT=$port torchrun --nproc_per_node=$ndev "$SCRIPT" \
--do-run \
--bench-mode kernel \
--ops $ops \
--grid-shape 48 8 2 \
--num-devices $ndev \
--bytes-grid $bytes \
--output-dir "$outdir"
local rc=$?
if [ $rc -eq 0 ]; then
echo " OK ($(date '+%H:%M:%S'))"
elif [ $rc -eq 139 ]; then
echo " SIGSEGV at shutdown (known torch_npu issue, data is safe)"
else
echo " WARNING: exit code $rc, continuing..." >&2
fi
}
PORT=29700
echo "=========================================="
echo "Round 1: allReduce (all nd)"
echo "=========================================="
run_session $((PORT++)) 16 "all_reduce" "$MSG_BYTES" "$OUTPUT_DIR" \
"allReduce nd=16"
run_session $((PORT++)) 8 "all_reduce" "$MSG_BYTES" "$OUTPUT_DIR" \
"allReduce nd=8"
run_session $((PORT++)) 4 "all_reduce" "$MSG_BYTES" "$OUTPUT_DIR" \
"allReduce nd=4"
run_session $((PORT++)) 2 "all_reduce" "$MSG_BYTES" "$OUTPUT_DIR" \
"allReduce nd=2"
echo ""
echo "=========================================="
echo "Round 2: allGather + reduceScatter (all nd)"
echo "=========================================="
run_session $((PORT++)) 16 "all_gather reduce_scatter" "$MSG_BYTES" "$OUTPUT_DIR" \
"allGather+reduceScatter nd=16"
run_session $((PORT++)) 8 "all_gather reduce_scatter" "$MSG_BYTES" "$OUTPUT_DIR" \
"allGather+reduceScatter nd=8"
run_session $((PORT++)) 4 "all_gather reduce_scatter" "$MSG_BYTES" "$OUTPUT_DIR" \
"allGather+reduceScatter nd=4"
run_session $((PORT++)) 2 "all_gather reduce_scatter" "$MSG_BYTES" "$OUTPUT_DIR" \
"allGather+reduceScatter nd=2"
echo ""
echo "=========================================="
echo "Round 3: alltoallv (all nd)"
echo "=========================================="
run_session $((PORT++)) 16 "all_to_all" "$MSG_BYTES" "$OUTPUT_DIR" \
"alltoallv nd=16"
run_session $((PORT++)) 8 "all_to_all" "$MSG_BYTES" "$OUTPUT_DIR" \
"alltoallv nd=8"
run_session $((PORT++)) 4 "all_to_all" "$MSG_BYTES" "$OUTPUT_DIR" \
"alltoallv nd=4"
run_session $((PORT++)) 2 "all_to_all" "$MSG_BYTES" "$OUTPUT_DIR" \
"alltoallv nd=2"
echo ""
echo "=========================================="
echo "Collection complete"
echo "=========================================="
echo "End time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
echo "Output directory:"
ls -lh "$OUTPUT_DIR/"
echo ""
echo "CSV files:"
wc -l "$OUTPUT_DIR"/*.csv 2>/dev/null || echo "(no CSV files found)"
echo ""
echo "Mode: kernel (profiler -> kernel_details hcom_* Duration, excl. AivKernel, no inter-iter sync)"
echo "Grid: 128B~512MB powers-of-2 (23 points), >=512KB per-msg session (active=1, 10 sessions), <512KB batch (active=10)"
exit 0
fi
if [ "${NNODES:-1}" -ge 2 ]; then
set -e
NODE_RANK="${NODE_RANK:?ERROR: NODE_RANK must be set in multi-node mode (0 on master)}"
MASTER_ADDR="${MASTER_ADDR:?ERROR: MASTER_ADDR must be set to NODE_RANK=0 host IP}"
MASTER_PORT="${MASTER_PORT:-29700}"
NPROC="${NPROC:-16}"
QUICK="${QUICK:-0}"
WORLD_SIZE=$((NNODES * NPROC))
BASEDIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$BASEDIR/generate_comm_microbench.py"
OUTPUT_DIR="${1:-./hccl_bench_inter_pod_v8.5}"
mkdir -p "$OUTPUT_DIR" || { echo "ERROR: cannot create output dir '$OUTPUT_DIR'" >&2; exit 2; }
ND_LIST=""
nd=32
while [ "$nd" -le "$WORLD_SIZE" ]; do
ND_LIST="$ND_LIST $nd"
nd=$((nd * 2))
done
for extra in 384 768; do
[ "$extra" -le "$WORLD_SIZE" ] && ND_LIST="$ND_LIST $extra"
done
ND_LIST="$(printf '%s\n' $ND_LIST | sort -n -u | tr '\n' ' ')"
ND_LIST="${ND_LIST% }"
if [ -z "$ND_LIST" ]; then
echo "ERROR: empty device list for WORLD_SIZE=$WORLD_SIZE (NNODES=$NNODES * NPROC=$NPROC)." >&2
echo " Inter-pod (tier=0) needs world_size>=32; intra-node nd<=16 is covered by single-node mode." >&2
exit 1
fi
if [ "$QUICK" = "1" ]; then
MSG_BYTES_INTERPOD="1024 65536 1048576 16777216 268435456"
else
MSG_BYTES_INTERPOD="128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912"
fi
echo "=========================================="
echo "HCCL Inter-Pod Microbenchmark (tier=0)"
echo "=========================================="
echo "NNODES : $NNODES (world_size=$WORLD_SIZE)"
echo "NODE_RANK : $NODE_RANK"
echo "MASTER_ADDR : $MASTER_ADDR"
echo "MASTER_PORT : $MASTER_PORT (base; round i uses base + i)"
echo "NPROC/node : $NPROC"
echo "ND_LIST : $ND_LIST"
echo "MSG_BYTES cnt : $(echo $MSG_BYTES_INTERPOD | wc -w | tr -d ' ')"
echo "QUICK : $QUICK"
echo "Output dir : $OUTPUT_DIR"
echo "Start time : $(date '+%Y-%m-%d %H:%M:%S')"
echo "=========================================="
run_round_interpod() {
local idx="$1"; shift
local desc="$1"; shift
local ops="$@"
local port=$((MASTER_PORT + idx))
echo ""
echo "--- [$desc] $(date '+%H:%M:%S') port=$port ---"
echo " ops=$ops nd=$ND_LIST"
set +e
torchrun \
--nnodes=$NNODES --node_rank=$NODE_RANK \
--master_addr=$MASTER_ADDR --master_port=$port \
--nproc_per_node=$NPROC \
"$SCRIPT" \
--do-run --bench-mode kernel \
--ops $ops \
--grid-shape 48 8 2 \
--num-devices $ND_LIST \
--topology-tier 0 \
--bytes-grid $MSG_BYTES_INTERPOD \
--output-dir "$OUTPUT_DIR"
local rc=$?
set -e
if [ $rc -eq 0 ]; then
echo " OK ($(date '+%H:%M:%S'))"
elif [ $rc -eq 139 ]; then
echo " SIGSEGV at shutdown (known torch_npu issue, data is safe)"
else
echo " WARNING: exit code $rc, continuing..." >&2
fi
}
run_round_interpod 1 "Round 1: allReduce" all_reduce
run_round_interpod 2 "Round 2: allGather+reduceScatter" all_gather reduce_scatter
run_round_interpod 3 "Round 3: alltoallv" all_to_all
echo ""
echo "=========================================="
echo "Inter-pod collection complete"
echo "End time : $(date '+%Y-%m-%d %H:%M:%S')"
echo "Output : $OUTPUT_DIR"
echo "=========================================="
ls -lh "$OUTPUT_DIR"/ 2>/dev/null
echo ""
wc -l "$OUTPUT_DIR"/*.csv 2>/dev/null || echo "(no CSV files found)"
exit 0
fi