Skip to content

Commit a23d771

Browse files
Set some wheel building optimization options.
* Also adds a requirements.txt and updates docs to reference it versus stringy pip install. * Adds doc with instructions on creating a wheel. Fixes #370
1 parent 92ae692 commit a23d771

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.code-workspace
55
.ipynb_checkpoints
66
*.venv/
7+
mlir_venv/
78

89
/build/
910
__pycache__

Diff for: README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ python -m venv mlir_venv
4646
source mlir_venv/bin/activate
4747
# Some older pip installs may not be able to handle the recent PyTorch deps
4848
python -m pip install --upgrade pip
49-
# Install latest PyTorch nightlies
50-
python -m pip install --pre torch torchvision pybind11 -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
49+
# Install latest PyTorch nightlies and build requirements.
50+
python -m pip install -r requirements.txt
5151
```
5252

5353
## Build
@@ -178,3 +178,14 @@ manually `source`'d in a shell.
178178
- `#torch-mlir` channel on the LLVM [Discord](https://discord.gg/xS7Z362)
179179
- Issues [here](https://github.com/llvm/torch-mlir/issues)
180180
- [`torch-mlir` section](https://llvm.discourse.group/c/projects-that-want-to-become-official-llvm-projects/torch-mlir/41) of LLVM Discourse
181+
182+
## Build Python Packages
183+
184+
We have preliminary support for building Python packages. This can be done
185+
with the following commands:
186+
187+
```
188+
python -m pip install --upgrade pip
189+
python -m pip install -r requirements.txt
190+
CMAKE_GENERATOR=Ninja python setup.py bdist_wheel
191+
```

Diff for: python/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include(AddMLIRPython)
22

3+
# Disables generation of "version soname" (i.e. libFoo.so.<version>), which
4+
# causes pure duplication as part of Python wheels.
5+
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON)
6+
37
# The directory at which the Python import tree begins.
48
# See documentation for `declare_mlir_python_sources`'s ROOT_DIR
59
# argument.

Diff for: requirements.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
2+
--pre
3+
4+
numpy
5+
torch
6+
torchvision
7+
8+
# Build requirements.
9+
pybind11
10+
wheel

Diff for: setup.py

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def run(self):
6464
f"-DLLVM_ENABLE_PROJECTS=mlir",
6565
f"-DLLVM_EXTERNAL_PROJECTS=torch-mlir",
6666
f"-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR={src_dir}",
67+
# Optimization options for building wheels.
68+
f"-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON",
69+
f"-DCMAKE_C_VISIBILITY_PRESET=hidden",
70+
f"-DCMAKE_CXX_VISIBILITY_PRESET=hidden",
6771
]
6872
os.makedirs(cmake_build_dir, exist_ok=True)
6973
cmake_cache_file = os.path.join(cmake_build_dir, "CMakeCache.txt")

0 commit comments

Comments
 (0)