Skip to content

Instantly share code, notes, and snippets.

View uaudith's full-sized avatar
Thinking

Udith Amasura uaudith

Thinking
View GitHub Profile
@uaudith
uaudith / whenGPU.sh
Created August 10, 2023 15:52
Are there too many individuals utilizing the GPU? Avoid waiting and manually checking for availability. Opt to use it immediately when a GPU's utilization falls below a certain threshold.
#!/bin/bash
# Written by uaudith[uaudith.eu.org]
# Use the environment variable $CUDA_VISIBLE_DEVICES inside your program to get comma separated list of free devices
command_to_run="$@"
utilization_threshold=0 #Will run the command if the device utilization percentage is less than this
get_free_gpus() {
mapfile -t util_array < <(nvidia-smi --query-gpu=utilization.gpu --format=csv,nounits,noheader)