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

Support for map-style and math Fortran intrinsics #1368

Closed
5 tasks
mcopik opened this issue Sep 12, 2023 · 3 comments
Closed
5 tasks

Support for map-style and math Fortran intrinsics #1368

mcopik opened this issue Sep 12, 2023 · 3 comments
Labels
enhancement New feature or request fortran good first issue Good for newcomers

Comments

@mcopik
Copy link
Contributor

mcopik commented Sep 12, 2023

We are currently missing support for many Fortran intrinsics. We want to start with map-style Fortran intrinsics and math functions - these have already been added to Fortran AST components, but we need to verify they are correctly handled when translating AST and generating SDFG.

Map Style Intrinsics

Currently, the Fortran frontend supports the SUM intrinsic, translated to a (nested) loop summing variables in an array. However, it does not seem to work entirely correctly. For example, this code is valid in Fortran but fails in DaCe - we fail to preallocate loop iterator variables when the SUM is the first node:

PROGRAM ranges_test
implicit none
double precision d(3,4,5)
d(:,:,:) = 42
CALL array_ranges_test_function(d)
end

SUBROUTINE array_ranges_test_function(d)
double precision d(3,4,5),e(3,4,5)

d(1,1,1)=SUM(e(:,1,:))

END SUBROUTINE array_ranges_test_function

Error:

Traceback (most recent call last):
  File "/work/dace/2023/fortran/dace/tests/fortran/intrinsincs_map.py", line 90, in <module>
    test_fortran_frontend_intrinsic()
  File "/work/dace/2023/fortran/dace/tests/fortran/intrinsincs_map.py", line 76, in test_fortran_frontend_intrinsic
    sdfg = fortran_parser.create_sdfg_from_string(test_string, "sum_intrinsinc_test")
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 1087, in create_sdfg_from_string
    ast2sdfg.translate(program, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 131, in translate
    self.ast_elements[node.__class__](node, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 168, in ast2sdfg
    self.translate(node.main_program.execution_part.execution, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 134, in translate
    self.translate(i, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 131, in translate
    self.ast_elements[node.__class__](node, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 861, in call2sdfg
    self.subroutine2sdfg(i, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 768, in subroutine2sdfg
    self.translate(node.execution_part, new_sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 131, in translate
    self.ast_elements[node.__class__](node, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 178, in basicblock2sdfg
    self.translate(i, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 131, in translate
    self.ast_elements[node.__class__](node, sdfg)
  File "/work/dace/2023/fortran/dace/dace/frontend/fortran/fortran_parser.py", line 283, in forstmt2sdfg
    raise ValueError("Unknown variable " + decl_node.lval.name)
ValueError: Unknown variable tmp_parfor_0

This are handled in PRs #1390 and #1394

Math Style Intrinsics

Another type of intrinsics we want to support are math functions. Currently, we support SQRT, COSH, ABS, EXP, and TANH. To support this, we must ensure that the function we translate to is supported in DaCe.

Math intrinsics we need to cover:

  • ACOS
  • ATAN2
  • ASIN
  • SINH
  • LOG

CC: @acalotoiu

@mcopik
Copy link
Contributor Author

mcopik commented Oct 12, 2023

PR #1390 should resolve the problems with SUM. I am working towards full support for other loop-based intrinsics such as ANY and ALL.

Help is welcome with math functions :-)

@yx-xyc
Copy link

yx-xyc commented Mar 11, 2024

Hi @mcopik,

I’ve been getting into the DaCe project, I would like to start by helping support fortran math intrinsics to get my feet wet.

I've added some mapping entries for LOG in FortranIntrinsics.replace_function_name and FortranIntrinsics.replace_function_reference, but I’ve hit a bit of a roadblock – my test for LOG isn't passing, and I suspect there's something missing in my approach.

To give you a better idea of where I’m at, I've opened a PR [https://github.com//pull/1545]. It's still a work in progress, but I thought it might help to show exactly where I'm stuck. Any hints, tips, or guidance you can offer would be awesome and really appreciated. Just looking for a nudge in the right direction. Thanks a lot for taking the time to check this out. Excited to hear your thoughts and hoping to make this feature work with your help!

@mcopik
Copy link
Contributor Author

mcopik commented Mar 12, 2024

@yx-xyc Thanks for your interest! In fact, we made a lot of progress on this issue in branch multi_sdfg.

Furthermore, this is a very specific problem related to one part of DaCe's frontend. I'd recommend to look at other more general issues, which will give you better exposure to DaCe and help to understand SDFGs better :)

@mcopik mcopik closed this as completed Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fortran good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants