MCPcopy Create free account
hub / github.com/MegEngine/MegCC / CompileKernel

Method CompileKernel

compiler/lib/CodeGen/AutoKernelFunc.cpp:48–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48KernelGen::KernelObj codegen::AutoKernelFuncInternal::CompileKernel(
49 mlir::ModuleOp mod, std::string func_name) const {
50 KernelGen::KernelObj rst;
51 llvm::InitializeNativeTarget();
52 llvm::InitializeNativeTargetAsmPrinter();
53 std::vector<std::string> libs;
54 auto opt_pipeline = mlir::makeOptimizingTransformer(3, 1, 0);
55 auto&& mb_engine = mlir::ExecutionEngine::create(
56 mod, nullptr, opt_pipeline, llvm::None,
57 std::vector<llvm::StringRef>(libs.begin(), libs.end()), true, false);
58
59 CC_ASSERT(mb_engine && "Error can't create engine\n");
60 std::unique_ptr<mlir::ExecutionEngine> my_engine = std::move(*mb_engine);
61
62 auto lkup_rst = my_engine->lookup(func_name);
63 CC_ASSERT(lkup_rst && "lkup_rst ");
64 char temp_filename[100] = "/tmp/megcc_obj.XXXXXXX";
65 CC_ASSERT(mkstemp(temp_filename));
66 CC_ASSERT(unlink(temp_filename) == 0);
67
68 my_engine->dumpToObjectFile(temp_filename);
69 std::ifstream obj_input(temp_filename, std::ios::binary);
70
71 // copies all data into buffer
72 std::vector<uint8_t> buffer(std::istreambuf_iterator<char>(obj_input), {});
73 rst.kernel_symbol = func_name;
74 rst.kernel_bin = buffer;
75 return rst;
76}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected