Skip to content

Allow arbitrary walk-back in reduction nodes to find inplace_binop. - #7349

Merged
sklam merged 5 commits into
numba:masterfrom
IntelLabs:issue7344
Sep 10, 2021
Merged

sklam merged 5 commits into
numba:masterfrom
IntelLabs:issue7344

Conversation

@DrTodd13

Copy link
Copy Markdown
Contributor

Resolves #7344

Previously, there could only be one extra assignment after the inplace_binop node for a reduction before the assignment to the reduction variable. In this issue, there was an additional assignment. The solution is to start at the enf with the reduction variable and walk backwards through the reduce nodes so long as they are all assignments and link with each other until we get to inplace_binop.

@gmarkall

Copy link
Copy Markdown
Member

Many thanks for the PR! I've tested with the reproducer from #7344, and this does appear to resolve the issue.

@DrTodd13

Copy link
Copy Markdown
Contributor Author

@stuartarchibald or @gmarkall On how many cores does CI currently run? The test for this issue will only be effective with 2+ cores. Just want to make sure we have at least that many.

@seibert

seibert commented Aug 27, 2021 •

Copy link
Copy Markdown
Contributor

The public CI runs on Azure Pipelines which, according to this, get 2 cores for Windows and Linux environments, and 3 cores for macOS. The internal CI system has at least 4 cores for all test environments.

@stuartarchibald stuartarchibald left a comment

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.

Thanks for the patch, the fix does make the original MWR work correctly but there seems to be a similar issue in a variant. Thanks for taking a look at it!

Comment thread numba/parfors/parfor.py Outdated
Comment on lines +3572 to +3578
cur_index = 1
acc_expr = nodes[-cur_index].value
while isinstance(acc_expr, ir.Var):
require(len(nodes) >= cur_index + 1)
require(nodes[-(cur_index + 1)].target.name == nodes[-cur_index].value.name)
cur_index += 1
acc_expr = nodes[-cur_index].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.

It seems like this might be relying on a naming pattern? The following variant on the original MWR breaks for variable t:

from numba import njit, prange
import numpy as np

@njit(parallel=True)
def test_impl(A, cond):
    s = 1
    t = 10
    for i in prange(A.shape[0]):
        if cond[i]:
            s += 1
            t += 1
        else:
            s += 2
    return s, t

print(test_impl(np.ones(10), (np.arange(10) % 2).astype('bool')))

@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review Effort - medium Medium size effort needed and removed 3 - Ready for Review labels Aug 30, 2021
@stuartarchibald stuartarchibald added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Aug 31, 2021

@stuartarchibald stuartarchibald left a comment

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.

Thanks for the patch and fixes.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Sep 10, 2021
@sklam
sklam merged commit 13b509e into numba:master Sep 10, 2021
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 - medium Medium size effort needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incoherent behaviour with prange

5 participants