code: def getAvailable(
      order="first",
      limit=1,
      maxLoad=0.5,
      maxMemory=0.5,
      memoryFree=0,
      includeNan=False,
      excludeID=[],
      excludeUUID=[],
  ):
      # order = first | last | random | load | memory
      #    first --> select the GPU with the lowest ID (DEFAULT)
      #    last --> select the GPU with the highest ID
      #    random --> select a random available GPU
      #    load --> select the GPU with the lowest load
      #    memory --> select the GPU with the most memory available
      # limit = 1 (DEFAULT), 2, ..., Inf
      #     Limit sets the upper limit for the number of GPUs to return. E.g. if limit = 2, but only one is available, only one is returned.
  
      # Get device IDs, load and memory usage
      GPUs = getGPUs()
  
      # Determine, which GPUs are available
      GPUavailability = getAvailability(
          GPUs,
          maxLoad=maxLoad,
          maxMemory=maxMemory,
          memoryFree=memoryFree,
          includeNan=includeNan,
          excludeID=excludeID,
          excludeUUID=excludeUUID,
      )
      availAbleGPUindex = [
          idx
          for idx in range(0, len(GPUavailability))
          if (GPUavailability[idx] == 1)
      ]
      # Discard unavailable GPUs
      GPUs = [GPUs[g] for g in availAbleGPUindex]
  
      # Sort available GPUs according to the order argument
      if order == "first":
          GPUs.sort(
              key=lambda x: float("inf") if math.isnan(x.id) else x.id,
              reverse=False,
          )
      elif order == "last":
          GPUs.sort(
              key=lambda x: float("-inf") if math.isnan(x.id) else x.id,
              reverse=True,
          )
      elif order == "random":
          GPUs = [
              GPUs[g]
              for g in random.sample(range(0, len(GPUs)), len(GPUs))
          ]
      elif order == "load":
          GPUs.sort(
              key=lambda x: float("inf")
              if math.isnan(x.load)
              else x.load,
              reverse=False,
          )
      elif order == "memory":
          GPUs.sort(
              key=lambda x: float("inf")
              if math.isnan(x.memoryUtil)
              else x.memoryUtil,
              reverse=False,
          )
  
      # Extract the number of desired GPUs, but limited to the total number of available GPUs
      GPUs = GPUs[0 : min(limit, len(GPUs))]
  
      # Extract the device IDs from the GPUs and return them
      deviceIds = [gpu.id for gpu in GPUs]
  
      return deviceIds
  
file_path: gputil/GPUtil/GPUtil.py
imports: from subprocess import Popen, PIPE
  from distutils import spawn
  import os
  import math
  import random
  import time
  import sys
  import platform
label_desc: Use image node_id 3 for calling a global function with example usage: getAvailable(order, limit, maxLoad, maxMemory, memoryFree, includeNan, excludeID, excludeUUID) and returns: deviceIds