You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom.py 779 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. import os
  3. from .._imperative_rt.ops._custom import (
  4. _get_custom_op_list,
  5. _install,
  6. _make_custom_op,
  7. _uninstall,
  8. get_custom_op_abi_tag,
  9. )
  10. __all__ = ["load"]
  11. def _gen_custom_op_maker(custom_op_name):
  12. def op_maker(**kwargs):
  13. return _make_custom_op(custom_op_name, kwargs)
  14. return op_maker
  15. def load(lib_path):
  16. lib_path = os.path.abspath(lib_path)
  17. lib_name = os.path.splitext(lib_path)[0]
  18. op_in_this_lib = _install(lib_name, lib_path)
  19. for op in op_in_this_lib:
  20. op_maker = _gen_custom_op_maker(op)
  21. globals()[op] = op_maker
  22. __all__.append(op)
  23. def unload(lib_path):
  24. lib_path = os.path.abspath(lib_path)
  25. lib_name = os.path.splitext(lib_path)[0]
  26. _uninstall(lib_name)