I think bellow code has some problems,it’s extracted from\src\relay\backend\compile_engine.cc.
I think the original purpose of the code is that the same global_symblol can only be registered once for each external codegen。
but the actual result is that the name of global_symbol can’t be same with code_gen_name, for example, we can’t set global_symbol name with “ccompiler” for relay.ext.ccompiler.
and the code logic is error, because cached_symbol.count(sn) is always 0, so the if sentence is always false。
current false version:
Array<tvm::runtime::Module> LowerExternalFunctions() {
...
std::unordered_map<std::string, std::string> cached_symbol;
...
auto symbol_name = src_func->GetAttr<String>(tvm::attr::kGlobalSymbol);
...
std::string sn = symbol_name.value();
if (cached_symbol.count(sn)) {
cached_symbol[sn] = code_gen_name;
} else {
ICHECK_NE(sn, code_gen_name)
<< "Found duplicated symbol: " << sn << " for: " << code_gen_name;
}
}
I think the code should be modified to bellow
if (!cached_symbol.count(sn)) {
cached_symbol[sn] = code_gen_name;
} else {
ICHECK_NE(cached_symbol[sn], code_gen_name)
<< "Found duplicated symbol: " << sn << " for: " << code_gen_name;
}