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

[Fix] Fix arf op's write conflict when num_orientations is not 1 #2822

Merged
merged 3 commits into from
Jun 9, 2023

Conversation

dflhw
Copy link
Contributor

@dflhw dflhw commented Jun 6, 2023

Motivation

  1. When num_orientations is not 1, the calculation result of active_rotated_filter op on cpu is inconsistent with that on cuda.
  2. Issue link: 2718,the modified code can pass the sample test.
  3. This change does not affect scenarios where num_orientations is 1.

Modification

Indexes are added to prevent data from being written to only the first feature map.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Checklist

Before PR:

  • I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects, like MMDet or MMCls.
  • CLA has been signed and all committers have signed the CLA in this PR.

@zhouzaida zhouzaida requested a review from grimoire June 7, 2023 03:14
@grimoire
Copy link
Member

grimoire commented Jun 7, 2023

Hi, Thanks for the PR.
Actually, I am a little bit confused with this OP.
Let's say, if two threads have the same i, j, k, idx (and fmIndex) and different l. They will store different val to the same target. That does seems not make sense.
I will try to contact the origin repo owner to see if it is a bug.

@dflhw
Copy link
Contributor Author

dflhw commented Jun 7, 2023

Hi, Thanks for the PR. Actually, I am a little bit confused with this OP. Let's say, if two threads have the same i, j, k, idx (and fmIndex) and different l. They will store different val to the same target. That does seems not make sense. I will try to contact the origin repo owner to see if it is a bug.

Hi, Thanks for your reply.
To ensure that every input value is taken, the values of indices here are combinations of permutation of 1 to kH * kW.
Keep i, j, k have the same value. When num_orientations is 1, the value range of l is 1 to kH * kW. In this case, the value of idx ranges from 1 to kH * kW, there is no write conflit.
But when num_orientations is 2(or other num), the value range of l is 1 to 2 * kH * kW, the value range of idx is still 1 to kH * kW. So the value range of l is kH * kW to 2 * kH * kW will write to the same address as 1 to kH * kW. In this case, it is need to add kH * kW to idx.
If num_orientations is 3, it is need to add kH * kW to idx when the value range of l is kH * kW to 2 * kH * kW and add 2 * kH * kW to idx when the value range of l is 2 * kH * kW to 3 * kH * kW.

@grimoire
Copy link
Member

grimoire commented Jun 7, 2023

Can I assume elements of indices[oir_id, :, :, rot_id] are shuffle of arange(kH * kW), and each element is unique? I have no rotation detection background.

PS: bank conflict is a term that is widely used to describe shared memory visit problems in CUDA. I think retitling this PR would be cool to avoid Ambiguity.

@dflhw
Copy link
Contributor Author

dflhw commented Jun 8, 2023

Can I assume elements of indices[oir_id, :, :, rot_id] are shuffle of arange(kH * kW), and each element is unique? I have no rotation detection background.

PS: bank conflict is a term that is widely used to describe shared memory visit problems in CUDA. I think retitling this PR would be cool to avoid Ambiguity.

Yeah, I think it is.
It seems that in this operator, in order to rotate a certain angle, there is a certain order of the indices[oir_id, :, :, rot_id].
Thanks for correcting the title, I will edit it.

@dflhw dflhw changed the title [Fix] fix arf op's bank conflict when num_orientations is not 1 [Fix] Fix arf op's write conflict when num_orientations is not 1 Jun 8, 2023
Copy link
Member

@grimoire grimoire left a comment

Choose a reason for hiding this comment

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

LGTM

@zhouzaida zhouzaida linked an issue Jun 9, 2023 that may be closed by this pull request
2 tasks
@zhouzaida zhouzaida merged commit e439825 into open-mmlab:1.x Jun 9, 2023
dflhw added a commit to dflhw/mmcv that referenced this pull request Jun 9, 2023
@dflhw
Copy link
Contributor Author

dflhw commented Jun 9, 2023

LGTM

Sorry, I misunderstood the use of indices,it seems that indices[:, :, :, rot_id] is permutation of arange(num_orientations * kH * kW), so the usage of indices in issue 2718 is wrong, it is not a bug, this pr should be reverted.

refer to: mmrotate orconv.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] active_rotated_filter op get a wrong value on cuda
3 participants