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

Python front-end tasklet memlet bug #1588

Open
BenWeber42 opened this issue Jun 11, 2024 · 2 comments
Open

Python front-end tasklet memlet bug #1588

BenWeber42 opened this issue Jun 11, 2024 · 2 comments
Labels
bug Something isn't working frontend

Comments

@BenWeber42
Copy link
Contributor

When using the explicit dataflow mode of the Python front-end to declare a tasklet with connectors, the body of the tasklet doesn't correctly recognize the variables introduced by memlets.

This example triggers this bug:

@dace.program
def add_tasklet(A: dace.float64[1], B: dace.float64[1], R: dace.float64[1]):

    with dace.tasklet(dace.Language.Python):
        a << A[0]
        b << B[0]
        r >> R[0]
        r = a + b

The whole test is available here:
https://github.com/BenWeber42/dace/blob/tasklet-connector-bug/tests/python_frontend/tasklet_connector_test.py

The generated SDFG contains a tasklet with the code r = (None + None).
It seems like the memlet declarations (a << A[0] and b << B[0]) are not recognized in the tasklet body (r = a + b).

@BenWeber42 BenWeber42 added frontend bug Something isn't working labels Jun 11, 2024
@alexnick83
Copy link
Contributor

This is partially a UX issue. a and b in r = a + b (line 15) are considered a and b from lines 18 and 19. This happens due to Python's scoping rules and the frontend's preprocessing actively looking for global variables. A quick fix is to either rename the variables or move the program outside the testing method (in another scope). My guess is that preprocessing is not taking into account definitions with << and >>, so a better solution would address that issue.

@BenWeber42 BenWeber42 changed the title Pythoh front-end tasklet memlet bug Python front-end tasklet memlet bug Jun 11, 2024
@BenWeber42
Copy link
Contributor Author

Ok, thanks!, your proposed work-around fixed the issue.

For my understanding, the issue is that Python's scoping rules and DaCe's scoping rules are different in this case. Particularly in a DaCe tasklet, a << A[0], b << B[0] and r >> R[0] can declare new variables (i.e., variables a, b and r), whereas in Python they cannot declare new variables. In Python, they only count as variable usages.

  • Python sees a << A[0], b << B[0] and r >> R[0], considers them only variable usages of a, b and r.
  • Python checks whether there are local or parameter declarations of those
  • There are none, hence Python assumes a, b and r are part of the closure of the add_tasklet method
  • When the DaCe Python front-end preprocesses the add_tasklet dace program, it uses the closure computed by Python to determine that a, b and r must come from the outside, hence they become parameters of the SDFG

Preferably, preprocessing should take into account, that a << A[0], b << B[0] and r >> R[0] can in fact declare local variables. Thus, a, b and r are not part of the closure and don't become parameters of the SDFG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend
Projects
None yet
Development

No branches or pull requests

2 participants