| 19 | |
| 20 | |
| 21 | class HeaderGen: |
| 22 | _dtypes = None |
| 23 | _oprs = None |
| 24 | _fout = None |
| 25 | _elemwise_modes = None |
| 26 | _has_netinfo = False |
| 27 | _midout_files = None |
| 28 | |
| 29 | _file_without_hash = False |
| 30 | |
| 31 | def __init__(self): |
| 32 | self._dtypes = set() |
| 33 | self._oprs = set() |
| 34 | self._elemwise_modes = set() |
| 35 | self._graph_hashes = set() |
| 36 | self._midout_files = [] |
| 37 | |
| 38 | _megvii3_root_cache = None |
| 39 | |
| 40 | @classmethod |
| 41 | def get_megvii3_root(cls): |
| 42 | if cls._megvii3_root_cache is not None: |
| 43 | return cls._megvii3_root_cache |
| 44 | wd = Path(__file__).resolve().parent |
| 45 | while wd.parent != wd: |
| 46 | workspace_file = wd / "WORKSPACE" |
| 47 | if workspace_file.is_file(): |
| 48 | cls._megvii3_root_cache = str(wd) |
| 49 | return cls._megvii3_root_cache |
| 50 | wd = wd.parent |
| 51 | return None |
| 52 | |
| 53 | _megengine_root_cache = None |
| 54 | |
| 55 | @classmethod |
| 56 | def get_megengine_root(cls): |
| 57 | if cls._megengine_root_cache is not None: |
| 58 | return cls._megengine_root_cache |
| 59 | wd = Path(__file__).resolve().parent.parent |
| 60 | cls._megengine_root_cache = str(wd) |
| 61 | return cls._megengine_root_cache |
| 62 | |
| 63 | def extend_netinfo(self, data): |
| 64 | self._has_netinfo = True |
| 65 | if "hash" not in data: |
| 66 | self._file_without_hash = True |
| 67 | else: |
| 68 | self._graph_hashes.add(str(data["hash"])) |
| 69 | for i in data["dtypes"]: |
| 70 | self._dtypes.add(i) |
| 71 | for i in data["opr_types"]: |
| 72 | self._oprs.add(i) |
| 73 | |
| 74 | def extend_midout(self, fname): |
| 75 | self._midout_files.append(fname) |
| 76 | |
| 77 | def extend_elemwise_mode_info(self, fname): |
| 78 | for line in open(fname): |