xref: /petsc/lib/petsc/bin/cuda_use_first_gpu.sh (revision 47c84c5acc69ca2c78267fc7dfb4d7203bd055c8)
1#!/bin/bash
2
3# Set the env var CUDA_VISIBLE_DEVICES following these example rules:
4#  1) If CUDA_VISIBLE_DEVICES=1,2,3, pick the first GPU and set CUDA_VISIBLE_DEVICES=1
5#  2) If CUDA_VISIBLE_DEVICES=(empty), keep it empty
6#  3) If CUDA_VISIBLE_DEVICES in unset, set CUDA_VISIBLE_DEVICES=0
7# Note if use ${CUDA_VISIBLE_DEVICES:-0}, in case 2) it would set CUDA_VISIBLE_DEVICES=0, which is not what we want.
8export CUDA_VISIBLE_DEVICES=$(echo ${CUDA_VISIBLE_DEVICES-0} | cut -d ',' -f 1)
9exec "$@"
10