[Mesa-dev] [PATCH shader-db 3/3] si-report.py: report private memory usage

Nicolai Hähnle nhaehnle at gmail.com
Tue Nov 29 19:49:45 UTC 2016


For the series:

Acked-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

On 28.11.2016 12:25, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
>  si-report.py | 43 ++++++++++++++++++++++++++++++-------------
>  1 file changed, 30 insertions(+), 13 deletions(-)
>
> diff --git a/si-report.py b/si-report.py
> index 17b7c66..093fb39 100755
> --- a/si-report.py
> +++ b/si-report.py
> @@ -75,20 +75,21 @@ def cmp_max_per(current, comp):
>
>  def cmp_min_per(current, comp):
>      return calculate_percent_change(comp[1], comp[2]) < calculate_percent_change(current[1], current[2])
>
>  class si_stats:
>      metrics = [
>          ('sgprs', 'SGPRS', ''),
>          ('vgprs', 'VGPRS', ''),
>          ('spilled_sgprs', 'Spilled SGPRs', ''),
>          ('spilled_vgprs', 'Spilled VGPRs', ''),
> +        ('privmem_vgprs', 'Private memory VGPRs', ''),
>          ('scratch_size', 'Scratch size', 'dwords per thread'),
>          ('code_size', 'Code Size', 'bytes'),
>          ('lds', 'LDS', 'blocks'),
>          ('maxwaves', 'Max Waves', ''),
>          ('waitstates', 'Wait states', ''),
>      ]
>
>      def __init__(self):
>          self.error = False
>
> @@ -181,49 +182,61 @@ class si_stats:
>          for name in self.get_metrics():
>              x = self.__dict__[name]
>              if type(x) == tuple and x[0] is not 0:
>                  return False
>              if type(x) != tuple and x is not 0:
>                  return False
>          return True
>
>
>  class si_parser(object):
> -    re_stats = re.compile(
> -        r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
> -        r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
> -        r"([0-9]+) Spilled VGPRs: ([0-9]+)")
> +    re_stats = [
> +        re.compile(
> +            r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
> +            r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
> +            r"([0-9]+) Spilled VGPRs: ([0-9]+) PrivMem VGPRs: ([0-9]+)"),
> +        re.compile(
> +            r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
> +            r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
> +            r"([0-9]+) Spilled VGPRs: ([0-9]+)"),
> +    ]
> +
>      re_nop = re.compile("^\ts_nop ([0-9]+)")
>
>      def __init__(self):
>          self._stats = None
>          self._in_disasm = False
>
>      def finish(self):
>          return self._stats
>
>      def parse(self, msg):
>          if not self._in_disasm:
>              if msg == "Shader Disassembly Begin":
>                  old_stats = self._stats
>                  self._stats = si_stats()
>                  self._in_disasm = True
>                  return old_stats
>
> -            match = si_parser.re_stats.match(msg)
> +            for re in si_parser.re_stats:
> +                match = re.match(msg)
> +                if match is not None:
> +                    break
> +
>              if match is not None:
>                  if self._stats == None:
>                      self._stats = si_stats()
>                  self._stats.sgprs = int(match.group(1))
>                  self._stats.vgprs = int(match.group(2))
>                  self._stats.spilled_sgprs = int(match.group(7))
>                  self._stats.spilled_vgprs = int(match.group(8))
> +                self._stats.privmem_vgprs = int(match.group(9)) if match.lastindex >= 9 else 0
>                  self._stats.code_size = int(match.group(3))
>                  self._stats.lds = int(match.group(4))
>                  self._stats.scratch_size = int(match.group(5)) / (64 * 4)
>                  self._stats.maxwaves = int(match.group(6))
>                  old_stats = self._stats
>                  self._stats = None
>                  return old_stats
>
>              if msg == "LLVM compile failed":
>                  old_stats = self._stats
> @@ -470,59 +483,62 @@ class grouped_stats:
>          self.before.add(before)
>          self.after.add(after)
>
>      def set_one_shader(self, before, after):
>          self.before = before
>          self.after = after
>          self.diff = subtract_stats(after, before)
>
>      def print_vgpr_spilling_app(self, name):
>          if (self.after.spilled_vgprs > 0 or
> -            self.after.scratch_size > 0):
> -            print " {:22}{:6}{:10}{:10}".format(
> +            self.after.privmem_vgprs > 0):
> +            print " {:22}{:6}{:10}{:10}{:10}".format(
>                  name,
>                  self.num_shaders,
>                  self.after.spilled_vgprs,
> +                self.after.privmem_vgprs,
>                  self.after.scratch_size)
>
>      def print_one_shader_vgpr_spill(self, name):
>          if (self.after.spilled_vgprs > 0 or
> -            self.after.scratch_size > 0):
> -            print " {:65}{:10}{:10}{:10}".format(
> +            self.after.privmem_vgprs > 0):
> +            print " {:65}{:10}{:10}{:10}{:10}".format(
>                  name,
>                  self.after.vgprs,
>                  self.after.spilled_vgprs,
> +                self.after.privmem_vgprs,
>                  self.after.scratch_size)
>
>      def print_sgpr_spilling_app(self, name):
>          if self.after.spilled_sgprs > 0:
>              print " {:22}{:6}{:10}{:>9.1f}".format(
>                  name,
>                  self.num_shaders,
>                  self.after.spilled_sgprs,
>                  float(self.after.spilled_sgprs) / float(self.num_shaders))
>
>      def print_one_shader_sgpr_spill(self, name):
>          if self.after.spilled_sgprs > 0:
>              print " {:65}{:10}{:10}".format(
>                  name,
>                  self.after.sgprs,
>                  self.after.spilled_sgprs)
>
>      def print_percentages(self, name):
> -        print " {:22}{:6}{}{}{}{}{}{}{}{}".format(
> +        print " {:22}{:6}{}{}{}{}{}{}{}{}{}".format(
>              name,
>              self.num_shaders,
>              format_percent_change(self.before.sgprs, self.after.sgprs),
>              format_percent_change(self.before.vgprs, self.after.vgprs),
>              format_percent_change(self.before.spilled_sgprs, self.after.spilled_sgprs),
>              format_percent_change(self.before.spilled_vgprs, self.after.spilled_vgprs),
> +            format_percent_change(self.before.privmem_vgprs, self.after.privmem_vgprs),
>              format_percent_change(self.before.scratch_size, self.after.scratch_size),
>              format_percent_change(self.before.code_size, self.after.code_size),
>              format_percent_change(self.before.maxwaves, self.after.maxwaves, more_is_better = True),
>              format_percent_change(self.before.waitstates, self.after.waitstates))
>
>      def print_regression(self, name, field):
>          more_is_better = field == "maxwaves"
>          print " {:65}{:10}{:10}{}{}".format(
>              name,
>              self.before.__dict__[field],
> @@ -584,40 +600,41 @@ def print_tables(before_all_results, after_all_results):
>              total.add(before, after)
>
>              if not subtract_stats(before, after).is_empty():
>                  total_affected.add(before, after)
>
>              # we don't have to add all shaders, just those that we may need
>              # to display
>              if (is_regression(before, after) or
>                  after.scratch_size > 0 or
>                  after.spilled_vgprs > 0 or
> +                after.privmem_vgprs > 0 or
>                  after.spilled_sgprs > 0):
>                  name = get_shader_name(shaders, file)
>                  shaders[name].set_one_shader(before, after)
>
>      # worst VGPR spills
>      num = 0
>      sort_key = lambda v: -v[1].after.scratch_size
>      for name, stats in sorted(shaders.items(), key = sort_key):
>          if num == 0:
>              print_yellow(" WORST VGPR SPILLS (not deltas)" + (" " * 40) +
> -                         "VGPRs SpillVGPR ScratchSize")
> +                         "VGPRs SpillVGPR  PrivVGPR ScratchSize")
>          stats.print_one_shader_vgpr_spill(name)
>          num += 1
>          if num == num_listed:
>              break
>      if num > 0:
>          print
>
>      # VGPR spilling apps
> -    print_yellow(" VGPR SPILLING APPS   Shaders SpillVGPR ScratchSize")
> +    print_yellow(" VGPR SPILLING APPS   Shaders SpillVGPR  PrivVGPR ScratchSize")
>      for name, stats in sorted(apps.items()):
>          stats.print_vgpr_spilling_app(name)
>      print
>
>      # worst SGPR spills
>      num = 0
>      sort_key = lambda v: -v[1].after.spilled_sgprs
>      for name, stats in sorted(shaders.items(), key = sort_key):
>          if num == 0:
>              print_yellow(" WORST SGPR SPILLS (not deltas)" + (" " * 40) +
> @@ -659,21 +676,21 @@ def print_tables(before_all_results, after_all_results):
>                  print_yellow(" WORST REGRESSIONS - {:49}".format(metrics[i][1]) +
>                               "Before     After     Delta Percentage")
>              stats.print_regression(name, field)
>              num += 1
>              if num == num_listed:
>                  break
>          if num > 0:
>              print
>
>      # percentages
> -    legend = "Shaders     SGPRs     VGPRs SpillSGPR SpillVGPR   Scratch  CodeSize  MaxWaves     Waits"
> +    legend = "Shaders     SGPRs     VGPRs SpillSGPR SpillVGPR  PrivVGPR   Scratch  CodeSize  MaxWaves     Waits"
>      print_yellow(" PERCENTAGE DELTAS    " + legend)
>      for name, stats in sorted(apps.items()):
>          stats.print_percentages(name)
>      print " " + ("-" * (21 + len(legend)))
>      total_affected.print_percentages("All affected")
>      print " " + ("-" * (21 + len(legend)))
>      total.print_percentages("Total")
>      print
>
>  def main():
>


More information about the mesa-dev mailing list