Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Serialization/Deserialization of runtime module #15244

Merged
merged 20 commits into from
Aug 28, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replace u_char to uint8_t
  • Loading branch information
sunggg committed Aug 10, 2023
commit fcdb6fcd18b6c3e1b2694ab25851a1e8c40e14ca
8 changes: 4 additions & 4 deletions src/support/base64.h
Original file line number Diff line number Diff line change
@@ -305,21 +305,21 @@ inline size_t b64strlen(const std::string b64str) {
return length;
}

inline void b64decode(const std::string b64str, u_char* ret) {
inline void b64decode(const std::string b64str, uint8_t* ret) {
size_t index = 0;
const auto length = b64str.size();
for (size_t i = 0; i < length; i += 4) {
int8_t ch0 = base64::DecodeTable[(int32_t)b64str[i]];
int8_t ch1 = base64::DecodeTable[(int32_t)b64str[i + 1]];
int8_t ch2 = base64::DecodeTable[(int32_t)b64str[i + 2]];
int8_t ch3 = base64::DecodeTable[(int32_t)b64str[i + 3]];
u_char st1 = (ch0 << 2) + (ch1 >> 4);
uint8_t st1 = (ch0 << 2) + (ch1 >> 4);
ret[index++] = st1;
if (b64str[i + 2] != '=') {
u_char st2 = ((ch1 & 0b1111) << 4) + (ch2 >> 2);
uint8_t st2 = ((ch1 & 0b1111) << 4) + (ch2 >> 2);
ret[index++] = st2;
if (b64str[i + 3] != '=') {
u_char st3 = ((ch2 & 0b11) << 6) + ch3;
uint8_t st3 = ((ch2 & 0b11) << 6) + ch3;
ret[index++] = st3;
}
}
4 changes: 2 additions & 2 deletions src/target/codegen.cc
Original file line number Diff line number Diff line change
@@ -391,7 +391,7 @@ std::string ExportModuleToBase64(tvm::runtime::Module module) {
tvm::runtime::Module ImportModuleFromBase64(std::string base64str) {
auto length = tvm::support::b64strlen(base64str);

std::vector<u_char> bytes(length); // bytes stream
std::vector<uint8_t> bytes(length); // bytes stream
tvm::support::b64decode(base64str, bytes.data());

auto now = std::chrono::system_clock::now();
@@ -401,7 +401,7 @@ tvm::runtime::Module ImportModuleFromBase64(std::string base64str) {
const std::string file_name = "tmp-module-" + datetime.str() + ".so";
LOG(INFO) << file_name;
std::unique_ptr<FILE, Deleter> pFile(fopen(file_name.c_str(), "wb"), Deleter(file_name));
fwrite(bytes.data(), sizeof(u_char), length, pFile.get());
fwrite(bytes.data(), sizeof(uint8_t), length, pFile.get());
fflush(pFile.get());

std::string load_f_name = "runtime.module.loadfile_so";