code: def _gpu_stump(
      T_A_fname,
      T_B_fname,
      m,
      range_stop,
      excl_zone,
      μ_Q_fname,
      σ_Q_fname,
      QT_fname,
      QT_first_fname,
      M_T_fname,
      Σ_T_fname,
      Q_subseq_isconstant_fname,
      T_subseq_isconstant_fname,
      w,
      ignore_trivial=True,
      range_start=1,
      device_id=0,
      k=1,
  ):
      """
      A Numba CUDA version of STOMP for parallel computation of the
      matrix profile, matrix profile indices, left matrix profile indices,
      and right matrix profile indices.
  
      Parameters
      ----------
      T_A_fname : str
          The file name for the time series or sequence for which to compute
          the matrix profile
  
      T_B_fname : str
          The file name for the time series or sequence that will be used to annotate T_A.
          For every subsequence in T_A, its nearest neighbor in T_B will be recorded.
  
      m : int
          Window size
  
      range_stop : int
          The index value along T_B for which to stop the matrix profile
          calculation. This parameter is here for consistency with the
          distributed `stumped` algorithm.
  
      excl_zone : int
          The half width for the exclusion zone relative to the current
          sliding window
  
      μ_Q_fname : str
          The file name for the mean of the query sequence, `Q`, relative to
          the current sliding window
  
      σ_Q_fname : str
          The file name for the standard deviation of the query sequence, `Q`,
          relative to the current sliding window
  
      QT_fname : str
          The file name for the dot product between some query sequence,`Q`,
          and time series, `T`
  
      QT_first_fname : str
          The file name for the QT for the first window relative to the current
          sliding window
  
      M_T_fname : str
          The file name for the sliding mean of time series, `T`
  
      Σ_T_fname : str
          The file name for the sliding standard deviation of time series, `T`
  
      Q_subseq_isconstant_fname : str
          The file name for the rolling isconstant in `Q`
  
      T_subseq_isconstant_fname : str
          The file name for the rolling isconstant in `T`
  
      w : int
          The total number of sliding windows to iterate over
  
      ignore_trivial : bool
          Set to `True` if this is a self-join. Otherwise, for AB-join, set this to
          `False`. Default is `True`.
  
      range_start : int
          The starting index value along T_B for which to start the matrix
          profile calculation. Default is 1.
  
      device_id : int
          The (GPU) device number to use. The default value is `0`.
  
      k : int
          The number of top `k` smallest distances used to construct the matrix profile.
          Note that this will increase the total computational time and memory usage
          when k > 1.
  
      Returns
      -------
      profile_fname : str
          The file name for the matrix profile
  
      indices_fname : str
          The file name for the matrix profile indices. The first column of the
          array consists of the matrix profile indices, the second column consists
          of the left matrix profile indices, and the third column consists of the
          right matrix profile indices.
  
      Notes
      -----
      `DOI: 10.1109/ICDM.2016.0085 \
      <https://www.cs.ucr.edu/~eamonn/STOMP_GPU_final_submission_camera_ready.pdf>`__
  
      See Table II, Figure 5, and Figure 6
  
      Timeseries, T_A, will be annotated with the distance location
      (or index) of all its subsequences in another times series, T_B.
  
      Return: For every subsequence, Q, in T_A, you will get a distance
      and index for the closest subsequence in T_A. Thus, the array
      returned will have length T_A.shape[0]-m+1. Additionally, the
      left and right matrix profiles are also returned.
  
      Note: Unlike in the Table II where T_A.shape is expected to be equal
      to T_B.shape, this implementation is generalized so that the shapes of
      T_A and T_B can be different. In the case where T_A.shape == T_B.shape,
      then our algorithm reduces down to the same algorithm found in Table II.
  
      Additionally, unlike STAMP where the exclusion zone is m/2, the default
      exclusion zone for STOMP is m/4 (See Definition 3 and Figure 3).
  
      For self-joins, set `ignore_trivial = True` in order to avoid the
      trivial match.
  
      Note that left and right matrix profiles are only available for self-joins.
      """
      threads_per_block = config.STUMPY_THREADS_PER_BLOCK
      blocks_per_grid = math.ceil(w / threads_per_block)
  
      T_A = np.load(T_A_fname, allow_pickle=False)
      T_B = np.load(T_B_fname, allow_pickle=False)
      QT = np.load(QT_fname, allow_pickle=False)
      QT_first = np.load(QT_first_fname, allow_pickle=False)
      μ_Q = np.load(μ_Q_fname, allow_pickle=False)
      σ_Q = np.load(σ_Q_fname, allow_pickle=False)
      M_T = np.load(M_T_fname, allow_pickle=False)
      Σ_T = np.load(Σ_T_fname, allow_pickle=False)
      Q_subseq_isconstant = np.load(
          Q_subseq_isconstant_fname, allow_pickle=False
      )
      T_subseq_isconstant = np.load(
          T_subseq_isconstant_fname, allow_pickle=False
      )
  
      nlevel = np.floor(np.log2(k) + 1).astype(np.int64)
      # number of levels in binary search tree from which `bfs` is constructed.
  
      with cuda.gpus[device_id]:
          device_T_A = cuda.to_device(T_A)
          device_QT_odd = cuda.to_device(QT)
          device_QT_even = cuda.to_device(QT)
          device_QT_first = cuda.to_device(QT_first)
          device_μ_Q = cuda.to_device(μ_Q)
          device_σ_Q = cuda.to_device(σ_Q)
          device_Q_subseq_isconstant = cuda.to_device(
              Q_subseq_isconstant
          )
  
          if ignore_trivial:
              device_T_B = device_T_A
              device_M_T = device_μ_Q
              device_Σ_T = device_σ_Q
              device_T_subseq_isconstant = device_Q_subseq_isconstant
          else:
              device_T_B = cuda.to_device(T_B)
              device_M_T = cuda.to_device(M_T)
              device_Σ_T = cuda.to_device(Σ_T)
              device_T_subseq_isconstant = cuda.to_device(
                  T_subseq_isconstant
              )
  
          profile = np.full((w, k), np.inf, dtype=np.float64)
          indices = np.full((w, k), -1, dtype=np.int64)
  
          profile_L = np.full(w, np.inf, dtype=np.float64)
          indices_L = np.full(w, -1, dtype=np.int64)
  
          profile_R = np.full(w, np.inf, dtype=np.float64)
          indices_R = np.full(w, -1, dtype=np.int64)
  
          device_profile = cuda.to_device(profile)
          device_profile_L = cuda.to_device(profile_L)
          device_profile_R = cuda.to_device(profile_R)
          device_indices = cuda.to_device(indices)
          device_indices_L = cuda.to_device(indices_L)
          device_indices_R = cuda.to_device(indices_R)
          device_bfs = cuda.to_device(
              core._bfs_indices(k, fill_value=-1)
          )
  
          _compute_and_update_PI_kernel[
              blocks_per_grid, threads_per_block
          ](
              range_start - 1,
              device_T_A,
              device_T_B,
              m,
              device_QT_even,
              device_QT_odd,
              device_QT_first,
              device_μ_Q,
              device_σ_Q,
              device_M_T,
              device_Σ_T,
              device_Q_subseq_isconstant,
              device_T_subseq_isconstant,
              w,
              ignore_trivial,
              excl_zone,
              device_profile,
              device_profile_L,
              device_profile_R,
              device_indices,
              device_indices_L,
              device_indices_R,
              False,
              device_bfs,
              nlevel,
              k,
          )
  
          for i in range(range_start, range_stop):
              _compute_and_update_PI_kernel[
                  blocks_per_grid, threads_per_block
              ](
                  i,
                  device_T_A,
                  device_T_B,
                  m,
                  device_QT_even,
                  device_QT_odd,
                  device_QT_first,
                  device_μ_Q,
                  device_σ_Q,
                  device_M_T,
                  device_Σ_T,
                  device_Q_subseq_isconstant,
                  device_T_subseq_isconstant,
                  w,
                  ignore_trivial,
                  excl_zone,
                  device_profile,
                  device_profile_L,
                  device_profile_R,
                  device_indices,
                  device_indices_L,
                  device_indices_R,
                  True,
                  device_bfs,
                  nlevel,
                  k,
              )
  
          profile = device_profile.copy_to_host()
          profile_L = device_profile_L.copy_to_host()
          profile_R = device_profile_R.copy_to_host()
          indices = device_indices.copy_to_host()
          indices_L = device_indices_L.copy_to_host()
          indices_R = device_indices_R.copy_to_host()
  
          profile[:, :] = np.sqrt(profile)
          profile_L[:] = np.sqrt(profile_L)
          profile_R[:] = np.sqrt(profile_R)
  
          profile_fname = core.array_to_temp_file(profile)
          profile_L_fname = core.array_to_temp_file(profile_L)
          profile_R_fname = core.array_to_temp_file(profile_R)
          indices_fname = core.array_to_temp_file(indices)
          indices_L_fname = core.array_to_temp_file(indices_L)
          indices_R_fname = core.array_to_temp_file(indices_R)
  
      return (
          profile_fname,
          profile_L_fname,
          profile_R_fname,
          indices_fname,
          indices_L_fname,
          indices_R_fname,
      )
  
file_path: stumpy/stumpy/gpu_stump.py
imports: import math
  import multiprocessing
  import os
  import numpy
  from numba import cuda
  from .None import config, core
  from .gpu_aamp import gpu_aamp
label_desc: Use image node_id 2 for calling a global function with example usage: _gpu_stump(T_A_fname, T_B_fname, m, range_stop, excl_zone, μ_Q_fname, σ_Q_fname, QT_fname, QT_first_fname, M_T_fname, Σ_T_fname, Q_subseq_isconstant_fname, T_subseq_isconstant_fname, w, ignore_trivial, range_start, device_id, k) and returns: profile_fname,  profile_L_fname,  profile_R_fname,  indices_fname,  indices_L_fname,  indices_R_fname