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

[Frontend] add fuse-elementwise-ops pass #1326

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

erick-xanadu
Copy link
Contributor

Context: stablehlo lowering creates many elementwise operations. It is possible to fuse them and thus reduce code size. For example:

import pennylane as qml
import catalyst
import jax

MATSIZE=128 #scale with me

@catalyst.qjit(keep_intermediate=True)
#@jax.jit
def func(a, b):
    return jax.scipy.linalg.expm(1j*a)

a = jax.numpy.outer(jax.numpy.array([2]*MATSIZE), jax.numpy.array([2]*MATSIZE))
b = jax.numpy.outer(jax.numpy.array([3]*MATSIZE), jax.numpy.array([3]*MATSIZE))

print(func(a,b))

Produces a stablehlo of 1176 lines after stablehlo lowering and 14039 lines in LLVM.
After this change that goes down to 759 and 9936 respectively.
I also expect this to possibly reduce execution time, but I haven't benchmarked it yet.

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@@ -191,6 +191,7 @@ def get_hlo_lowering_stage(_options: CompileOptions) -> List[str]:
"func.func(linalg-detensorize{aggressive-mode})",
"detensorize-scf",
"canonicalize",
"linalg-fuse-elementwise-ops",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this a bit earlier in the pipeline so the execution time of more passes can benefit from the code size reduction?

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 this pull request may close these issues.

2 participants