microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
9baed694a34dcb074db66e9f74c93a4e5bb6f9a2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

onnxruntime_extensions/cmake_helper.py

35lines · modecode

1import inspect
2from ._ocos import default_opset_domain
3from . import _cuops
4
5
6ALL_CUSTOM_OPS = {_name: _obj for _name, _obj in inspect.getmembers(_cuops)
7 if (inspect.isclass(_obj) and issubclass(_obj, _cuops.CustomOp))}
8
9
10OPMAP_TO_CMAKE_FLAGS = {'GPT2Tokenizer': 'OCOS_ENABLE_GPT2_TOKENIZER',
11 'BlingFireSentenceBreaker': 'OCOS_ENABLE_BLINGFIRE'
12 }
13
14
15def 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