Loads a contrib op library from the given path. NOTE(mrry): On Windows, we currently assume that some contrib op libraries are statically linked into the main TensorFlow Python extension DLL - use dynamically linked ops if the .so is present. Args: path: An absolute path to a shared ob
(path)
| 28 | |
| 29 | |
| 30 | def load_op_library(path): |
| 31 | """Loads a contrib op library from the given path. |
| 32 | |
| 33 | NOTE(mrry): On Windows, we currently assume that some contrib op |
| 34 | libraries are statically linked into the main TensorFlow Python |
| 35 | extension DLL - use dynamically linked ops if the .so is present. |
| 36 | |
| 37 | Args: |
| 38 | path: An absolute path to a shared object file. |
| 39 | |
| 40 | Returns: |
| 41 | A Python module containing the Python wrappers for Ops defined in the |
| 42 | plugin. |
| 43 | """ |
| 44 | if os.name == 'nt': |
| 45 | # To avoid making every user_ops aware of windows, re-write |
| 46 | # the file extension from .so to .dll if .so file doesn't exist. |
| 47 | if not os.path.exists(path): |
| 48 | path = re.sub(r'\.so$', '.dll', path) |
| 49 | |
| 50 | # Currently we have only some user_ops as dlls on windows - don't try |
| 51 | # to load them if the dll is not found. |
| 52 | # TODO(mrry): Once we have all of them this check should be removed. |
| 53 | if not os.path.exists(path): |
| 54 | return None |
| 55 | path = resource_loader.get_path_to_datafile(path) |
| 56 | ret = load_library.load_op_library(path) |
| 57 | assert ret, 'Could not load %s' % path |
| 58 | return ret |