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

easier parfor construction/translation #29

Open
ninegua opened this issue Aug 17, 2017 · 1 comment
Open

easier parfor construction/translation #29

ninegua opened this issue Aug 17, 2017 · 1 comment

Comments

@ninegua
Copy link

ninegua commented Aug 17, 2017

I'm thinking maybe we could build facilities similar to @lower_builtin to help translating various numpy functions to parfor. Here is an idea:

@parfor_call(np.transpose, types.Array)
def array_transpose(sig, args, arg_shapes)
    return array_T(sig.args[0], args[0], arg_shapes[0])

@parfor_getattr(types.Array, 'T')
def array_T(typ, inp, shape)
    out_shape = [shape[1], shape[0]]
    init = allocate_array(typ, out_shape)
    def body_func(out, i, j):
        out[i, j] = inp[j, i]
    loopnest = mk_loopnest(body_func, out_shape)
    return mk_parfor(init, loopnest)

This would translate both np.transpose(a) and a.T, by doing some pattern match on incoming IR (usually an assignment).

I think we can extend it further to incorporate array analysis too. So in the end we build two dictionaries that map function names (or getattr) to its corresponding (1) shape analysis, and (2) parfor translation. Eventually I'd see it merged into @lower_builtin so that all related handling of a single numpy call would sit in one place, but that is perhaps quite a stretch.

What do you think? @ehsantn @DrTodd13

@ehsantn
Copy link

ehsantn commented Aug 29, 2017

The overall approach is very useful. In terms of details, I think we can write actual functions similar to @lower_builtin instead of things like mk_loopnest. prange can help with this.

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