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