EnzymeAD / EnzymeAD/Enzyme-JAX

Optimize Gather/Scatter into reshape with slice

Open
#1,682 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
MLIR
Stars
131
Forks
53
Avg merge
1d 10h
Merged PRs (30d)
193

Description

The pre shape optimization IR is https://gist.github.com/wsmoses/40ec1e499cdf79ee0e65f1e2f77b74a8

We emit a bunch of gather/scatters that are needless. We should optimize them into slice/dynamic_update slice.

The reason they are emitted as gather/scatter is because during raising the tensor is 1d so it's not purely affine. However, clearly here the memory is two-dimensional so if we reshape it first to a 2d tensor, we can use a slice/dynamic update slice.

A walkthrough of the gather-scatter pattern is here: https://github.com/EnzymeAD/Enzyme-JAX/blob/8e83bb047e01f2f0499b5a0680405ff029330436/test/lit_tests/raising/affine_to_stablehlo_scatgath.mlir#L116

A sample optimization for gather is here: https://github.com/EnzymeAD/Enzyme-JAX/pull/1038/files

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.