From 95a7beee9acb1b591d6faac72a0c631aa1a43de6 Mon Sep 17 00:00:00 2001 From: wrongtest Date: Fri, 21 Aug 2020 17:01:05 +0800 Subject: [PATCH 1/2] fix: remove warning for if (unsigned < 0...) --- src/runtime/crt/common/ndarray.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/crt/common/ndarray.c b/src/runtime/crt/common/ndarray.c index f16db693b76f..681a17be6160 100644 --- a/src/runtime/crt/common/ndarray.c +++ b/src/runtime/crt/common/ndarray.c @@ -76,7 +76,7 @@ int TVMNDArray_Load(TVMNDArray* ret, const char** strm) { *strm += sizeof(ndim); dtype = ((DLDataType*)*strm)[0]; // NOLINT(*) *strm += sizeof(dtype); - if ((ndim < 0) || (ndim > TVM_CRT_MAX_NDIM)) { + if (ndim > TVM_CRT_MAX_NDIM) { fprintf(stderr, "Invalid ndim=%d: expected to be 0 ~ %d.\n", ndim, TVM_CRT_MAX_NDIM); status = -1; } From a5a5086c49b1a567e37ed4e79c829c921a45d79d Mon Sep 17 00:00:00 2001 From: wrongtest Date: Mon, 7 Sep 2020 13:11:59 +0800 Subject: [PATCH 2/2] change used types related to dlpack ndim to int32_t --- src/runtime/crt/common/ndarray.c | 16 ++++++++-------- .../tvm/runtime/crt/internal/common/ndarray.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/runtime/crt/common/ndarray.c b/src/runtime/crt/common/ndarray.c index 681a17be6160..4bae6de7da39 100644 --- a/src/runtime/crt/common/ndarray.c +++ b/src/runtime/crt/common/ndarray.c @@ -29,7 +29,7 @@ #include "crt_config.h" -TVMNDArray TVMNDArray_Create(uint32_t ndim, const tvm_index_t* shape, DLDataType dtype, +TVMNDArray TVMNDArray_Create(int32_t ndim, const tvm_index_t* shape, DLDataType dtype, DLContext ctx) { TVMNDArray ret; memset(&ret, 0, sizeof(TVMNDArray)); @@ -42,12 +42,12 @@ TVMNDArray TVMNDArray_Create(uint32_t ndim, const tvm_index_t* shape, DLDataType return ret; } -TVMNDArray TVMNDArray_Empty(uint32_t ndim, const tvm_index_t* shape, DLDataType dtype, +TVMNDArray TVMNDArray_Empty(int32_t ndim, const tvm_index_t* shape, DLDataType dtype, DLContext ctx) { TVMNDArray ret = TVMNDArray_Create(ndim, shape, dtype, ctx); int64_t num_elems = 1; int elem_bytes = (dtype.bits + 7) / 8; - uint32_t idx; + int32_t idx; for (idx = 0; idx < ret.dl_tensor.ndim; ++idx) { num_elems *= shape[idx]; } @@ -68,15 +68,15 @@ int TVMNDArray_Load(TVMNDArray* ret, const char** strm) { reserved = ((uint64_t*)*strm)[0]; // NOLINT(*) *strm += sizeof(reserved); DLContext ctx; - uint32_t ndim; + int ndim; // sizeof ndim should match dlpack DLDataType dtype; ctx = ((DLContext*)*strm)[0]; // NOLINT(*) *strm += sizeof(ctx); - ndim = ((uint32_t*)*strm)[0]; // NOLINT(*) + ndim = ((int*)*strm)[0]; // NOLINT(*) *strm += sizeof(ndim); dtype = ((DLDataType*)*strm)[0]; // NOLINT(*) *strm += sizeof(dtype); - if (ndim > TVM_CRT_MAX_NDIM) { + if ((ndim < 0) || (ndim > TVM_CRT_MAX_NDIM)) { fprintf(stderr, "Invalid ndim=%d: expected to be 0 ~ %d.\n", ndim, TVM_CRT_MAX_NDIM); status = -1; } @@ -85,7 +85,7 @@ int TVMNDArray_Load(TVMNDArray* ret, const char** strm) { status = -1; } int64_t shape[TVM_CRT_MAX_NDIM] = {0}; - uint32_t idx; + int32_t idx; if (ndim != 0) { for (idx = 0; idx < ndim; idx++) { shape[idx] = ((int64_t*)*strm)[0]; // NOLINT(*) @@ -114,7 +114,7 @@ int TVMNDArray_Load(TVMNDArray* ret, const char** strm) { return status; } -TVMNDArray TVMNDArray_CreateView(TVMNDArray* arr, const tvm_index_t* shape, uint32_t ndim, +TVMNDArray TVMNDArray_CreateView(TVMNDArray* arr, const tvm_index_t* shape, int32_t ndim, DLDataType dtype) { TVMNDArray ret = TVMNDArray_Create(ndim, shape, dtype, arr->dl_tensor.ctx); ret.dl_tensor.data = arr->dl_tensor.data; diff --git a/src/runtime/crt/include/tvm/runtime/crt/internal/common/ndarray.h b/src/runtime/crt/include/tvm/runtime/crt/internal/common/ndarray.h index 8da4b3c720c0..46f65bd7e433 100644 --- a/src/runtime/crt/include/tvm/runtime/crt/internal/common/ndarray.h +++ b/src/runtime/crt/include/tvm/runtime/crt/internal/common/ndarray.h @@ -41,15 +41,15 @@ typedef struct TVMNDArray { DLTensor dl_tensor; } TVMNDArray; -TVMNDArray TVMNDArray_Create(uint32_t ndim, const tvm_index_t* shape, DLDataType dtype, +TVMNDArray TVMNDArray_Create(int32_t ndim, const tvm_index_t* shape, DLDataType dtype, DLContext ctx); -TVMNDArray TVMNDArray_Empty(uint32_t ndim, const tvm_index_t* shape, DLDataType dtype, +TVMNDArray TVMNDArray_Empty(int32_t ndim, const tvm_index_t* shape, DLDataType dtype, DLContext ctx); int TVMNDArray_Load(TVMNDArray* ret, const char** strm); -TVMNDArray TVMNDArray_CreateView(TVMNDArray* arr, const tvm_index_t* shape, uint32_t ndim, +TVMNDArray TVMNDArray_CreateView(TVMNDArray* arr, const tvm_index_t* shape, int32_t ndim, DLDataType dtype); int TVMNDArray_Release(TVMNDArray* arr);