code: def check_cub_version(compiler, settings):
      global _cub_version
      global _cub_path
  
      # This is guaranteed to work for any CUB source because the search
      # precedence follows that of include paths.
      # - On CUDA, CUB < 1.9.9 does not provide version.cuh and would error out
      # - On ROCm, hipCUB has the same version as rocPRIM (as of ROCm 3.5.0)
      try:
          out = build_and_run(
              compiler,
              """
                              #ifndef CUPY_USE_HIP
                              #include <cub/version.cuh>
                              #else
                              #include <hipcub/hipcub_version.hpp>
                              #endif
                              #include <stdio.h>
  
                              int main() {
                                #ifndef CUPY_USE_HIP
                                printf("%d", CUB_VERSION);
                                #else
                                printf("%d", HIPCUB_VERSION);
                                #endif
                                return 0;
                              }""",
              include_dirs=settings["include_dirs"],
              define_macros=settings["define_macros"],
          )
      except Exception as e:
          # could be in a git submodule?
          try:
              # CuPy's bundle
              cupy_cub_include = _cub_path
              a = subprocess.run(
                  " ".join(["git", "describe", "--tags"]),
                  stdout=subprocess.PIPE,
                  stderr=subprocess.PIPE,
                  shell=True,
                  cwd=cupy_cub_include,
              )
              if a.returncode == 0:
                  tag = a.stdout.decode()[:-1]
  
                  # CUB's tag convention changed after 1.8.0: "v1.9.0" -> "1.9.0"
                  # In any case, we normalize it to be in line with CUB_VERSION
                  if tag.startswith("v"):
                      tag = tag[1:]
                  tag = tag.split(".")
                  out = int(tag[0]) * 100000 + int(tag[1]) * 100
                  try:
                      out += int(tag[2])
                  except ValueError:
                      # there're local commits so tag is like 1.8.0-1-gdcbb288f,
                      # we add the number of commits to the version
                      local_patch = tag[2].split("-")
                      out += int(local_patch[0]) + int(local_patch[1])
              else:
                  raise RuntimeError(
                      "Cannot determine CUB version from git tag"
                      "\n{0}".format(e)
                  )
          except Exception as e:
              utils.print_warning(
                  "Cannot determine CUB version\n{0}".format(e)
              )
              # 0: CUB is not built (makes no sense), -1: built with unknown ver
              out = -1
  
      _cub_version = int(out)
      settings["define_macros"].append(
          ("CUPY_CUB_VERSION_CODE", _cub_version)
      )
      return True
  
imports: import contextlib
  import os
  import re
  import shlex
  import shutil
  import subprocess
  import sys
  import tempfile
  from typing import List, Set
  import cupy_builder
  import cupy_builder.install_utils
  from cupy_builder import _environment
  from cupy_builder._context import Context
label_desc: Use image node_id 21 for calling a global function with example usage: check_cub_version(compiler, settings) and returns: True