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.

minddata_parser.py 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. """Minddata aicpu parser."""
  16. import os
  17. from mindspore.profiler.common.util import get_file_join_name, fwrite_format
  18. from mindspore import log as logger
  19. from mindspore.profiler.common.validator.validate_path import \
  20. validate_and_normalize_path
  21. class MinddataParser:
  22. """Minddata Aicpu Parser."""
  23. @staticmethod
  24. def parse_minddata_aicpu_data(minddata_aicpu_source_path):
  25. """
  26. Parse minddata get_next info which contains queue size and execute time.
  27. Args:
  28. minddata_aicpu_source_path (str): the source file path.
  29. Returns:
  30. list[Union[str, float]], the converted data.
  31. """
  32. result = list()
  33. try:
  34. minddata_aicpu_source_path = validate_and_normalize_path(minddata_aicpu_source_path)
  35. with open(minddata_aicpu_source_path) as source_data_file:
  36. source_data = source_data_file.read()
  37. step_data = source_data.split("\x00")
  38. for one_step in step_data:
  39. if one_step:
  40. node_info = one_step.split(", ")
  41. node_name, node_start, node_end, queue_size = "", 0, 0, 0
  42. if node_info:
  43. node_name = node_info[0].replace("Node:", "")
  44. if len(node_info) > 3 and "queue" in node_info[1]:
  45. queue_size = node_info[1].replace("queue size:", "")
  46. queue_size = int(queue_size) if queue_size.isdigit() else queue_size
  47. node_start = node_info[2].replace("Run start:", "")
  48. node_start = int(node_start) if node_start.isdigit() else node_start
  49. node_end = node_info[3].replace("Run end:", "")
  50. node_end = int(node_end) if node_end.isdigit() else node_end
  51. elif len(node_info) > 3 and "Run" in node_info[1]:
  52. queue_size = node_info[3].replace("queue size:", "")
  53. queue_size = int(queue_size) if queue_size.isdigit() else queue_size
  54. node_start = node_info[1].replace("Run start:", "")
  55. node_start = int(node_start) if node_start.isdigit() else node_start
  56. node_end = node_info[2].replace("Run end:", "")
  57. node_end = int(node_end) if node_end.isdigit() else node_end
  58. one_step_list = [node_name, node_start, node_end, queue_size]
  59. result.append(one_step_list)
  60. except OSError:
  61. logger.error("Open get_next profiling file error.")
  62. return result
  63. @staticmethod
  64. def execute(source_path, output_path, device_id):
  65. """
  66. Execute the parser.
  67. Args:
  68. source_path (str): the source file path.
  69. output_path (str): the output file path.
  70. device_id (str): the device id.
  71. """
  72. col_names = ["node_name", "start_time", "end_time", "queue_size"]
  73. source_path = validate_and_normalize_path(source_path)
  74. minddata_aicpu_source_path = get_file_join_name(
  75. input_path=source_path, file_name='DATA_PREPROCESS.AICPUMI')
  76. if not minddata_aicpu_source_path:
  77. minddata_aicpu_source_path = get_file_join_name(
  78. input_path=source_path, file_name='DATA_PREPROCESS.dev.AICPUMI')
  79. if not minddata_aicpu_source_path:
  80. minddata_aicpu_source_path = get_file_join_name(
  81. input_path=os.path.join(source_path, "data"), file_name='DATA_PREPROCESS.AICPUMI')
  82. if not minddata_aicpu_source_path:
  83. minddata_aicpu_source_path = get_file_join_name(
  84. input_path=os.path.join(source_path, "data"), file_name='DATA_PREPROCESS.dev.AICPUMI')
  85. if not minddata_aicpu_source_path:
  86. return
  87. minddata_aicpu_output_path = os.path.join(output_path, "minddata_aicpu_" + device_id + ".txt")
  88. minddata_aicpu_data = MinddataParser.parse_minddata_aicpu_data(minddata_aicpu_source_path)
  89. if minddata_aicpu_data:
  90. fwrite_format(minddata_aicpu_output_path, " ".join(col_names), is_start=True)
  91. fwrite_format(minddata_aicpu_output_path, minddata_aicpu_data, is_start=True)