FrozenGene commented on a change in pull request #4657: [CodeGen] Generate blob use LLVM directly URL: https://github.com/apache/incubator-tvm/pull/4657#discussion_r364573509
########## File path: src/codegen/codegen.cc ########## @@ -211,5 +220,30 @@ std::string PackImportsToC(const runtime::Module& mod, bool system_lib) { << "#endif\n"; return os.str(); } + +runtime::Module PackImportsToLLVM(const runtime::Module& mod, + bool system_lib, + const std::string& target) { + std::string bin = SerializeModule(mod); + + std::ostringstream os; + uint64_t nbytes = bin.length(); + os << std::hex; + for (size_t i = 0; i < sizeof(nbytes); ++i) { + os << std::setfill('0') << std::setw(2) << ((nbytes >> (i * 8)) & 0xffUL); + } + for (size_t i = 0; i < bin.length(); ++i) { + int c = bin[i]; + os << std::setfill('0') << std::setw(2) << (c & 0xff); + } + + // Call codegen_blob to generate LLVM module + std::string codegen_f_name = "codegen.codegen_blob"; + // the codegen function. + const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name); + CHECK(codegen_f != nullptr) << "codegen.codegen_blob is not presented."; + return (*codegen_f)(os.str(), system_lib, target); Review comment: Sorry for missing your comment before. I find one strange thing of this. When I do this: ``` std::string bin = SerializeModule(mod); std::string header; for (size_t i = 0; i < sizeof(nbytes); ++i) { header.push_back(((nbytes >> (i * 8)) & 0xffUL)); } std::string blob = header + bin; std::cout << "blob " << blob; // Could print content // Call codegen_blob to generate LLVM module std::string codegen_f_name = "codegen.codegen_blob"; // the codegen function. const PackedFunc* codegen_f = runtime::Registry::Get(codegen_f_name); CHECK(codegen_f != nullptr) << "codegen.codegen_blob is not presented."; runtime::Module m = (*codegen_f)(blob, system_lib, target); return m; ``` Inside the codegen.codegen_blob function, after accepting the blob string data. Can not print blob. Do I miss something? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services