Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Change-Id: If12cd240685d7791fc60bc0cfb66389cdc186b73
  • Loading branch information
liangfu committed Mar 23, 2020
1 parent 28d9cc7 commit 33a053f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions apps/bundle_deploy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
# Setup build environment
TVM_ROOT=$(shell cd ../..; pwd)
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
PKG_CXXFLAGS = -std=c++14 -O2 -fPIC \
PKG_CXXFLAGS = -Wall -std=c++14 -O2 -fPIC \
-I${TVM_ROOT}/include \
-I${DMLC_CORE}/include \
-I${TVM_ROOT}/3rdparty/dlpack/include
PKG_CFLAGS = -std=c99 -O2 -fPIC \
PKG_CFLAGS = -Wall -std=c99 -O2 -fPIC \
-I${TVM_ROOT}/include \
-I${DMLC_CORE}/include \
-I${TVM_ROOT}/3rdparty/dlpack/include
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/crt/crt_runtime_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int TVMModGetFunction(TVMModuleHandle mod,
if (!strcmp(func_name, "load_params")) {
*out = &TVMGraphRuntime_LoadParams;
} else {
status -1;
status = -1;
}
return status;
}
Expand Down
28 changes: 14 additions & 14 deletions src/runtime/crt/graph_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,24 @@ int TVMGraphRuntimeGraphAttr_Load(TVMGraphRuntimeGraphAttr * attr, JSONReader *r
if (!(reader->NextArrayItem(reader))) { fprintf(stderr, "Invalid json format\n"); }
reader->BeginArray(reader);
while (reader->NextArrayItem(reader)) {
attr->shape = vrealloc(attr->shape, sizeof(attr->shape[0])*(shape_count+1)*TVM_CRT_MAX_NDIM);
attr->shape =
vrealloc(attr->shape, sizeof(attr->shape[0])*(shape_count+1)*TVM_CRT_MAX_NDIM);
attr->ndim = vrealloc(attr->ndim, sizeof(attr->ndim[0])*(shape_count+1));
reader->BeginArray(reader);
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+0]));
int64_t * attr_shape_ptr = attr->shape + shape_count*TVM_CRT_MAX_NDIM;
reader->ReadInteger(reader, attr_shape_ptr + 0);
uint32_t ndim = 1;
if (reader->NextArrayItem(reader)) {
if (reader->NextArrayItem(reader)) {
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+1])); ndim++;
reader->ReadInteger(reader, attr_shape_ptr + 1); ndim++;
if (reader->NextArrayItem(reader)) {
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+2])); ndim++;
reader->ReadInteger(reader, attr_shape_ptr + 2); ndim++;
if (reader->NextArrayItem(reader)) {
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+3])); ndim++;
reader->ReadInteger(reader, attr_shape_ptr + 3); ndim++;
if (reader->NextArrayItem(reader)) {
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+4])); ndim++;
reader->ReadInteger(reader, attr_shape_ptr + 4); ndim++;
if (reader->NextArrayItem(reader)) {
reader->ReadInteger(reader, &(attr->shape[shape_count*TVM_CRT_MAX_NDIM+5])); ndim++;
reader->ReadInteger(reader, attr_shape_ptr + 5); ndim++;
reader->NextArrayItem(reader);
}
}
Expand Down Expand Up @@ -475,10 +477,8 @@ int TVMGraphRuntime_LoadParams(TVMGraphRuntime * runtime, const char * param_blo

for (idx = 0; idx < size; idx++) {
int32_t in_idx = runtime->GetInputIndex(runtime, names + TVM_CRT_STRLEN_NAME * idx);
if (!(in_idx >= 0)) {
fprintf(stderr, "Found param for non-existent input: %s\n", names + TVM_CRT_STRLEN_NAME * idx);
status = -1;
}
CHECK_GT(in_idx, 0,
"Found param for non-existent input: %s\n", names + TVM_CRT_STRLEN_NAME * idx);
uint32_t eid = runtime->GetEntryId(runtime, runtime->input_nodes[in_idx], 0);
if (!(eid < runtime->data_entry_count)) {
fprintf(stderr, "`entry_id`=%d is greater than expected(%d).\n",
Expand Down Expand Up @@ -543,7 +543,7 @@ int TVMGraphRuntime_GetOutput(TVMGraphRuntime * runtime, const int32_t idx, DLTe
}

void TVMGraphRuntime_SetupStorage(TVMGraphRuntime * runtime) {
uint32_t idx, dim;
uint32_t idx;

// Grab saved optimization plan from graph.
TVMGraphRuntimeGraphAttr * attrs = &(runtime->attrs);
Expand Down Expand Up @@ -602,7 +602,7 @@ void TVMGraphRuntime_SetupStorage(TVMGraphRuntime * runtime) {
TVMNDArray_CreateView(&(runtime->storage_pool[storage_id]),
attrs->shape+idx*TVM_CRT_MAX_NDIM, attrs->ndim[idx], vtype[idx]);
CHECK_NE(runtime->data_entry[idx].dl_tensor.data, 0,
"fail to create for node with idx=%d, storage_id=%d\n", idx, storage_id);
"fail to create for node with idx=%d, storage_id=%lu\n", idx, storage_id);
}

// Release memory
Expand Down Expand Up @@ -766,6 +766,6 @@ void TVMGraphRuntimeRelease(TVMGraphRuntime ** pptr) {
vfree(g_fexecs);
g_fexecs = 0;
}

CHECK_EQ(vleak_size, 0, "found memory leak, leak size=%d", vleak_size);
}
10 changes: 5 additions & 5 deletions src/runtime/crt/load_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ int JSONReader_ReadString(JSONReader * reader, char * out_str) {
if (ch == '\\') {
char sch = reader->NextChar(reader);
switch (sch) {
case 'r': snprintf(output, sizeof(output), "%s\r", output); break;
case 'n': snprintf(output, sizeof(output), "%s\n", output); break;
case '\\': snprintf(output, sizeof(output), "%s\\", output); break;
case 't': snprintf(output, sizeof(output), "%s\t", output); break;
case '\"': snprintf(output, sizeof(output), "%s\"", output); break;
case 'r': snprintf(output + strlen(output), sizeof(output), "\r"); break;
case 'n': snprintf(output + strlen(output), sizeof(output), "\n"); break;
case '\\': snprintf(output + strlen(output), sizeof(output), "\\"); break;
case 't': snprintf(output + strlen(output), sizeof(output), "\t"); break;
case '\"': snprintf(output + strlen(output), sizeof(output), "\""); break;
default: fprintf(stderr, "unknown string escape %c\n", sch);
}
} else {
Expand Down
29 changes: 15 additions & 14 deletions src/runtime/crt/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void TLB_Set(TLB * tlb, char * data, Page * page) {
if (entry == 0) {
tlb->entries[tlb->count].addr = data;
tlb->entries[tlb->count].page = *page;
tlb->count ++;
tlb->count++;
} else {
entry->addr = data;
entry->page = *page;
Expand Down Expand Up @@ -130,7 +130,7 @@ typedef struct MultiMap {
uint32_t count;
IndexedEntry * (*lower_bound)(struct MultiMap * map, uint32_t npage);
IndexedEntry * (*end)(struct MultiMap * map);
IndexedEntry * (*erase)(struct MultiMap * map, IndexedEntry * entry);
void (*erase)(struct MultiMap * map, IndexedEntry * entry);
void (*insert)(struct MultiMap * map, uint32_t npage, Page * p);
} MultiMap;

Expand All @@ -150,10 +150,11 @@ IndexedEntry * MultiMap_End(struct MultiMap * map) {
return entry;
}

IndexedEntry * MultiMap_Erase(struct MultiMap * map, IndexedEntry * entry) {
void MultiMap_Erase(struct MultiMap * map, IndexedEntry * entry) {
for (uint32_t idx = 0; idx < map->count; idx++) {
if ((map->entries + idx) == entry) {
memcpy(map->entries + idx, map->entries + (idx + 1), sizeof(IndexedEntry) * (map->count - idx));
memcpy(map->entries + idx, map->entries + (idx + 1),
sizeof(IndexedEntry) * (map->count - idx));
map->count--;
break;
}
Expand Down Expand Up @@ -193,7 +194,7 @@ typedef struct MemoryManager {
* \return The virtual address
*/
void (*Free)(struct MemoryManager * mgr, void* data);

// Physical address -> page
PageTable ptable;
// Virtual address -> page
Expand All @@ -216,19 +217,19 @@ void* MemoryManager_Alloc(MemoryManager * mgr, tvm_index_t size) {
if (it != free_map->end(free_map)) {
Page p = it->page;
free_map->erase(free_map, it);
data = (void*)p.data;
data = p.data;
start = p.ptable_begin;
npage = p.num_pages;
} else {
PageTable * ptable = &(mgr->ptable);
start = ptable->count;
CHECK_LE((start + npage), (sizeof(g_memory_pool) / kPageSize),
"insufficient memory, start=%d, npage=%d, total=%d",
"insufficient memory, start=%ld, npage=%ld, total=%ld",
start, npage, start + npage);
/* insert page entry */
Page p = PageCreate(start, npage);
ptable->resize(ptable, start + npage, &p);
data = (void*)p.data;
data = p.data;
TLB * pmap = &(mgr->pmap);
pmap->set(pmap, data, &p);
}
Expand Down Expand Up @@ -267,18 +268,18 @@ void* MemoryManager_Realloc(MemoryManager * mgr, void * ptr, tvm_index_t size) {
// insert new page entry
IndexedEntry * it = free_map->lower_bound(free_map, npage);
if (it != free_map->end(free_map)) {
data = (void*)it->page.data;
data = it->page.data;
start = it->page.ptable_begin;
npage = it->page.num_pages;
free_map->erase(free_map, it);
} else {
start = ptable->count;
CHECK_LE((start + npage), (sizeof(g_memory_pool) / kPageSize),
"insufficient memory, start=%d, npage=%d, total=%d",
"insufficient memory, start=%ld, npage=%ld, total=%ld",
start, npage, start + npage);
Page p = PageCreate(start, npage);
ptable->resize(ptable, start + npage, &p);
data = (void*)p.data;
data = p.data;
pmap->set(pmap, data, &p);
}
// copy previous data to the new entry
Expand All @@ -293,19 +294,19 @@ void* MemoryManager_Realloc(MemoryManager * mgr, void * ptr, tvm_index_t size) {
if (it != free_map->end(free_map)) {
Page p = it->page;
free_map->erase(free_map, it);
data = (void*)p.data;
data = p.data;
start = p.ptable_begin;
npage = p.num_pages;
} else {
PageTable * ptable = &(mgr->ptable);
start = ptable->count;
CHECK_LE((start + npage), (sizeof(g_memory_pool) / kPageSize),
"insufficient memory, start=%d, npage=%d, total=%d",
"insufficient memory, start=%ld, npage=%ld, total=%ld",
start, npage, start + npage);
/* insert page entry */
Page p = PageCreate(start, npage);
ptable->resize(ptable, start + npage, &p);
data = (void*)p.data;
data = p.data;
TLB * pmap = &(mgr->pmap);
pmap->set(pmap, data, &p);
}
Expand Down

0 comments on commit 33a053f

Please sign in to comment.