microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
onnxruntime_extensions/cmake_helper.py
35lines · modecode
| 1 | import inspect |
| 2 | from ._ocos import default_opset_domain |
| 3 | from . import _cuops |
| 4 | |
| 5 | |
| 6 | ALL_CUSTOM_OPS = {_name: _obj for _name, _obj in inspect.getmembers(_cuops) |
| 7 | if (inspect.isclass(_obj) and issubclass(_obj, _cuops.CustomOp))} |
| 8 | |
| 9 | |
| 10 | OPMAP_TO_CMAKE_FLAGS = {'GPT2Tokenizer': 'OCOS_ENABLE_GPT2_TOKENIZER', |
| 11 | 'BlingFireSentenceBreaker': 'OCOS_ENABLE_BLINGFIRE' |
| 12 | } |
| 13 | |
| 14 | |
| 15 | def gen_cmake_oplist(opconfig_file, oplist_cmake_file = '_selectedoplist.cmake'): |
| 16 | |
| 17 | ext_domain = default_opset_domain() |
| 18 | with open(oplist_cmake_file, 'w') as f: |
| 19 | print("# Auto-Generated File, not edited!!!", file=f) |
| 20 | with open(opconfig_file, 'r') as opfile: |
| 21 | for _ln in opfile: |
| 22 | if _ln.startswith(ext_domain): |
| 23 | items = _ln.strip().split(';') |
| 24 | if len(items) < 3: |
| 25 | raise RuntimeError("The malformated operator config file.") |
| 26 | for _op in items[2].split(','): |
| 27 | if not _op: |
| 28 | continue # is None or "" |
| 29 | if _op not in OPMAP_TO_CMAKE_FLAGS: |
| 30 | raise RuntimeError("Cannot find the custom operator({})\'s build flags, " |
| 31 | + "Please update the OPMAP_TO_CMAKE_FLAGS dictionary.".format(_op)) |
| 32 | print("set({} ON CACHE INTERNAL \"\")".format(OPMAP_TO_CMAKE_FLAGS[_op]), file=f) |
| 33 | print("# End of Building the Operator CMake variables", file=f) |
| 34 | |
| 35 | print('The cmake tool file has been generated successfully.') |
| 36 | |