forked from microsoft/mscclpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] switch to setup.py to build package
- Loading branch information
Crutcher Dunnavant
committed
Apr 12, 2023
1 parent
516349c
commit d9077e5
Showing
10 changed files
with
135 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
.vscode/ | ||
.hypothesis/ | ||
build/ | ||
dist/ | ||
__pycache__ | ||
.*.swp | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,30 @@ | ||
# Python bindings | ||
|
||
Test instructions: | ||
* Compile the `libmscclpp.so` library. | ||
* Install `cmake` verion >= 3.18 | ||
* setup a python virtual env | ||
* `pip install -r requirements.txt` | ||
* `./tesh.sh` | ||
|
||
Rough build attemtps | ||
``` | ||
# cd to this directory: | ||
# setup/enter pyenv environment for python 3.9 | ||
# install nanabind and the test requirements. | ||
pip install -r requirements.txt | ||
# setup and build the CMake environments. | ||
# this requires nanobind, installed above. | ||
./setup.sh | ||
# test the module | ||
pytest build/mscclpp | ||
``` | ||
* Compile the `libmscclpp.so` library. | ||
* Install `cmake` verion >= 3.18 | ||
* setup a python virtual env | ||
* `pip install -r dev-requirements.txt` | ||
* `./tesh.sh` | ||
|
||
## Run CI: | ||
|
||
## Installing `gdrcopy` and `mpi` | ||
This assumes that some things are built/installed | ||
```bash | ||
./ci.sh | ||
``` | ||
# assumes WORKDIR has: | ||
# git clone [email protected]/NVIDIA/gdrcopy.git | ||
# git clone [email protected]:microsoft/mscclpp.git | ||
uname -r | ||
# 5.4.0-1090-azure | ||
# install | ||
|
||
# break /usr/sbin/policy-rc.d so we can install modules | ||
echo '#!/bin/sh | ||
exit 0' > /usr/sbin/policy-rc.d | ||
## Build a wheel: | ||
|
||
apt update | ||
apt install -y \ | ||
build-essential devscripts debhelper check \ | ||
libsubunit-dev fakeroot pkg-config dkms \ | ||
linux-headers-5.4.0-1090-azure | ||
apt install -y nvidia-dkms-525-server | ||
Setup dev environment, then: | ||
|
||
```bash | ||
python setup.py bdist_wheel | ||
``` | ||
|
||
cd $WORKDIR/gdrcopy | ||
sed -i 's/\(-L \$(CUDA)\/lib64\)/\1 \1\/stubs/' tests/Makefile | ||
cd packages | ||
CUDA=/usr/local/cuda ./build-deb-packages.sh | ||
dpkg -i gdrdrv-dkms_2.3-1_amd64.Ubuntu20_04.deb | ||
dpkg -i libgdrapi_2.3-1_amd64.Ubuntu20_04.deb | ||
dpkg -i gdrcopy-tests_2.3-1_amd64.Ubuntu20_04+cuda11.6.deb | ||
dpkg -i gdrcopy_2.3-1_amd64.Ubuntu20_04.deb | ||
# validate: | ||
# $ sanity | ||
# Running suite(s): Sanity | ||
# 100%: Checks: 27, Failures: 0, Errors: 0 | ||
# dkms install -m gdrdrv/2.3 | ||
cd $WORKDIR/mscclpp | ||
## Installing mpi and numa libs. | ||
|
||
``` | ||
## numctl | ||
apt install -y numactl libnuma-dev libnuma1 | ||
# if not mpi testing | ||
USE_MPI_FOR_TESTS=0 make -j | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ PyHamcrest | |
nanobind | ||
|
||
torch | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import shutil | ||
import sys | ||
import logging | ||
from setuptools import Extension, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
import subprocess | ||
|
||
THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
class CustomExt(Extension): | ||
def __init__(self, name): | ||
# don't invoke the original build_ext for this special extension | ||
super().__init__(name, sources=[]) | ||
|
||
|
||
class custom_build_ext(build_ext): | ||
def run(self): | ||
for ext in self.extensions: | ||
if isinstance(ext, CustomExt): | ||
self.build_extension(ext) | ||
else: | ||
super().run() | ||
|
||
def build_extension(self, ext): | ||
if sys.platform == "darwin": | ||
return | ||
|
||
# these dirs will be created in build_py, so if you don't have | ||
# any python sources to bundle, the dirs will be missing | ||
build_temp = os.path.abspath(self.build_temp) | ||
os.makedirs(build_temp, exist_ok=True) | ||
|
||
try: | ||
subprocess.check_output( | ||
["cmake", "-S", THIS_DIR, "-B", build_temp], | ||
stderr=subprocess.STDOUT, | ||
) | ||
subprocess.check_output( | ||
["cmake", "--build", build_temp], | ||
stderr=subprocess.STDOUT, | ||
) | ||
except subprocess.CalledProcessError as e: | ||
logging.error(e.output.decode()) | ||
raise | ||
|
||
libname = os.path.basename(self.get_ext_fullpath(ext.name)) | ||
|
||
target_dir = os.path.join( | ||
os.path.dirname(self.get_ext_fullpath(ext.name)), | ||
"mscclpp", | ||
) | ||
|
||
shutil.copy( | ||
os.path.join(build_temp, "libmscclpp.so"), | ||
target_dir, | ||
) | ||
|
||
shutil.copy( | ||
os.path.join(build_temp, libname), | ||
target_dir, | ||
) | ||
|
||
|
||
setup( | ||
name='mscclpp', | ||
version='0.1.0', | ||
description='Python bindings for mscclpp', | ||
# packages=['mscclpp'], | ||
package_dir={'': 'src'}, | ||
packages=find_packages(where='./src'), | ||
ext_modules=[CustomExt('_py_mscclpp')], | ||
cmdclass={ | ||
"build_ext": custom_build_ext, | ||
}, | ||
install_requires=[ | ||
'torch', | ||
'nanobind', | ||
], | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Python in-place installs move the .so files into the source directories. | ||
*.so |