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 ir_utils._max_label being updated incorrectly #7156

Merged
merged 7 commits into from Jun 29, 2021

Conversation

sklam
Copy link
Member

@sklam sklam commented Jun 25, 2021

Fixes #7155.

This patch changes ir_utils._max_label into an instance of _MaxLabel so it is easier to enforce the correct update logic. It also means that we no longer need to use global _max_label to update it.

Additional notes

As demonstrate by this patch, #7155 is not caused by the retargeting support or any of the recent work to make target-specific overload. It is just unfortunate that the bug is revealed in a case that make use of the retargeting support. I'm also unsure if we really should keep the included testcase, which is not representative of the problem but just a coincident that it revealed the problem. It is likely overly difficult to create a minimal reproducer for the problem.

It is now changed to an object to avoid mutating global variable.
The `_MaxLabel` class also enforce that its value must be mutated via the update method.
@sklam sklam added this to the Numba 0.54 RC milestone Jun 25, 2021
@sklam sklam marked this pull request as ready for review June 25, 2021 23:19
@sklam
Copy link
Member Author

sklam commented Jun 26, 2021

The tests are taking overly long because of high memory consumption. The problem is not unique to this PR branch. On mainline, running python runtests.py numba/tests/test_parfors.py quickly uses up >1GB on my machine.

@stuartarchibald
Copy link
Contributor

The tests are taking overly long because of high memory consumption. The problem is not unique to this PR branch. On mainline, running python runtests.py numba/tests/test_parfors.py quickly uses up >1GB on my machine.

Like this: #7028 (comment) ?

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. Few minor queries else looks good. I plan on testing this manually next.

self._value = max(newval, self._value)


_the_max_label = _MaxLabel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Now delete the class? There should only be one of these so make it awkward to obtain another?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

ir_utils._max_label = max_label
ir_utils._the_max_label.update(max_label)
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this the bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

One of the bugs. I stopped looking further for where exactly the problems are and just batch fixes all the _max_label

Comment on lines -1666 to +1675
f_ir.blocks = add_offset_to_labels(f_ir.blocks, _max_label + 1)
f_ir.blocks = add_offset_to_labels(f_ir.blocks, _the_max_label.next())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is different? It's advancing the counter whereas originally the offset was set as _max_label+1 but the counter was not updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

The counter not updated part had me worried. That's why i changed it to advance. Worse case is that there's a hole the label space, but I want to be certain that there is no reuse of label.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, it seems like it ought to update else there is potential for reuse, and like you said, worse case is that the label space has gaps which is relatively harmless.

numba/tests/parfors_max_label_error.py Outdated Show resolved Hide resolved
Comment on lines +33 to +34
target_registry["CustomCPU"] = CustomCPU
dispatcher_registry[target_registry["CustomCPU"]] = CustomCPUDispatcher
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok because this test is run in a subprocess. Were it run in the test suite there might be a name collision for the string "CustomCPU" had another test registered that as a target.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. The test is also highly dependent of the internal state of ir_utils that it must be executing in a fresh process to replicate.

@stuartarchibald stuartarchibald added 4 - Waiting on reviewer Waiting for reviewer to respond to author Effort - short Short size effort needed 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jun 28, 2021
@stuartarchibald
Copy link
Contributor

@sklam #7160 should sort out the issue with memory pressure from the parfors tests.

sklam and others added 2 commits June 29, 2021 09:55
Co-authored-by: stuartarchibald <stuartarchibald@users.noreply.github.com>
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the patch and fixes.

@stuartarchibald stuartarchibald added 4 - Waiting on CI Review etc done, waiting for CI to finish and removed 4 - Waiting on author Waiting for author to respond to review labels Jun 29, 2021
@sklam
Copy link
Member Author

sklam commented Jun 29, 2021

cancelling CI build until we have #7160 merged

@sklam sklam added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on CI Review etc done, waiting for CI to finish labels Jun 29, 2021
@sklam
Copy link
Member Author

sklam commented Jun 29, 2021

CI passed. Merging

@sklam sklam merged commit 25ccc9f into numba:master Jun 29, 2021
@sklam sklam deleted the fix/parfor_maxlabel_bug branch June 30, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge Effort - short Short size effort needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parfors max_label issue causing undefined behavior
2 participants