parameters: (op_data, ai_data, index=None)
return_statement: return hotspots
docstring: Get the hotspots information
docstring_summary: Get the hotspots information
docstring_tokens: Get the hotspots information
function: def get_hotspots(op_data, ai_data, index=None):
      """
      Get the hotspots information
      """
      import itertools
  
      marker = itertools.cycle(("o", ",", "^", "+", "*", ">", "<"))
  
      if "type" not in op_data or "type" not in ai_data:
          return []
  
      op_data_type = op_data["type"]
      ai_data_type = ai_data["type"]
  
      op_type = None
      ai_type = None
      if "cpu_roofline" in op_data_type:
          op_type = "cpu"
      if "cpu_roofline" in ai_data_type:
          ai_type = "cpu"
      if "gpu_roofline" in op_data_type:
          op_type = "gpu"
      if "gpu_roofline" in ai_data_type:
          ai_type = "gpu"
  
      if index is None:
          index = RANK_INDEX
  
      if "ranks" in op_data:
          op_data = op_data["ranks"][index]
      if "ranks" in ai_data:
          ai_data = ai_data["ranks"][index]
  
      op_graph_data = op_data["graph"]
      ai_graph_data = ai_data["graph"]
      hotspots = []
  
      avg_runtime = 0.0
      max_runtime = 0.0
      max_length = min([len(op_graph_data), len(ai_graph_data)])
      all_runtime = []
  
      def get_runtime(_data, extra=[]):
          opts = ["runtime", "elapsed"] + extra
          for opt in opts:
              if opt in _data.keys():
                  return float(_data[opt])
              elif opt.title() in _data.keys():
                  return float(_data[opt.title()])
          # print("Could not find runtime field in {}. Searched: {}".format(_data, opts))
          return None
  
      def get_flops(_data, extra=[]):
          opts = [
              "flops",
              "counted_ops",
              "flop_count",
              "flop_count_sp",
              "flop_count_dp",
              "flop_count_hp",
              "DP_operations",
              "SP_operations",
          ] + extra
          for opt in opts:
              if opt in _data.keys():
                  value = float(_data[opt])
                  if value > 0.0:
                      return value
              elif opt.title() in _data.keys():
                  value = float(_data[opt.title()])
                  if value > 0.0:
                      return value
          # print("Could not find flops field in {}. Searched: {}".format(_data, opts))
          return None
  
      def get_bandwidth(_data, extra=[]):
          opts = [
              "bandwidth",
              "counted_ins",
              "ldst_executed",
              "L/S completed",
              "Loads_Stores_completed",
          ] + extra
          for opt in opts:
              if opt in _data.keys():
                  return float(_data[opt])
              elif opt.title() in _data.keys():
                  return float(_data[opt.title()])
          # print("Could not find bandwidth field in {}. Searched: {}".format(_data, opts))
          return None
  
      def check_ignore(_ai, _op):
          if (
              "cuptiOverhead" in _ai
              or "cudaRuntime" in _ai
              or "cuptiOverhead" in _op
              or "cudaRuntime" in _op
          ):
              return True
          return False
  
      for i in range(0, max_length):
          if check_ignore(ai_graph_data[i]["prefix"], op_graph_data[i]["prefix"]):
              continue
  
          ai_repr = ai_graph_data[i]["entry"]["repr_data"]
          op_repr = op_graph_data[i]["entry"]["repr_data"]
          all_runtime += filter(
              None, [get_runtime(ai_repr), get_runtime(op_repr)]
          )
  
      for rt in all_runtime:
          avg_runtime += rt
  
      if len(all_runtime) > 1:
          max_runtime = max(all_runtime)
          avg_runtime -= max_runtime
          avg_runtime /= len(all_runtime) - 1.0
  
      for i in range(0, max_length):
          if check_ignore(ai_graph_data[i]["prefix"], op_graph_data[i]["prefix"]):
              continue
  
          runtimes = []
          flop = None
          bandwidth = None
  
          ai_repr = ai_graph_data[i]["entry"]["repr_data"]
          op_repr = op_graph_data[i]["entry"]["repr_data"]
  
          label = op_graph_data[i]["prefix"]
          runtimes += filter(None, [get_runtime(ai_repr), get_runtime(op_repr)])
  
          flop = get_flops(op_repr)
  
          if flop is None:
              print("No flops found in {}!".format(op_repr))
              continue
  
          if op_type == "gpu" or ai_type == "gpu":
              bandwidth = get_bandwidth(op_repr)
          elif ai_type == "cpu" or op_type == "cpu":
              bandwidth = get_bandwidth(ai_repr)
  
          if bandwidth is None:
              bandwidth = get_bandwidth(op_repr)
              if bandwidth is None:
                  bandwidth = get_bandwidth(ai_repr)
  
          runtime = 0.0
          for rt in runtimes:
              runtime += rt
          runtime /= len(runtimes)
  
          intensity = flop / bandwidth if bandwidth != 0.0 else 0.0
          flop = flop / GIGABYTE / runtime
          proportion = runtime / avg_runtime
          label = (
              re.sub(r"^[|0-9]+", " ", label)
              .replace("> [cxx] ", "")
              .replace("> [_c_] ", "")
              .replace("> [pyc] ", "")
          )
  
          if VERBOSE > 1:
              print(
                  "intensity: {}, flop: {}, proportion: {}, label: {}".format(
                      intensity, flop, proportion, label
                  )
              )
  
          if VERBOSE > 0:
              print(
                  "{} : runtime = {}, avg = {}, proportion = {}, flop = {}".format(
                      label, runtime, avg_runtime, proportion, flop
                  )
              )
  
          # this can arise from overflow
          if flop <= 1.0e-3 or bandwidth <= 0.0:
              continue
  
          my_marker = next(marker)
          hotspots.append([intensity, flop, proportion, my_marker, label])
      return hotspots
function_tokens: def get_hotspots ( op_data , ai_data , index = None ) : import itertools marker = itertools . cycle ( ( "o" , "," , "^" , "+" , "*" , ">" , "<" ) ) if "type" not in op_data or "type" not in ai_data : return [ ] op_data_type = op_data [ "type" ] ai_data_type = ai_data [ "type" ] op_type = None ai_type = None if "cpu_roofline" in op_data_type : op_type = "cpu" if "cpu_roofline" in ai_data_type : ai_type = "cpu" if "gpu_roofline" in op_data_type : op_type = "gpu" if "gpu_roofline" in ai_data_type : ai_type = "gpu" if index is None : index = RANK_INDEX if "ranks" in op_data : op_data = op_data [ "ranks" ] [ index ] if "ranks" in ai_data : ai_data = ai_data [ "ranks" ] [ index ] op_graph_data = op_data [ "graph" ] ai_graph_data = ai_data [ "graph" ] hotspots = [ ] avg_runtime = 0.0 max_runtime = 0.0 max_length = min ( [ len ( op_graph_data ) , len ( ai_graph_data ) ] ) all_runtime = [ ] def get_runtime ( _data , extra = [ ] ) : opts = [ "runtime" , "elapsed" ] + extra for opt in opts : if opt in _data . keys ( ) : return float ( _data [ opt ] ) elif opt . title ( ) in _data . keys ( ) : return float ( _data [ opt . title ( ) ] ) # print("Could not find runtime field in {}. Searched: {}".format(_data, opts)) return None def get_flops ( _data , extra = [ ] ) : opts = [ "flops" , "counted_ops" , "flop_count" , "flop_count_sp" , "flop_count_dp" , "flop_count_hp" , "DP_operations" , "SP_operations" , ] + extra for opt in opts : if opt in _data . keys ( ) : value = float ( _data [ opt ] ) if value > 0.0 : return value elif opt . title ( ) in _data . keys ( ) : value = float ( _data [ opt . title ( ) ] ) if value > 0.0 : return value # print("Could not find flops field in {}. Searched: {}".format(_data, opts)) return None def get_bandwidth ( _data , extra = [ ] ) : opts = [ "bandwidth" , "counted_ins" , "ldst_executed" , "L/S completed" , "Loads_Stores_completed" , ] + extra for opt in opts : if opt in _data . keys ( ) : return float ( _data [ opt ] ) elif opt . title ( ) in _data . keys ( ) : return float ( _data [ opt . title ( ) ] ) # print("Could not find bandwidth field in {}. Searched: {}".format(_data, opts)) return None def check_ignore ( _ai , _op ) : if ( "cuptiOverhead" in _ai or "cudaRuntime" in _ai or "cuptiOverhead" in _op or "cudaRuntime" in _op ) : return True return False for i in range ( 0 , max_length ) : if check_ignore ( ai_graph_data [ i ] [ "prefix" ] , op_graph_data [ i ] [ "prefix" ] ) : continue ai_repr = ai_graph_data [ i ] [ "entry" ] [ "repr_data" ] op_repr = op_graph_data [ i ] [ "entry" ] [ "repr_data" ] all_runtime += filter ( None , [ get_runtime ( ai_repr ) , get_runtime ( op_repr ) ] ) for rt in all_runtime : avg_runtime += rt if len ( all_runtime ) > 1 : max_runtime = max ( all_runtime ) avg_runtime -= max_runtime avg_runtime /= len ( all_runtime ) - 1.0 for i in range ( 0 , max_length ) : if check_ignore ( ai_graph_data [ i ] [ "prefix" ] , op_graph_data [ i ] [ "prefix" ] ) : continue runtimes = [ ] flop = None bandwidth = None ai_repr = ai_graph_data [ i ] [ "entry" ] [ "repr_data" ] op_repr = op_graph_data [ i ] [ "entry" ] [ "repr_data" ] label = op_graph_data [ i ] [ "prefix" ] runtimes += filter ( None , [ get_runtime ( ai_repr ) , get_runtime ( op_repr ) ] ) flop = get_flops ( op_repr ) if flop is None : print ( "No flops found in {}!" . format ( op_repr ) ) continue if op_type == "gpu" or ai_type == "gpu" : bandwidth = get_bandwidth ( op_repr ) elif ai_type == "cpu" or op_type == "cpu" : bandwidth = get_bandwidth ( ai_repr ) if bandwidth is None : bandwidth = get_bandwidth ( op_repr ) if bandwidth is None : bandwidth = get_bandwidth ( ai_repr ) runtime = 0.0 for rt in runtimes : runtime += rt runtime /= len ( runtimes ) intensity = flop / bandwidth if bandwidth != 0.0 else 0.0 flop = flop / GIGABYTE / runtime proportion = runtime / avg_runtime label = ( re . sub ( r"^[|0-9]+" , " " , label ) . replace ( "> [cxx] " , "" ) . replace ( "> [_c_] " , "" ) . replace ( "> [pyc] " , "" ) ) if VERBOSE > 1 : print ( "intensity: {}, flop: {}, proportion: {}, label: {}" . format ( intensity , flop , proportion , label ) ) if VERBOSE > 0 : print ( "{} : runtime = {}, avg = {}, proportion = {}, flop = {}" . format ( label , runtime , avg_runtime , proportion , flop ) ) # this can arise from overflow if flop <= 1.0e-3 or bandwidth <= 0.0 : continue my_marker = next ( marker ) hotspots . append ( [ intensity , flop , proportion , my_marker , label ] ) return hotspots