File size: 606 Bytes
e4e3c4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

# Get the command to execute from the user
command_to_execute="$1"

# Get the maximum number of GPUs to use from the user
max_gpus="$2"

# Get the number of instances to start per GPU from the user
instances_per_gpu="$3"

# Set the CUDA_VISIBLE_DEVICES flag for each GPU
for gpu_id in $(seq 0 $(($max_gpus - 1))); do
    export CUDA_VISIBLE_DEVICES="$gpu_id"
    # Start the specified number of instances for this GPU
    for i in $(seq 1 "$instances_per_gpu"); do
        # Run the command in the background
        $command_to_execute &
    done
done

# Wait for all instances to finish
wait