Skip to content

Instantly share code, notes, and snippets.

@link89
Created December 23, 2025 08:39
Show Gist options
  • Select an option

  • Save link89/ba51fc48bf78bab20f309a40a0ef66b1 to your computer and use it in GitHub Desktop.

Select an option

Save link89/ba51fc48bf78bab20f309a40a0ef66b1 to your computer and use it in GitHub Desktop.
Nvidia MPS activate script for slurm
#!/bin/bash
env | grep CUDA_
export CUDA_MPS_PIPE_DIRECTORY=$HOME/.nv_mps/$SLURM_JOB_ID/pipe
export CUDA_MPS_LOG_DIRECTORY=$HOME/.nv_mps/$SLURM_JOB_ID/log
mkdir -p $CUDA_MPS_PIPE_DIRECTORY $CUDA_MPS_LOG_DIRECTORY
cleanup_mps() {
echo "shutdown MPS server ..."
echo "quit" | nvidia-cuda-mps-control
}
trap cleanup_mps EXIT SIGINT SIGTERM SIGKILL
echo "start MPS server ..."
nvidia-cuda-mps-control -d
sleep 5··
MPS_PROCS=$(ps aux | grep -E "nvidia-cuda-mps-(control|server)" | grep -v grep | wc -l)
if [ $MPS_PROCS -eq 0 ]; then
echo "ERROR: MPS server not found"
exit 1
fi
echo "MPS server start successfully, nprocs: $MPS_PROCS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment