diff --git a/.gitignore b/.gitignore index 9fbfccca6dfda997d8a0dbfc4b373590feeecad8..f37378e300efeb5362882eb8d6eb59f028563a0e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ install*/ __pycache__ *.pyc *.egg-info +dist*/ # Mermaid *.mmd diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a033be8453876643e5c802ccca2b4d33ffe29b..d973a04ec5136347c3ddc7fc92989e65b0f34a42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,15 @@ cmake_minimum_required(VERSION 3.15) -set(project aidge_backend_cpu) # This will also be python module name -set(module_name _${project}) # target name -set(version 2.0.0) +file(READ "${CMAKE_SOURCE_DIR}/version.txt" version) +file(READ "${CMAKE_SOURCE_DIR}/project_name.txt" project) + +message(STATUS "Project name: ${project}") +message(STATUS "Project version: ${version}") + +# Note : project name is {project} and python module name is also {project} +set(module_name _${project}) # target name + project(${project}) ############################################## diff --git a/README.md b/README.md index a4eb6a153aa225b939af46fad12fd016c9506ab8..0a0fe37f8672fde09055d3356951579bd1b56d6c 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,19 @@ So far be sure to have the correct requirements to use this library - GCC - Make - CMake +- aidge_core - Python (optional, if you have no intend to use this library in python with pybind) +## Pip installation -## Compilation +You will need to install first the aidge_core library before installing aidge_cpu. +Also, make sure that the install path was set before installing aidge_core library. +Then run in your python environnement : +``` bash +pip install . -v +``` + +## Standard C++ Compilation You will need to compile first the Core library before compiling the CPU one. The makefile is designed to do it for you. diff --git a/aidge_backend_cpu/__init__.py b/aidge_backend_cpu/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8f18440daf33134718273b4b3fdd4d99039b6ddf --- /dev/null +++ b/aidge_backend_cpu/__init__.py @@ -0,0 +1 @@ +from aidge_backend_cpu.aidge_backend_cpu import * # import so generated by PyBind \ No newline at end of file diff --git a/project_name.txt b/project_name.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8a086fc063978638db5a0fcfe1dc2e5c9d0c1b7 --- /dev/null +++ b/project_name.txt @@ -0,0 +1 @@ +aidge_backend_cpu \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..0b0f66e9132d66cdb6385d7f8c6c69ae0cc5d0e3 --- /dev/null +++ b/setup.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +""" Aidge + +#TODO To change +POC of the next framework named Aidge +""" + +DOCLINES = (__doc__ or '').split("\n") + +import sys +import os + +# Python supported version checks +if sys.version_info[:2] < (3, 7): + raise RuntimeError("Python version >= 3.7 required.") + + +CLASSIFIERS = """\ +Development Status :: 2 - Pre-Alpha +""" + +import shutil +import pathlib +import subprocess +import multiprocessing + +from math import ceil + +from setuptools import setup, Extension +from setuptools import find_packages +from setuptools.command.build_ext import build_ext + +def get_project_name() -> str: + return open(pathlib.Path().absolute() / "project_name.txt", "r").read() + +def get_project_version() -> str: + aidge_root = pathlib.Path().absolute() + version = open(aidge_root / "version.txt", "r").read().strip() + return version + + +class CMakeExtension(Extension): + def __init__(self, name): + super().__init__(name, sources=[]) + +class CMakeBuild(build_ext): + + def run(self): + # This lists the number of processors available on the machine + # The compilation will use half of them + max_jobs = str(ceil(multiprocessing.cpu_count() / 2)) + + cwd = pathlib.Path().absolute() + + build_temp = cwd / "build" + if not build_temp.exists(): + build_temp.mkdir(parents=True, exist_ok=True) + + build_lib = pathlib.Path(self.build_lib) + if not build_lib.exists(): + build_lib.mkdir(parents=True, exist_ok=True) + + os.chdir(str(build_temp)) + + # Impose to use the executable of the python + # used to launch setup.py to setup PythonInterp + param_py = "-DPYTHON_EXECUTABLE=" + sys.executable + + install_path = f"{build_temp}/install" if "AIDGE_INSTALL" not in os.environ else os.environ["AIDGE_INSTALL"] + + self.spawn(['cmake', str(cwd), param_py, '-DTEST=OFF', f'-DCMAKE_INSTALL_PREFIX:PATH={install_path}']) + if not self.dry_run: + self.spawn(['make', 'all', 'install', '-j', max_jobs]) + os.chdir(str(cwd)) + + aidge_package = build_lib / (get_project_name()) + + # Get "aidge core" package + # ext_lib = build_temp + print(build_temp.absolute()) + # Copy all shared object files from build_temp/lib to aidge_package + for root, _, files in os.walk(build_temp.absolute()): + for file in files: + if file.endswith('.so') and (root != str(aidge_package.absolute())): + currentFile=os.path.join(root, file) + shutil.copy(currentFile, str(aidge_package.absolute())) + + # Copy version.txt in aidge_package + os.chdir(os.path.dirname(__file__)) + shutil.copy("version.txt", str(aidge_package.absolute())) + + +if __name__ == '__main__': + + setup( + name=get_project_name(), + version=get_project_version(), + python_requires='>=3.7', + description=DOCLINES[0], + long_description_content_type="text/markdown", + long_description="\n".join(DOCLINES[2:]), + classifiers=[c for c in CLASSIFIERS.split('\n') if c], + platforms=["Linux"], + packages=find_packages(where="."), + include_package_data=True, + ext_modules=[CMakeExtension(get_project_name())], + cmdclass={ + 'build_ext': CMakeBuild, + }, + zip_safe=False, + + )