1+ import os
12import re
23from pathlib import Path
34
5+ import yaml
6+
47INPUT_DIR = Path ("tools/api_tracer/trace_output_tmp" )
58
69
@@ -12,33 +15,55 @@ def parse_api(api):
1215 return api
1316
1417
15- def process_file (input_path ):
18+ def process_file (input_path , target_apis ):
1619 input_name = input_path .name
1720 output_name = input_name [4 :]
1821 output_path = input_path .parent / output_name
1922
23+ output_excluded_name = output_name .replace (".txt" , "_excluded.txt" )
24+ output_excluded_path = input_path .parent / output_excluded_name
25+
2026 apis = set ()
2127 with input_path .open ("r" ) as f :
2228 apis = set ([line .strip () for line in f if line .strip ()])
2329 print (f"Read { len (apis )} apis from { input_path } " , flush = True )
2430
2531 alias_apis = set ()
32+ excluded_apis = set ()
2633 for api in apis :
34+ alias_api = api
35+ if alias_api not in target_apis :
36+ excluded_apis .add (api )
37+ continue
2738 alias_apis .add (parse_api (api ))
2839
2940 with output_path .open ("w" ) as f :
3041 f .writelines (f"{ line } \n " for line in sorted (alias_apis ))
3142 print (f"Write { len (alias_apis )} alias apis to { output_path } " , flush = True )
3243
44+ with output_excluded_path .open ("w" ) as f :
45+ f .writelines (f"{ line } \n " for line in sorted (excluded_apis ))
46+ print (f"Write { len (excluded_apis )} excluded apis to { output_excluded_path } " , flush = True )
47+
3348
3449def main ():
35- input_files = list (INPUT_DIR .glob ("api_apis*.txt" ))
50+ yaml_path = os .path .join (
51+ os .path .dirname (os .path .abspath (__file__ )),
52+ "api_list" ,
53+ "torch_api_list.yaml" ,
54+ )
55+ target_apis = []
56+ with open (yaml_path , "r" , encoding = "utf-8" ) as f :
57+ target_apis = yaml .safe_load (f )
58+ print (f"Loaded { len (target_apis )} target APIs." )
59+
60+ input_files = list (INPUT_DIR .glob ("api_apis.txt" ))
3661 if not input_files :
3762 print (f"No input files found in { INPUT_DIR } " , flush = True )
3863 return
3964
4065 for input_file in sorted (input_files ):
41- process_file (input_file )
66+ process_file (input_file , target_apis )
4267
4368
4469if __name__ == "__main__" :
0 commit comments