-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Remove comparison of unsigned expression < 0 warning #6319
Conversation
Thanks @wrongtest . This might revealed another problem, as the default data structure for ndim should be int32_t as in https://github.com/dmlc/dlpack/blob/master/include/dlpack/dlpack.h#L136 So perhaps we want to change the API to use the new value. There is always a temptation to use unsigned integers to represent values that can are non-negative. And there can be an active debate. On one hand, having unsigned values are great because we don't need to worry about negative checks like this one. On the other hand, unsigned values also creates potential problems, when there are a lot of implicit conversion between unsigned and signed, and potential underflow during subtraction. So gradually my view has changed from use unsigned for non-neg values to use signed when possible. To make things consistent, perhaps we should change the arguments of these APIs to int or int32_t. |
i guess the root problem here is we aren't able to use a higher-level language construct to describe the memory layout since we are serializing/deserializing. because of that, we're casting and can't rely on |
src/runtime/crt/common/ndarray.c
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wrongtest I think it would make more sense here to change the type of ndim
to int to match the dlpack.h header:
https://github.com/dmlc/dlpack/blob/master/include/dlpack/dlpack.h#L136
then we'd need to keep the original check. would you be up for making this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not have noticed your comment later. I update related types of ndarray.c to int32_t. While original dlpack ndim is just defined as int
, line 71 use also int
instead of int32_t.
I run a local compile with -Wsign-compare -Wsign-conversion
to ensure no inconsistency introduced internally in this file.
30f27e5
to
a5a5086
Compare
Thanks @wrongtest @areusch ! |
* fix: remove warning for if (unsigned < 0...) * change used types related to dlpack ndim to int32_t
* fix: remove warning for if (unsigned < 0...) * change used types related to dlpack ndim to int32_t
* fix: remove warning for if (unsigned < 0...) * change used types related to dlpack ndim to int32_t
remove "comparison of unsigned expression < 0" warning