From bce6116c4cc6d7bf47119c3777c49d2eb368a12a Mon Sep 17 00:00:00 2001 From: hrouis <houssemeddine.rouis92@gmail.com> Date: Fri, 13 Dec 2024 18:16:35 +0100 Subject: [PATCH 01/11] fix:cast pointers for cudaMalloc in cuda tests --- unit_tests/loss/classification/Test_BCE.cpp | 6 +++--- unit_tests/loss/regression/Test_MSE.cpp | 6 +++--- unit_tests/metrics/Test_Accuracy.cpp | 4 ++-- unit_tests/optimizer/Test_Adam.cpp | 8 ++++---- unit_tests/optimizer/Test_SGD.cpp | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/unit_tests/loss/classification/Test_BCE.cpp b/unit_tests/loss/classification/Test_BCE.cpp index cbcdc80..6e7e200 100644 --- a/unit_tests/loss/classification/Test_BCE.cpp +++ b/unit_tests/loss/classification/Test_BCE.cpp @@ -112,7 +112,7 @@ TEST_CASE("[loss/classification] BCE", "[loss][classification][BCE]") { pred[i] = valueDist(gen); } float * d_pred; - cudaMalloc(&d_pred, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_pred), nb_elements * sizeof(float)); cudaMemcpy(d_pred, pred.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); // create random targets @@ -121,7 +121,7 @@ TEST_CASE("[loss/classification] BCE", "[loss][classification][BCE]") { targ[i] = valueDist(gen); } float * d_targ; - cudaMalloc(&d_targ, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_targ), nb_elements * sizeof(float)); cudaMemcpy(d_targ, targ.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); // compute the BCE manually @@ -132,7 +132,7 @@ TEST_CASE("[loss/classification] BCE", "[loss][classification][BCE]") { tmp_res_manual[i] = - ((targ[i] + eps1) * std::log(pred[i] + eps1) + (1.0f - targ[i] + eps2) * std::log(1.0f - pred[i] + eps2)); } float * d_tmp_res_manual; - cudaMalloc(&d_tmp_res_manual, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_tmp_res_manual), nb_elements * sizeof(float)); cudaMemcpy(d_tmp_res_manual, tmp_res_manual.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); std::shared_ptr<Tensor> tmp_tensor = std::make_shared<Tensor>(dims); diff --git a/unit_tests/loss/regression/Test_MSE.cpp b/unit_tests/loss/regression/Test_MSE.cpp index c0ecd4d..d551479 100644 --- a/unit_tests/loss/regression/Test_MSE.cpp +++ b/unit_tests/loss/regression/Test_MSE.cpp @@ -112,7 +112,7 @@ TEST_CASE("[loss/regression] MSE", "[loss][regression][MSE]") { pred[i] = valueDist(gen); } float * d_pred; - cudaMalloc(&d_pred, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_pred), nb_elements * sizeof(float)); cudaMemcpy(d_pred, pred.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); // create random targets @@ -121,7 +121,7 @@ TEST_CASE("[loss/regression] MSE", "[loss][regression][MSE]") { targ[i] = valueDist(gen); } float * d_targ; - cudaMalloc(&d_targ, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_targ), nb_elements * sizeof(float)); cudaMemcpy(d_targ, targ.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); // compute the MSE manually @@ -130,7 +130,7 @@ TEST_CASE("[loss/regression] MSE", "[loss][regression][MSE]") { tmp_res_manual[i] = std::pow(pred[i] - targ[i],2); } float * d_tmp_res_manual; - cudaMalloc(&d_tmp_res_manual, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_tmp_res_manual), nb_elements * sizeof(float)); cudaMemcpy(d_tmp_res_manual, tmp_res_manual.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); std::shared_ptr<Tensor> tmp_tensor = std::make_shared<Tensor>(dims); diff --git a/unit_tests/metrics/Test_Accuracy.cpp b/unit_tests/metrics/Test_Accuracy.cpp index fa33bd5..f598255 100644 --- a/unit_tests/metrics/Test_Accuracy.cpp +++ b/unit_tests/metrics/Test_Accuracy.cpp @@ -122,7 +122,7 @@ TEST_CASE("[metrics] Accuracy", "[metrics][Accuracy]") { pred[i] = valueDist(gen); } float * d_pred; - cudaMalloc(&d_pred, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_pred), nb_elements * sizeof(float)); cudaMemcpy(d_pred, pred.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); // create random targets @@ -131,7 +131,7 @@ TEST_CASE("[metrics] Accuracy", "[metrics][Accuracy]") { targ[i] = valueDist(gen); } float * d_targ; - cudaMalloc(&d_targ, nb_elements * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_targ), nb_elements * sizeof(float)); cudaMemcpy(d_targ, targ.get(), nb_elements * sizeof(float), cudaMemcpyHostToDevice); diff --git a/unit_tests/optimizer/Test_Adam.cpp b/unit_tests/optimizer/Test_Adam.cpp index cd171e3..632cba9 100644 --- a/unit_tests/optimizer/Test_Adam.cpp +++ b/unit_tests/optimizer/Test_Adam.cpp @@ -197,10 +197,10 @@ TEST_CASE("[learning/Adam] update", "[Optimizer][Adam]") { } // Allocate device memory - cudaMalloc(&d_val_tensors[i], size_tensors[i] * sizeof(float)); - cudaMalloc(&d_val_grad_tensors[i], size_tensors[i] * sizeof(float)); - cudaMalloc(&d_val_momentum1_tensors[i], size_tensors[i] * sizeof(float)); - cudaMalloc(&d_val_momentum1_tensors[i], size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_tensors[i]), size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_grad_tensors[i]), size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_momentum1_tensors[i]), size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_momentum1_tensors[i]), size_tensors[i] * sizeof(float)); // Copy data to device cudaMemcpy(d_val_tensors[i], val_tensors[i].get(), size_tensors[i] * sizeof(float), cudaMemcpyHostToDevice); diff --git a/unit_tests/optimizer/Test_SGD.cpp b/unit_tests/optimizer/Test_SGD.cpp index 14986a7..fd82a16 100644 --- a/unit_tests/optimizer/Test_SGD.cpp +++ b/unit_tests/optimizer/Test_SGD.cpp @@ -205,9 +205,9 @@ TEST_CASE("[learning/SGD] update", "[Optimizer][SGD]") { } // Allocate device memory - cudaMalloc(&d_val_tensors[i], size_tensors[i] * sizeof(float)); - cudaMalloc(&d_val_grad_tensors[i], size_tensors[i] * sizeof(float)); - cudaMalloc(&d_val_momentum_tensors[i], size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_tensors[i]), size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_grad_tensors[i]), size_tensors[i] * sizeof(float)); + cudaMalloc(reinterpret_cast<void **>(&d_val_momentum_tensors[i]), size_tensors[i] * sizeof(float)); // Copy data to device cudaMemcpy(d_val_tensors[i], val_tensors[i].get(), size_tensors[i] * sizeof(float), cudaMemcpyHostToDevice); -- GitLab From cfecb6548048164cd526853df782a0ea52b7f9c7 Mon Sep 17 00:00:00 2001 From: hrouis <houssemeddine.rouis92@gmail.com> Date: Thu, 19 Dec 2024 16:40:03 +0100 Subject: [PATCH 02/11] fix step increasing when updating LR --- include/aidge/learning/learningRate/LRScheduler.hpp | 2 +- unit_tests/learningRate/Test_LRScheduler.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/aidge/learning/learningRate/LRScheduler.hpp b/include/aidge/learning/learningRate/LRScheduler.hpp index 97dc6c5..6519dc4 100644 --- a/include/aidge/learning/learningRate/LRScheduler.hpp +++ b/include/aidge/learning/learningRate/LRScheduler.hpp @@ -100,7 +100,7 @@ public: * @note Else, the learning rate is updated using the provided function. */ constexpr void update() { - mLR = (mStep++ < mSwitchStep) ? + mLR = (++mStep < mSwitchStep) ? static_cast<float>(mStep) * mInitialWarmUp : mStepFunc(mLR, mStep); }; diff --git a/unit_tests/learningRate/Test_LRScheduler.cpp b/unit_tests/learningRate/Test_LRScheduler.cpp index 12c7f69..a67e260 100644 --- a/unit_tests/learningRate/Test_LRScheduler.cpp +++ b/unit_tests/learningRate/Test_LRScheduler.cpp @@ -73,9 +73,12 @@ TEST_CASE("[learning/LR] Construction & evolution", "[LRScheduler]") { // profiling std::vector<float> profile = myLR.lr_profiling(nbSteps); + // Validate profiling results against ground truth + REQUIRE(truth == profile); + // learning rate computation std::size_t step = 0; - for (; (step < nbSteps) && (truth[step] == profile[step]) && (truth[step] == myLR.learningRate()); ++step) { + for (; (step < nbSteps) && (truth[step] == myLR.learningRate()); ++step) { myLR.update(); } -- GitLab From 28b0135170c1bcfede2fc7a7223a4df84a68bde1 Mon Sep 17 00:00:00 2001 From: cmoineau <cyril.moineau@cea.fr> Date: Wed, 11 Dec 2024 08:45:23 +0000 Subject: [PATCH 03/11] Update learning with https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/277 --- .gitignore | 3 +- CMakeLists.txt | 23 ++++++++++++ .../utils/sys_info/LearningVersionInfo.hpp | 37 +++++++++++++++++++ include/aidge/version.h.in | 11 ++++++ pyproject.toml | 18 +++++---- python_binding/pybind_learning.cpp | 3 +- .../sys_info/pybind_LearningVersionInfo.cpp | 12 ++++++ setup.cfg | 3 ++ 8 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 include/aidge/utils/sys_info/LearningVersionInfo.hpp create mode 100644 include/aidge/version.h.in create mode 100644 python_binding/utils/sys_info/pybind_LearningVersionInfo.cpp create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 1695487..70998b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # C++ Build build*/ install*/ - +include/aidge/learning_version.h # VSCode .vscode @@ -10,7 +10,6 @@ install*/ __pycache__ *.pyc *.egg-info -aidge_learning/_version.py wheelhouse/* # Mermaid diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b5a43f..9593a41 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_learning VERSION ${version} DESCRIPTION "Functions and alogrithms to train models in the AIDGE framework" @@ -10,6 +25,7 @@ project(aidge_learning 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} set(module_name _${CMAKE_PROJECT_NAME}) # target name @@ -92,6 +108,13 @@ if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) append_coverage_compiler_flags() endif() +message(STATUS "Creating ${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/learning_version.h") +# Generate version.h file from config file version.h.in +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/version.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/learning_version.h" +) + ############################################## # Installation instructions include(GNUInstallDirs) diff --git a/include/aidge/utils/sys_info/LearningVersionInfo.hpp b/include/aidge/utils/sys_info/LearningVersionInfo.hpp new file mode 100644 index 0000000..7572e24 --- /dev/null +++ b/include/aidge/utils/sys_info/LearningVersionInfo.hpp @@ -0,0 +1,37 @@ +#ifndef AIDGE_UTILS_SYS_INFO_LEARNING_VERSION_INFO_H +#define AIDGE_UTILS_SYS_INFO_LEARNING_VERSION_INFO_H + +#include "aidge/utils/Log.hpp" +#include "aidge/learning_version.h" + +namespace Aidge { + +constexpr inline const char * getLearningProjectVersion(){ + return PROJECT_VERSION; +} + +constexpr inline const char * getLearningGitHash(){ + return PROJECT_GIT_HASH; +} + +void showLearningVersion() { + Log::info("Aidge Learning: {} ({}), {} {}", getLearningProjectVersion(), getLearningGitHash(), __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_LEARNING_VERSION_INFO_H diff --git a/include/aidge/version.h.in b/include/aidge/version.h.in new file mode 100644 index 0000000..4b876f6 --- /dev/null +++ b/include/aidge/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/pyproject.toml b/pyproject.toml index f2c248c..05b6f93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,18 +5,25 @@ dependencies = [] requires-python = ">= 3.7" readme = "README.md" license = { file = "LICENSE" } -classifiers = [ +classifiers = [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python :: 3" ] -dynamic = ["version"] # defined in tool.setuptools_scm +dynamic = ["version"] # defined in pbr + +[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_learning" +Issues = "https://gitlab.eclipse.org/eclipse/aidge/aidge_learning/-/issues/" +Changelog = "https://gitlab.eclipse.org/eclipse/aidge/aidge_learning/-/releases" [build-system] requires = [ "setuptools>=64", - "setuptools_scm[toml]==7.1.0", "cmake>=3.15.3.post1", - "toml" + "toml", + "pbr" ] build-backend = "setuptools.build_meta" @@ -28,9 +35,6 @@ where = ["."] # list of folders that contain the packages (["."] by default) include = ["aidge_learning*"] # package names should match these glob patterns (["*"] by default) exclude = ["aidge_learning.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_learning/_version.py" ##################################################### # CIBUILDWHEEL diff --git a/python_binding/pybind_learning.cpp b/python_binding/pybind_learning.cpp index b16c2a9..9585934 100644 --- a/python_binding/pybind_learning.cpp +++ b/python_binding/pybind_learning.cpp @@ -22,6 +22,7 @@ void init_SGD(py::module&); void init_Adam(py::module&); void init_LRScheduler(py::module&); void init_Accuracy(py::module&); +void init_LearningSysInfo(py::module&); void init_Aidge(py::module& m) { init_Loss(m); @@ -29,7 +30,7 @@ void init_Aidge(py::module& m) { init_SGD(m); init_Adam(m); init_Accuracy(m); - + init_LearningSysInfo(m); init_LRScheduler(m); } diff --git a/python_binding/utils/sys_info/pybind_LearningVersionInfo.cpp b/python_binding/utils/sys_info/pybind_LearningVersionInfo.cpp new file mode 100644 index 0000000..c4ae60f --- /dev/null +++ b/python_binding/utils/sys_info/pybind_LearningVersionInfo.cpp @@ -0,0 +1,12 @@ + +#include <pybind11/pybind11.h> +#include "aidge/utils/sys_info/LearningVersionInfo.hpp" + +namespace py = pybind11; +namespace Aidge { +void init_LearningSysInfo(py::module& m){ + m.def("show_version", &showLearningVersion); + m.def("get_project_version", &getLearningProjectVersion); + m.def("get_git_hash", &getLearningGitHash); +} +} 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 4e1c660ec29d6d522b58eca12ea33ed026e5fdd5 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Sun, 19 Jan 2025 18:55:09 +0100 Subject: [PATCH 04/11] Hotfix: replaced std::cout --- unit_tests/loss/classification/Test_BCE.cpp | 6 +++--- unit_tests/loss/regression/Test_MSE.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/unit_tests/loss/classification/Test_BCE.cpp b/unit_tests/loss/classification/Test_BCE.cpp index 6e7e200..34149f3 100644 --- a/unit_tests/loss/classification/Test_BCE.cpp +++ b/unit_tests/loss/classification/Test_BCE.cpp @@ -69,7 +69,7 @@ TEST_CASE("[loss/classification] BCE", "[loss][classification][BCE]") { for (std::size_t i = 0; i < nb_elements; ++i) { tmp_res_manual[i] = - ((targ[i] + eps1) * std::log(pred[i] + eps1) + (1.0f - targ[i] + eps2) * std::log(1.0f - pred[i] + eps2)); } - std::cout << "Output manual:" << std::endl; + fmt::println("Output manual:"); std::shared_ptr<Tensor> tmp_tensor = std::make_shared<Tensor>(dims); tmp_tensor->setBackend("cpu"); tmp_tensor->getImpl()->setRawPtr(tmp_res_manual.get(), nb_elements); @@ -77,13 +77,13 @@ TEST_CASE("[loss/classification] BCE", "[loss][classification][BCE]") { const float res_manual = std::accumulate(&tmp_res_manual[0], &tmp_res_manual[nb_elements], 0.0f, std::plus<float>()) / static_cast<float>(nb_elements); // compute the BCE using Aidge::loss::BCE function - std::cout << "Input 0 manual:" << std::endl; + fmt::println("Input 0 manual:"); std::shared_ptr<Tensor> pred_tensor = std::make_shared<Tensor>(dims); pred_tensor->setBackend("cpu"); pred_tensor->getImpl()->setRawPtr(pred.get(), nb_elements); pred_tensor->print(); - std::cout << "Input 1 manual:" << std::endl; + fmt::println("Input 1 manual:"); std::shared_ptr<Tensor> targ_tensor = std::make_shared<Tensor>(dims); targ_tensor->setBackend("cpu"); targ_tensor->getImpl()->setRawPtr(targ.get(), nb_elements); diff --git a/unit_tests/loss/regression/Test_MSE.cpp b/unit_tests/loss/regression/Test_MSE.cpp index d551479..adf4aa3 100644 --- a/unit_tests/loss/regression/Test_MSE.cpp +++ b/unit_tests/loss/regression/Test_MSE.cpp @@ -71,7 +71,7 @@ TEST_CASE("[loss/regression] MSE", "[loss][regression][MSE]") { for (std::size_t i = 0; i < nb_elements; ++i) { tmp_res_manual[i] = std::pow(pred[i] - targ[i],2); } - std::cout << "Pow output manual:" << std::endl; + fmt::println("Pow output manual:"); std::shared_ptr<Tensor> tmp_tensor = std::make_shared<Tensor>(dims); tmp_tensor->setBackend("cpu"); tmp_tensor->getImpl()->setRawPtr(tmp_res_manual.get(), nb_elements); @@ -79,13 +79,13 @@ TEST_CASE("[loss/regression] MSE", "[loss][regression][MSE]") { const float res_manual = std::accumulate(&tmp_res_manual[0], &tmp_res_manual[nb_elements], 0.0f, std::plus<float>()) / static_cast<float>(nb_elements); // compute the MSE using Aidge::loss::MSE function - std::cout << "Sub input 0 manual:" << std::endl; + fmt::println("Sub input 0 manual:"); std::shared_ptr<Tensor> pred_tensor = std::make_shared<Tensor>(dims); pred_tensor->setBackend("cpu"); pred_tensor->getImpl()->setRawPtr(pred.get(), nb_elements); pred_tensor->print(); - std::cout << "Sub input 1 manual:" << std::endl; + fmt::println("Sub input 1 manual:"); std::shared_ptr<Tensor> targ_tensor = std::make_shared<Tensor>(dims); targ_tensor->setBackend("cpu"); targ_tensor->getImpl()->setRawPtr(targ.get(), nb_elements); -- GitLab From 967c196e7b50f14fdac9afdf0b32c50fb17c3daf Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Mon, 20 Jan 2025 10:23:14 +0100 Subject: [PATCH 05/11] Hotfix: add fmt dependency --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9593a41..9928853 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,20 @@ if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) Include(CodeCoverage) endif() +# ############################################## +# Find system dependencies +Include(FetchContent) + +FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 10.2.1 # or a later release +) + +set(FMT_SYSTEM_HEADERS ON) +FetchContent_MakeAvailable(fmt) +set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON) + ############################################## # FIND Dependencies @@ -94,6 +108,7 @@ if (PYBIND) ) endif() +target_link_libraries(${module_name} PUBLIC fmt::fmt) target_compile_features(${module_name} PRIVATE cxx_std_14) target_compile_options(${module_name} PRIVATE -- GitLab From 1072c36d87bce18de9fa9a3ca2b0ae04cb3f25d8 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Mon, 20 Jan 2025 10:57:12 +0100 Subject: [PATCH 06/11] Hotfix fmt not linking --- CMakeLists.txt | 15 --------------- aidge_learning-config.cmake.in | 3 +++ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9928853..9593a41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,20 +46,6 @@ if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) Include(CodeCoverage) endif() -# ############################################## -# Find system dependencies -Include(FetchContent) - -FetchContent_Declare( - fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 10.2.1 # or a later release -) - -set(FMT_SYSTEM_HEADERS ON) -FetchContent_MakeAvailable(fmt) -set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON) - ############################################## # FIND Dependencies @@ -108,7 +94,6 @@ if (PYBIND) ) endif() -target_link_libraries(${module_name} PUBLIC fmt::fmt) target_compile_features(${module_name} PRIVATE cxx_std_14) target_compile_options(${module_name} PRIVATE diff --git a/aidge_learning-config.cmake.in b/aidge_learning-config.cmake.in index fbd5327..d5c65ca 100644 --- a/aidge_learning-config.cmake.in +++ b/aidge_learning-config.cmake.in @@ -1,5 +1,8 @@ @PACKAGE_INIT@ +include(CMakeFindDependencyMacro) +find_dependency(aidge_core) + include(${CMAKE_CURRENT_LIST_DIR}/aidge_learning-config-version.cmake) include(${CMAKE_CURRENT_LIST_DIR}/aidge_learning-targets.cmake) -- GitLab From d20dc245f1ccd8f55c7dbd68f0903607d19345aa Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Wed, 29 Jan 2025 10:09:43 +0000 Subject: [PATCH 07/11] 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 9593a41..f882314 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 a3f4d9c9575da278b077d4d31c9217004e56fd8a Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Wed, 29 Jan 2025 10:10:04 +0000 Subject: [PATCH 08/11] Change Python minimum version 3.7 -> 3.8 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 05b6f93..fa1f8c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "aidge_learning" description="Functions and alogrithms to train models in the AIDGE framework" dependencies = [] -requires-python = ">= 3.7" +requires-python = ">= 3.8" readme = "README.md" license = { file = "LICENSE" } classifiers = [ @@ -104,7 +104,7 @@ persistent = true # Minimum Python version to use for version dependent checks. Will default to the # version used to run pylint. -py-version = "3.7" +py-version = "3.8" # When enabled, pylint would attempt to guess common misconfiguration and emit # user-friendly hints instead of false-positive error messages. -- GitLab From c4e8c035f0e3f9156ecc4e9c32dbb9f148240296 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Wed, 29 Jan 2025 10:10:49 +0000 Subject: [PATCH 09/11] UPD: 'setup.py' to access compilation options from environment variables set by 'setup.sh' --- setup.py | 79 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/setup.py b/setup.py index 5a61afc..e4ea585 100644 --- a/setup.py +++ b/setup.py @@ -26,9 +26,15 @@ class CMakeExtension(Extension): class CMakeBuild(build_ext): def run(self): + # Impose to use the executable of the python + # used to launch setup.py to setup PythonInterp + python_executable = sys.executable + print(f"python executable : {python_executable}") + # 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() @@ -40,18 +46,8 @@ 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 : {python_executable}") - - compile_type = ( - "Release" - if "AIDGE_PYTHON_BUILD_TYPE" not in os.environ - else os.environ["AIDGE_PYTHON_BUILD_TYPE"] - ) + # package_prefix = build_lib if not self.editable_mode else SETUP_DIR + # pybind_install_prefix = (package_prefix / PROJECT_NAME).absolute() install_path = ( os.path.join(sys.prefix, "lib", "libAidge") @@ -59,31 +55,52 @@ class CMakeBuild(build_ext): else os.environ["AIDGE_INSTALL"] ) - build_gen = ( - ["-G", os.environ["AIDGE_BUILD_GEN"]] - if "AIDGE_BUILD_GEN" in os.environ + # 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") + with_cuda = os.environ.get("AIDGE_WITH_CUDA", "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 [] ) - - 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", - ] - ) + test_onoff = os.environ.get("AIDGE_BUILD_TEST", "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}", + f"-DCUDA={with_cuda}", + "-DPYBIND=ON", + # f"-DPYBIND_INSTALL_PREFIX:PATH={pybind_install_prefix}", + "-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 c92fc955f440ddca2da39ce50d1045cafe531498 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Wed, 29 Jan 2025 23:54:25 +0000 Subject: [PATCH 10/11] FEAT: unit-tests/CMakeLists.txt add minimum version for Catch2 --- unit_tests/CMakeLists.txt | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 27dab59..a5004bc 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) -# Fetch and make available Catch2 for unit testing -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.7.1 # or a later release -) -FetchContent_MakeAvailable(Catch2) +# Try to find system installed Catch2 +find_package(Catch2 ${CATCH2_MIN_VERSION} QUIET) + +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() # Gather all source files for the test executable file(GLOB_RECURSE src_files "*.cpp") -- GitLab From c19db949634ae99a7919c921ca328af496b8b899 Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Fri, 31 Jan 2025 21:59:47 +0000 Subject: [PATCH 11/11] UPD: version 0.2.2 -> 0.2.3 --- CHANGELOG | 2 ++ pyproject.toml | 20 ++++++++++++++++++-- version.txt | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2a033b6..a318592 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +# Version 0.2.3 (January 31, 2025) + # Version 0.2.2 (December 12, 2024) # Version 0.1.1 (May 14, 2024) diff --git a/pyproject.toml b/pyproject.toml index fa1f8c7..68fc74f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,8 +7,24 @@ readme = "README.md" license = { file = "LICENSE" } classifiers = [ "Development Status :: 2 - Pre-Alpha", - "Programming Language :: Python :: 3" - ] + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)", + "Programming Language :: C++", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Software Development" +] dynamic = ["version"] # defined in pbr [project.urls] diff --git a/version.txt b/version.txt index ee1372d..7179039 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.2.2 +0.2.3 -- GitLab