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

Hoisting logic needs to consider dependency on prior unhoistable variable #9586

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

sklam
Copy link
Member

@sklam sklam commented May 24, 2024

Fix #9581, #9490.

Comment on lines 891 to 894
unhoistable = {assgn.target.name for assgn, _reason in not_hoisted}
use_unhoist = uses & unhoistable
diff = uses.difference(dep_on_param)
diff |= use_unhoist
Copy link
Member Author

Choose a reason for hiding this comment

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

@DrTodd13, I need your expertise here. I only did the smallest change I can think of.

The origin is that a static_getitem(array, index) is referring to an array that is previously placed into not_hoisted. The source code looks like:

for .. in loop:
    array = solve(arg)
    res = array[1]     # the static getitem
    if compute(res):
          break
use(array)

Pre-patch logic will cause that static_getitem to be hoisted out of the loop. I changed it to look into the list of not_hoisted and ban hoisting on uses that refer to it.

@sklam sklam marked this pull request as ready for review May 24, 2024 13:28
@sklam sklam requested a review from DrTodd13 as a code owner May 24, 2024 13:28
Copy link
Contributor

@DrTodd13 DrTodd13 left a comment

Choose a reason for hiding this comment

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

Looks good in general. Just my one suggestion.

numba/parfors/parfor_lowering.py Outdated Show resolved Hide resolved
@sklam
Copy link
Member Author

sklam commented May 24, 2024

@DrTodd13, i just realize you have a PR that sounds similar. Will #9397 fix this as well?

@DrTodd13
Copy link
Contributor

DrTodd13 commented May 24, 2024

@DrTodd13, i just realize you have a PR that sounds similar. Will #9397 fix this as well?

@sklam
My instinct is to say that if the dependency is two lines right after each other then that other PR wouldn't help but it is worth trying it. I'd also suggest maybe rebasing this PR against mine and doing them together rather than separately.

@sklam
Copy link
Member Author

sklam commented May 28, 2024

I confirmed that #9397 do not fix the issues #9581, #9490.

@sklam sklam modified the milestones: 0.60.0-rc1, 0.60.0 May 28, 2024
@sklam sklam added 4 - Waiting on second reviewer Patch needs a second reviewer. and removed 3 - Ready for Review labels Jun 3, 2024
@@ -47,8 +47,9 @@ def stable_fit(X, y, threshold=3):
rmse = np.sqrt(np.mean(resid_sub ** 2))
first = np.fabs(resid_sub[0]) / rmse < threshold
last = np.fabs(resid_sub[-1]) / rmse < threshold
slope = np.fabs(beta_sub[1]) / rmse < threshold
Copy link
Member

Choose a reason for hiding this comment

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

I think it's probably worth commenting here that the changes added here also test #9581? Whilst I don't know much about parfors, I'd guess it's not going to be obvious without going through git blame which parts of the modified test case are relevant to #9490 only and which are relevant to #9581.

Copy link
Member

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

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

Without the fix in parfor_lowering, the modified test case fails with:

test_issue9490_non_det_ssa_problem (numba.tests.test_parfors.TestParfors.test_issue9490_non_det_ssa_problem) ... FAIL

======================================================================
FAIL: test_issue9490_non_det_ssa_problem (numba.tests.test_parfors.TestParfors.test_issue9490_non_det_ssa_problem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/tests/test_parfors.py", line 2397, in test_issue9490_non_det_ssa_problem
    subp.check_output(cmd, env=envs,
  File "/home/gmarkall/miniforge3/envs/numbadev/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gmarkall/miniforge3/envs/numbadev/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/home/gmarkall/miniforge3/envs/numbadev/bin/python', '-m', 'numba.tests.parfor_iss9490_usecase']' died with <Signals.SIGSEGV: 11>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/tests/test_parfors.py", line 2402, in test_issue9490_non_det_ssa_problem
    self.fail(msg=msg)
AssertionError: subprocess failed with output:
Fatal Python error: Segmentation fault

Current thread 0x00007178c7191740 (most recent call first):
  File "/home/gmarkall/numbadev/numba/numba/tests/parfor_iss9490_usecase.py", line 69 in check
  File "/home/gmarkall/numbadev/numba/numba/tests/parfor_iss9490_usecase.py", line 78 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

and the reproducer from #9581 also segfaults.

With the change in this PR, the test case passes and the reproducer from #9581 executes to completion.

I don't have enough knowledge of parfors to have an opinion on the fix, but from a "works for me" perspective, this PR appears to do the job.

@esc esc added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on second reviewer Patch needs a second reviewer. labels Jun 10, 2024
@esc esc merged commit cd2ef39 into numba:main Jun 10, 2024
21 checks passed
@sklam sklam deleted the fix/bug9581 branch June 10, 2024 13:48
esc added a commit to esc/numba that referenced this pull request Jun 11, 2024
 Hoisting logic needs to consider dependency on prior unhoistable variable
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-det bug with prange code 2
4 participants