MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _write_midout

Method _write_midout

tools/gen_header_for_bin_reduce.py:231–258  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

229 self._fout.write("#define {} {}\n".format(name, val))
230
231 def _write_midout(self):
232 if not self._midout_files:
233 return
234
235 gen = os.path.join(
236 self.get_megengine_root(), "third_party", "midout", "gen_header.py"
237 )
238 if self.get_megvii3_root():
239 gen = os.path.join(
240 self.get_megvii3_root(), "brain", "midout", "gen_header.py"
241 )
242 print("use {} to gen bin_reduce header".format(gen))
243 cvt = subprocess.run(
244 [gen] + self._midout_files, stdout=subprocess.PIPE, check=True,
245 ).stdout.decode("utf-8")
246 self._fout.write("// midout \n")
247 self._fout.write(cvt)
248 if cvt.find(" half,") > 0:
249 change = open(self._fout.name).read().replace(" half,", " __fp16,")
250 with open("fix_fp16_bin_reduce.h", "w") as fix_fp16:
251 fix_fp16.write(change)
252 msg = (
253 "WARNING:\n"
254 "hit half in trace, try use fix_fp16_bin_reduce.h when build failed with bin_reduce.h\n"
255 "which caused by LLVM mangle issue on __fp16 dtype, if you find msg 'error: use of undeclared identifier 'half'\n"
256 "then try use fix_fp16_bin_reduce.h, if build failed again, submit a issue to Engine team!!!"
257 )
258 print(msg)
259
260
261def main():

Callers 1

generateMethod · 0.95

Calls 10

get_megengine_rootMethod · 0.95
get_megvii3_rootMethod · 0.95
printFunction · 0.85
joinMethod · 0.80
formatMethod · 0.45
runMethod · 0.45
writeMethod · 0.45
findMethod · 0.45
replaceMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected