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

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

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
@@ -11,20 +11,20 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
python: ['3.10', '3.11', '3.12']
python: ['3.10'] # , '3.11', '3.12'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Finch-mlir CI build needs to support other oses, archs, and Python versions.

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!

@@ -94,13 +94,15 @@ def _from_scipy(arr: ScipySparseArray, copy: bool | None = None) -> Array:
case "coo":
if copy is not None and not copy:
raise RuntimeError(f"`scipy.sparse.{type(arr.__name__)}` cannot be zero-copy converted.")
coords = np.stack([arr.row, arr.col], axis=1)
row, col = arr.row, arr.col
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should raise a RuntimeError if row.dtype != col.dtype.

Comment on lines 20 to 21
if os.name == "posix":
MLIR_C_RUNNER_UTILS = f"{finch_lib_path}/{MLIR_C_RUNNER_UTILS}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs something for Windows.

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?

@mtsokol mtsokol force-pushed the updated-llvm-nightly-test branch 7 times, most recently from 1dca588 to 57ca082 Compare November 5, 2024 18:25
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