lfortran / lfortran/lfortran

Array optimizations

Open
#348 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.2k
Forks
271
Avg merge
1d 2h
Merged PRs (30d)
173

Description

Original issue: https://gitlab.com/lfortran/lfortran/-/issues/383

Very frequently I use array operations such as:

  • maxval(abs(a-b)) for finding maximum error between a and b.
  • sqrt(dot_product(array,array)) or even sqrt(sum(x**2)) to compute a norm. There is now a norm2 intrinsic for this.

I think the compiler optimizer should be able to recognize such common expressions and generate optimal code for those.

Implementation: this could be an ASR pass that recognized such expressions and replaces them with internal functions. Alternatively, once we have some general framework for simplifying such array operations (perhaps using Mathematics of Arrays), it could handle such a case.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed ASR pass approach and the alternative Mathematics of Arrays direction described in the issue. Define how expressions such as maxval(abs(a-b)), sqrt(dot_product(array,array)), and sqrt(sum(x**2)) should be recognized and replaced with internal functions, then verify that the resulting code is optimized.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, fortran
Domain
compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.