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, we can accept the blob string 
data. Print the blob is empty. But if we use previous os << std::hex to get hex 
data, we could accept the data successfully. 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

Reply via email to