We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1006545 + 14bfb8d commit 864ba3fCopy full SHA for 864ba3f
10 files changed
README.md
@@ -49,67 +49,3 @@ array([0, 1], dtype=uint64)
49
>>> values
50
array([ 8. , 33.625])
51
```
52
-
53
-# Building MLIR
54
55
-Until LLVM 16.0 is released, the required MLIR operations in the sparse_tensor dialect will only be
56
-available on the main repo branch, meaning there aren't any packages readily available to install
57
-from conda-forge.
58
59
-To build locally, download the LLVM repo from GitHub.
60
61
-```
62
-git clone https://github.com/llvm/llvm-project.git
63
64
65
-Next create a conda environment for building the project.
66
67
68
-conda create -n mlir_build_env -y
69
-conda activate mlir_build_env
70
-conda install python=3.10 numpy pyyaml cmake ninja pybind11 python-mlir-graphblas
71
72
73
-Define `PREFIX` as the location of your environment (active env location when running `conda info`).
74
-Then run cmake.
75
76
77
-export PREFIX=/location/to/your/conda/environment
78
79
-cd llvm-project
80
-mkdir build
81
-cd build
82
83
-cmake -G Ninja ../llvm \
84
- -DCMAKE_INSTALL_PREFIX=$PREFIX \
85
- -DLLVM_ENABLE_PROJECTS=mlir \
86
- -DLLVM_BUILD_EXAMPLES=ON \
87
- -DLLVM_INSTALL_UTILS=ON \
88
- -DLLVM_TARGETS_TO_BUILD="X86;AArch64;NVPTX;AMDGPU" \
89
- -DCMAKE_BUILD_TYPE=Release \
90
- -DLLVM_ENABLE_ASSERTIONS=ON \
91
- -DLLVM_BUILD_LLVM_DYLIB=ON \
92
- -DMLIR_ENABLE_BINDINGS_PYTHON=ON \
93
- -DPython3_EXECUTABLE=`which python`
94
95
96
-If building on a Mac, perform this additional step.
97
98
99
-cp $PREFIX/lib/libtinfo* lib/
100
-cp $PREFIX/lib/libz* lib/
101
102
103
-Then build the project
104
105
106
-cmake --build .
107
-cmake --install .
108
109
110
-Finally, set `LLVM_BUILD_DIR` to point to the current build directory.
111
-Now python-mlir-graphblas should be usable. Verify by running tests.
112
113
114
-LLVM_BUILD_DIR=. pytest --pyargs mlir_graphblas
115
dev-environment.yml
@@ -0,0 +1,12 @@
1
+# To use:
2
+# $ conda env create -f dev-environment.yml
3
+# $ conda activate mlir-graphblas-dev
4
+
5
+name: mlir-graphblas-dev
6
+channels:
7
+ - conda-forge
8
+ - nodefaults # Only from conda-forge for faster solving
9
+dependencies:
10
+ - python
11
+ - mlir-python-bindings >=16.0
12
+ - pytest
mlir_graphblas/__init__.py
@@ -1,7 +1,8 @@
-# TODO: remove this once mlir-python-bindings can be properly installed
-import os
-import sys
-sys.path.append(f"{os.environ['LLVM_BUILD_DIR']}/tools/mlir/python_packages/mlir_core")
+try:
+ import mlir
+ import mlir.ir
+except ImportError:
+ raise ImportError("Missing mlir-python-bindings")
from .operations import *
from .operators import *
mlir_graphblas/compiler.py
@@ -2,7 +2,7 @@
from mlir import ir
from mlir import passmanager
-from .utils import LIBMLIR_C_RUNNER_UTILS
+from .utils import MLIR_C_RUNNER_UTILS
engine_cache = {}
@@ -12,8 +12,7 @@ def compile(module: ir.Module, pipeline=None, *, opt_level=2, shared_libs=None):
if pipeline is None:
13
pipeline = 'builtin.module(sparse-compiler{reassociate-fp-reductions=1 enable-index-optimizations=1})'
14
if shared_libs is None:
15
- shared_libs = [LIBMLIR_C_RUNNER_UTILS]
+ shared_libs = [MLIR_C_RUNNER_UTILS]
16
# print(module)
17
passmanager.PassManager.parse(pipeline).run(module)
18
- return execution_engine.ExecutionEngine(
19
- module, opt_level=opt_level, shared_libs=shared_libs)
+ return execution_engine.ExecutionEngine(module, opt_level=opt_level, shared_libs=shared_libs)
mlir_graphblas/implementations.py
@@ -358,7 +358,6 @@ def main(x, y):
358
359
def ewise_add(out_type: DType, op: BinaryOp, left: SparseTensorBase, right: SparseTensorBase):
360
assert left.ndims == right.ndims
361
- assert left.dtype == right.dtype
362
363
if left._obj is None:
364
if right.dtype == out_type:
mlir_graphblas/tests/test_operations.py
@@ -177,7 +177,15 @@ def test_mxm(mm):
177
# rowwise @ colwise
178
z.clear()
179
operations.mxm(z, Semiring.plus_times, x, ycol)
180
- matrix_compare(z, *expected)
+ try:
181
+ matrix_compare(z, *expected)
182
+ except AssertionError:
183
+ # Check for dense return, indicating lack of lex insert fix
184
+ matrix_compare(z,
185
+ [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4],
186
+ [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4],
187
+ [20.9, 0, 0, 0, 0, 16.5, 0, 0, 0, 0, 5.5, 0, 0, 0, 70.4, 0, 0, 0, 0, 0, 0, 0, 0, 13.2, 0])
188
+ pytest.xfail("Waiting for lex insert fix")
189
# colwise @ colwise
190
191
operations.mxm(z, Semiring.plus_times, xcol, ycol)
mlir_graphblas/tests/utils.py
@@ -5,6 +5,7 @@
def vector_compare(vec, i, v):
assert vec.ndims == 1
+ assert len(i) == len(v), f"{len(i)} != {len(v)}"
idx, vals = vec.extract_tuples()
assert vals.dtype == vec.dtype.np_type
np_assert_equal(idx, i)
@@ -13,12 +14,15 @@ def vector_compare(vec, i, v):
def matrix_compare(mat, r, c, v):
assert mat.ndims == 2
+ assert len(r) == len(c), f"{len(r)} != {len(c)}"
+ assert len(r) == len(v), f"{len(r)} != {len(v)}"
rows, cols, vals = mat.extract_tuples()
20
assert vals.dtype == mat.dtype.np_type
21
+ combo = np.core.records.fromarrays([r, c], names='r,c')
22
if mat.is_rowwise():
- sort_order = np.argsort(r)
23
+ sort_order = np.argsort(combo, order=['r', 'c'])
24
else:
- sort_order = np.argsort(c)
25
+ sort_order = np.argsort(combo, order=['c', 'r'])
26
np_assert_equal(rows, np.array(r)[sort_order])
27
np_assert_equal(cols, np.array(c)[sort_order])
28
np_assert_allclose(vals, np.array(v)[sort_order])
mlir_graphblas/utils.py
@@ -1,5 +1,6 @@
-import ctypes
import numpy as np
+import ctypes
+from ctypes.util import find_library
from enum import Enum
from mlir.dialects.sparse_tensor import DimLevelType
@@ -8,13 +9,9 @@
GrbDimensionMismatch, GrbOutputNotEmpty, GrbIndexOutOfBounds, GrbEmptyObject
)
+MLIR_C_RUNNER_UTILS = find_library("mlir_c_runner_utils")
+c_lib = ctypes.CDLL(MLIR_C_RUNNER_UTILS)
LLVMPTR = ctypes.POINTER(ctypes.c_char)
-# TODO: fix this once a proper package exists
-LIBMLIR_C_RUNNER_UTILS = f"{os.environ['LLVM_BUILD_DIR']}/lib/libmlir_c_runner_utils.dylib"
-c_lib = ctypes.CDLL(LIBMLIR_C_RUNNER_UTILS)
def get_sparse_output_pointer():
0 commit comments