code: def used_mem_on_dev(
      device: Union[ivy.Device, ivy.NativeDevice],
      /,
      *,
      process_specific: bool = False,
  ) -> float:
      """Get the used memory (in GB) for a given device string. In case of CPU,
      the used RAM is returned.
  
      Parameters
      ----------
      device
          The device string to convert to native device handle.
      process_specific
          Whether to check the memory used by this python process alone. Default is
          False.
  
      Returns
      -------
      ret
          The used memory on the device in GB.
  
      Examples
      --------
      >>> x = ivy.used_mem_on_dev("cpu", process_specific = False)
      >>> print(x)
      6.219563008
  
      >>> x = ivy.used_mem_on_dev("cpu", process_specific = True)
      >>> print(x)
      0.902400346
  
      >>> y = ivy.used_mem_on_dev("gpu:0", process_specific = False)
      >>> print(y)
      0.525205504
      """
      ivy.clear_cached_mem_on_dev(device)
      if "gpu" in device:
          handle = _get_nvml_gpu_handle(device)
          if process_specific:
              pid = os.getpid()
              for (
                  process
              ) in pynvml.nvmlDeviceGetComputeRunningProcesses(handle):
                  if process.pid == pid:
                      return process.usedGpuMemory / 1e9
          info = pynvml.nvmlDeviceGetMemoryInfo(handle)
          return info.used / 1e9
      elif device == "cpu":
          if process_specific:
              return psutil.Process(os.getpid()).memory_info().rss / 1e9
          vm = psutil.virtual_memory()
          return (vm.total - vm.available) / 1e9
      else:
          raise ivy.utils.exceptions.IvyException(
              'Invalid device string input, must be on the form "gpu:idx" or "cpu", but'
              f" found {device}"
          )
  
imports: import os
  import gc
  import abc
  import math
  import psutil
  import warnings
  import types
  from typing import Type, Optional, Tuple
  from typing import Union, Callable, Iterable, Any
  import ivy
  from ivy.func_wrapper import handle_out_argument, to_native_arrays_and_back, inputs_to_native_arrays, handle_nestable, handle_array_like_without_promotion, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 14 for calling a global function with example usage: used_mem_on_dev() and returns: unknown, unknown, unknown, unknown