Skip to content
Snippets Groups Projects
Commit 6bf5786c authored by Andreas Herten's avatar Andreas Herten
Browse files

Add script for distributing to CPU and GPU

parent 019a2d38
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
# Distribute a Slurm set of tasks on a node between NUMA domains with and
# without GPU affinity, using a different executable for each.
#
# Launch with
# srun -n 8 bash cpu-gpu-distrib.sh
# or other Slurm options, like
# srun -n 8 --cpus-per-task 6 bash cpu-gpu-distrib.sh
#
# I'd imagine that further command line parameters might need to be passed;
# in that case
# srun […] bash cpu-gpu-distrib.sh --a=b --c -d conf.conf
#
# -Andreas Herten, 12 August 2021
# Define our apps for GPU and CPU; TODO!
cpu_app="echo app.cpu"
gpu_app="echo app.gpu"
# Define arrays with CPU and GPU NUMA domains
# These are associative arrays as Bash has built-in lookup for them
declare -A numa_domains_cpu=( [2]=1 [0]=1 [4]=1 [6]=1 )
declare -A numa_domains_gpu=( [3]=1 [1]=1 [7]=1 [5]=1 )
# Parse current NUMA domain with numactl and other things
# The final printf gets rid of any spurious newline or space
current_numa_domain=$(numactl -s | grep nodebind | sed "s/nodebind: //" | xargs printf '%i')
# Central branch - we do one thing for GPU and another for CPU
if [[ -n "${numa_domains_gpu[${current_numa_domain}]}" ]]; then
# launch GPU
$gpu_app $*
else
# launch CPU
$cpu_app $*
fi
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment