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

Codegen: Scalar Return Values are Impossible #1610

Open
philip-paul-mueller opened this issue Jun 27, 2024 · 0 comments
Open

Codegen: Scalar Return Values are Impossible #1610

philip-paul-mueller opened this issue Jun 27, 2024 · 0 comments

Comments

@philip-paul-mueller
Copy link
Collaborator

philip-paul-mueller commented Jun 27, 2024

It is impossible to return a scalar from an SDFG.

This is a code generator issue, as the final signature of the C function of __return is a scalar and not a pointer (okay calling it on the Python side must also be different then).
The ability to return scalars is an intended behaviour, see CompiledSDFG._convert_return_values() that handles this case, but it does not work.

PR#1609 adds unit tests for properly testing this case (previously only array returns where tested).
Furthermore, it patches the validation to detect such cases and rejects such SDFG, however, it is not a solution.
A true solution would allow that any (global) scalar can be used to pass information to the outside, as it is possible with arrays.

Code to reproduce:

import dace
import numpy
@dace.program(auto_optimize=False, recreate_sdfg=True)
def testee(
    A: dace.float64[20],
) -> dace.float64:
    return dace.float64(A[3])

A = np.random.rand(20)
sdfg = testee.to_sdfg()
res = sdfg(A=A)
assert isinstance(res, np.float64)
assert A[3] == res

By dropping the return value annotation in the above code, the frontend would actually promote the return value to an array and it would work, but no scalar is returned then.

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

1 participant