Move Op in operator registry to another library, like `OpInfo`
Created by: reyoung
OpInfo is stored in OpRegistry in op_register.{h/cc}. However, Operator needs its OpInfo to know which input or output is duplicated, which output is intermediate. OpRegistry needs to register Operator. There is a cycle dependency here.
In the same time, it seems we should move Kernels to OpInfo as its field. Since our OpInfo's field can be nullptr.
Also, we should make the global OpInfo fit Google C++ style. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables .
// in .h
struct OpInfo {
...
};
extern std::unordered_map<string, OpInfo>& GlobalOpInfo();
// in .cpp
// Never destroy OpInfo, Leave it to operator system. Declare it as a pointer
// to avoid complex global value initialization in C++, since global value initialization
// in C++ is out of order.
static std::unordered_map<string, OpInfo>* g_op_info = nullptr;
std::unordered_map<string, OpInfo> GlobalOpInfo() {
if (g_op_info == nullptr) {
// No need to consider multi-thread situation
g_op_info = new std::unordered_map<string, OpInfo>();
}
return *g_op_info;
}
If it should be done, I could give a PR in next day. Help is also welcome.