nvidia-gpu-discovery.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. ################################################################################
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ################################################################################
  19. source "$(dirname "$0")"/gpu-discovery-common.sh
  20. if [ $# -lt 1 ]; then
  21. echo "Usage: ./nvidia-gpu-discovery.sh gpu-amount [--enable-coordination-mode] [--coordination-file filePath]"
  22. exit 1
  23. fi
  24. AMOUNT=$1
  25. shift
  26. COORDINATION_FILE="/var/tmp/flink-gpu-coordination"
  27. COORDINATION_MODE=""
  28. EXIT_NON_ZERO=""
  29. while [[ $# -ge 1 ]]
  30. do
  31. key="$1"
  32. shift
  33. case $key in
  34. --enable-coordination-mode)
  35. COORDINATION_MODE="coordination"
  36. ;;
  37. --coordination-file)
  38. COORDINATION_FILE="$1"
  39. shift
  40. ;;
  41. *)
  42. # unknown option
  43. ;;
  44. esac
  45. done
  46. if [ $AMOUNT -eq 0 ]; then
  47. exit 0
  48. fi
  49. csv_index=`nvidia-smi --query-gpu=index --format=csv,noheader`
  50. if [ $? -ne 0 ]; then
  51. exit 1
  52. fi
  53. IFS=',' read -r -a indexes <<< $(echo $csv_index)
  54. gpu_discovery "${indexes[*]}" $AMOUNT $COORDINATION_MODE $COORDINATION_FILE