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

GPUPersistentKernel fails to validate sdfg with local variables #1304

Closed
kylosus opened this issue Jul 10, 2023 · 3 comments · Fixed by #1322
Closed

GPUPersistentKernel fails to validate sdfg with local variables #1304

kylosus opened this issue Jul 10, 2023 · 3 comments · Fixed by #1322

Comments

@kylosus
Copy link
Contributor

kylosus commented Jul 10, 2023

Describe the bug
GPUPersistentKernel transformation incorrectly considers symbols defined within the SDFG as free symbols and fails to validate.

To Reproduce
Consider the following toy example:

import dace as dc
import numpy as np

from dace.sdfg.graph import SubgraphView
from dace.transformation.subgraph import GPUPersistentKernel

import dace.transformation.transformation

N = dc.symbol('N', dtype=dc.int64)


@dc.program(auto_optimize=False, device=dace.DeviceType.GPU)
def func(A: dc.float64[N], B: dc.float64[N]):
    a = 10.2

    for t in range(1, 10000):
        if t < N:
            A[:] = (A + B + a) / 2
            a += 1


if __name__ == "__main__":
    # Initialization
    N = 10000
    A = np.random.rand(N)
    B = np.random.rand(N)

    sdfg = func.to_sdfg()
    sdfg.apply_gpu_transformations()
    content_nodes = set(sdfg.nodes()) - {sdfg.start_state, sdfg.sink_nodes()[0]}
    subgraph = SubgraphView(sdfg, content_nodes)

    transform = GPUPersistentKernel()
    transform.setup_match(subgraph)
    transform.kernel_prefix = 'stuff'
    transform.apply(sdfg)

    func = sdfg.compile()
    func(A=A, B=B, N=N)

Attempting to call this dace program fails with the following error:

Traceback (most recent call last):
  File ".../jacobi_test_2.py", line 49, in <module>
    func(A=A, B=B, N=N)
  File ".../dace/codegen/compiled_sdfg.py", line 334, in __call__
    argtuple, initargtuple = self._construct_args(kwargs)
  File ".../dace/dace/codegen/compiled_sdfg.py", line 395, in _construct_args
    raise KeyError("Missing program argument \"{}\"".format(a))
KeyError: 'Missing program argument "a"'

Adding extra a=0 and t=0 args allows the sdfg to pass the validation and runs as expected.

Desktop (please complete the following information):

  • Python 3.10.12
  • Dace latest master branch

Additional context
Changing this line to the following fixes it but I'm not sure if it's a full solution.

sdfg.add_edge(launch_state, exit_state_out, InterstateEdge(None, entry_edge.data.assignments))
@tbennun
Copy link
Collaborator

tbennun commented Jul 17, 2023

Thank you for reporting! After looking into the issue, it looks like the transformation did not remove the symbols that are now unused from the outer SDFG. This is now fixed in #1322.

@tbennun
Copy link
Collaborator

tbennun commented Jul 18, 2023

@kylosus The PR was merged, please let us know if this fixes your issue.

@kylosus
Copy link
Contributor Author

kylosus commented Jul 18, 2023

Seems to be working as expected. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants