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

ENH: Update MLIR backend to LLVM 20.dev #799

Merged
merged 1 commit into from
Nov 7, 2024
Merged

Conversation

mtsokol
Copy link
Collaborator

@mtsokol mtsokol commented Oct 23, 2024

This PR replaces #787 and fixes #797


This PR updates MLIR backend to current LLVM 20.dev (so main branch):

  • I ran it locally against latest LLVM version.
  • Moved COO format to SoA convention link.
  • Updated tensor.empty call link.

As one can see it fixes a bunch of skips in the test suite: sparse/mlir_backend/tests/test_simple.py

  • Dense+Dense and COO+COO now works.
  • Reshaping Dense and COO formats also works.

It's thanks to changes already present in main branch, added after 19.x branched, and:

@mtsokol mtsokol added the enhancement Indicates new feature requests label Oct 23, 2024
@mtsokol mtsokol self-assigned this Oct 23, 2024
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Copy link

codspeed-hq bot commented Oct 23, 2024

CodSpeed Performance Report

Merging #799 will degrade performances by 24.56%

Comparing updated-llvm-nightly-test (d511c5c) with main (bbe2b58)

Summary

❌ 1 regressions
✅ 339 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main updated-llvm-nightly-test Change
test_index_slice[side=100-rank=2-format='gcxs'] 2.5 ms 3.4 ms -24.56%

@mtsokol mtsokol force-pushed the updated-llvm-nightly-test branch 4 times, most recently from ed208b8 to 49cfb20 Compare October 25, 2024 11:59
@mtsokol
Copy link
Collaborator Author

mtsokol commented Oct 25, 2024

We still need more wheels for finch-milr package on PyPI but the PR itself can be already reviewed.

Copy link
Collaborator

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

Thanks for the test changes, overall the essence of this change LGTM, it is mlir -> Finch_mlir and figuring out the COO format better. Thanks!

sparse/mlir_backend/_conversions.py Show resolved Hide resolved
sparse/mlir_backend/_core.py Outdated Show resolved Hide resolved
Comment on lines +118 to +133
singleton_counter += 1
fields.append(
(
f"indices_{compressed_counter}_coords_{singleton_counter}",
get_nd_memref_descr(1, idx_dtype),
)
)
else:
fields.append((f"indices_{compressed_counter}", get_nd_memref_descr(1, idx_dtype)))

if LevelFormat.Singleton == level.format:
singleton_counter += 1
fields.append(
(f"indices_{compressed_counter}_coords_{singleton_counter}", get_nd_memref_descr(1, idx_dtype))
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably handle SOA and without SOA separately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my opinion we should only support SoA singleton format:

  1. Non-SoA singleton looks to be buggy for basic operations link
  2. Mixed singleton levels aren't allowed: https://github.com/llvm/llvm-project/blob/8d38fbf2f027c72332c8ba03ff0ff0f83b4dcf02/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp#L811

What would be the benefit of supporting non-SoA singleton levels separately?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd be able to support the current COO format only for non-SoA.

Copy link
Collaborator Author

@mtsokol mtsokol Nov 6, 2024

Choose a reason for hiding this comment

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

What do you mean by that? Can you give some example?
With this PR we can support COO format (also input objects of type scipy.sparse.coo_array) where MLIR-backend implementation uses SoA representation.

Copy link
Collaborator

@hameerabbasi hameerabbasi Nov 6, 2024

Choose a reason for hiding this comment

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

The existing Numba COO format uses the non-SoA format, and we pretty much have to support this to be backwards compatible. Doesn't have to be in this PR though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I'm still missing the point here. Numba is a separate backend that supports only 1D and 2D COO arrays. MLIR backend supports >=2D COO arrays.
What do you mean by backward compatibility here? Can you give an example where backward compatibility breaks here? If a user passes scipy.sparse.coo_array object to sparse.asarray function it it will work for any backend regardless of an internal representation (SoA or non-SoA).

Copy link
Collaborator

@hameerabbasi hameerabbasi Nov 7, 2024

Choose a reason for hiding this comment

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

So, sparse.COO has a constructor that takes coords and a .coords attribute. The attribute is a 2D NumPy array.

Ideally, I'd like to keep it a 2D np.ndarray as otherwise I'm not 100% sure how much will break.

We could do this with np.stack, but that would incur a performance penalty.

Also the current Numba backend supports ND, not 2D. SciPy supports only 2D, however.

I'm thinking of a future where all of sparse is powered by Finch-MLIR, ideally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think for accessing coords, np.stack could be an option. My caveat for non-SoA in MLIR backend is that it already has some issues with basic operations: https://discourse.llvm.org/t/passmanager-fails-on-simple-coo-addition-example/81247

@mtsokol mtsokol force-pushed the updated-llvm-nightly-test branch 7 times, most recently from 1dca588 to 57ca082 Compare November 5, 2024 18:25
Copy link
Collaborator

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

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

Just one comment plus CI/Windows and should be good to go.

.github/workflows/ci.yml Show resolved Hide resolved
@mtsokol mtsokol merged commit 9b431e7 into main Nov 7, 2024
16 of 17 checks passed
@mtsokol mtsokol deleted the updated-llvm-nightly-test branch November 7, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SOA level property and change COO format once in LLVM
2 participants