code: def build_stripe_map(
      matrix,
      group_width,
      window_size,
      stripe_map,
      stripe_ids,
      perm_map,
      used_stripes,
  ):
      global stripe_set, stripe_set_config
  
      window_size = int(window_size / group_width)
  
      if (
          stripe_set is None
          or stripe_set_config is None
          or stripe_set_config != (group_width, window_size)
      ):
          num_stripes = int(matrix.shape[1] / group_width)
          assert group_width * num_stripes == matrix.shape[1]
          stripe_set = generate_stripe_groups(num_stripes, window_size)
          stripe_set_config = (group_width, window_size)
  
      # step through each, update the stripe_map/stripe_ids if necessary
      updates = 0
      use_cuda = use_gpu()
      gpu_list = []
      gpu_groups = []
      for i, s in enumerate(stripe_set):
          sg = (
              []
          )  # build the group of stripes, check if any members changed
          need_update = i >= len(stripe_map)
          for stripe in s:
              sg.append(stripe)
              if stripe in used_stripes:
                  need_update = True
  
          # pre-populate if we're building fresh
          if i >= len(stripe_map):
              stripe_ids.append(sg)
              stripe_map.append(0.0)
              perm_map.append(
                  [c for c in range(group_width * window_size)]
              )
  
          # update entries if needed (only stripe_map and perm_map)
          if need_update:
              updates += 1
  
              if not use_cuda:  # do the work here if using the CPU
                  subset = collect_stripes(matrix, sg, group_width)
                  (
                      sub_result,
                      sub_duration,
                      permutation,
                      improvement,
                  ) = search_matrix(subset, group_width)
                  stripe_map[i] = improvement
                  perm_map[i] = permutation
              else:  # otherwise, just track the work needed to farm off to the GPU
                  gpu_groups.append(sg)
                  gpu_list.append(i)
  
      if use_cuda:  # if using the GPU, perform the work
          matrix_view = np.copy(matrix).astype(np.float32).flatten()
          all_permutations = generate_all_unique_combinations(
              window_size * group_width, group_width
          )
          num_permutations = len(all_permutations)
          permutation_view = (
              np.copy(np.asarray(all_permutations))
              .astype(np.uint32)
              .flatten()
          )
          stripe_groups_view = (
              np.asarray(gpu_groups).astype(np.uint32).flatten()
          )
          num_gpu_groups = len(gpu_list)
          gpu_improvement = np.zeros(
              (num_gpu_groups), dtype=np.float32
          ).flatten()
          gpu_permutation = np.zeros(
              (num_gpu_groups), dtype=np.uint32
          ).flatten()
  
          result = permutation_search_cuda_kernels.build_permute_map(
              matrix_view,
              matrix.shape[0],
              matrix.shape[1],
              stripe_groups_view,
              num_gpu_groups,
              window_size,
              permutation_view,
              window_size * group_width,
              gpu_improvement,
              gpu_permutation,
          )
  
          # put the data where python expects it
          for i in range(len(gpu_list)):
              stripe_map[gpu_list[i]] = gpu_improvement[i]
              perm_map[gpu_list[i]] = all_permutations[
                  gpu_permutation[i]
              ]
  
      return stripe_map, stripe_ids, perm_map
  
file_path: apex/apex/contrib/sparsity/permutation_search_kernels/exhaustive_search.py
imports: from .permutation_utilities import *
  import pickle
  import os.path
  from os import path
  import math
label_desc: Use image node_id 9 for calling a global function with example usage: build_stripe_map(matrix, group_width, window_size, stripe_map, stripe_ids, perm_map, used_stripes) and returns: stripe_map,  stripe_ids,  perm_map