3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
14 def InitOpsLibrary(name):
15 """Loads a dynamic library that contains custom operators into Caffe2. 17 Since Caffe2 uses static variable registration, you can optionally load a 18 separate .so file that contains custom operators and registers that into 19 the caffe2 core binary. In C++, this is usually done by either declaring 20 dependency during compilation time, or via dynload. This allows us to do 21 registration similarly on the Python side. 24 name: a name that ends in .so, such as "my_custom_op.so". Otherwise, 25 the command will simply be ignored. 29 if not os.path.exists(name):
33 print(
'Ignoring {} as it is not a valid file.'.format(name))
38 _IMPORTED_DYNDEPS = set()
41 def GetImportedOpsLibraries():
42 return _IMPORTED_DYNDEPS
46 _IMPORTED_DYNDEPS.add(path)
47 with extension_loader.DlopenGuard():
50 core.RefreshRegisteredOperators()