You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpu_analyser.py 4.4 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """The gpu base analyser."""
  16. import csv
  17. import os
  18. from mindinsight.profiler.analyser.base_analyser import BaseAnalyser
  19. from mindinsight.profiler.common.log import logger
  20. class GpuAnalyser(BaseAnalyser):
  21. """Gpu base analyser."""
  22. _csv_file_to_analyse = ""
  23. def _load(self):
  24. """Load data according to the parsed AICORE operator types file."""
  25. op_type_file_path = os.path.join(
  26. self._profiling_dir,
  27. self._csv_file_to_analyse.format(self._device_id)
  28. )
  29. if not os.path.isfile(op_type_file_path):
  30. logger.warning('The file <%s> does not exist.', op_type_file_path)
  31. return
  32. with open(op_type_file_path, 'r') as file:
  33. csv_reader = csv.reader(file)
  34. _ = next(csv_reader)
  35. for info in csv_reader:
  36. self._data.append(self._convert_field_type(info))
  37. @staticmethod
  38. def _convert_field_type(row):
  39. """
  40. Convert the field type to the specific type.
  41. Args:
  42. row (list): One row data from parsed data.
  43. Returns:
  44. list, the converted data.
  45. """
  46. return row
  47. def _filter(self, filter_condition):
  48. """
  49. Filter the profiling data according to the filter condition.
  50. Args:
  51. filter_condition (dict): The filter condition.
  52. """
  53. def _inner_filter(item: list):
  54. return self._default_filter(item, filter_condition)
  55. self._result = list(filter(_inner_filter, self._data))
  56. class GpuOpTypeAnalyser(GpuAnalyser):
  57. """Gpu operation type analyser."""
  58. _col_names = ["op_type", "type_occurrences", "total_time", "proportion", "avg_time"]
  59. _csv_file_to_analyse = 'gpu_op_type_info_{}.csv'
  60. @staticmethod
  61. def _convert_field_type(row):
  62. """
  63. Convert the field type to the specific type.
  64. Args:
  65. row (list): One row data from parsed data.
  66. Returns:
  67. list, the converted data.
  68. """
  69. return [row[0], int(row[1]), float(row[2]), float(row[3]), float(row[4])]
  70. class GpuOpInfoAnalyser(GpuAnalyser):
  71. """Gpu operation detail info analyser."""
  72. _col_names = ["op_side", "op_type", "op_name", "op_full_name",
  73. "op_occurrences", "op_total_time", "op_avg_time",
  74. "proportion", "cuda_activity_cost_time", "cuda_activity_call_count"]
  75. _csv_file_to_analyse = 'gpu_op_detail_info_{}.csv'
  76. @staticmethod
  77. def _convert_field_type(row):
  78. """
  79. Convert the field type to the specific type.
  80. Args:
  81. row (list): One row data from parsed data.
  82. Returns:
  83. list, the converted data.
  84. """
  85. return [row[0], row[1], row[2], row[3], int(row[4]), float(row[5]),
  86. float(row[6]), float(row[7]), float(row[8]), int(row[9])]
  87. class GpuCudaActivityAnalyser(GpuAnalyser):
  88. """Gpu activity type analyser."""
  89. _col_names = ["name", "type", "op_full_name", "stream_id",
  90. "block_dim", "grid_dim", "occurrences", "total_duration",
  91. "avg_duration", "max_duration", "min_duration"]
  92. _csv_file_to_analyse = 'gpu_activity_data_{}.csv'
  93. @staticmethod
  94. def _convert_field_type(row):
  95. """
  96. Convert the field type to the specific type.
  97. Args:
  98. row (list): One row data from parsed data.
  99. Returns:
  100. list, the converted data.
  101. """
  102. return [row[0], row[1], row[2], row[3], row[4], row[5], int(row[6]),
  103. float(row[7]), float(row[8]), float(row[9]), float(row[10])]