From 04632556f86a7d83948b468f878e7b86878cc320 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Tue, 10 Dec 2024 09:12:47 +0000 Subject: [PATCH] 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 +++++++++++++++++++ python_binding/pybind_opencv.cpp | 4 +- .../sys_info/pybind_OpencvVersionInfo.cpp | 11 ++++++ 8 files changed, 95 insertions(+), 7 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 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 e27b11e..07cb6bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,21 @@ cmake_minimum_required(VERSION 3.15) 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" @@ -9,8 +24,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 ############################################## @@ -104,13 +120,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/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); +} +} -- GitLab