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

[CRT]fix to reduce RAM size during loading model #5507

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions src/runtime/crt/graph_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void TVMGraphRuntime_SetupStorage(TVMGraphRuntime * runtime) {
pool_entry_count = sid + 1;
}
pool_entry[sid].size = MAX(pool_entry[sid].size, bytes);
pool_entry[sid].bits = MAX(pool_entry[sid].bits, t.bits);
pool_entry[sid].device_type = device_type;
}

Expand All @@ -682,8 +683,23 @@ void TVMGraphRuntime_SetupStorage(TVMGraphRuntime * runtime) {
TVMGraphRuntimePoolEntry pit = pool_entry[idx];
int64_t shape[TVM_CRT_MAX_NDIM] = {0, };
TVMContext ctx = runtime->ctxs[0];
DLDataType dtype = {kDLFloat, 32, 1};
shape[0] = (pit.size + 3) / 4;
DLDataType dtype;
if (pit.bits == 8) {
dtype.code = kDLInt;
dtype.bits = 8;
dtype.lanes = 1;
shape[0] = pit.size;
} else if (pit.bits == 16) {
dtype.code = kDLInt;
dtype.bits = 16;
dtype.lanes = 1;
shape[0] = (pit.size + 1) / 2;
} else {
dtype.code = kDLFloat;
dtype.bits = 32;
dtype.lanes = 1;
shape[0] = (pit.size + 3) / 4;
}
runtime->storage_pool[runtime->storage_pool_count] = TVMNDArray_Empty(1, shape, dtype, ctx);
CHECK_NE(runtime->storage_pool[runtime->storage_pool_count].dl_tensor.data, 0,
"fail to create storage_pool with idx=%d\n", idx);
Expand Down
1 change: 1 addition & 0 deletions src/runtime/crt/graph_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct TVMOpParam {
typedef struct TVMGraphRuntimePoolEntry {
size_t size;
int device_type;
int bits;
} TVMGraphRuntimePoolEntry;

// Node entry
Expand Down