diff --git a/Makefile.common b/Makefile.common index cbc178c5..3d682513 100644 --- a/Makefile.common +++ b/Makefile.common @@ -23,21 +23,20 @@ # UNAME_M := $(shell uname -m) -ifeq (, $(shell which python3 )) + +PYTHON=$(shell which python3) +ifeq (, $(PYTHON) ) $(error "python3 not found in $(PATH)") endif -PYVER=$(shell python3 -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)") - CC=/usr/bin/clang++-8 LD=/usr/bin/ld -PYTHON=/usr/bin/python$(PYVER) SWIG=/usr/bin/swig ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) EIGEN_INCLUDES=-isystem $(ROOT_DIR)/packages/eigen-eigen-323c052e1731 DNNC_INCLUDES= -I$(ROOT_DIR)/include -PY_INCLUDES= -I$(wildcard /usr/include/python$(PYVER)*) +PY_INCLUDES= -I$(shell python3 -c "from sysconfig import get_paths as gp; print(gp()['include'])") LD_FLAGS=-shared CPP_FLAGS=-O3 -Wall -std=c++17 -fPIC -march=native diff --git a/setup.py b/setup.py index 38cc9c0e..3dd25abe 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@ # how to run this script: python setup.py bdist_wheel -# hot to test install: python -m pip install ~/dnnc/master/dnnCompiler/dist/dnnc-0.1-py3-none-any.whl --root pip_install_test -# reference: https://dzone.com/articles/executable-package-pip-install +# how to test install: python -m pip install ~/dnnc/master/dnnCompiler/dist/dnnc-0.1-py3-none-any.whl --root pip_install_test import os, sys, glob -import shutil, errno +import shutil, errno, subprocess, multiprocessing import setuptools + NAME='deepC' VERSION=0.12 @@ -20,6 +20,26 @@ def is_pure(self): def has_ext_modules(self): return True; +from setuptools.command.build_ext import build_ext as buildext +class make_build(setuptools.Command): + + def initialize_options(self): + self.jobs = multiprocessing.cpu_count() + + def finalize_options(self): + self.jobs = int(self.jobs) + + def run(self): + cmd = "make CC=g++ SRC -j " + str(self.jobs) + subprocess.call(cmd, shell=True) + cmd = "make CC=g++ all " + subprocess.call(cmd, shell=True) + +class build_ext(buildext): + def run(self): + self.run_command('make_build') + + #create the links to src dir inside deepC for proper installation. def link_dir(dir_name): try: @@ -41,13 +61,26 @@ def source_files(directory): paths.append(os.path.join(path, filename)) return paths +cmdclass = { + 'make_build': make_build, + 'build_ext': build_ext, +} + +ext_modules = [ + setuptools.Extension( + name=str(NAME+".dnnc"), + sources=[ + str(source_files('include')) + + str(source_files('packages')) + ]) +] + packages = setuptools.find_packages() tests_require = [] tests_require.append('unittest') install_requires = [] install_requires.extend([ - 'numpy>=1.16.1', 'onnx==1.5.0', ]) @@ -58,6 +91,8 @@ def source_files(directory): long_description_content_type="text/markdown", long_description=long_description, packages=packages, + ext_modules=ext_modules, + cmdclass=cmdclass, include_package_data=True, package_data={'':['_dnnc.so'] + source_files('include') +