Merge pull request #7 from aartbik/bik
[mpact][compiler] package mpact python sources into proper modules
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b935118..933e6b4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@
set(MPACT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "Building the MPACT compiler at ${MPACT_SOURCE_DIR} (into ${MPACT_BINARY_DIR})")
+set(MPACT_PYTHON_PACKAGES_DIR "${MPACT_BINARY_DIR}/python_packages")
+
add_subdirectory(benchmark)
add_subdirectory(python)
add_subdirectory(test)
diff --git a/README.md b/README.md
index b2d0214..5b3580e 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@
Also make sure to set the Python paths as follows.
```shell
-export PYTHONPATH=`pwd`/build/tools/torch-mlir/python_packages/torch_mlir:`pwd`/python
+export PYTHONPATH=`pwd`/build/tools/torch-mlir/python_packages/torch_mlir:`pwd`/build/tools/mpact/python_packages/mpact
```
### Install build requirements
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 4d49440..ac10ed2 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -2,4 +2,28 @@
# The MPACT Compiler Python Modules
#-------------------------------------------------------------------------------
+# The directory at which the Python import tree begins.
+set(MPACT_PYTHON_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mpact")
+
declare_mlir_python_sources(MPACTPythonSources)
+
+declare_mlir_python_sources(MPACTPythonSources.PublicAPI
+ ROOT_DIR "${MPACT_PYTHON_ROOT_DIR}"
+ ADD_TO_PARENT MPACTPythonSources
+ SOURCES
+ mpactbackend.py
+)
+
+#-------------------------------------------------------------------------------
+# Python Modules
+#-------------------------------------------------------------------------------
+
+set(_source_components
+ MPACTPythonSources
+)
+
+add_mlir_python_modules(MPACTPythonModules
+ ROOT_PREFIX "${MPACT_PYTHON_PACKAGES_DIR}/mpact/mpact"
+ INSTALL_PREFIX "python_packages/mpact/mpact"
+ DECLARED_SOURCES ${_source_components}
+)
diff --git a/python/mpactbackend.py b/python/mpact/mpactbackend.py
similarity index 100%
rename from python/mpactbackend.py
rename to python/mpact/mpactbackend.py
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 378640d..019d820 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -11,7 +11,7 @@
set(MPACT_TEST_DEPENDS
FileCheck count not
- MPACTPythonSources
+ MPACTPythonModules
TorchMLIRPythonModules
torch-mlir-opt
)
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index a727344..8dc4ba4 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -73,7 +73,7 @@
llvm_config.with_environment(
"PYTHONPATH",
[
- os.path.join(config.mpact_src_root, "python"),
+ os.path.join(config.mpact_obj_root, "python_packages/mpact"),
os.path.join(config.torch_mlir_obj_root, "python_packages/torch_mlir"),
],
append_path=True,
diff --git a/test/python/sparse_gcn.py b/test/python/sparse_gcn.py
index f2d7b2f..d1d00a0 100644
--- a/test/python/sparse_gcn.py
+++ b/test/python/sparse_gcn.py
@@ -2,7 +2,7 @@
import torch
-from mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
+from mpact.mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
class GraphConv(torch.nn.Module):
diff --git a/test/python/sparse_lif.py b/test/python/sparse_lif.py
index 5f57f32..d717af3 100644
--- a/test/python/sparse_lif.py
+++ b/test/python/sparse_lif.py
@@ -2,7 +2,7 @@
import torch
-from mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
+from mpact.mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
def spike(input):
diff --git a/test/python/spmv.py b/test/python/spmv.py
index cb0e491..29467e1 100644
--- a/test/python/spmv.py
+++ b/test/python/spmv.py
@@ -2,7 +2,7 @@
import torch
-from mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
+from mpact.mpactbackend import mpact_jit, mpact_jit_compile, mpact_jit_run
class SpMVNet(torch.nn.Module):
def forward(self, x, v):