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.

dump_test_utils.py 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright 2021 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. """
  16. Utils for testing dump feature.
  17. """
  18. import json
  19. async_dump_dict = {
  20. "common_dump_settings": {
  21. "dump_mode": 0,
  22. "path": "",
  23. "net_name": "Net",
  24. "iteration": "0",
  25. "input_output": 2,
  26. "kernels": ["Default/TensorAdd-op3"],
  27. "support_device": [0, 1, 2, 3, 4, 5, 6, 7],
  28. "op_debug_mode": 0
  29. }
  30. }
  31. e2e_dump_dict = {
  32. "common_dump_settings": {
  33. "dump_mode": 0,
  34. "path": "",
  35. "net_name": "Net",
  36. "iteration": "0",
  37. "input_output": 0,
  38. "kernels": ["Default/Conv-op12"],
  39. "support_device": [0, 1, 2, 3, 4, 5, 6, 7],
  40. "op_debug_mode": 0
  41. },
  42. "e2e_dump_settings": {
  43. "enable": True,
  44. "trans_flag": False
  45. }
  46. }
  47. async_dump_dict_2 = {
  48. "common_dump_settings": {
  49. "dump_mode": 0,
  50. "path": "/tmp/async_dump/test_async_dump_net_multi_layer_mode1",
  51. "net_name": "test",
  52. "iteration": "0",
  53. "input_output": 2,
  54. "kernels": [
  55. "default/TensorAdd-op10",
  56. "Gradients/Default/network-WithLossCell/_backbone-ReLUReduceMeanDenseRelu/dense-Dense/gradBiasAdd/"\
  57. "BiasAddGrad-op8",
  58. "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/SoftmaxCrossEntropyWithLogits-op5",
  59. "Default/optimizer-Momentum/tuple_getitem-op29",
  60. "Default/optimizer-Momentum/ApplyMomentum-op12"
  61. ],
  62. "support_device": [0, 1, 2, 3, 4, 5, 6, 7],
  63. "op_debug_mode": 0
  64. }
  65. }
  66. def generate_dump_json(dump_path, json_file_name, test_key):
  67. """
  68. Util function to generate dump configuration json file.
  69. """
  70. if test_key == "test_async_dump":
  71. data = async_dump_dict
  72. data["common_dump_settings"]["path"] = dump_path
  73. elif test_key == "test_e2e_dump":
  74. data = e2e_dump_dict
  75. data["common_dump_settings"]["path"] = dump_path
  76. elif test_key == "test_async_dump_net_multi_layer_mode1":
  77. data = async_dump_dict_2
  78. data["common_dump_settings"]["path"] = dump_path
  79. else:
  80. raise ValueError(
  81. "Failed to generate dump json file. The test name value " + test_key + " is invalid.")
  82. with open(json_file_name, 'w') as f:
  83. json.dump(data, f)