Instantiates all known local backends.
()
| 217 | |
| 218 | |
| 219 | def _get_local_backends(): |
| 220 | """Instantiates all known local backends.""" |
| 221 | global _local_backends |
| 222 | if _local_backends is not None: |
| 223 | return _local_backends |
| 224 | |
| 225 | _local_backends = collections.OrderedDict() |
| 226 | for name, factory in _local_backend_factories.items(): |
| 227 | logging.vlog(2, "Initializing backend '%s'" % name) |
| 228 | try: |
| 229 | backend = factory() |
| 230 | except RuntimeError: |
| 231 | if name == 'cpu': |
| 232 | # We always expect CPU to initialize successfully. |
| 233 | raise |
| 234 | else: |
| 235 | # If the backend isn't built into the binary, or if it has no devices, |
| 236 | # we expect a RuntimeError. |
| 237 | continue |
| 238 | _local_backends[name] = backend |
| 239 | return _local_backends |
| 240 | |
| 241 | |
| 242 | def get_local_backend(name=None): |
no test coverage detected