Skip to content

Commit 7fd79ee

Browse files
authored
Merge pull request #1 from faasm/horovod-2
Add Horovod and MXNet
2 parents a8a9b7f + 85730af commit 7fd79ee

File tree

20 files changed

+513
-167
lines changed

20 files changed

+513
-167
lines changed

.gitmodules

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@
1313
[submodule "third-party/pyfaasm"]
1414
path = third-party/pyfaasm
1515
url = https://github.com/faasm/pyfaasm.git
16-
16+
[submodule "third-party/horovod"]
17+
path = third-party/horovod
18+
url = https://github.com/faasm/horovod
19+
branch = faasm
20+
[submodule "third-party/mxnet"]
21+
path = third-party/mxnet
22+
url = https://github.com/faasm/incubator-mxnet
23+
branch = faasm
24+
[submodule "third-party/libffi"]
25+
path = third-party/libffi
26+
url = https://github.com/faasm/libffi.git

README.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
This build cross-compiles CPython and a number of Python modules to WebAssembly
44
for use in [Faasm](https://github.com/faasm/faasm).
55

6-
You can see a list of the installed modules in the
7-
[`install_modules.sh`](scripts/install_modules.sh) script.
6+
You can try to install arbitrary packages, but the ones that definitely work
7+
can be listed with:
8+
9+
```bash
10+
inv libs.show
11+
```
812

913
The build uses the [Faasm
1014
toolchain](https://github.com/faasm/faasm-toolchain) to cross-compile both
@@ -44,15 +48,21 @@ compiling and the version on the build machine need to match _exactly_.
4448
To set up the relevant build machine python:
4549

4650
```
47-
cd ansible
48-
ansible-playbook python3_8.yml
51+
./bin/install_build_python.sh
4952
```
5053

5154
This will install Python at `/usr/local/faasm/python3.8`.
5255

5356
When cross-compiling we _have_ to use this Python when running commands and
5457
scripts on the build machine (not any other Python that might be installed).
5558

59+
### Upgrading Pip
60+
61+
Do **not** upgrade Pip in the build machine copy of Python.
62+
63+
The versions of Pip and Python for wasm and the build machine must match
64+
exactly.
65+
5666
### Building CPython to WebAssembly
5767

5868
You can build CPython by running (with optional `--clean`):
@@ -79,7 +89,7 @@ we use [crossenv](https://github.com/benfogle/crossenv).
7989
To set up crossenv:
8090

8191
```
82-
./scripts/crossenv_setup.sh
92+
./bin/crossenv_setup.sh
8393
```
8494

8595
You can then activate with:
@@ -91,7 +101,7 @@ You can then activate with:
91101
From inside the virtual environment, you can inspect the set-up with:
92102

93103
```
94-
python scripts/sanity_check.py | less
104+
python bin/sanity_check.py | less
95105
```
96106

97107
This will display the environment used to install Python modules (including the
@@ -105,18 +115,28 @@ environment:
105115

106116
- Modify the CPython build (see `tasks.py`)
107117
- Rerun the CPython build (`inv cpython --clean`)
108-
- Rebuild the crossenv (`./scripts/crossenv_setup.sh`)
109-
- Enter the crossenv and inspect the environment with `scripts/sanity_check.py`
118+
- Rebuild the crossenv (`./bin/crossenv_setup.sh`)
119+
- Enter the crossenv and inspect the environment with `bin/sanity_check.py`
110120

111121
## Modules
112122

113123
With the crossenv activated, we can build modules with normal `pip`.
114124

115-
To install all the modules, you can run:
125+
There is a wrapper script that will apply modifications if we know about them.
126+
To run this you must first have the cross-env activated as described above.
116127

117-
```
118-
# NOTE: run this from a clean terminal, _not_ through the Faasm CLI
119-
./scripts/install_modules.sh
128+
```bash
129+
# Install all supported modules
130+
inv libs.install
131+
132+
# Install experimental modules
133+
inv libs.install --experimental
134+
135+
# Install numpy
136+
inv libs.install --name numpy
137+
138+
# (Attempt) to install arbitrary module
139+
inv libs.install --name <module_name>
120140
```
121141

122142
Libraries will then be installed to
@@ -129,8 +149,52 @@ debugger.
129149

130150
You can also set `DISTUTILS_DEBUG=1` to get distutils to print more info.
131151

152+
## Experimental modules
153+
154+
Some of the modules are experimental, these may require some extra set-up.
155+
156+
### MXNet and Horovod
157+
158+
To install the Python MXNet module we first need to cross-compile the MXNet
159+
shared library:
160+
161+
```
162+
# Update all submodules
163+
cd third-party/mxnet
164+
git submodule update --init
165+
cd ../horovod
166+
git submodule update --init
167+
168+
# Run our MXNet cross-compile (outside crossenv)
169+
cd ../..
170+
inv mxnet
171+
```
172+
173+
Then we can install mxnet and horovod:
174+
175+
```
176+
. ./cross_venv/bin/activate
177+
inv libs.install --name mxnet
178+
inv libs.install --name horovod
179+
```
180+
181+
### Cleaning and uninstalling
182+
183+
```
184+
# Clean then rebuild
185+
inv mxnet --clean
186+
187+
# Uninstall mxnet
188+
inv mxnet.uninstall
189+
```
190+
132191
## Running in Faasm
133192

134193
See the [Faasm python
135194
docs](https://github.com/faasm/faasm/blob/master/docs/python.md).
136195

196+
## BLAS and LAPACK
197+
198+
Faasm's normal BLAS and LAPACK support using CLAPACK should be picked up by
199+
numpy due to the addition of the [site.cfg](../third-party/numpy/site.cfg).
200+

ansible/ansible.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

ansible/python3_8.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
PROJ_ROOT = dirname(dirname(abspath(__file__)))
88

9-
WASM_CPYTHON = join(PROJ_ROOT, "third-party", "cpython", "install", "wasm",
10-
"bin", "python3.8")
9+
WASM_CPYTHON = join(
10+
PROJ_ROOT, "third-party", "cpython", "install", "wasm", "bin", "python3.8"
11+
)
1112

1213
CROSSENV_VENV_DIR = join(PROJ_ROOT, "cross_venv")
1314
CROSSENV_SYSROOT = "/usr/local/faasm/llvm-sysroot"
@@ -21,19 +22,18 @@ def main():
2122

2223
# Set logging level
2324
level = logging.DEBUG
24-
logging.basicConfig(level=level, format='%(levelname)s: %(message)s')
25+
logging.basicConfig(level=level, format="%(levelname)s: %(message)s")
2526

2627
# Invoke the cross-env builder
2728
print("Building crossenv at {}".format(CROSSENV_VENV_DIR))
2829
builder = CrossEnvBuilder(
29-
with_cross_pip=True,
30-
with_build_pip=True,
3130
host_python=WASM_CPYTHON,
3231
host_sysroot=CROSSENV_SYSROOT,
32+
with_cross_pip=True,
33+
with_build_pip=True,
3334
)
3435
builder.create(CROSSENV_VENV_DIR)
3536

3637

3738
if __name__ == "__main__":
3839
main()
39-
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@ BUILD_PYTHON_BIN=/usr/local/faasm/python3.8/bin
1111
BUILD_PYTHON=${BUILD_PYTHON_BIN}/python3.8
1212
BUILD_PIP=${BUILD_PYTHON_BIN}/pip3.8
1313

14+
FAASM_DIR=/usr/local/code/faasm
15+
FAASMCLI=${FAASM_DIR}/faasmcli
16+
1417
# Install the build machine python dependencies
1518
CROSSENV_SRC_DIR=${PROJ_ROOT}/third-party/crossenv
1619
echo "Installing crossenv from ${CROSSENV_SRC_DIR}"
1720
pushd ${CROSSENV_SRC_DIR} >> /dev/null
1821
${BUILD_PIP} install -e .
22+
popd >> /dev/null
1923

2024
echo "Installing cython"
2125
${BUILD_PIP} install cython
22-
popd >> /dev/null
2326

24-
pushd ${PROJ_ROOT} >> /dev/null
27+
echo "Installing invoke"
28+
${BUILD_PIP} install invoke
29+
30+
echo "Installing Faasmcli"
31+
pushd ${FAASMCLI} >> /dev/null
32+
${BUILD_PIP} install .
33+
popd >> /dev/null
2534

2635
# Run the set-up script
27-
${BUILD_PYTHON} scripts/crossenv_setup.py
36+
pushd ${PROJ_ROOT} >> /dev/null
37+
${BUILD_PYTHON} bin/crossenv_setup.py
2838

2939
# Enter the env and print details
3040
source cross_venv/bin/activate
@@ -35,4 +45,3 @@ echo "python3.8 is: $(which python3.8)"
3545

3646
popd >> /dev/null
3747

38-

bin/install_build_python.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
PYTHON_VER=Python-3.8.2
6+
TAR_NAME=${PYTHON_VER}.tgz
7+
TAR_URL=https://www.python.org/ftp/python/3.8.2/${TAR_NAME}
8+
9+
INSTALL_PREFIX=/usr/local/faasm/python3.8
10+
PYTHON_BIN=${INSTALL_PREFIX}/bin/python3.8
11+
PIP_BIN=${INSTALL_PREFIX}/bin/pip3.8
12+
13+
N_PROC=$(nproc --ignore 1)
14+
15+
pushd /tmp/ >> /dev/null
16+
17+
# Download the TAR file and extract
18+
wget ${TAR_URL}
19+
tar -xf ${TAR_NAME}
20+
21+
# Configure and install
22+
pushd ${PYTHON_VER} >> /dev/null
23+
./configure --prefix=${INSTALL_PREFIX}
24+
make -j ${N_PROC} altinstall
25+
popd >> /dev/null
26+
27+
# Print version
28+
${PYTHON_BIN} --version
29+
${PIP_BIN} --version
30+
31+
popd >> /dev/null
32+
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ def main():
77
# Sysconfig checks
88
print("Platform: {}".format(sysconfig.get_platform()))
99
print("Python version: {}".format(sysconfig.get_python_version()))
10-
print("Current installation scheme: {}".format(
11-
sysconfig._get_default_scheme()))
10+
print(
11+
"Current installation scheme: {}".format(
12+
sysconfig._get_default_scheme()
13+
)
14+
)
1215
print("Paths")
1316
pprint(sysconfig.get_paths())
1417
print("Variables")

libffi.imports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ffi_call

scripts/install_modules.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)