Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]refactor: use static init instead of call_once. #672

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions pytorch_blade/src/compiler/mlir/converters/torch_mlir_op_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ bool IsTorchMlirSupported(const torch::jit::Node& node) {
}

// clang-format off
const std::unordered_set<std::string> &GetTorchMlirWhiteList() {
static std::unordered_set<std::string> white_list{
std::unordered_set<std::string> CreateTorchMlirWhiteList() {
std::unordered_set<std::string> white_list{
"aten::_autocast_to_reduced_precision",
"aten::__and__",
"aten::add",
Expand Down Expand Up @@ -113,24 +113,26 @@ const std::unordered_set<std::string> &GetTorchMlirWhiteList() {
"torch_blade::fake_quant"
};

auto custom_ops = env::ReadStringFromEnvVar("TORCH_MHLO_OP_WHITE_LIST", "");
std::ostringstream ostr;
ostr << "User defined white list: [";
std::istringstream f(custom_ops);
std::string s;
for (auto s : StrSplit(custom_ops, ';')) {
white_list.insert(std::string(s));
ostr << s << ", ";
}
ostr << "]";
LOG(INFO) << ostr.str();

static std::once_flag white;
std::call_once(white, []() {
auto custom_ops = env::ReadStringFromEnvVar("TORCH_MHLO_OP_WHITE_LIST", "");
std::ostringstream ostr;
ostr << "User defined white list: [";
std::istringstream f(custom_ops);
std::string s;
for (auto s : StrSplit(custom_ops, ';')) {
white_list.insert(std::string(s));
ostr << s << ", ";
}
ostr << "]";
LOG(INFO) << ostr.str();
});
return white_list;
}
// clang-format off

const std::unordered_set<std::string> &GetTorchMlirWhiteList() {
static std::unordered_set<std::string> white_list = CreateTorchMlirWhiteList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you please link the c++ 11 standard doc reference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refer to this SO answer or C++11 standard 6.7

return white_list;
}

} // namespace blade
} // namespace torch