From 968411c839177096dda388448b18d2248455b928 Mon Sep 17 00:00:00 2001 From: Ryan Danehy Date: Tue, 12 Dec 2023 14:12:00 -0800 Subject: [PATCH 1/5] SDK compliance of adding api version --- resolve/resolve_defs.hpp.in | 7 ++++--- resolve/utilities/version.cpp | 20 ++++++++++++++++++++ resolve/utilities/version.hpp | 18 ++++++++++++++++++ tests/functionality/CMakeLists.txt | 5 +++++ tests/functionality/testversion.cpp | 19 +++++++++++++++++++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 resolve/utilities/version.cpp create mode 100644 resolve/utilities/version.hpp create mode 100644 tests/functionality/testversion.cpp diff --git a/resolve/resolve_defs.hpp.in b/resolve/resolve_defs.hpp.in index 15cd5791..49a39203 100644 --- a/resolve/resolve_defs.hpp.in +++ b/resolve/resolve_defs.hpp.in @@ -11,9 +11,10 @@ #cmakedefine RESOLVE_USE_EIGEN #cmakedefine RESOLVE_USE_KLU #define RESOLVE_VERSION "@PROJECT_VERSION@" -// #define RESOLVE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ -// #define RESOLVE_VERSION_MINOR @PROJECT_VERSION_MINOR@ -// #define RESOLVE_VERSION_PATCH @PROJECT_VERSION_PATCH@ + +#define RESOLVE_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@" +#define RESOLVE_VERSION_MINOR "@PROJECT_VERSION_MINOR@" +#define RESOLVE_VERSION_PATCH "@PROJECT_VERSION_PATCH@" // /// Date of build with the format "%Y-%m-%d" // #define RESOLVE_RELEASE_DATE "@RESOLVE_RELEASE_DATE@" diff --git a/resolve/utilities/version.cpp b/resolve/utilities/version.cpp new file mode 100644 index 00000000..bab47d25 --- /dev/null +++ b/resolve/utilities/version.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include "version.hpp" +#include + +// Function that splits the verison in major minor and patch ints +int ReSolveVersionGetVersion(int *major, int *minor, int *patch) { + *major = atoi(RESOLVE_VERSION_MAJOR); + *minor = atoi(RESOLVE_VERSION_MINOR); + *patch = atoi(RESOLVE_VERSION_PATCH); + return 0; +} + +// Function that grabs ReSolves Version as a string +int ReSolveVersionGetVersionStr(std::string &str) { + str = RESOLVE_VERSION; + return 0; +} + diff --git a/resolve/utilities/version.hpp b/resolve/utilities/version.hpp new file mode 100644 index 00000000..49555186 --- /dev/null +++ b/resolve/utilities/version.hpp @@ -0,0 +1,18 @@ +#ifndef RESOLVE_VERSION_H +#define RESOLVE_VERSION_H + + +/** + * Sets major, minor, and patch versions for current ReSolve build. The user is + * responsible for free'ing this memory. + */ +int ResolveVersionGetVersion(int *, int *, int *); + +/** + * Sets string with build version for current ExaGO build in format + * "major.minor.patch". The user is responsible for free'ing this memory. + */ +int ReSolveVersionGetVersionStr(std::string &); + + +#endif \ No newline at end of file diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index 5fae41cd..b1edc86a 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -6,6 +6,10 @@ ]] +# Build basic version test +add_executable(version.exe testversion.cpp) +target_link_libraries(version.exe PRIVATE ReSolve) + # Build KLU+KLU test add_executable(klu_klu_test.exe testKLU.cpp) target_link_libraries(klu_klu_test.exe PRIVATE ReSolve) @@ -81,6 +85,7 @@ install(DIRECTORY data DESTINATION bin/resolve/tests/functionality) set(test_data_dir ${CMAKE_SOURCE_DIR}/tests/functionality/) +add_test(NAME version COMMAND $ "${test_data_dir}") add_test(NAME klu_klu_test COMMAND $ "${test_data_dir}") if(RESOLVE_USE_CUDA) add_test(NAME klu_rf_test COMMAND $ "${test_data_dir}") diff --git a/tests/functionality/testversion.cpp b/tests/functionality/testversion.cpp new file mode 100644 index 00000000..0555599a --- /dev/null +++ b/tests/functionality/testversion.cpp @@ -0,0 +1,19 @@ +#include +#include + + +#include +#include + +//author: RD +//version test to check to make sure ReSolve's version can be printed + + +int main(int argc, char *argv[]) +{ + std::string versionstr; + ReSolveVersionGetVersionStr(versionstr); + std::cout<<"ReSolveVersionGetVersionStr Test: "< Date: Wed, 13 Dec 2023 21:34:01 -0500 Subject: [PATCH 2/5] Final touches to version test. --- CMakeLists.txt | 2 +- resolve/CMakeLists.txt | 1 + resolve/SystemSolver.cpp | 7 +++++- resolve/utilities/CMakeLists.txt | 1 + resolve/utilities/version.cpp | 20 --------------- resolve/utilities/version.hpp | 18 ------------- resolve/utilities/version/CmakeLists.txt | 26 +++++++++++++++++++ resolve/utilities/version/version.cpp | 25 ++++++++++++++++++ resolve/utilities/version/version.hpp | 18 +++++++++++++ tests/functionality/CMakeLists.txt | 2 +- tests/functionality/testVersion.cpp | 32 ++++++++++++++++++++++++ tests/functionality/testversion.cpp | 19 -------------- 12 files changed, 111 insertions(+), 60 deletions(-) delete mode 100644 resolve/utilities/version.cpp delete mode 100644 resolve/utilities/version.hpp create mode 100644 resolve/utilities/version/CmakeLists.txt create mode 100644 resolve/utilities/version/version.cpp create mode 100644 resolve/utilities/version/version.hpp create mode 100644 tests/functionality/testVersion.cpp delete mode 100644 tests/functionality/testversion.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccb0d79..6717f280 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.22) # Adds version settings and set variable CMAKE_PROJECT_VERSION -project(ReSolve VERSION "0.1.0") +project(ReSolve VERSION "0.99.1") set(CMAKE_CXX_STANDARD 11) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 078bb4d6..24523009 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -74,6 +74,7 @@ set(ReSolve_Targets_List resolve_logger resolve_tpl resolve_workspace + resolve_version ) # Temporary until there is CPU-only option for FGMRES diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 59d160bb..467217e1 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -94,10 +96,13 @@ namespace ReSolve delete resVector_; delete factorizationSolver_; delete refactorizationSolver_; + +#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (irMethod_ != "none") { delete iterativeSolver_; delete gs_; } +#endif delete matrixHandler_; delete vectorHandler_; @@ -364,6 +369,7 @@ namespace ReSolve void SystemSolver::setRefinementMethod(std::string method, std::string gsMethod) { +#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (iterativeSolver_ != nullptr) delete iterativeSolver_; @@ -375,7 +381,6 @@ namespace ReSolve gsMethod_ = gsMethod; -#if defined(RESOLVE_USE_HIP) || defined(RESOLVE_USE_CUDA) if (method == "fgmres") { if (gsMethod == "cgs2") { gs_ = new GramSchmidt(vectorHandler_, GramSchmidt::cgs2); diff --git a/resolve/utilities/CMakeLists.txt b/resolve/utilities/CMakeLists.txt index b66ae0eb..c866713d 100644 --- a/resolve/utilities/CMakeLists.txt +++ b/resolve/utilities/CMakeLists.txt @@ -7,3 +7,4 @@ ]] add_subdirectory(logger) +add_subdirectory(version) diff --git a/resolve/utilities/version.cpp b/resolve/utilities/version.cpp deleted file mode 100644 index bab47d25..00000000 --- a/resolve/utilities/version.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -#include "version.hpp" -#include - -// Function that splits the verison in major minor and patch ints -int ReSolveVersionGetVersion(int *major, int *minor, int *patch) { - *major = atoi(RESOLVE_VERSION_MAJOR); - *minor = atoi(RESOLVE_VERSION_MINOR); - *patch = atoi(RESOLVE_VERSION_PATCH); - return 0; -} - -// Function that grabs ReSolves Version as a string -int ReSolveVersionGetVersionStr(std::string &str) { - str = RESOLVE_VERSION; - return 0; -} - diff --git a/resolve/utilities/version.hpp b/resolve/utilities/version.hpp deleted file mode 100644 index 49555186..00000000 --- a/resolve/utilities/version.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RESOLVE_VERSION_H -#define RESOLVE_VERSION_H - - -/** - * Sets major, minor, and patch versions for current ReSolve build. The user is - * responsible for free'ing this memory. - */ -int ResolveVersionGetVersion(int *, int *, int *); - -/** - * Sets string with build version for current ExaGO build in format - * "major.minor.patch". The user is responsible for free'ing this memory. - */ -int ReSolveVersionGetVersionStr(std::string &); - - -#endif \ No newline at end of file diff --git a/resolve/utilities/version/CmakeLists.txt b/resolve/utilities/version/CmakeLists.txt new file mode 100644 index 00000000..fbeb397e --- /dev/null +++ b/resolve/utilities/version/CmakeLists.txt @@ -0,0 +1,26 @@ +#[[ + +@brief Build ReSolve output log system + +@author Slaven Peles + +]] + +set(Logger_SRC + version.cpp +) + +set(Logger_HEADER_INSTALL + version.hpp +) + +# Build shared library ReSolve +add_library(resolve_version OBJECT ${Logger_SRC}) + +target_include_directories(resolve_version PUBLIC + $ + $ + $ +) + +install(FILES ${Logger_HEADER_INSTALL} DESTINATION include/resolve/utilities/version) diff --git a/resolve/utilities/version/version.cpp b/resolve/utilities/version/version.cpp new file mode 100644 index 00000000..33033f58 --- /dev/null +++ b/resolve/utilities/version/version.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "version.hpp" +#include + +namespace ReSolve +{ + // Function that splits the verison in major minor and patch ints + int VersionGetVersion(int* major, int* minor, int* patch) + { + *major = atoi(RESOLVE_VERSION_MAJOR); + *minor = atoi(RESOLVE_VERSION_MINOR); + *patch = atoi(RESOLVE_VERSION_PATCH); + return 0; + } + + // Function that grabs ReSolves Version as a string + int VersionGetVersionStr(std::string &str) + { + str = RESOLVE_VERSION; + return 0; + } + +} diff --git a/resolve/utilities/version/version.hpp b/resolve/utilities/version/version.hpp new file mode 100644 index 00000000..9ce8ccd6 --- /dev/null +++ b/resolve/utilities/version/version.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace ReSolve +{ + + /** + * Sets major, minor, and patch versions for current ReSolve build. The user is + * responsible for free'ing this memory. + */ + int VersionGetVersion(int *, int *, int *); + + /** + * Sets string with build version for current ExaGO build in format + * "major.minor.patch". The user is responsible for free'ing this memory. + */ + int VersionGetVersionStr(std::string &); + +} diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index b1edc86a..44eea929 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -7,7 +7,7 @@ ]] # Build basic version test -add_executable(version.exe testversion.cpp) +add_executable(version.exe testVersion.cpp) target_link_libraries(version.exe PRIVATE ReSolve) # Build KLU+KLU test diff --git a/tests/functionality/testVersion.cpp b/tests/functionality/testVersion.cpp new file mode 100644 index 00000000..38402fd1 --- /dev/null +++ b/tests/functionality/testVersion.cpp @@ -0,0 +1,32 @@ +#include +#include + + +#include + +//author: RD +//version test to check to make sure ReSolve's version can be printed + +/** + * @brief Test ReSolve version + * + * The purpose of this mildly annoying test is to force developers + * to change version at two different places. The hope is this test + * will fail if the version is changed accidentally. + * + * @return int If test was successful return zero + */ +int main() +{ + std::string answer("0.99.1"); + std::string versionstr; + ReSolve::VersionGetVersionStr(versionstr); + std::cout << "ReSolveVersionGetVersionStr Test: " << versionstr << std::endl << std::endl; + + if (versionstr != answer) { + std::cout << "ReSolve version set incorrectly!\n"; + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/tests/functionality/testversion.cpp b/tests/functionality/testversion.cpp deleted file mode 100644 index 0555599a..00000000 --- a/tests/functionality/testversion.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - - -#include -#include - -//author: RD -//version test to check to make sure ReSolve's version can be printed - - -int main(int argc, char *argv[]) -{ - std::string versionstr; - ReSolveVersionGetVersionStr(versionstr); - std::cout<<"ReSolveVersionGetVersionStr Test: "< Date: Wed, 13 Dec 2023 22:12:03 -0500 Subject: [PATCH 3/5] Don't export resolve_version target. --- resolve/CMakeLists.txt | 2 +- tests/functionality/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 24523009..a02ffdb6 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -74,7 +74,6 @@ set(ReSolve_Targets_List resolve_logger resolve_tpl resolve_workspace - resolve_version ) # Temporary until there is CPU-only option for FGMRES @@ -117,6 +116,7 @@ target_include_directories(ReSolve INTERFACE # TODO: Make this PRIVATE dependency (requires refactoring ReSolve code) target_link_libraries(ReSolve PUBLIC ${ReSolve_Targets_List}) +target_link_libraries(ReSolve PRIVATE resolve_version) # Install targets install(TARGETS ReSolve diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index 44eea929..c606d5ff 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -60,7 +60,7 @@ if(RESOLVE_USE_HIP) endif(RESOLVE_USE_HIP) # Install tests -set(installable_tests klu_klu_test.exe) +set(installable_tests klu_klu_test.exe version.exe) if(RESOLVE_USE_CUDA) set(installable_tests ${installable_tests} From 08f2e49b94a5f395d3c1d4f03c1fa50e3d0beb1b Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Wed, 13 Dec 2023 22:24:09 -0500 Subject: [PATCH 4/5] Fix capitalization in CMake. --- resolve/utilities/version/{CmakeLists.txt => CMakeLists.txt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename resolve/utilities/version/{CmakeLists.txt => CMakeLists.txt} (88%) diff --git a/resolve/utilities/version/CmakeLists.txt b/resolve/utilities/version/CMakeLists.txt similarity index 88% rename from resolve/utilities/version/CmakeLists.txt rename to resolve/utilities/version/CMakeLists.txt index fbeb397e..9315db15 100644 --- a/resolve/utilities/version/CmakeLists.txt +++ b/resolve/utilities/version/CMakeLists.txt @@ -1,6 +1,6 @@ #[[ -@brief Build ReSolve output log system +@brief Build ReSolve function that returns version at runtime @author Slaven Peles From 48013a9bc2dc7c98185f70d90cd292534ff7c692 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Wed, 13 Dec 2023 22:36:27 -0500 Subject: [PATCH 5/5] Add -fpic to version target. --- resolve/utilities/version/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/resolve/utilities/version/CMakeLists.txt b/resolve/utilities/version/CMakeLists.txt index 9315db15..457c7bc5 100644 --- a/resolve/utilities/version/CMakeLists.txt +++ b/resolve/utilities/version/CMakeLists.txt @@ -16,6 +16,7 @@ set(Logger_HEADER_INSTALL # Build shared library ReSolve add_library(resolve_version OBJECT ${Logger_SRC}) +set_property(TARGET resolve_version PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(resolve_version PUBLIC $