1# Copyright 2023 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"""Compile akg info""" 16import sys 17 18def clean_env(): 19 """clear akg python env""" 20 import gc 21 22 imported_modules = set(sys.modules.keys()) 23 for obj_key in imported_modules: 24 if "conda" in obj_key: 25 continue 26 if "akg" in obj_key or "topi" in obj_key or "tvm" in obj_key: 27 del sys.modules[obj_key] 28 try: 29 del globals()[obj_key] 30 except KeyError: 31 pass 32 try: 33 del locals()[obj_key] 34 except KeyError: 35 pass 36 37 gc.collect() 38 39def run_compiler(info_path): 40 """invoke akg to compile the info""" 41 try: 42 from mindspore_lite.akg.ms import compilewithjson 43 except ImportError: 44 from akg.ms import compilewithjson 45 with open(info_path, 'r') as f: 46 info_str = f.read() 47 compilewithjson(info_str) 48 clean_env() 49 50 51if __name__ == "__main__": 52 if len(sys.argv) == 2: 53 run_compiler(sys.argv[1]) 54 else: 55 raise ValueError("The input args length should be 2, but got {}.".format(len(sys.argv))) 56