__init__.py 655 B

1234567891011121314151617181920212223242526
  1. import pkgutil
  2. from importlib.util import module_from_spec
  3. from sys import modules
  4. _backends = []
  5. for module_finder, module_name, is_pkg in pkgutil.iter_modules(
  6. __path__,
  7. prefix=__name__ + ".",
  8. ):
  9. # skip .py files (like libdevice.py)
  10. if not is_pkg:
  11. continue
  12. # import backends (like cuda and hip) that are included during setup.py
  13. spec = module_finder.find_spec(module_name)
  14. if spec is None or spec.loader is None:
  15. continue
  16. module = module_from_spec(spec)
  17. spec.loader.exec_module(module)
  18. _backends.append(module_name)
  19. modules[module_name] = module
  20. __all__ = _backends
  21. del _backends