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

[MLIR][sparse] Add soa property to sparse_tensor Python bindings #109135

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

mtsokol
Copy link
Contributor

@mtsokol mtsokol commented Sep 18, 2024

Hi!

It looks like SoA property is missing from the Python bindings:

In [1]: from mlir.dialects import sparse_tensor

In [2]: sparse_tensor.LevelProperty.soa
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 sparse_tensor.LevelProperty.soa

AttributeError: type object 'mlir._mlir_libs._mlirDialectsSparseTensor.LevelPro' has no attribute 'soa'

which is required to get Python equivalent of:

#COO = #sparse_tensor.encoding<{
    map = (i, j) -> (i : compressed(nonunique), j : singleton(soa)), posWidth = 64, crdWidth = 64
}>

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added mlir:sparse Sparse compiler in MLIR mlir labels Sep 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-mlir

Author: Mateusz Sokół (mtsokol)

Changes

Hi!

It looks like SoA property is missing from the Python bindings:

In [1]: from mlir.dialects import sparse_tensor

In [2]: sparse_tensor.LevelProperty.soa
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----&gt; 1 sparse_tensor.LevelProperty.soa

AttributeError: type object 'mlir._mlir_libs._mlirDialectsSparseTensor.LevelPro' has no attribute 'soa'

which is required to get Python equivalent of:

#COO = #sparse_tensor.encoding&lt;{
    map = (i, j) -&gt; (i : compressed(nonunique), j : singleton(soa)), posWidth = 64, crdWidth = 64
}&gt;

Full diff: https://github.com/llvm/llvm-project/pull/109135.diff

4 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/SparseTensor.h (+1)
  • (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+2-1)
  • (modified) mlir/lib/CAPI/Dialect/SparseTensor.cpp (+3-1)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_output.py (+4)
diff --git a/mlir/include/mlir-c/Dialect/SparseTensor.h b/mlir/include/mlir-c/Dialect/SparseTensor.h
index 125469f57c5f55..c816c1b58690ea 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -39,6 +39,7 @@ enum MlirSparseTensorLevelFormat {
 enum MlirSparseTensorLevelPropertyNondefault {
   MLIR_SPARSE_PROPERTY_NON_UNIQUE = 0x0001,
   MLIR_SPARSE_PROPERTY_NON_ORDERED = 0x0002,
+  MLIR_SPARSE_PROPERTY_SOA = 0x0004,
 };
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
index 584981cfe99bf1..a730bf500be98c 100644
--- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
+++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
@@ -33,7 +33,8 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) {
   py::enum_<MlirSparseTensorLevelPropertyNondefault>(m, "LevelProperty",
                                                      py::module_local())
       .value("non_ordered", MLIR_SPARSE_PROPERTY_NON_ORDERED)
-      .value("non_unique", MLIR_SPARSE_PROPERTY_NON_UNIQUE);
+      .value("non_unique", MLIR_SPARSE_PROPERTY_NON_UNIQUE)
+      .value("soa", MLIR_SPARSE_PROPERTY_SOA);
 
   mlir_attribute_subclass(m, "EncodingAttr",
                           mlirAttributeIsASparseTensorEncodingAttr)
diff --git a/mlir/lib/CAPI/Dialect/SparseTensor.cpp b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
index f2a0ab33c0224f..cf25b5263678fb 100644
--- a/mlir/lib/CAPI/Dialect/SparseTensor.cpp
+++ b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
@@ -36,7 +36,9 @@ static_assert(
 static_assert(static_cast<int>(MLIR_SPARSE_PROPERTY_NON_ORDERED) ==
                       static_cast<int>(LevelPropNonDefault::Nonordered) &&
                   static_cast<int>(MLIR_SPARSE_PROPERTY_NON_UNIQUE) ==
-                      static_cast<int>(LevelPropNonDefault::Nonunique),
+                      static_cast<int>(LevelPropNonDefault::Nonunique) &&
+                  static_cast<int>(MLIR_SPARSE_PROPERTY_SOA) ==
+                      static_cast<int>(LevelPropNonDefault::SoA),
               "MlirSparseTensorLevelProperty (C-API) and "
               "LevelPropertyNondefault (C++) mismatch");
 
diff --git a/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py b/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
index 544273eb18835e..7d9aa37ba2890c 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
+++ b/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
@@ -129,6 +129,10 @@ def main():
         prop = st.LevelProperty
         levels = [
             [builder(fmt.compressed, [prop.non_unique]), builder(fmt.singleton)],
+            [
+                builder(fmt.compressed, [prop.non_unique]),
+                builder(fmt.singleton, [prop.soa]),
+            ],
             [builder(fmt.dense), builder(fmt.compressed)],
             [builder(fmt.dense), builder(fmt.loose_compressed)],
             [builder(fmt.compressed), builder(fmt.compressed)],

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-mlir-sparse

Author: Mateusz Sokół (mtsokol)

Changes

Hi!

It looks like SoA property is missing from the Python bindings:

In [1]: from mlir.dialects import sparse_tensor

In [2]: sparse_tensor.LevelProperty.soa
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----&gt; 1 sparse_tensor.LevelProperty.soa

AttributeError: type object 'mlir._mlir_libs._mlirDialectsSparseTensor.LevelPro' has no attribute 'soa'

which is required to get Python equivalent of:

#COO = #sparse_tensor.encoding&lt;{
    map = (i, j) -&gt; (i : compressed(nonunique), j : singleton(soa)), posWidth = 64, crdWidth = 64
}&gt;

Full diff: https://github.com/llvm/llvm-project/pull/109135.diff

4 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/SparseTensor.h (+1)
  • (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+2-1)
  • (modified) mlir/lib/CAPI/Dialect/SparseTensor.cpp (+3-1)
  • (modified) mlir/test/Integration/Dialect/SparseTensor/python/test_output.py (+4)
diff --git a/mlir/include/mlir-c/Dialect/SparseTensor.h b/mlir/include/mlir-c/Dialect/SparseTensor.h
index 125469f57c5f55..c816c1b58690ea 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -39,6 +39,7 @@ enum MlirSparseTensorLevelFormat {
 enum MlirSparseTensorLevelPropertyNondefault {
   MLIR_SPARSE_PROPERTY_NON_UNIQUE = 0x0001,
   MLIR_SPARSE_PROPERTY_NON_ORDERED = 0x0002,
+  MLIR_SPARSE_PROPERTY_SOA = 0x0004,
 };
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
index 584981cfe99bf1..a730bf500be98c 100644
--- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
+++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
@@ -33,7 +33,8 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) {
   py::enum_<MlirSparseTensorLevelPropertyNondefault>(m, "LevelProperty",
                                                      py::module_local())
       .value("non_ordered", MLIR_SPARSE_PROPERTY_NON_ORDERED)
-      .value("non_unique", MLIR_SPARSE_PROPERTY_NON_UNIQUE);
+      .value("non_unique", MLIR_SPARSE_PROPERTY_NON_UNIQUE)
+      .value("soa", MLIR_SPARSE_PROPERTY_SOA);
 
   mlir_attribute_subclass(m, "EncodingAttr",
                           mlirAttributeIsASparseTensorEncodingAttr)
diff --git a/mlir/lib/CAPI/Dialect/SparseTensor.cpp b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
index f2a0ab33c0224f..cf25b5263678fb 100644
--- a/mlir/lib/CAPI/Dialect/SparseTensor.cpp
+++ b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
@@ -36,7 +36,9 @@ static_assert(
 static_assert(static_cast<int>(MLIR_SPARSE_PROPERTY_NON_ORDERED) ==
                       static_cast<int>(LevelPropNonDefault::Nonordered) &&
                   static_cast<int>(MLIR_SPARSE_PROPERTY_NON_UNIQUE) ==
-                      static_cast<int>(LevelPropNonDefault::Nonunique),
+                      static_cast<int>(LevelPropNonDefault::Nonunique) &&
+                  static_cast<int>(MLIR_SPARSE_PROPERTY_SOA) ==
+                      static_cast<int>(LevelPropNonDefault::SoA),
               "MlirSparseTensorLevelProperty (C-API) and "
               "LevelPropertyNondefault (C++) mismatch");
 
diff --git a/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py b/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
index 544273eb18835e..7d9aa37ba2890c 100644
--- a/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
+++ b/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
@@ -129,6 +129,10 @@ def main():
         prop = st.LevelProperty
         levels = [
             [builder(fmt.compressed, [prop.non_unique]), builder(fmt.singleton)],
+            [
+                builder(fmt.compressed, [prop.non_unique]),
+                builder(fmt.singleton, [prop.soa]),
+            ],
             [builder(fmt.dense), builder(fmt.compressed)],
             [builder(fmt.dense), builder(fmt.loose_compressed)],
             [builder(fmt.compressed), builder(fmt.compressed)],

Copy link
Contributor

@aartbik aartbik 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 adding!

@mtsokol
Copy link
Contributor Author

mtsokol commented Oct 2, 2024

Hi! I think we can merge it?

@PeimingLiu PeimingLiu merged commit b50ce4c into llvm:main Oct 2, 2024
9 checks passed
Copy link

github-actions bot commented Oct 2, 2024

@mtsokol Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 2, 2024

LLVM Buildbot has detected a new failure on builder mlir-rocm-mi200 running on mi200-buildbot while building mlir at step 6 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/6026

Here is the relevant piece of the build log for the reference
Step 6 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/SparseTensor/python/test_output.py' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
env SUPPORT_LIB=/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/lib/libmlir_c_runner_utils.so    /usr/bin/python3.8 /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py | /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# executed command: env SUPPORT_LIB=/vol/worker/mi200-buildbot/mlir-rocm-mi200/build/lib/libmlir_c_runner_utils.so /usr/bin/python3.8 /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# .---command stderr------------
# | /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:55: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 0:
# | /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 1:
# | /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:75: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 2:
# `-----------------------------
# executed command: /vol/worker/mi200-buildbot/mlir-rocm-mi200/build/bin/FileCheck /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# .---command stderr------------
# | /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:186:11: error: CHECK: expected string not found in input
# |  # CHECK: Passed 17 tests
# |           ^
# | <stdin>:2:18: note: scanning from here
# | TEST: test_output
# |                  ^
# | <stdin>:3:1: note: possible intended match here
# | Passed 21 tests
# | ^
# | 
# | Input file: <stdin>
# | Check file: /vol/worker/mi200-buildbot/mlir-rocm-mi200/llvm-project/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |              1:  
# |              2: TEST: test_output 
# | check:186'0                      X error: no match found
# |              3: Passed 21 tests 
# | check:186'0     ~~~~~~~~~~~~~~~~
# | check:186'1     ?                possible intended match
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 2, 2024

LLVM Buildbot has detected a new failure on builder mlir-nvidia-gcc7 running on mlir-nvidia while building mlir at step 6 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/4512

Here is the relevant piece of the build log for the reference
Step 6 (test-build-check-mlir-build-only-check-mlir) failure: test (failure)
******************** TEST 'MLIR :: Integration/Dialect/SparseTensor/python/test_output.py' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
env SUPPORT_LIB=/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/lib/libmlir_c_runner_utils.so    /usr/bin/python3.10 /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py | /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# executed command: env SUPPORT_LIB=/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/lib/libmlir_c_runner_utils.so /usr/bin/python3.10 /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# .---command stderr------------
# | /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:55: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 0:
# | /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:65: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 1:
# | /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:75: SyntaxWarning: "is" with a literal. Did you mean "=="?
# |   if id_map is 2:
# `-----------------------------
# executed command: /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.obj/bin/FileCheck /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# .---command stderr------------
# | /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py:186:11: error: CHECK: expected string not found in input
# |  # CHECK: Passed 17 tests
# |           ^
# | <stdin>:2:18: note: scanning from here
# | TEST: test_output
# |                  ^
# | <stdin>:3:1: note: possible intended match here
# | Passed 21 tests
# | ^
# | 
# | Input file: <stdin>
# | Check file: /vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/mlir/test/Integration/Dialect/SparseTensor/python/test_output.py
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |              1:  
# |              2: TEST: test_output 
# | check:186'0                      X error: no match found
# |              3: Passed 21 tests 
# | check:186'0     ~~~~~~~~~~~~~~~~
# | check:186'1     ?                possible intended match
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

********************


@mtsokol
Copy link
Contributor Author

mtsokol commented Oct 2, 2024

It looks like I missed updating test count (I wonder why it wasn't caught in the PR's CI job). Here's a fix for it: #110882

PeimingLiu pushed a commit that referenced this pull request Oct 2, 2024
This PR fixes a test failure introduced in
#109135
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
@mtsokol
Copy link
Contributor Author

mtsokol commented Oct 3, 2024

Thank you for merging it!

Would it be possible to backport this PR, #108615 and #110882 to release/19.x branch?

xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:sparse Sparse compiler in MLIR mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants