code: def _get_num_warps_from_ir_str(src: str):
      ttgir_num_warps_pattern = (
          r'"triton_gpu.num-warps"\s?=\s?(\d+)\s?:'
      )
      # TODO(jlebar): Using a regex to get num-warps is a hack, and will break if
      # e.g. someone has an instruction (not module) attribute named "num-warps".
      num_warps_matches = re.findall(ttgir_num_warps_pattern, src)
      assert (
          len(num_warps_matches) == 1
      ), "Expected exactly one match for num_warps"
      num_warps = int(num_warps_matches[0])
  
      # If warp specialization is enabled, the true number of warps from
      # the perspective of e.g. CUDA is num-warps times the number of
      # specialized groups.
      num_warp_groups_matches = re.findall(
          r'"triton_gpu.num-warp-groups-per-cta"\s?=\s?(\d+)\s?:', src
      )
      assert (
          len(num_warp_groups_matches) == 0
          or len(num_warp_groups_matches) == 1
      ), "Expected triton_gpu.num-warp-groups-per-cta attribute to appear 0 or 1 times"
      if num_warp_groups_matches:
          num_warps *= int(num_warp_groups_matches[0])
  
      return num_warps
  
imports: from __future__ import annotations
  import hashlib
  import json
  from .._C.libtriton import get_env_vars, ir
  from ..backends import backends
  from ..None import __version__
  from ..runtime.autotuner import OutOfResources
  from ..runtime.cache import get_cache_manager
  from ..runtime.driver import driver
  from ..backends.nvidia.compiler import InfoFromBackendForTensorMap
  from dataclasses import dataclass
  from .code_generator import ast_to_ttir
  from pathlib import Path
  import re
  import functools
  import os
label_desc: Use image node_id 2 for calling a global function with example usage: _get_num_warps_from_ir_str(src) and returns: num_warps