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

Support Reduction of Arrays #47

Open
ehsantn opened this issue Nov 22, 2017 · 3 comments
Open

Support Reduction of Arrays #47

ehsantn opened this issue Nov 22, 2017 · 3 comments

Comments

@ehsantn
Copy link

ehsantn commented Nov 22, 2017

We need to support reduction of arrays in the gufunc backend. Example below.

import numpy as np
import numba

@numba.njit(parallel=True)
def f(n):
    A = np.ones(3)
    B = np.ones(3)
    for i in numba.prange(n):
        A += B

    return A

print(f(10))
@ninegua
Copy link

ninegua commented Nov 22, 2017

Right now since we don't translate A += B to parfor, the above example should be relatively easier to handle.

But more generally, if it was written as A = A + B, then the reduction code becomes a parfor before lowering, and then at lowering stage, it would be rather difficult to extract the set of reduction instructions.

@ninegua
Copy link

ninegua commented Nov 22, 2017

Also, with prange it is possible to write:

 for i in numba.prange(n):
        A += B
        C[i] = A

This is a lot more difficult to handle correctly. In general, there are a lot of restrictions on what can be safely parallelized for an arbitrary loop. We are not doing a good job at checking them.

@ehsantn
Copy link
Author

ehsantn commented Nov 22, 2017

Yes, it can get very complicated. We should check as many conditions as possible. They should be documented for sure.

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

No branches or pull requests

2 participants