Skip to content

Fix signed-unsigned warnings#34791

Closed
malfet wants to merge 1 commit intopytorch:masterfrom
malfet:malfet/fix-signed-unsigned-warnings
Closed

Fix signed-unsigned warnings#34791
malfet wants to merge 1 commit intopytorch:masterfrom
malfet:malfet/fix-signed-unsigned-warnings

Conversation

@malfet
Copy link
Copy Markdown
Contributor

@malfet malfet commented Mar 15, 2020

And few typos
Test Plan: CI

@malfet malfet requested review from ezyang and xiaomengy March 15, 2020 23:20
@malfet malfet requested a review from apaszke as a code owner March 15, 2020 23:20
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 15, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Mar 16, 2020

💊 CircleCI build failures summary and remediations

As of commit 8c0d9b0 (more details on the Dr. CI page):


None of the build failures appear to be your fault 💚


  • 2/2 broken upstream at merge base 76d9e76 on Mar 17 from 8:00am to 6:10pm (9 commits; d9b97a4 - 3e68d0c)

    Please rebase on the viable/strict branch (expand for instructions)

    Since your merge base is older than viable/strict, run these commands:

    git fetch https://github.com/pytorch/pytorch viable/strict
    git rebase FETCH_HEAD
    

    Check out the recency history of this "viable master" tracking branch.


🚧 1 upstream failure:

These were probably caused by upstream breakages:


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

This comment has been revised 6 times.

@ezyang ezyang requested a review from zdevito March 16, 2020 20:07
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Mar 16, 2020

@zdevito can you take a look at this? I fear that manually fixing these warnings is a losing battle unless we come up with some broader strategy about what to do in these cases. In the past, we've forced people to use int64_t as much as possible, which has helped, but whenever we call standard library functions like size() you end up with unsigned creeping in.

(The patch looks generally reasonable, and we don't have to block the PR itself on fixing htese things.)

@malfet
Copy link
Copy Markdown
Contributor Author

malfet commented Mar 17, 2020

@ezyang would it be easier if I split this PR into few smaller ones?

Copy link
Copy Markdown
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think everything looks fine here except that we should be replacing int with uint32_t and not size_t. The point is to stop the warnings, I don't want to also change indexing math to 64-bits in a way that might slow something down.

Comment thread caffe2/operators/boolean_mask_ops.cc Outdated
Comment thread caffe2/operators/byte_weight_dequant_op.h Outdated
Comment thread caffe2/operators/elementwise_ops.cc Outdated
Comment thread caffe2/operators/index_ops.h Outdated
@zdevito
Copy link
Copy Markdown
Contributor

zdevito commented Mar 17, 2020

re warnings (not specific to this PR): the best bet is to actually get warnings clean by turning off the warnings our code is not clean against, and then gradually expand the set. Currently we just introduce warnings because they are impossible to see.

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Mar 17, 2020

@zdevito IIUC, the 32-bit/64-bit difference isn't a big deal in CPU code; it's just in CUDA where it really slays you?

And few typos
Test Plan: CI
@malfet malfet force-pushed the malfet/fix-signed-unsigned-warnings branch from f560bd3 to 8c0d9b0 Compare March 17, 2020 19:33
@malfet
Copy link
Copy Markdown
Contributor Author

malfet commented Mar 17, 2020

Updated the diff to use auto foo = 0U instead of int foo = 0 or size_t foo = 0U. This way compiler is free to choose whatever type it thinks fits best for the architecture, which is currently unsigned int for all architectures we support.

@malfet
Copy link
Copy Markdown
Contributor Author

malfet commented Mar 17, 2020

@ezyang, I don't think x86_64 is capable of non-vectorized 32-bit arithmetic.
IMO performance would only be affected on 32-bit architectures (ARMv7 or x86), GPUs or if value ever needs to be stored to memory.

// Verify inputs == outputs
CAFFE_ENFORCE_EQ(init_.inputs.size(), init_.outputs.size());
for (auto i = 0; i < init_.inputs.size(); i++) {
for (auto i = 0U; i < init_.inputs.size(); i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer for (size_t i = 0; ...), but this is fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think size_t is better, I'll change it after my stack of diffs land

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I'll change this in my code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please loop @zdevito on that one, because I had size_t there initially and he suggested to use unsigned int out of performance considerations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But personally I agree, that if upper limit it 64-bit unsigned value, then loop iterator should also be 64-bit unsigned value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually all of params.inputs, devices_ or elements are std::vectors. While in std::vector the return type of std::vector::size() is std::vector::size_type, which in most cases is size_t. If there is platform concerns, I think we'd better use std::vector::size_type i = 0; And I don't think there should be performance issues for such a for-loop iterative variable especially the vectors should be considerable small.
And for the case in the computation code, do we have any benchmark for the differences between the type in for-loops?

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malfet is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet merged this pull request in 6f737dd.

@malfet malfet deleted the malfet/fix-signed-unsigned-warnings branch March 19, 2020 17:40
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
And few typos
Pull Request resolved: pytorch#34791

Test Plan: CI

Differential Revision: D20524879

Pulled By: malfet

fbshipit-source-id: 58fa03bd6356979e77cd1bffb6370d41a177c409
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants