3
3
from __future__ import print_function
4
4
import collections
5
5
import os
6
+ import sys
6
7
7
8
BANNER = "Auto-generated by generate-wrappers.py script. Do not modify"
8
9
WRAPPER_SRC_NAMES = {
53
54
"PROD_AVX512SKX_MICROKERNEL_SRCS" ,
54
55
]
55
56
56
- def update_sources ():
57
+ def update_sources (xnnpack_path ):
57
58
sources = collections .defaultdict (list )
58
- with open ("./ XNNPACK/CMakeLists.txt" ) as cmake :
59
+ with open (os . path . join ( xnnpack_path , " XNNPACK/CMakeLists.txt") ) as cmake :
59
60
lines = cmake .readlines ()
60
61
i = 0
61
62
while i < len (lines ):
@@ -74,17 +75,16 @@ def update_sources():
74
75
sources [name ].append (value [4 :])
75
76
else :
76
77
i += 1
77
- print (sources )
78
78
return sources
79
79
80
- if __name__ == "__main__" :
80
+ def gen_wrappers ( xnnpack_path ) :
81
81
xnnpack_sources = collections .defaultdict (list )
82
- sources = update_sources ()
82
+ sources = update_sources (xnnpack_path )
83
83
for name in WRAPPER_SRC_NAMES :
84
84
xnnpack_sources [WRAPPER_SRC_NAMES [name ]].extend (sources [name ])
85
85
for condition , filenames in xnnpack_sources .items ():
86
86
for filename in filenames :
87
- filepath = os .path .join ("XNNPACK/wrappers " , filename )
87
+ filepath = os .path .join (xnnpack_path , "xnnpack_wrappers " , filename )
88
88
if not os .path .isdir (os .path .dirname (filepath )):
89
89
os .makedirs (os .path .dirname (filepath ))
90
90
with open (filepath , "w" ) as wrapper :
@@ -102,3 +102,38 @@ def update_sources():
102
102
print ("#if %s" % condition , file = wrapper )
103
103
print ("#include <%s>" % filename , file = wrapper )
104
104
print ("#endif /* %s */" % condition , file = wrapper )
105
+
106
+ # update xnnpack_wrapper_defs.bzl file under the same folder
107
+ with open (os .path .join (os .path .dirname (__file__ ), "xnnpack_wrapper_defs.bzl" ), 'w' ) as wrapper_defs :
108
+ print ('"""' , file = wrapper_defs )
109
+ print (BANNER , file = wrapper_defs )
110
+ print ('"""' , file = wrapper_defs )
111
+ for name in WRAPPER_SRC_NAMES :
112
+ print ('\n ' + name + ' = [' , file = wrapper_defs )
113
+ for file_name in sources [name ]:
114
+ print (' "xnnpack_wrappers/{}",' .format (file_name ), file = wrapper_defs )
115
+ print (']' , file = wrapper_defs )
116
+
117
+ # update xnnpack_src_defs.bzl file under the same folder
118
+ with open (os .path .join (os .path .dirname (__file__ ), "xnnpack_src_defs.bzl" ), 'w' ) as src_defs :
119
+ print ('"""' , file = src_defs )
120
+ print (BANNER , file = src_defs )
121
+ print ('"""' , file = src_defs )
122
+ for name in SRC_NAMES :
123
+ print ('\n ' + name + ' = [' , file = src_defs )
124
+ for file_name in sources [name ]:
125
+ print (' "XNNPACK/src/{}",' .format (file_name ), file = src_defs )
126
+ print (']' , file = src_defs )
127
+
128
+
129
+ def main (argv ):
130
+ if argv is None or len (argv ) == 0 :
131
+ gen_wrappers ("." )
132
+ else :
133
+ gen_wrappers (argv [0 ])
134
+
135
+ # The first argument is the place where the "xnnpack_wrappers" folder will be created.
136
+ # Run it without arguments will generate "xnnpack_wrappers" in the current path.
137
+ # The two .bzl files will always be generated in the current path.
138
+ if __name__ == "__main__" :
139
+ main (sys .argv [1 :])
0 commit comments