| 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 | |
| 261 | def main(): |