-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75c3779
commit 56536fc
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# memory MB | ||
|
||
gpu_count=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l) | ||
|
||
memory_usage_max=30000 | ||
|
||
while true; do | ||
|
||
IFS=$'\n' read -d '' -r -a memory_usage_array <<< "$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits)" | ||
IFS=$'\n' read -d '' -r -a memory_total_array <<< "$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits)" | ||
|
||
need_wait=false | ||
|
||
for ((i=0; i<$gpu_count; i++)); do | ||
|
||
memory_usage_i=$((${memory_usage_array[$i]})) | ||
memory_total_i=$((${memory_total_array[$i]})) | ||
memory_remin_i=$(($memory_total_i-$memory_usage_i)) | ||
|
||
if [ $memory_remin_i -lt $memory_usage_max ]; then | ||
need_wait=true | ||
fi | ||
|
||
done | ||
|
||
if [ "$need_wait" = false ]; then | ||
break | ||
fi | ||
|
||
echo "wait for gpu free" | ||
sleep 5m | ||
|
||
unset memory_usage_array | ||
unset memory_total_array | ||
|
||
done |