MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / get

Method get

src/jit/impl/compiler.cpp:54–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54Compiler* Compiler::get(ComputingGraph& graph, CompNode comp_node) {
55 static EmptyCompiler empty_compiler;
56 if (comp_node == CompNode::default_cpu()) {
57 // oprs in the internal graph are on default cpu; this case handles
58 // nested JITExecutor
59 return &empty_compiler;
60 }
61
62 CompilerHolder* holder;
63 {
64 static std::mutex mtx;
65 MGB_LOCK_GUARD(mtx);
66 holder = graph.options().user_data.get_user_data_or_create<CompilerHolder>();
67 }
68 MGB_LOCK_GUARD(holder->mtx);
69 auto&& compiler = holder->dev2compiler[comp_node.device_type()];
70 std::string backend = gopt::JITFusionPass::get_jit_backend_str();
71 mgb_assert(
72 !backend.empty(),
73 "code issue happened, need call config_jit_backends before get compiler");
74 //! please keep logic with JITFusionPass::Impl::config_jit_backends
75 mgb_log_debug("Compiler: JIT backend: %s", backend.c_str());
76 if (!compiler) {
77 switch (comp_node.device_type()) {
78#if MGB_CUDA
79 case CompNode::DeviceType::CUDA:
80#if MGB_JIT_HALIDE
81 if (!strcmp(backend.c_str(), "HALIDE")) {
82 compiler = std::make_unique<HalideCudaCompiler>();
83 break;
84 }
85#endif
86#if MGB_JIT_MLIR
87 if (!strcmp(backend.c_str(), "MLIR")) {
88 compiler =
89 std::make_unique<MLIRCompiler>(CompNode::DeviceType::CUDA);
90 break;
91 }
92#endif
93 if (!strcmp(backend.c_str(), "NVRTC")) {
94 compiler = std::make_unique<CudaCompiler>();
95 break;
96 }
97 mgb_throw(
98 InternalError,
99 "No compiler support for cuda, may caused by build not enable "
100 "MLIR/HALIDE module or error config jit backend env");
101 break;
102#endif
103 case CompNode::DeviceType::CPU:
104#if MGB_JIT_MLIR
105 if (!strcmp(backend.c_str(), "MLIR")) {
106 compiler =
107 std::make_unique<MLIRCompiler>(CompNode::DeviceType::CPU);
108 break;
109 }
110#endif
111 mgb_throw(

Callers 15

makeMethod · 0.45
TESTFunction · 0.45
loadMethod · 0.45
copy_opr_shallowMethod · 0.45
read_sharedMethod · 0.45
SharedMemProxyImplMethod · 0.45
load_shared_bufMethod · 0.45
as_opr_descMethod · 0.45
makeMethod · 0.45
dumpMethod · 0.45
ExternCOprRunnerMethod · 0.45
get_output_var_shapeMethod · 0.45

Calls 3

device_typeMethod · 0.45
emptyMethod · 0.45
to_stringMethod · 0.45

Tested by 14

makeMethod · 0.36
TESTFunction · 0.36
SetUpMethod · 0.36
TEST_FFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
compile_and_runFunction · 0.36
run_testFunction · 0.36
TESTFunction · 0.36
run_testFunction · 0.36
run_testFunction · 0.36
TESTFunction · 0.36