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
pull/377/head
Stella Laurenzo 2021-10-21 21:18:08 -07:00
parent 92ae692387
commit a23d77100b
5 changed files with 32 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.code-workspace *.code-workspace
.ipynb_checkpoints .ipynb_checkpoints
*.venv/ *.venv/
mlir_venv/
/build/ /build/
__pycache__ __pycache__

View File

@ -46,8 +46,8 @@ python -m venv mlir_venv
source mlir_venv/bin/activate source mlir_venv/bin/activate
# Some older pip installs may not be able to handle the recent PyTorch deps # Some older pip installs may not be able to handle the recent PyTorch deps
python -m pip install --upgrade pip python -m pip install --upgrade pip
# Install latest PyTorch nightlies # Install latest PyTorch nightlies and build requirements.
python -m pip install --pre torch torchvision pybind11 -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html python -m pip install -r requirements.txt
``` ```
## Build ## Build
@ -178,3 +178,14 @@ manually `source`'d in a shell.
- `#torch-mlir` channel on the LLVM [Discord](https://discord.gg/xS7Z362) - `#torch-mlir` channel on the LLVM [Discord](https://discord.gg/xS7Z362)
- Issues [here](https://github.com/llvm/torch-mlir/issues) - Issues [here](https://github.com/llvm/torch-mlir/issues)
- [`torch-mlir` section](https://llvm.discourse.group/c/projects-that-want-to-become-official-llvm-projects/torch-mlir/41) of LLVM Discourse - [`torch-mlir` section](https://llvm.discourse.group/c/projects-that-want-to-become-official-llvm-projects/torch-mlir/41) of LLVM Discourse
## Build Python Packages
We have preliminary support for building Python packages. This can be done
with the following commands:
```
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
CMAKE_GENERATOR=Ninja python setup.py bdist_wheel
```

View File

@ -1,5 +1,9 @@
include(AddMLIRPython) include(AddMLIRPython)
# Disables generation of "version soname" (i.e. libFoo.so.<version>), which
# causes pure duplication as part of Python wheels.
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON)
# The directory at which the Python import tree begins. # The directory at which the Python import tree begins.
# See documentation for `declare_mlir_python_sources`'s ROOT_DIR # See documentation for `declare_mlir_python_sources`'s ROOT_DIR
# argument. # argument.

10
requirements.txt 100644
View File

@ -0,0 +1,10 @@
-f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
--pre
numpy
torch
torchvision
# Build requirements.
pybind11
wheel

View File

@ -64,6 +64,10 @@ class CMakeBuild(build_py):
f"-DLLVM_ENABLE_PROJECTS=mlir", f"-DLLVM_ENABLE_PROJECTS=mlir",
f"-DLLVM_EXTERNAL_PROJECTS=torch-mlir", f"-DLLVM_EXTERNAL_PROJECTS=torch-mlir",
f"-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR={src_dir}", f"-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR={src_dir}",
# Optimization options for building wheels.
f"-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON",
f"-DCMAKE_C_VISIBILITY_PRESET=hidden",
f"-DCMAKE_CXX_VISIBILITY_PRESET=hidden",
] ]
os.makedirs(cmake_build_dir, exist_ok=True) os.makedirs(cmake_build_dir, exist_ok=True)
cmake_cache_file = os.path.join(cmake_build_dir, "CMakeCache.txt") cmake_cache_file = os.path.join(cmake_build_dir, "CMakeCache.txt")