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

tuple of tuple arguments not allowed in parfor loop #9098

Open
albop opened this issue Jul 27, 2023 · 4 comments
Open

tuple of tuple arguments not allowed in parfor loop #9098

albop opened this issue Jul 27, 2023 · 4 comments
Labels
Blocked awaiting long term feature For PRs/Issues that require the implementation of a long term plan feature ParallelAccelerator

Comments

@albop
Copy link

albop commented Jul 27, 2023

The following code

import numpy as np
import numba as nb
from numba import prange

@nb.jit
def my_fun(vals, grid, coef, x):
    return vals[0] + coef[0] + x[0] # + grid[0][0]

@nb.jit(nopython=True, parallel=True)
def run_in_pfor(vals, grid, coef, x):
    t = 0.0
    for h in prange(6):
        res = my_fun(vals, grid, coef, x)
        t += res
    return t

vals = np.random.rand(5)
grid = ((0., 1., 5),)
coef = vals.copy()
x = np.array([0.22])
run_in_pfor(vals, grid, coef, x)

raises an exception ending in

numba.core.errors.LoweringError: Failed in nopython mode pipeline (step: native parfor lowering)
scalar type Tuple(float64, float64, int64) given for non scalar argument #3

File "notuple.py", line 12:
def run_in_pfor(vals, grid, coef, x):
    <source elided>
    t = 0.0
    for h in prange(6):
    ^

During: lowering "id=0[LoopNest(index_variable = parfor_index.6, range = (0, $const20.3, 1))]{40: <ir.Block at /home/pablo/Econforge/interpolation.py/notuple.py (12)>}Var(parfor_index.6, notuple.py:12)" at /home/pablo/Econforge/interpolation.py/notuple.py (12)

full stacktrace attached : stacktrace.txt .

If I replace grid = ((0., 1., 5),) by grid = (0., 1., 5) it works (it is not used by the function anyway).

@albop
Copy link
Author

albop commented Jul 27, 2023

Original discussion here: EconForge/interpolation.py#107 (comment)

@guilhermeleobas
Copy link
Collaborator

guilhermeleobas commented Jul 27, 2023

Hi @albop, thanks for the report. I can confirm the bug in Numba and only works if parallel=True.

I'll put this topic for discussion at the next triage meeting. I'll check if this is a limitation by design, or if it is actually a bug.

@DrTodd13
Copy link
Collaborator

DrTodd13 commented Aug 1, 2023

Hi @albop, thanks for the report. I can confirm the bug in Numba and only works if parallel=True.

I'll put this topic for discussion at the next triage meeting. I'll check if this is a limitation by design, or if it is actually a bug.

Limitation by design. For a long time, parallel region didn't support tuples at all but eventually we added the ability to support tuples but the implementation is necessarily very ugly. Supporting nested tuples would be ugly squared. There is some talk of replacing the internal gufunc mechanism to not have this tuple restriction at which point this problem will go away.

@DrTodd13 DrTodd13 added Blocked awaiting long term feature For PRs/Issues that require the implementation of a long term plan feature and removed bug - failure to compile Bugs: failed to compile valid code labels Aug 1, 2023
@albop
Copy link
Author

albop commented Aug 1, 2023

Fair enough. Thanks for the clarification @DrTodd13 . I can certainly find an ugly workaround in the meantime ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked awaiting long term feature For PRs/Issues that require the implementation of a long term plan feature ParallelAccelerator
Projects
None yet
Development

No branches or pull requests

3 participants