From 5f3cf54b9b12ea47c8e0203b86888638a2fa7061 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Tue, 10 Dec 2024 09:12:47 +0000 Subject: [PATCH 1/6] Update backend_cuda with https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/277 --- .gitignore | 1 + CMakeLists.txt | 30 +++++++++++++-- aidge_backend_opencv/__init__.py | 2 +- include/aidge/backend/opencv.hpp | 5 ++- include/aidge/backend/version.h.in | 11 ++++++ .../utils/sys_info/OpencvVersionInfo.hpp | 38 +++++++++++++++++++ pyproject.toml | 17 ++++++--- python_binding/pybind_opencv.cpp | 4 +- .../sys_info/pybind_OpencvVersionInfo.cpp | 11 ++++++ setup.cfg | 3 ++ 10 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 include/aidge/backend/version.h.in create mode 100644 include/aidge/utils/sys_info/OpencvVersionInfo.hpp create mode 100644 python_binding/utils/sys_info/pybind_OpencvVersionInfo.cpp create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 81fde16..04377cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # C++ Build build*/ install*/ +include/aidge/backend/opencv_version.h # VSCode .vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index bfe4b03..efd9fb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,21 @@ set(CXX_STANDARD 14) file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version) +# Parse version.txt to retrieve Major, Minor and Path +string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" _ MATCHES ${version}) +set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2}) +set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3}) + +# Retrieve latest git commit +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + project(aidge_backend_opencv VERSION ${version} DESCRIPTION "Opencv implementations of the operators and tensor of aidge framework" @@ -10,8 +25,9 @@ project(aidge_backend_opencv message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") message(STATUS "Project version: ${version}") +message(STATUS "Latest git commit: ${GIT_COMMIT_HASH}") -# Note : project name is {project} and python module name is also {project} +# Note : project name is {project} and python module name is also {project} set(module_name _${CMAKE_PROJECT_NAME}) # target name ############################################## @@ -113,13 +129,19 @@ install(TARGETS ${module_name} EXPORT ${CMAKE_PROJECT_NAME}-targets install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -#Export the targets to a script +message(STATUS "Creating ${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/opencv_version.h") +# Generate version.h file from config file version.h.in +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/version.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/opencv_version.h" +) +#Export the targets to a script install(EXPORT ${CMAKE_PROJECT_NAME}-targets FILE "${CMAKE_PROJECT_NAME}-targets.cmake" DESTINATION ${INSTALL_CONFIGDIR} - COMPONENT ${module_name} -) + COMPONENT ${module_name} +) #Create a ConfigVersion.cmake file include(CMakePackageConfigHelpers) diff --git a/aidge_backend_opencv/__init__.py b/aidge_backend_opencv/__init__.py index 8900ab0..7ef3077 100644 --- a/aidge_backend_opencv/__init__.py +++ b/aidge_backend_opencv/__init__.py @@ -1,3 +1,3 @@ # Example 1: import .so generated by PyBind import aidge_core -from aidge_backend_opencv.aidge_backend_opencv import * +from aidge_backend_opencv.aidge_backend_opencv import * # import so generated by PyBind diff --git a/include/aidge/backend/opencv.hpp b/include/aidge/backend/opencv.hpp index 41f01a5..b854b69 100644 --- a/include/aidge/backend/opencv.hpp +++ b/include/aidge/backend/opencv.hpp @@ -12,10 +12,13 @@ #ifndef AIDGE_OPENCV_OPENCV_H_ #define AIDGE_OPENCV_OPENCV_H_ + +#include "aidge/backend/opencv_version.h" + #include "aidge/backend/opencv/data/DataUtils.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp" #include "aidge/backend/opencv/database/MNIST.hpp" #include "aidge/backend/opencv/stimuli/StimulusImpl_opencv_imread.hpp" #include "aidge/backend/opencv/utils/Utils.hpp" -#endif /* AIDGE_OPENCV_OPENCV_H_ */ \ No newline at end of file +#endif /* AIDGE_OPENCV_OPENCV_H_ */ diff --git a/include/aidge/backend/version.h.in b/include/aidge/backend/version.h.in new file mode 100644 index 0000000..4b876f6 --- /dev/null +++ b/include/aidge/backend/version.h.in @@ -0,0 +1,11 @@ +#ifndef VERSION_H +#define VERSION_H + +namespace Aidge { +static constexpr const int PROJECT_VERSION_MAJOR = @PROJECT_VERSION_MAJOR@; +static constexpr const int PROJECT_VERSION_MINOR = @PROJECT_VERSION_MINOR@; +static constexpr const int PROJECT_VERSION_PATCH = @PROJECT_VERSION_PATCH@; +static constexpr const char * PROJECT_VERSION = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"; +static constexpr const char * PROJECT_GIT_HASH = "@GIT_COMMIT_HASH@"; +} +#endif // VERSION_H diff --git a/include/aidge/utils/sys_info/OpencvVersionInfo.hpp b/include/aidge/utils/sys_info/OpencvVersionInfo.hpp new file mode 100644 index 0000000..4146d24 --- /dev/null +++ b/include/aidge/utils/sys_info/OpencvVersionInfo.hpp @@ -0,0 +1,38 @@ +#ifndef AIDGE_UTILS_SYS_INFO_OPENCV_VERSION_INFO_H +#define AIDGE_UTILS_SYS_INFO_OPENCV_VERSION_INFO_H + +#include "aidge/utils/Log.hpp" +#include "aidge/backend/opencv_version.h" + +namespace Aidge { + +constexpr inline const char * getBackendOpencvProjectVersion(){ + return PROJECT_VERSION; +} + +constexpr inline const char * getBackendOpencvGitHash(){ + return PROJECT_GIT_HASH; +} + +void showBackendOpencvVersion() { + Log::info("Aidge backend OpenCV: {} ({}), {} {}", getBackendOpencvProjectVersion(), getBackendOpencvGitHash(), __DATE__, __TIME__); + // Compiler version + #if defined(__clang__) + /* Clang/LLVM. ---------------------------------------------- */ + Log::info("Clang/LLVM compiler version: {}.{}.{}\n", __clang_major__ , __clang_minor__, __clang_patchlevel__); + #elif defined(__ICC) || defined(__INTEL_COMPILER) + /* Intel ICC/ICPC. ------------------------------------------ */ + Log::info("Intel ICC/ICPC compiler version: {}\n", __INTEL_COMPILER); + #elif defined(__GNUC__) || defined(__GNUG__) + /* GNU GCC/G++. --------------------------------------------- */ + Log::info("GNU GCC/G++ compiler version: {}.{}.{}", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + #elif defined(_MSC_VER) + /* Microsoft Visual Studio. --------------------------------- */ + Log::info("Microsoft Visual Studio compiler version: {}\n", _MSC_VER); + #else + Log::info("Unknown compiler\n"); + #endif + +} +} // namespace Aidge +#endif // AIDGE_UTILS_SYS_INFO_OPENCV_VERSION_INFO_H diff --git a/pyproject.toml b/pyproject.toml index 485d231..248df13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,21 +5,28 @@ dependencies = [ "numpy>=1.21.6", ] requires-python = ">= 3.7" -dynamic = ["version"] # defined in tool.setuptools_scm +dynamic = ["version"] # defined by pbr readme = "README.md" license = { file = "LICENSE" } -classifiers = [ +classifiers = [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python :: 3" ] +[project.urls] +Homepage = "https://www.deepgreen.ai/en/platform" +Documentation = "https://eclipse-aidge.readthedocs.io/en/latest/" +Repository = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_opencv" +Issues = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_opencv/-/issues/" +Changelog = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_opencv/-/releases" + [build-system] requires = [ "setuptools>=64", - "setuptools_scm[toml]==7.1.0", "cmake>=3.15.3.post1", "toml", "opencv-python>=4.9.0.80", + "pbr" ] build-backend = "setuptools.build_meta" @@ -31,9 +38,7 @@ where = ["."] # list of folders that contain the packages (["."] by default) include = ["aidge_backend_opencv*"] # package names should match these glob patterns (["*"] by default) exclude = ["aidge_backend_opencv.unit_tests*"] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) -# SETUPTOOLS_SCM -[tool.setuptools_scm] -write_to = "aidge_backend_opencv/_version.py" + ##################################################### # CIBUILDWHEEL diff --git a/python_binding/pybind_opencv.cpp b/python_binding/pybind_opencv.cpp index 276467d..6c6a7c1 100644 --- a/python_binding/pybind_opencv.cpp +++ b/python_binding/pybind_opencv.cpp @@ -1,14 +1,16 @@ #include <pybind11/pybind11.h> // Need to call this header to register tensorImpl when initializing opencv python module -#include "aidge/backend/opencv.hpp" +#include "aidge/backend/opencv.hpp" namespace py = pybind11; namespace Aidge { void init_MNIST(py::module&); +void init_OpencvVersionInfo(py::module&); PYBIND11_MODULE(aidge_backend_opencv, m) { init_MNIST(m); + init_OpencvVersionInfo(m); } } diff --git a/python_binding/utils/sys_info/pybind_OpencvVersionInfo.cpp b/python_binding/utils/sys_info/pybind_OpencvVersionInfo.cpp new file mode 100644 index 0000000..ebd9bfc --- /dev/null +++ b/python_binding/utils/sys_info/pybind_OpencvVersionInfo.cpp @@ -0,0 +1,11 @@ +#include <pybind11/pybind11.h> +#include "aidge/utils/sys_info/OpencvVersionInfo.hpp" + +namespace py = pybind11; +namespace Aidge { +void init_OpencvVersionInfo(py::module& m){ + m.def("show_version", &showBackendOpencvVersion); + m.def("get_project_version", &getBackendOpencvProjectVersion); + m.def("get_git_hash", &getBackendOpencvGitHash); +} +} diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..aa0f227 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +# pbr file +[metadata] +version = file: version.txt -- GitLab From 38b22658906216f2d610e71d01b425e338a20811 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Wed, 29 Jan 2025 23:47:46 +0000 Subject: [PATCH 2/6] FEAT: unit-tests/CMakeLists.txt add minimum version for Catch2 --- unit_tests/CMakeLists.txt | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 91a55da..d42626e 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -1,12 +1,23 @@ -Include(FetchContent) +# Catch2 configuration +set(CATCH2_MIN_VERSION 3.3.0) -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.7.1 # or a later release -) +# Try to find system installed Catch2 +find_package(Catch2 ${CATCH2_MIN_VERSION} QUIET) -FetchContent_MakeAvailable(Catch2) +if(NOT Catch2_FOUND) + message(STATUS "Catch2 not found in system, retrieving from git") + Include(FetchContent) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG devel # or a later release + ) + FetchContent_MakeAvailable(Catch2) + message(STATUS "Fetched Catch2 version ${Catch2_VERSION}") +else() + message(STATUS "Using system Catch2 version ${Catch2_VERSION}") +endif() file(GLOB_RECURSE src_files "*.cpp") @@ -16,7 +27,13 @@ target_link_libraries(tests${module_name} PUBLIC ${module_name}) target_link_libraries(tests${module_name} PRIVATE Catch2::Catch2WithMain) +# Setup testing list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) include(CTest) include(Catch) + +# Discover and add tests catch_discover_tests(tests${module_name}) + +# Set test configuration for CTest +set(CTEST_CONFIGURATION_TYPE ${CMAKE_BUILD_TYPE}) \ No newline at end of file -- GitLab From 2002a73ab7e090db080d9dd815f321a4ccc1a4f5 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Tue, 28 Jan 2025 16:19:39 +0000 Subject: [PATCH 3/6] Enforce C++-14 in 'CMakeLists.txt' --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efd9fb3..c96a470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.18) -set(CXX_STANDARD 14) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version) -- GitLab From 78bfbf3e17334b4b3d5260f053709cb023f877af Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Tue, 28 Jan 2025 16:19:52 +0000 Subject: [PATCH 4/6] Change Python minimum version 3.7 -> 3.8 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 248df13..d0176c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ description="Opencv implementations of the operators and tensor of aidge framewo dependencies = [ "numpy>=1.21.6", ] -requires-python = ">= 3.7" +requires-python = ">= 3.8" dynamic = ["version"] # defined by pbr readme = "README.md" license = { file = "LICENSE" } -- GitLab From ee203a5b82f6403ff7cb2c04b5dec451a4ebc227 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Tue, 28 Jan 2025 16:21:31 +0000 Subject: [PATCH 5/6] UPD: 'setup.py' to access compilation options from environment variables set by 'setup.sh' --- setup.py | 73 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/setup.py b/setup.py index 1af040b..6e8ed89 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ class CMakeBuild(build_ext): # 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)) + max_jobs = os.environ.get("AIDGE_NB_PROC", max_jobs) cwd = pathlib.Path().absolute() @@ -41,49 +42,61 @@ class CMakeBuild(build_ext): 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 - python_executable = sys.executable - print(f"python executable :\t{python_executable}") - compile_type = ( - "Release" - if "AIDGE_PYTHON_BUILD_TYPE" not in os.environ - else os.environ["AIDGE_PYTHON_BUILD_TYPE"] - ) - install_path = ( os.path.join(sys.prefix, "lib", "libAidge") if "AIDGE_INSTALL" not in os.environ else os.environ["AIDGE_INSTALL"] ) - build_gen = ( - ["-G", os.environ["AIDGE_BUILD_GEN"]] - if "AIDGE_BUILD_GEN" in os.environ + os.chdir(str(build_temp)) + + # Impose to use the executable of the python + # used to launch setup.py to setup PythonInterp + python_executable = sys.executable + print(f"python executable :\t{python_executable}") + # Read environment variables for CMake options + c_compiler = os.environ.get("AIDGE_C_COMPILER", "gcc") + cxx_compiler = os.environ.get("AIDGE_CXX_COMPILER", "g++") + build_type = os.environ.get("AIDGE_BUILD_TYPE", "Release") + asan = os.environ.get("AIDGE_ASAN", "OFF") + cmake_arch = os.environ.get("AIDGE_CMAKE_ARCH", "") + + build_gen = os.environ.get("AIDGE_BUILD_GEN", "") + build_gen_opts = ( + ["-G", build_gen] + if build_gen else [] ) + test_onoff = os.environ.get("AIDGE_BUILD_TEST", "OFF") - self.spawn( - [ - "cmake", - *build_gen, - str(cwd), - "-DTEST=OFF", - f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}", - f"-DCMAKE_BUILD_TYPE={compile_type}", - "-DPYBIND=ON", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCOVERAGE=OFF", - ] - ) + os.chdir(str(build_temp)) + + cmake_cmd = [ + "cmake", + *build_gen_opts, + str(cwd), + f"-DTEST={test_onoff}", + f"-DCMAKE_INSTALL_PREFIX:PATH={install_path}", + f"-DCMAKE_BUILD_TYPE={build_type}", + f"-DCMAKE_C_COMPILER={c_compiler}", + f"-DCMAKE_CXX_COMPILER={cxx_compiler}", + f"-DENABLE_ASAN={asan}", + "-DPYBIND=ON", + "-DCMAKE_EXPORT_COMPILE_COMMANDS=1", + "-DCOVERAGE=OFF", + ] + + # Append architecture-specific arguments if provided + if cmake_arch: + cmake_cmd.append(cmake_arch) + + self.spawn(cmake_cmd) if not self.dry_run: self.spawn( - ["cmake", "--build", ".", "--config", compile_type, "-j", max_jobs] + ["cmake", "--build", ".", "--config", build_type, "-j", max_jobs] ) - self.spawn(["cmake", "--install", ".", "--config", compile_type]) + self.spawn(["cmake", "--install", ".", "--config", build_type]) os.chdir(str(cwd)) aidge_package = build_lib / (get_project_name()) -- GitLab From 6fe5f273ad47f8c803fdabbd7a431e4110d3056b Mon Sep 17 00:00:00 2001 From: Maxence Naud <maxence.naud@cea.fr> Date: Fri, 31 Jan 2025 17:21:04 +0000 Subject: [PATCH 6/6] update version 0.1.4 -> 0.1.5 --- CHANGELOG | 6 ++++++ version.txt | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 55c85a0..97e6a77 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +# Version 0.1.5 (January 31, 2024) + +- Enforce C++14 in 'CMakeLists.txt' +- Remove scm dependency to check versions compatibility +- Change 'setup.py' to use more environment variables in its build process + # Version 0.1.4 (December 6, 2024) # Version 0.0.1 (January 23, 2024) diff --git a/version.txt b/version.txt index 845639e..9faa1b7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.4 +0.1.5 -- GitLab