Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Copy Markdown
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
Copy Markdown
Contributor 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
11 changes: 5 additions & 6 deletions pytorch_blade/src/compiler/mlir/runtime/disc_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ const char* GetBackendName() {
return DiscEngine::GetBackendName();
}

namespace {
bool InitBladeDiscEngine() {
static std::once_flag flag;
std::call_once(flag, [&]() {
auto torch_blade_engine_creator =
torch::blade::backends::EngineCreatorRegister().RegisterBackend(
DiscEngine::GetBackendName(), &DiscEngine::Create);
});
torch::blade::backends::EngineCreatorRegister().RegisterBackend(
DiscEngine::GetBackendName(), &DiscEngine::Create);
return true;
}
static bool init_dummy = InitBladeDiscEngine();
} // namespace

} // namespace disc
} // namespace blade
} // namespace torch
1 change: 0 additions & 1 deletion pytorch_blade/src/compiler/mlir/runtime/disc_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace torch {
namespace blade {
namespace disc {
const char* GetBackendName();
bool InitBladeDiscEngine();
} // namespace disc
} // namespace blade
} // namespace torch
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ void ReplaceDiscClass(
std::vector<c10::IValue> RegisterDiscClass(
const std::shared_ptr<Graph>& graph) {
torch::blade::backends::InitTorchBladeEngine();
torch::blade::disc::InitBladeDiscEngine();
std::vector<c10::IValue> disc_inputs;
std::vector<torch::jit::Node*> disc_nodes;
std::copy_if(
Expand Down