pytorch / glow

Compiler for Neural Network hardware accelerators
Apache License 2.0
3.21k stars 688 forks source link

Use static registry pattern for backends/device managers #2342

Open bertmaher opened 5 years ago

bertmaher commented 5 years ago

Right now we have to explicitly add all supported backends to switch tables in createBackend (and createDeviceManager). It'd be nice to use a static registry pattern (I think https://www.bfilipek.com/2018/02/factory-selfregister.html is a decent overview of this pattern) to allow backends to register their existence at startup. That will also break an annoying dependence cycle where Backend depends on DeviceSpecificBackend and vice versa, because the interface and factory dependences go either direction.

It'd also be worthwhile to look at how LLVM solves this problem with its backends, since LLVM usually does things The Right Way.

nickgg commented 5 years ago

@rdzhabarov any more to do here?