File size: 2,066 Bytes
81159d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# parallel_collect.sh
# Usage: parallel_collect.sh <n_gpus> <total_seeds> <target_kept> <seed_timeout> <final_meta> \
#          <merge_script> -- <collect_cmd_template>
#
# collect_cmd_template must accept:
#   --out DIR --seeds A-B --max-kept N  (plus any extra args before --)
#   SHARD_OUT, SHARD_SEEDS, SHARD_TARGET are substituted per GPU
#
# Runs n_gpus parallel shards, each on its own GPU, merges results into final_meta dir.

N_GPUS=$1; TOTAL_SEEDS=$2; TARGET=$3; TIMEOUT=$4; FINAL_DIR=$5; MERGE_PY=$6
shift 6; [ "$1" = "--" ] && shift
CMD=("$@")

RUN=/lustre/fsw/portfolios/nvr/users/jtremblay/yu/1027_run

log() { echo "== $(date '+%F %T') [parallel_collect] $*"; }

# Split seeds across GPUs
PER=$((TOTAL_SEEDS / N_GPUS))
PER_TARGET=$((TARGET / N_GPUS + 2))  # slight over-collect per shard

PIDS=()
SHARD_DIRS=()
for gpu in $(seq 0 $((N_GPUS-1))); do
    SSTART=$((gpu * PER))
    SEND=$(( (gpu == N_GPUS-1) ? TOTAL_SEEDS-1 : (gpu+1)*PER - 1 ))
    SHARD_DIR="${FINAL_DIR}_gpu${gpu}"
    mkdir -p "$SHARD_DIR"
    SHARD_DIRS+=("$SHARD_DIR")
    log "GPU $gpu: seeds ${SSTART}-${SEND} -> $SHARD_DIR"

    (
        export CUDA_VISIBLE_DEVICES=$gpu
        export OMNIGIBSON_GPU_ID=$gpu
        bash $RUN/collect_with_skip.sh \
            "$SHARD_DIR/collect_meta.json" \
            "$PER_TARGET" \
            "$TIMEOUT" -- \
            "${CMD[@]}" \
            --out "$SHARD_DIR" \
            --seeds "${SSTART}-${SEND}" \
            --max-kept "$PER_TARGET" \
            2>&1 | tee "${RUN}/logs/$(basename $FINAL_DIR)_gpu${gpu}.log"
    ) &
    PIDS+=($!)
    # Stagger startup by 30s to avoid Isaac Sim init collisions
    sleep 30
done

log "Waiting for ${#PIDS[@]} shards (PIDs: ${PIDS[*]})"
for pid in "${PIDS[@]}"; do
    wait "$pid"
    log "Shard PID $pid done"
done

log "All shards done. Merging into $FINAL_DIR"
python3 "$MERGE_PY" "${SHARD_DIRS[@]}" "$FINAL_DIR" "$TARGET"
log "Merge done. kept=$(python3 -c "import json; d=json.load(open('$FINAL_DIR/collect_meta.json')); print(d.get('n_kept',0))" 2>/dev/null)"