From e077fb711106268f65bbf8cf7d10e7f0a2245259 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 22 Feb 2024 18:03:09 -0500 Subject: [PATCH 1/9] Move random classes to separate folder. --- resolve/CMakeLists.txt | 9 +-- resolve/LinSolverIterativeRandFGMRES.cpp | 4 +- resolve/LinSolverIterativeRandFGMRES.hpp | 2 +- resolve/random/CMakeLists.txt | 56 +++++++++++++++++++ .../{ => random}/RandSketchingCountSketch.cpp | 2 +- .../{ => random}/RandSketchingCountSketch.hpp | 2 +- resolve/{ => random}/RandSketchingFWHT.cpp | 2 +- resolve/{ => random}/RandSketchingFWHT.hpp | 2 +- resolve/{ => random}/RandSketchingManager.cpp | 1 + resolve/{ => random}/RandSketchingManager.hpp | 14 ++++- 10 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 resolve/random/CMakeLists.txt rename resolve/{ => random}/RandSketchingCountSketch.cpp (98%) rename resolve/{ => random}/RandSketchingCountSketch.hpp (95%) rename resolve/{ => random}/RandSketchingFWHT.cpp (99%) rename resolve/{ => random}/RandSketchingFWHT.hpp (96%) rename resolve/{ => random}/RandSketchingManager.cpp (96%) rename resolve/{ => random}/RandSketchingManager.hpp (83%) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 9851fe5e..73f3c001 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -15,9 +15,6 @@ set(ReSolve_SRC LinSolverIterativeFGMRES.cpp LinSolverDirectCpuILU0.cpp LinSolverIterativeRandFGMRES.cpp - RandSketchingManager.cpp - RandSketchingCountSketch.cpp - RandSketchingFWHT.cpp LinSolverDirectSerialILU0.cpp ) @@ -38,6 +35,7 @@ set(ReSolve_ROCM_SRC LinSolverDirectRocSolverRf.cpp LinSolverDirectRocSparseILU0.cpp ) + # Header files to be installed set(ReSolve_HEADER_INSTALL Common.hpp @@ -47,9 +45,6 @@ set(ReSolve_HEADER_INSTALL LinSolverDirectCpuILU0.hpp SystemSolver.hpp GramSchmidt.hpp - RandSketchingManager.hpp - RandSketchingCountSketch.hpp - RandSketchingFWHT.hpp MemoryUtils.hpp) set(ReSolve_KLU_HEADER_INSTALL @@ -73,6 +68,7 @@ add_subdirectory(workspace) # Next build vector and matrix objects that may use this backend. add_subdirectory(vector) add_subdirectory(matrix) +add_subdirectory(random) # Build shared library ReSolve add_library(resolve_tpl INTERFACE) @@ -86,6 +82,7 @@ endif() set(ReSolve_Targets_List resolve_matrix resolve_vector + resolve_random resolve_logger resolve_tpl resolve_workspace diff --git a/resolve/LinSolverIterativeRandFGMRES.cpp b/resolve/LinSolverIterativeRandFGMRES.cpp index d18502c1..1511527b 100644 --- a/resolve/LinSolverIterativeRandFGMRES.cpp +++ b/resolve/LinSolverIterativeRandFGMRES.cpp @@ -7,8 +7,8 @@ #include #include #include "LinSolverIterativeRandFGMRES.hpp" -#include -#include +#include +#include namespace ReSolve { diff --git a/resolve/LinSolverIterativeRandFGMRES.hpp b/resolve/LinSolverIterativeRandFGMRES.hpp index d484fd03..28da7f70 100644 --- a/resolve/LinSolverIterativeRandFGMRES.hpp +++ b/resolve/LinSolverIterativeRandFGMRES.hpp @@ -4,7 +4,7 @@ #include #include "LinSolver.hpp" #include "GramSchmidt.hpp" -#include "RandSketchingManager.hpp" +#include namespace ReSolve { diff --git a/resolve/random/CMakeLists.txt b/resolve/random/CMakeLists.txt new file mode 100644 index 00000000..34a1b3c2 --- /dev/null +++ b/resolve/random/CMakeLists.txt @@ -0,0 +1,56 @@ +#[[ + +@brief Build ReSolve random sketching module + +@author Slaven Peles + +]] + +# C++ code +set(Random_SRC + RandSketchingManager.cpp + RandSketchingCountSketch.cpp + RandSketchingFWHT.cpp +) + +# C++ code that depends on CUDA SDK libraries +set(Random_CUDASDK_SRC +) + +# and on HIP +set(Random_ROCM_SRC +) + +# Header files to be installed +set(Random_HEADER_INSTALL + RandSketchingManager.hpp + RandSketchingCountSketch.hpp + RandSketchingFWHT.hpp +) + +# Build shared library ReSolve::random +add_library(resolve_random SHARED ${Random_SRC}) +target_link_libraries(resolve_random PRIVATE resolve_logger resolve_vector) + +# Link to CUDA ReSolve backend if CUDA is support enabled +if (RESOLVE_USE_CUDA) + target_sources(resolve_random PRIVATE ${Random_CUDASDK_SRC}) + target_link_libraries(resolve_random PUBLIC resolve_backend_cuda) +endif() + +if (RESOLVE_USE_HIP) + target_sources(resolve_random PRIVATE ${Random_ROCM_SRC}) + target_link_libraries(resolve_random PUBLIC resolve_backend_hip) +endif() + +# Link to dummy device backend if GPU support is not enabled +if (NOT RESOLVE_USE_GPU) + target_link_libraries(resolve_random PUBLIC resolve_backend_cpu) +endif() + +target_include_directories(resolve_random INTERFACE + $ + $ +) + +install(FILES ${Random_HEADER_INSTALL} DESTINATION include/resolve/random) diff --git a/resolve/RandSketchingCountSketch.cpp b/resolve/random/RandSketchingCountSketch.cpp similarity index 98% rename from resolve/RandSketchingCountSketch.cpp rename to resolve/random/RandSketchingCountSketch.cpp index bcad7bd7..ec1ae5d6 100644 --- a/resolve/RandSketchingCountSketch.cpp +++ b/resolve/random/RandSketchingCountSketch.cpp @@ -9,7 +9,7 @@ #else #include #endif -#include +#include namespace ReSolve { diff --git a/resolve/RandSketchingCountSketch.hpp b/resolve/random/RandSketchingCountSketch.hpp similarity index 95% rename from resolve/RandSketchingCountSketch.hpp rename to resolve/random/RandSketchingCountSketch.hpp index 51e729f6..edd1eab1 100644 --- a/resolve/RandSketchingCountSketch.hpp +++ b/resolve/random/RandSketchingCountSketch.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include namespace ReSolve { diff --git a/resolve/RandSketchingFWHT.cpp b/resolve/random/RandSketchingFWHT.cpp similarity index 99% rename from resolve/RandSketchingFWHT.cpp rename to resolve/random/RandSketchingFWHT.cpp index 7469520a..39d8b15d 100644 --- a/resolve/RandSketchingFWHT.cpp +++ b/resolve/random/RandSketchingFWHT.cpp @@ -13,7 +13,7 @@ #else #include #endif -#include +#include namespace ReSolve { using out = io::Logger; diff --git a/resolve/RandSketchingFWHT.hpp b/resolve/random/RandSketchingFWHT.hpp similarity index 96% rename from resolve/RandSketchingFWHT.hpp rename to resolve/random/RandSketchingFWHT.hpp index 8cf4e21a..b2282e9e 100644 --- a/resolve/RandSketchingFWHT.hpp +++ b/resolve/random/RandSketchingFWHT.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include namespace ReSolve { // Forward declaration of vector::Vector class diff --git a/resolve/RandSketchingManager.cpp b/resolve/random/RandSketchingManager.cpp similarity index 96% rename from resolve/RandSketchingManager.cpp rename to resolve/random/RandSketchingManager.cpp index 796379a4..c341ea49 100644 --- a/resolve/RandSketchingManager.cpp +++ b/resolve/random/RandSketchingManager.cpp @@ -1,4 +1,5 @@ // this is a virtual class +#include #include "RandSketchingManager.hpp" namespace ReSolve { diff --git a/resolve/RandSketchingManager.hpp b/resolve/random/RandSketchingManager.hpp similarity index 83% rename from resolve/RandSketchingManager.hpp rename to resolve/random/RandSketchingManager.hpp index 236c850f..458d05c9 100644 --- a/resolve/RandSketchingManager.hpp +++ b/resolve/random/RandSketchingManager.hpp @@ -1,9 +1,17 @@ // this is a virtual class #pragma once #include -#include #include + +namespace ReSolve +{ + namespace vector + { + class Vector; + } +} + namespace ReSolve { class RandSketchingManager { using vector_type = vector::Vector; @@ -28,9 +36,9 @@ namespace ReSolve { virtual index_type getPaddedSize(); protected: - index_type n_;///< size of base vector + index_type n_; ///< size of base vector index_type k_rand_; ///< size of sketched vector - index_type N_; ///< padded n -- generally N_ > n_ + index_type N_; ///< padded n -- generally N_ > n_ MemoryHandler mem_; ///< Device memory manager object }; From 75202c820e1c1730bec2cc5440f9161c37b85319 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 22 Feb 2024 19:45:27 -0500 Subject: [PATCH 2/9] Break build dependencies within random sketching classes. --- examples/r_randGMRES.cpp | 3 +-- examples/r_randGMRES_CUDA.cpp | 3 +-- examples/r_randGMRES_cpu.cpp | 3 +-- resolve/LinSolverIterativeRandFGMRES.cpp | 3 +++ resolve/LinSolverIterativeRandFGMRES.hpp | 16 ++++++++++++---- resolve/MemoryUtils.hpp | 2 +- resolve/random/RandSketchingCountSketch.hpp | 10 ++++++---- resolve/random/RandSketchingFWHT.hpp | 2 ++ resolve/random/RandSketchingManager.hpp | 5 ++--- resolve/vector/VectorHandlerCpu.cpp | 3 +-- tests/functionality/testRandGMRES_Rocm.cpp | 3 +-- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/examples/r_randGMRES.cpp b/examples/r_randGMRES.cpp index 705694c3..0bfec15d 100644 --- a/examples/r_randGMRES.cpp +++ b/examples/r_randGMRES.cpp @@ -4,12 +4,11 @@ #include #include -#include #include #include #include #include -#include +#include #include #include #include diff --git a/examples/r_randGMRES_CUDA.cpp b/examples/r_randGMRES_CUDA.cpp index d570761d..dda08d3c 100644 --- a/examples/r_randGMRES_CUDA.cpp +++ b/examples/r_randGMRES_CUDA.cpp @@ -4,12 +4,11 @@ #include #include -#include #include #include #include #include -#include +#include #include #include #include diff --git a/examples/r_randGMRES_cpu.cpp b/examples/r_randGMRES_cpu.cpp index a5fabfeb..332f563c 100644 --- a/examples/r_randGMRES_cpu.cpp +++ b/examples/r_randGMRES_cpu.cpp @@ -4,13 +4,12 @@ #include #include -#include #include #include #include #include -#include #include +#include #include #include #include diff --git a/resolve/LinSolverIterativeRandFGMRES.cpp b/resolve/LinSolverIterativeRandFGMRES.cpp index 1511527b..1737f065 100644 --- a/resolve/LinSolverIterativeRandFGMRES.cpp +++ b/resolve/LinSolverIterativeRandFGMRES.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include +#include #include #include "LinSolverIterativeRandFGMRES.hpp" #include diff --git a/resolve/LinSolverIterativeRandFGMRES.hpp b/resolve/LinSolverIterativeRandFGMRES.hpp index 28da7f70..5f039937 100644 --- a/resolve/LinSolverIterativeRandFGMRES.hpp +++ b/resolve/LinSolverIterativeRandFGMRES.hpp @@ -1,13 +1,21 @@ #pragma once #include "Common.hpp" -#include -#include #include "LinSolver.hpp" -#include "GramSchmidt.hpp" -#include namespace ReSolve { + // Forward declarations + class RandSketchingManager; + class GramSchmidt; + namespace matrix + { + class Sparse; + } + namespace vector + { + class Vector; + } + /** * @brief Randomized (F)GMRES * diff --git a/resolve/MemoryUtils.hpp b/resolve/MemoryUtils.hpp index d87c621f..2eb43089 100644 --- a/resolve/MemoryUtils.hpp +++ b/resolve/MemoryUtils.hpp @@ -59,7 +59,7 @@ namespace ReSolve template int copyArrayHostToHost(T* dst, const T* src, I n) { - size_t nelements = static_cast(n); + std::size_t nelements = static_cast(n); memcpy(dst, src, nelements * sizeof(T)); return 0; } diff --git a/resolve/random/RandSketchingCountSketch.hpp b/resolve/random/RandSketchingCountSketch.hpp index edd1eab1..c8238a04 100644 --- a/resolve/random/RandSketchingCountSketch.hpp +++ b/resolve/random/RandSketchingCountSketch.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace ReSolve { @@ -30,11 +31,12 @@ namespace ReSolve { virtual int reset(); // if needed can be reset (like when Krylov method restarts) private: - index_type* h_labels_;///< label array size _n_, with values from _0_ to _k-1_ assigned by random - index_type* h_flip_; ///< flip array with valyes of 1 and -1 assigned by random + index_type* h_labels_{nullptr}; ///< label array size _n_, with values from _0_ to _k-1_ assigned by random + index_type* h_flip_{nullptr}; ///< flip array with valyes of 1 and -1 assigned by random - index_type* d_labels_; ///< h_labels GPU counterpart - index_type* d_flip_; ///< h_flip GPU counterpart + index_type* d_labels_{nullptr}; ///< h_labels GPU counterpart + index_type* d_flip_{nullptr}; ///< h_flip GPU counterpart memory::MemorySpace memspace_; + MemoryHandler mem_; ///< Device memory manager object }; } diff --git a/resolve/random/RandSketchingFWHT.hpp b/resolve/random/RandSketchingFWHT.hpp index b2282e9e..c829cb85 100644 --- a/resolve/random/RandSketchingFWHT.hpp +++ b/resolve/random/RandSketchingFWHT.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace ReSolve { // Forward declaration of vector::Vector class @@ -42,5 +43,6 @@ namespace ReSolve { real_type one_over_k_;///< 1/k, used many times for scaling so we store the value to avoid recomputation memory::MemorySpace memspace_; + MemoryHandler mem_; ///< Device memory manager object }; } diff --git a/resolve/random/RandSketchingManager.hpp b/resolve/random/RandSketchingManager.hpp index 458d05c9..2bcb357c 100644 --- a/resolve/random/RandSketchingManager.hpp +++ b/resolve/random/RandSketchingManager.hpp @@ -1,7 +1,6 @@ // this is a virtual class #pragma once #include -#include namespace ReSolve @@ -14,7 +13,8 @@ namespace ReSolve namespace ReSolve { class RandSketchingManager { - using vector_type = vector::Vector; + private: + using vector_type = vector::Vector; public: // constructor @@ -40,6 +40,5 @@ namespace ReSolve { index_type k_rand_; ///< size of sketched vector index_type N_; ///< padded n -- generally N_ > n_ - MemoryHandler mem_; ///< Device memory manager object }; } // namespace ReSolve diff --git a/resolve/vector/VectorHandlerCpu.cpp b/resolve/vector/VectorHandlerCpu.cpp index 32aa65a6..ff4bcb0a 100644 --- a/resolve/vector/VectorHandlerCpu.cpp +++ b/resolve/vector/VectorHandlerCpu.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -20,7 +19,7 @@ namespace ReSolve { * * @param new_workspace - workspace to be set */ - VectorHandlerCpu:: VectorHandlerCpu(LinAlgWorkspaceCpu* new_workspace) + VectorHandlerCpu::VectorHandlerCpu(LinAlgWorkspaceCpu* new_workspace) { workspace_ = new_workspace; } diff --git a/tests/functionality/testRandGMRES_Rocm.cpp b/tests/functionality/testRandGMRES_Rocm.cpp index 9dafa02e..5d7e7f81 100644 --- a/tests/functionality/testRandGMRES_Rocm.cpp +++ b/tests/functionality/testRandGMRES_Rocm.cpp @@ -4,12 +4,11 @@ #include #include #include -#include #include #include #include #include -#include +#include #include #include #include From 5eced487814152fa6fdcb3be4476c7feebc12936 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 23 Feb 2024 18:44:21 -0500 Subject: [PATCH 3/9] Gentle fixes to the build system. --- examples/CMakeLists.txt | 107 ++++++++++++-------- resolve/LinSolverIterativeRandFGMRES.cpp | 2 + resolve/SystemSolver.cpp | 20 ++-- resolve/random/CMakeLists.txt | 2 +- resolve/random/RandSketchingCountSketch.cpp | 10 +- resolve/random/RandSketchingFWHT.cpp | 8 +- resolve/random/RandSketchingManager.cpp | 29 ------ resolve/random/RandSketchingManager.hpp | 12 +-- resolve/workspace/LinAlgWorkspaceCUDA.cpp | 1 + resolve/workspace/LinAlgWorkspaceCpu.cpp | 1 + resolve/workspace/LinAlgWorkspaceHIP.cpp | 1 + tests/functionality/CMakeLists.txt | 88 ++++++++-------- tests/functionality/testRandGMRES_Cuda.cpp | 2 +- tests/functionality/testSysRandGMRES.cpp | 75 ++++++++------ 14 files changed, 189 insertions(+), 169 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 13912230..9905a8e1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,65 +28,76 @@ target_link_libraries(gmres_cpu_rand.exe PRIVATE ReSolve) # Create CUDA examples if(RESOLVE_USE_CUDA) - - # Build example with KLU factorization and GLU refactorization - add_executable(klu_glu.exe r_KLU_GLU.cpp) - target_link_libraries(klu_glu.exe PRIVATE ReSolve) - - # Build example with KLU factorization and Rf refactorization - add_executable(klu_rf.exe r_KLU_rf.cpp) - target_link_libraries(klu_rf.exe PRIVATE ReSolve) - - # Build example with KLU factorization, Rf refactorization, and FGMRES iterative refinement - add_executable(klu_rf_fgmres.exe r_KLU_rf_FGMRES.cpp) - target_link_libraries(klu_rf_fgmres.exe PRIVATE ReSolve) - - # Build example where matrix is factorized once, refactorized once and then the preconditioner is REUSED - add_executable(klu_rf_fgmres_reuse_refactorization.exe r_KLU_rf_FGMRES_reuse_factorization.cpp) - target_link_libraries(klu_rf_fgmres_reuse_refactorization.exe PRIVATE ReSolve) - - # Build example where matrix data is updated - add_executable(klu_glu_values_update.exe r_KLU_GLU_matrix_values_update.cpp) - target_link_libraries(klu_glu_values_update.exe PRIVATE ReSolve) + + if(RESOLVE_USE_KLU) + + # Build example with KLU factorization and GLU refactorization + add_executable(klu_glu.exe r_KLU_GLU.cpp) + target_link_libraries(klu_glu.exe PRIVATE ReSolve) + + # Build example with KLU factorization and Rf refactorization + add_executable(klu_rf.exe r_KLU_rf.cpp) + target_link_libraries(klu_rf.exe PRIVATE ReSolve) + + # Build example with KLU factorization, Rf refactorization, and FGMRES iterative refinement + add_executable(klu_rf_fgmres.exe r_KLU_rf_FGMRES.cpp) + target_link_libraries(klu_rf_fgmres.exe PRIVATE ReSolve) + + # Build example where matrix is factorized once, refactorized once and then the preconditioner is REUSED + add_executable(klu_rf_fgmres_reuse_refactorization.exe r_KLU_rf_FGMRES_reuse_factorization.cpp) + target_link_libraries(klu_rf_fgmres_reuse_refactorization.exe PRIVATE ReSolve) + # Build example where matrix data is updated + add_executable(klu_glu_values_update.exe r_KLU_GLU_matrix_values_update.cpp) + target_link_libraries(klu_glu_values_update.exe PRIVATE ReSolve) + + # Build example with a configurable system solver + add_executable(system_cuda.exe r_SysSolverCuda.cpp) + target_link_libraries(system_cuda.exe PRIVATE ReSolve) + + # Example in which factorization is redone if solution is bad + add_executable(klu_cusolverrf_check_redo.exe r_KLU_cusolverrf_redo_factorization.cpp) + target_link_libraries(klu_cusolverrf_check_redo.exe PRIVATE ReSolve) + + endif(RESOLVE_USE_KLU) + #rand solver add_executable(gmres_cusparse_rand.exe r_randGMRES_CUDA.cpp) target_link_libraries(gmres_cusparse_rand.exe PRIVATE ReSolve) - # Build example with a configurable system solver - add_executable(system_cuda.exe r_SysSolverCuda.cpp) - target_link_libraries(system_cuda.exe PRIVATE ReSolve) - - # Example in which factorization is redone if solution is bad - add_executable(klu_cusolverrf_check_redo.exe r_KLU_cusolverrf_redo_factorization.cpp) - target_link_libraries(klu_cusolverrf_check_redo.exe PRIVATE ReSolve) endif(RESOLVE_USE_CUDA) # Create HIP examples if(RESOLVE_USE_HIP) - # Build example with KLU factorization and rocsolver Rf refactorization - add_executable(klu_rocsolverrf.exe r_KLU_rocsolverrf.cpp) - target_link_libraries(klu_rocsolverrf.exe PRIVATE ReSolve) - # Build example with KLU factorization, rocsolver Rf refactorization, and FGMRES iterative refinement - add_executable(klu_rocsolverrf_fgmres.exe r_KLU_rocSolverRf_FGMRES.cpp) - target_link_libraries(klu_rocsolverrf_fgmres.exe PRIVATE ReSolve) - - # Example in which factorization is redone if solution is bad - add_executable(klu_rocsolverrf_check_redo.exe r_KLU_rocsolverrf_redo_factorization.cpp) - target_link_libraries(klu_rocsolverrf_check_redo.exe PRIVATE ReSolve) + if(RESOLVE_USE_KLU) + # Build example with KLU factorization and rocsolver Rf refactorization + add_executable(klu_rocsolverrf.exe r_KLU_rocsolverrf.cpp) + target_link_libraries(klu_rocsolverrf.exe PRIVATE ReSolve) + + # Build example with KLU factorization, rocsolver Rf refactorization, and FGMRES iterative refinement + add_executable(klu_rocsolverrf_fgmres.exe r_KLU_rocSolverRf_FGMRES.cpp) + target_link_libraries(klu_rocsolverrf_fgmres.exe PRIVATE ReSolve) + + # Example in which factorization is redone if solution is bad + add_executable(klu_rocsolverrf_check_redo.exe r_KLU_rocsolverrf_redo_factorization.cpp) + target_link_libraries(klu_rocsolverrf_check_redo.exe PRIVATE ReSolve) + + # Build example with a configurable system solver + add_executable(system_hip.exe r_SysSolverHip.cpp) + target_link_libraries(system_hip.exe PRIVATE ReSolve) + + # Build example with a configurable system solver + add_executable(system_hip_fgmres.exe r_SysSolverHipRefine.cpp) + target_link_libraries(system_hip_fgmres.exe PRIVATE ReSolve) + endif(RESOLVE_USE_KLU) + # Rand GMRES test with rocsparse add_executable(gmres_rocsparse_rand.exe r_randGMRES.cpp) target_link_libraries(gmres_rocsparse_rand.exe PRIVATE ReSolve) - # Build example with a configurable system solver - add_executable(system_hip.exe r_SysSolverHip.cpp) - target_link_libraries(system_hip.exe PRIVATE ReSolve) - # Build example with a configurable system solver - add_executable(system_hip_fgmres.exe r_SysSolverHipRefine.cpp) - target_link_libraries(system_hip_fgmres.exe PRIVATE ReSolve) endif(RESOLVE_USE_HIP) set(installable_executables "") @@ -97,11 +108,17 @@ if(RESOLVE_USE_KLU) endif() if(RESOLVE_USE_CUDA) - list(APPEND installable_executables klu_glu.exe klu_rf.exe klu_rf_fgmres.exe klu_glu_values_update.exe gmres_cusparse_rand.exe klu_cusolverrf_check_redo.exe) + if(RESOLVE_USE_KLU) + list(APPEND installable_executables klu_glu.exe klu_rf.exe klu_rf_fgmres.exe klu_glu_values_update.exe klu_cusolverrf_check_redo.exe) + endif() + list(APPEND installable_executables gmres_cusparse_rand.exe) endif(RESOLVE_USE_CUDA) if(RESOLVE_USE_HIP) - list(APPEND installable_executables klu_rocsolverrf.exe klu_rocsolverrf_fgmres.exe klu_rocsolverrf_check_redo.exe gmres_rocsparse_rand.exe) + if(RESOLVE_USE_KLU) + list(APPEND installable_executables klu_rocsolverrf.exe klu_rocsolverrf_fgmres.exe klu_rocsolverrf_check_redo.exe) + endif() + list(APPEND installable_executables gmres_rocsparse_rand.exe) endif(RESOLVE_USE_HIP) list(APPEND installable_executables gmres_cpu_rand.exe) diff --git a/resolve/LinSolverIterativeRandFGMRES.cpp b/resolve/LinSolverIterativeRandFGMRES.cpp index 1737f065..b6e07618 100644 --- a/resolve/LinSolverIterativeRandFGMRES.cpp +++ b/resolve/LinSolverIterativeRandFGMRES.cpp @@ -471,8 +471,10 @@ namespace ReSolve } if (is_matrix_handler_cuda || is_matrix_handler_hip) { + std::cout << "Memory space of randomized GMRES is on GPU ...\n"; memspace_ = memory::DEVICE; } else { + std::cout << "Memory space of randomized GMRES is on CPU ...\n"; memspace_ = memory::HOST; } } diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 381ee3cd..2a978723 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -263,14 +263,22 @@ namespace ReSolve if (precondition_method_ == "none") { // do nothing } else if (precondition_method_ == "ilu0") { + if (memspace_ == "cpu") { + // preconditioner_ = new LinSolverDirectSerialILU0(workspaceCpu_); + preconditioner_ = new LinSolverDirectCpuILU0(workspaceCpu_); #ifdef RESOLVE_USE_CUDA - preconditioner_ = new LinSolverDirectCuSparseILU0(workspaceCuda_); -#elif defined(RESOLVE_USE_HIP) - preconditioner_ = new LinSolverDirectRocSparseILU0(workspaceHip_); -#else - // preconditioner_ = new LinSolverDirectSerialILU0(workspaceCpu_); - preconditioner_ = new LinSolverDirectCpuILU0(workspaceCpu_); + } else if (memspace_ == "cuda") { + preconditioner_ = new LinSolverDirectCuSparseILU0(workspaceCuda_); #endif +#ifdef RESOLVE_USE_HIP + } else if (memspace_ == "hip") { + preconditioner_ = new LinSolverDirectRocSparseILU0(workspaceHip_); +#endif + } else { + out::error() << "Memory space " << memspace_ + << " not recognized ...\n"; + return 1; + } } else { out::error() << "Preconditioner method " << precondition_method_ << " not recognized ...\n"; diff --git a/resolve/random/CMakeLists.txt b/resolve/random/CMakeLists.txt index 34a1b3c2..f37de57e 100644 --- a/resolve/random/CMakeLists.txt +++ b/resolve/random/CMakeLists.txt @@ -8,7 +8,7 @@ # C++ code set(Random_SRC - RandSketchingManager.cpp + # RandSketchingManager.cpp RandSketchingCountSketch.cpp RandSketchingFWHT.cpp ) diff --git a/resolve/random/RandSketchingCountSketch.cpp b/resolve/random/RandSketchingCountSketch.cpp index ec1ae5d6..6e892607 100644 --- a/resolve/random/RandSketchingCountSketch.cpp +++ b/resolve/random/RandSketchingCountSketch.cpp @@ -1,13 +1,12 @@ #include "RandSketchingCountSketch.hpp" #include #include - +#include #ifdef RESOLVE_USE_HIP #include -#elif defined (RESOLVE_USE_CUDA) +#endif +#ifdef RESOLVE_USE_CUDA #include -#else -#include #endif #include @@ -23,6 +22,7 @@ namespace ReSolve RandSketchingCountSketch::RandSketchingCountSketch(memory::MemorySpace memspace) : memspace_(memspace) { + std::cout << "Count skecthing memory space: " << memspace_ << "\n"; h_labels_ = nullptr; h_flip_ = nullptr; @@ -109,7 +109,7 @@ namespace ReSolve for (int i=0; i #include -#include "RandSketchingFWHT.hpp" #include #include #include +#include #ifdef RESOLVE_USE_HIP #include -#elif defined (RESOLVE_USE_CUDA) +#endif +#ifdef RESOLVE_USE_CUDA #include -#else -#include #endif #include + namespace ReSolve { using out = io::Logger; diff --git a/resolve/random/RandSketchingManager.cpp b/resolve/random/RandSketchingManager.cpp index c341ea49..c561a58c 100644 --- a/resolve/random/RandSketchingManager.cpp +++ b/resolve/random/RandSketchingManager.cpp @@ -25,33 +25,4 @@ namespace ReSolve { { } - /** - * @brief Returns the size of base (non-sketched) vector. - * - * @return Base vector size _n_. - */ - index_type RandSketchingManager::getVectorSize() - { - return n_; - } - - /** - * @brief Returns the size of sketched vector. - * - * @return Sketched vector size _k_, generally _k_ =< _n_. - */ - index_type RandSketchingManager::getSketchSize() - { - return k_rand_; - } - - /** - * @brief If padding is used, returns size of padded vector. - * - * @return Sketched vector size _N_, generally _N_ >= _n_. - */ - index_type RandSketchingManager::getPaddedSize() - { - return N_; - } } diff --git a/resolve/random/RandSketchingManager.hpp b/resolve/random/RandSketchingManager.hpp index 2bcb357c..c973f05d 100644 --- a/resolve/random/RandSketchingManager.hpp +++ b/resolve/random/RandSketchingManager.hpp @@ -18,10 +18,14 @@ namespace ReSolve { public: // constructor - RandSketchingManager(); + RandSketchingManager() + { + } // destructor - virtual ~RandSketchingManager(); + virtual ~RandSketchingManager() + { + } // Actual sketching process virtual int Theta(vector_type* input, vector_type* output) = 0; @@ -31,10 +35,6 @@ namespace ReSolve { // Need to use with methods that restart virtual int reset() = 0; - virtual index_type getVectorSize(); - virtual index_type getSketchSize(); - virtual index_type getPaddedSize(); - protected: index_type n_; ///< size of base vector index_type k_rand_; ///< size of sketched vector diff --git a/resolve/workspace/LinAlgWorkspaceCUDA.cpp b/resolve/workspace/LinAlgWorkspaceCUDA.cpp index fd9a7d9d..f8bb2dc9 100644 --- a/resolve/workspace/LinAlgWorkspaceCUDA.cpp +++ b/resolve/workspace/LinAlgWorkspaceCUDA.cpp @@ -4,6 +4,7 @@ namespace ReSolve { LinAlgWorkspaceCUDA::LinAlgWorkspaceCUDA() { + std::cout << "Creating CUDA workspace ...\n"; handle_cusolversp_ = nullptr; handle_cusparse_ = nullptr; handle_cublas_ = nullptr; diff --git a/resolve/workspace/LinAlgWorkspaceCpu.cpp b/resolve/workspace/LinAlgWorkspaceCpu.cpp index c0f25248..fd3a3a36 100644 --- a/resolve/workspace/LinAlgWorkspaceCpu.cpp +++ b/resolve/workspace/LinAlgWorkspaceCpu.cpp @@ -5,6 +5,7 @@ namespace ReSolve { LinAlgWorkspaceCpu::LinAlgWorkspaceCpu() { + std::cout << "Creating CPU workspace ...\n"; } LinAlgWorkspaceCpu::~LinAlgWorkspaceCpu() diff --git a/resolve/workspace/LinAlgWorkspaceHIP.cpp b/resolve/workspace/LinAlgWorkspaceHIP.cpp index c46fdb41..94f605d3 100644 --- a/resolve/workspace/LinAlgWorkspaceHIP.cpp +++ b/resolve/workspace/LinAlgWorkspaceHIP.cpp @@ -4,6 +4,7 @@ namespace ReSolve { LinAlgWorkspaceHIP::LinAlgWorkspaceHIP() { + std::cout << "Creating HIP workspace ...\n"; handle_rocsparse_ = nullptr; handle_rocblas_ = nullptr; diff --git a/tests/functionality/CMakeLists.txt b/tests/functionality/CMakeLists.txt index ceb36179..8f336614 100644 --- a/tests/functionality/CMakeLists.txt +++ b/tests/functionality/CMakeLists.txt @@ -23,25 +23,27 @@ endif(RESOLVE_USE_KLU) if(RESOLVE_USE_CUDA) - # Build KLU+Rf test - add_executable(klu_rf_test.exe testKLU_Rf.cpp) - target_link_libraries(klu_rf_test.exe PRIVATE ReSolve) - - # Build KLU+Rf+fgmres test - add_executable(klu_rf_fgmres_test.exe testKLU_Rf_FGMRES.cpp) - target_link_libraries(klu_rf_fgmres_test.exe PRIVATE ReSolve) - - # System solver test with cusolver rf and iterative refinement - add_executable(sys_refactor_cuda_test.exe testSysRefactor.cpp) - target_link_libraries(sys_refactor_cuda_test.exe PRIVATE ReSolve) - - # Build KLU+GLU test - add_executable(klu_glu_test.exe testKLU_GLU.cpp) - target_link_libraries(klu_glu_test.exe PRIVATE ReSolve) - - # System solver test with GLU - add_executable(sys_glu_test.exe testSysGLU.cpp) - target_link_libraries(sys_glu_test.exe PRIVATE ReSolve) + if(RESOLVE_USE_KLU) + # Build KLU+Rf test + add_executable(klu_rf_test.exe testKLU_Rf.cpp) + target_link_libraries(klu_rf_test.exe PRIVATE ReSolve) + + # Build KLU+Rf+fgmres test + add_executable(klu_rf_fgmres_test.exe testKLU_Rf_FGMRES.cpp) + target_link_libraries(klu_rf_fgmres_test.exe PRIVATE ReSolve) + + # System solver test with cusolver rf and iterative refinement + add_executable(sys_refactor_cuda_test.exe testSysRefactor.cpp) + target_link_libraries(sys_refactor_cuda_test.exe PRIVATE ReSolve) + + # Build KLU+GLU test + add_executable(klu_glu_test.exe testKLU_GLU.cpp) + target_link_libraries(klu_glu_test.exe PRIVATE ReSolve) + + # System solver test with GLU + add_executable(sys_glu_test.exe testSysGLU.cpp) + target_link_libraries(sys_glu_test.exe PRIVATE ReSolve) + endif(RESOLVE_USE_KLU) # Build randSolver test add_executable(rand_gmres_cuda_test.exe testRandGMRES_Cuda.cpp) @@ -52,17 +54,19 @@ endif(RESOLVE_USE_CUDA) if(RESOLVE_USE_HIP) - # Build KLU+rossolver test - add_executable(rocsolver_rf_test.exe testKLU_RocSolver.cpp) - target_link_libraries(rocsolver_rf_test.exe PRIVATE ReSolve) - - # And another one to test FGMRES version - add_executable(rocsolver_rf_fgmres_test.exe testKLU_RocSolver_FGMRES.cpp) - target_link_libraries(rocsolver_rf_fgmres_test.exe PRIVATE ReSolve) - - # System solver test with rocm rf and iterative refinement - add_executable(sys_refactor_hip_test.exe testSysRefactor.cpp) - target_link_libraries(sys_refactor_hip_test.exe PRIVATE ReSolve) + if(RESOLVE_USE_KLU) + # Build KLU+rossolver test + add_executable(rocsolver_rf_test.exe testKLU_RocSolver.cpp) + target_link_libraries(rocsolver_rf_test.exe PRIVATE ReSolve) + + # And another one to test FGMRES version + add_executable(rocsolver_rf_fgmres_test.exe testKLU_RocSolver_FGMRES.cpp) + target_link_libraries(rocsolver_rf_fgmres_test.exe PRIVATE ReSolve) + + # System solver test with rocm rf and iterative refinement + add_executable(sys_refactor_hip_test.exe testSysRefactor.cpp) + target_link_libraries(sys_refactor_hip_test.exe PRIVATE ReSolve) + endif(RESOLVE_USE_KLU) # Build randSolver test add_executable(rand_gmres_hip_test.exe testRandGMRES_Rocm.cpp) @@ -78,19 +82,23 @@ if(RESOLVE_USE_KLU) endif() if(RESOLVE_USE_CUDA) - list(APPEND installable_tests klu_rf_test.exe - klu_rf_fgmres_test.exe - sys_refactor_cuda_test.exe - klu_glu_test.exe - sys_glu_test.exe - rand_gmres_cuda_test.exe) + if(RESOLVE_USE_KLU) + list(APPEND installable_tests klu_rf_test.exe + klu_rf_fgmres_test.exe + sys_refactor_cuda_test.exe + klu_glu_test.exe + sys_glu_test.exe) + endif() + list(APPEND installable_tests rand_gmres_cuda_test.exe) endif(RESOLVE_USE_CUDA) if(RESOLVE_USE_HIP) - list(APPEND installable_tests rocsolver_rf_test.exe - rocsolver_rf_fgmres_test.exe - sys_refactor_hip_test.exe - rand_gmres_hip_test.exe) + if(RESOLVE_USE_KLU) + list(APPEND installable_tests rocsolver_rf_test.exe + rocsolver_rf_fgmres_test.exe + sys_refactor_hip_test.exe) + endif() + list(APPEND installable_tests rand_gmres_hip_test.exe) endif(RESOLVE_USE_HIP) install(TARGETS ${installable_tests} diff --git a/tests/functionality/testRandGMRES_Cuda.cpp b/tests/functionality/testRandGMRES_Cuda.cpp index 87b2d5bd..1d3a90b1 100644 --- a/tests/functionality/testRandGMRES_Cuda.cpp +++ b/tests/functionality/testRandGMRES_Cuda.cpp @@ -9,9 +9,9 @@ #include #include #include -#include #include #include +#include #include using namespace ReSolve::constants; diff --git a/tests/functionality/testSysRandGMRES.cpp b/tests/functionality/testSysRandGMRES.cpp index e322119d..6753bcf3 100644 --- a/tests/functionality/testSysRandGMRES.cpp +++ b/tests/functionality/testSysRandGMRES.cpp @@ -12,37 +12,20 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include #include #include -#if defined (RESOLVE_USE_CUDA) -#include - using workspace_type = ReSolve::LinAlgWorkspaceCUDA; - ReSolve::memory::MemorySpace memspace = ReSolve::memory::DEVICE; - const std::string hwbackend("CUDA"); -#elif defined (RESOLVE_USE_HIP) -#include - using workspace_type = ReSolve::LinAlgWorkspaceHIP; - ReSolve::memory::MemorySpace memspace = ReSolve::memory::DEVICE; - const std::string hwbackend("HIP"); -#else - using workspace_type = ReSolve::LinAlgWorkspaceCpu; - ReSolve::memory::MemorySpace memspace = ReSolve::memory::HOST; - const std::string hwbackend("CPU"); -#endif - using namespace ReSolve::constants; +using namespace ReSolve::colors; // Use ReSolve data types. using real_type = ReSolve::real_type; @@ -50,18 +33,45 @@ using index_type = ReSolve::index_type; using vector_type = ReSolve::vector::Vector; // Forward declarations of helper functions that create test linear system +template +static int test(int argc, char *argv[], const std::string& hwbackend); static void processInputs(std::string& method, std::string& gs, std::string& sketch); static std::string headerInfo(const std::string& method, const std::string& gs, const std::string& sketch); -static ReSolve::matrix::Csr* generateMatrix(const index_type N); -static ReSolve::vector::Vector* generateRhs(const index_type N); +static ReSolve::matrix::Csr* generateMatrix(const index_type N, ReSolve::memory::MemorySpace memspace); +static ReSolve::vector::Vector* generateRhs(const index_type N, ReSolve::memory::MemorySpace memspace); int main(int argc, char *argv[]) +{ + int error_sum = 0; + +#ifndef RESOLVE_USE_GPU + error_sum += test(argc, argv, "CPU"); +#endif + +#ifdef RESOLVE_USE_HIP + error_sum += test(argc, argv, "HIP"); +#endif + +#ifdef RESOLVE_USE_CUDA + error_sum += test(argc, argv, "CUDA"); +#endif + + return error_sum; +} + +template +int test(int argc, char *argv[], const std::string& hwbackend) { // Error sum needs to be 0 at the end for test to PASS. // It is a FAIL otheriwse. int error_sum = 0; int status = 0; + ReSolve::memory::MemorySpace memspace = ReSolve::memory::DEVICE; + if (hwbackend == "CPU") { + memspace = ReSolve::memory::HOST; + } + // Collect all CLI ReSolve::CliOptions options(argc, argv); ReSolve::CliOptions::Option* opt = nullptr; @@ -81,11 +91,11 @@ int main(int argc, char *argv[]) processInputs(method, gs, sketch); // Generate linear system data - ReSolve::matrix::Csr* A = generateMatrix(N); - vector_type* vec_rhs = generateRhs(N); + ReSolve::matrix::Csr* A = generateMatrix(N, memspace); + vector_type* vec_rhs = generateRhs(N, memspace); // Create workspace and initialize its handles. - workspace_type workspace; + T workspace; workspace.initializeHandles(); // Create linear algebra handlers @@ -134,9 +144,10 @@ int main(int argc, char *argv[]) norm_b = vector_handler.dot(vec_rhs, vec_rhs, memspace); norm_b = std::sqrt(norm_b); real_type final_norm = solver.getIterativeSolver().getFinalResidualNorm(); - std::cout << headerInfo(method, gs, sketch) - << "\t Solver tolerance: "// : " - << tol << "\n" + std::cout << std::defaultfloat + << headerInfo(method, gs, sketch) + << "\t Hardware backend: " << hwbackend << "\n" + << "\t Solver tolerance: " << tol << "\n" << std::scientific << std::setprecision(16) << "\t Initial residual norm: ||b-Ax_0||_2 : " << solver.getIterativeSolver().getInitResidualNorm() << " \n" @@ -154,9 +165,9 @@ int main(int argc, char *argv[]) error_sum++; } if (error_sum == 0) { - std::cout<<"Test PASSED\n\n"; + std::cout << "Test " << GREEN << "PASSED" << CLEAR << "\n\n"; } else { - std::cout<<"Test FAILED, error sum: " << error_sum << "\n\n"; + std::cout << "Test " << RED << "FAILED" << CLEAR << ", error sum: " << error_sum << "\n\n"; } delete A; @@ -222,12 +233,12 @@ std::string headerInfo(const std::string& method, const std::string& gs, const s // do nothing } - std::string hw = "\t Hardware backend: " + hwbackend + "\n"; + // std::string hw = "\t Hardware backend: " + hwbackend + "\n"; - return header + hw; + return header; //+ hw; } -ReSolve::vector::Vector* generateRhs(const index_type N) +ReSolve::vector::Vector* generateRhs(const index_type N, ReSolve::memory::MemorySpace memspace) { vector_type* vec_rhs = new vector_type(N); vec_rhs->allocate(ReSolve::memory::HOST); @@ -246,7 +257,7 @@ ReSolve::vector::Vector* generateRhs(const index_type N) return vec_rhs; } -ReSolve::matrix::Csr* generateMatrix(const index_type N) +ReSolve::matrix::Csr* generateMatrix(const index_type N, ReSolve::memory::MemorySpace memspace) { std::vector r1 = {1., 5., 7., 8., 3., 2., 4.}; // sum 30 std::vector r2 = {1., 3., 2., 2., 1., 6., 7., 3., 2., 3.}; // sum 30 From 4a28c34277c775e392d3efacb4e068dc9db34cde Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 23 Feb 2024 19:32:29 -0500 Subject: [PATCH 4/9] Enable KLU-less build. --- resolve/CMakeLists.txt | 13 ++++++------- resolve/SystemSolver.cpp | 2 ++ resolve/cpu/CMakeLists.txt | 4 ++-- resolve/random/RandSketchingCountSketch.cpp | 2 ++ resolve/random/RandSketchingManager.hpp | 6 ++++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 73f3c001..5988f6d6 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -16,11 +16,11 @@ set(ReSolve_SRC LinSolverDirectCpuILU0.cpp LinSolverIterativeRandFGMRES.cpp LinSolverDirectSerialILU0.cpp + SystemSolver.cpp ) set(ReSolve_KLU_SRC LinSolverDirectKLU.cpp - SystemSolver.cpp ) # C++ code that links to CUDA SDK libraries @@ -92,6 +92,11 @@ set(ReSolve_Object_List resolve_options resolve_version ) +# If no GPU support is enabled, link to dummy device backend +if(NOT RESOLVE_USE_GPU) + add_subdirectory(cpu) + list(APPEND ReSolve_Targets_List resolve_backend_cpu) +endif(NOT RESOLVE_USE_GPU) # If CUDA support is enabled add CUDA SDK specific code and dependencies if(RESOLVE_USE_CUDA) @@ -111,12 +116,6 @@ if(RESOLVE_USE_HIP) list(APPEND ReSolve_HEADER_INSTALL ${ReSolve_ROCM_HEADER_INSTALL}) endif() -# If no GPU support is enabled, link to dummy device backend -if(NOT RESOLVE_USE_GPU) - add_subdirectory(cpu) - list(APPEND ReSolve_Targets_List resolve_backend_cpu) -endif() - # Set installable targets install(TARGETS ${ReSolve_Targets_List} EXPORT ReSolveTargets) diff --git a/resolve/SystemSolver.cpp b/resolve/SystemSolver.cpp index 2a978723..1ba90ca4 100644 --- a/resolve/SystemSolver.cpp +++ b/resolve/SystemSolver.cpp @@ -223,8 +223,10 @@ namespace ReSolve // Create factorization solver if (factorizationMethod_ == "none") { // do nothing +#ifdef RESOLVE_USE_KLU } else if (factorizationMethod_ == "klu") { factorizationSolver_ = new ReSolve::LinSolverDirectKLU(); +#endif } else { out::error() << "Unrecognized factorization " << factorizationMethod_ << "\n"; return 1; diff --git a/resolve/cpu/CMakeLists.txt b/resolve/cpu/CMakeLists.txt index 57b0bd75..02632abc 100644 --- a/resolve/cpu/CMakeLists.txt +++ b/resolve/cpu/CMakeLists.txt @@ -7,14 +7,14 @@ ]] set(ReSolve_CPU_SRC - MemoryUtils.cpp cpuVectorKernels.cpp cpuKernels.cpp + MemoryUtils.cpp ) set(ReSolve_CPU_HEADER_INSTALL - CpuMemory.hpp cpuKernels.h + CpuMemory.hpp ) # First create dummy backend diff --git a/resolve/random/RandSketchingCountSketch.cpp b/resolve/random/RandSketchingCountSketch.cpp index 6e892607..1d429fd7 100644 --- a/resolve/random/RandSketchingCountSketch.cpp +++ b/resolve/random/RandSketchingCountSketch.cpp @@ -1,7 +1,9 @@ #include "RandSketchingCountSketch.hpp" #include #include +#ifndef RESOLVE_USE_GPU #include +#endif #ifdef RESOLVE_USE_HIP #include #endif diff --git a/resolve/random/RandSketchingManager.hpp b/resolve/random/RandSketchingManager.hpp index c973f05d..3e903aa9 100644 --- a/resolve/random/RandSketchingManager.hpp +++ b/resolve/random/RandSketchingManager.hpp @@ -11,8 +11,10 @@ namespace ReSolve } } -namespace ReSolve { - class RandSketchingManager { +namespace ReSolve +{ + class RandSketchingManager + { private: using vector_type = vector::Vector; From c3495328cd35d49a76ec14aa62de3d8909626eb3 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Thu, 29 Feb 2024 17:29:14 -0500 Subject: [PATCH 5/9] Correct comments in resolve CMake file. --- resolve/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index 5988f6d6..83b4e2e8 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -30,7 +30,7 @@ set(ReSolve_CUDASDK_SRC LinSolverDirectCuSparseILU0.cpp ) -# HIP files +# C++ code that links to ROCm libraries set(ReSolve_ROCM_SRC LinSolverDirectRocSolverRf.cpp LinSolverDirectRocSparseILU0.cpp @@ -92,6 +92,7 @@ set(ReSolve_Object_List resolve_options resolve_version ) + # If no GPU support is enabled, link to dummy device backend if(NOT RESOLVE_USE_GPU) add_subdirectory(cpu) From 3aabe36cdc8b82513d3d09ace1e402a6763c39b0 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Fri, 1 Mar 2024 15:26:28 -0500 Subject: [PATCH 6/9] Remove debugging output. --- resolve/LinSolverIterativeRandFGMRES.cpp | 2 -- resolve/random/RandSketchingCountSketch.cpp | 23 ++++++++++------- resolve/random/RandSketchingFWHT.cpp | 13 +++++----- resolve/random/RandSketchingManager.cpp | 28 --------------------- resolve/workspace/LinAlgWorkspaceCUDA.cpp | 1 - resolve/workspace/LinAlgWorkspaceCpu.cpp | 1 - resolve/workspace/LinAlgWorkspaceHIP.cpp | 1 - tests/functionality/testSysRandGMRES.cpp | 4 +-- 8 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 resolve/random/RandSketchingManager.cpp diff --git a/resolve/LinSolverIterativeRandFGMRES.cpp b/resolve/LinSolverIterativeRandFGMRES.cpp index b6e07618..1737f065 100644 --- a/resolve/LinSolverIterativeRandFGMRES.cpp +++ b/resolve/LinSolverIterativeRandFGMRES.cpp @@ -471,10 +471,8 @@ namespace ReSolve } if (is_matrix_handler_cuda || is_matrix_handler_hip) { - std::cout << "Memory space of randomized GMRES is on GPU ...\n"; memspace_ = memory::DEVICE; } else { - std::cout << "Memory space of randomized GMRES is on CPU ...\n"; memspace_ = memory::HOST; } } diff --git a/resolve/random/RandSketchingCountSketch.cpp b/resolve/random/RandSketchingCountSketch.cpp index 1d429fd7..0eb77b83 100644 --- a/resolve/random/RandSketchingCountSketch.cpp +++ b/resolve/random/RandSketchingCountSketch.cpp @@ -24,7 +24,6 @@ namespace ReSolve RandSketchingCountSketch::RandSketchingCountSketch(memory::MemorySpace memspace) : memspace_(memspace) { - std::cout << "Count skecthing memory space: " << memspace_ << "\n"; h_labels_ = nullptr; h_flip_ = nullptr; @@ -32,7 +31,7 @@ namespace ReSolve d_flip_ = nullptr; } - // destructor + /// Destructor RandSketchingCountSketch::~RandSketchingCountSketch() { delete [] h_labels_; @@ -43,14 +42,16 @@ namespace ReSolve } } - // Actual sketching process /** * @brief Sketching method using CountSketch algorithm. + * + * Implements actual sketching process. * * @param[in] input - Vector size _n_ * @param[out] output - Vector size _k_ * - * @pre Both input and output variables are initialized and of correct size. Setup has been run at least once + * @pre Both input and output variables are initialized and of correct size. + * Setup has been run at least once * * @return output = Theta (input) * @@ -83,10 +84,11 @@ namespace ReSolve return 0; } - /// Setup the parameters, sampling matrices, permuations, etc /** * @brief Sketching setup method for CountSketch algorithm. - * + * + * Sets up parameters, sampling matrices, permuations, etc. + * * @param[in] n - Size of base vector * @param[in] k - Size of sketch * @@ -135,17 +137,20 @@ namespace ReSolve return 0; } - /// @todo Need to be fixed, this can be done on the GPU. /** * @brief Reset CountSketch arrays (for intance, if solver restarted) * * @param[in] n - Size of base vector * @param[in] k - Size of sketch * - * @pre _n_ > _k_. _k_ value DID NOT CHANGE from the time the setup function was executed. + * @pre _n_ > _k_. _k_ value DID NOT CHANGE from the time the setup function + * was executed. * - * @post The arrays needed for performing sketches with CountSketch (_flip_ and _labels_ ) are reset to new values. If GPU is enabled, the arrays will be copied to the GPU, as well + * @post The arrays needed for performing sketches with CountSketch + * (_flip_ and _labels_ ) are reset to new values. If GPU is enabled, the + * arrays will be copied to the GPU, as well * + * @todo Need to be fixed, this can be done on the GPU. */ int RandSketchingCountSketch::reset() // if needed can be reset (like when Krylov method restarts) { diff --git a/resolve/random/RandSketchingFWHT.cpp b/resolve/random/RandSketchingFWHT.cpp index d8366f66..754fdbb2 100644 --- a/resolve/random/RandSketchingFWHT.cpp +++ b/resolve/random/RandSketchingFWHT.cpp @@ -5,7 +5,9 @@ #include #include #include +#ifndef RESOLVE_USE_GPU #include +#endif #ifdef RESOLVE_USE_HIP #include #endif @@ -37,10 +39,8 @@ namespace ReSolve d_aux_ = nullptr; } - // destructor - /** - * @brief Default de-constructor + * @brief destructor * */ RandSketchingFWHT::~RandSketchingFWHT() @@ -63,10 +63,10 @@ namespace ReSolve } } - // Actual sketching process - /** * @brief Sketching method - it sketches a given vector (shrinks its size) + * + * Implements actula sketching process. * * @param[in] input - input vector, size _n_ * @param[out] output - output vector, size _k_ @@ -198,6 +198,7 @@ namespace ReSolve /** * @brief Reset values in the arrays used for sketching. * + * Sketching can be reset, similar to Krylov method restarts. * If the solver restarts, call this method between restarts. * * @post Everything is set up so you call call Theta. @@ -206,7 +207,7 @@ namespace ReSolve * * @todo Need to be fixed, this can be done on the GPU. */ - int RandSketchingFWHT::reset() // if needed can be reset (like when Krylov method restarts) + int RandSketchingFWHT::reset() { srand(static_cast(time(nullptr))); diff --git a/resolve/random/RandSketchingManager.cpp b/resolve/random/RandSketchingManager.cpp deleted file mode 100644 index c561a58c..00000000 --- a/resolve/random/RandSketchingManager.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// this is a virtual class -#include -#include "RandSketchingManager.hpp" - -namespace ReSolve { - - // constructor - /** - * @brief Simple constructor - * - */ - RandSketchingManager::RandSketchingManager() - { - k_rand_ = 0; - n_ = 0; - N_ = 0; - } - - // destructor - /** - * @brief Destructor - * - */ - RandSketchingManager::~RandSketchingManager() - { - } - -} diff --git a/resolve/workspace/LinAlgWorkspaceCUDA.cpp b/resolve/workspace/LinAlgWorkspaceCUDA.cpp index f8bb2dc9..fd9a7d9d 100644 --- a/resolve/workspace/LinAlgWorkspaceCUDA.cpp +++ b/resolve/workspace/LinAlgWorkspaceCUDA.cpp @@ -4,7 +4,6 @@ namespace ReSolve { LinAlgWorkspaceCUDA::LinAlgWorkspaceCUDA() { - std::cout << "Creating CUDA workspace ...\n"; handle_cusolversp_ = nullptr; handle_cusparse_ = nullptr; handle_cublas_ = nullptr; diff --git a/resolve/workspace/LinAlgWorkspaceCpu.cpp b/resolve/workspace/LinAlgWorkspaceCpu.cpp index fd3a3a36..c0f25248 100644 --- a/resolve/workspace/LinAlgWorkspaceCpu.cpp +++ b/resolve/workspace/LinAlgWorkspaceCpu.cpp @@ -5,7 +5,6 @@ namespace ReSolve { LinAlgWorkspaceCpu::LinAlgWorkspaceCpu() { - std::cout << "Creating CPU workspace ...\n"; } LinAlgWorkspaceCpu::~LinAlgWorkspaceCpu() diff --git a/resolve/workspace/LinAlgWorkspaceHIP.cpp b/resolve/workspace/LinAlgWorkspaceHIP.cpp index 94f605d3..c46fdb41 100644 --- a/resolve/workspace/LinAlgWorkspaceHIP.cpp +++ b/resolve/workspace/LinAlgWorkspaceHIP.cpp @@ -4,7 +4,6 @@ namespace ReSolve { LinAlgWorkspaceHIP::LinAlgWorkspaceHIP() { - std::cout << "Creating HIP workspace ...\n"; handle_rocsparse_ = nullptr; handle_rocblas_ = nullptr; diff --git a/tests/functionality/testSysRandGMRES.cpp b/tests/functionality/testSysRandGMRES.cpp index 6753bcf3..f069a651 100644 --- a/tests/functionality/testSysRandGMRES.cpp +++ b/tests/functionality/testSysRandGMRES.cpp @@ -233,9 +233,7 @@ std::string headerInfo(const std::string& method, const std::string& gs, const s // do nothing } - // std::string hw = "\t Hardware backend: " + hwbackend + "\n"; - - return header; //+ hw; + return header; } ReSolve::vector::Vector* generateRhs(const index_type N, ReSolve::memory::MemorySpace memspace) From da21ee57230270c06fc1a19b68227ea638eb78c4 Mon Sep 17 00:00:00 2001 From: pelesh Date: Wed, 6 Mar 2024 11:20:52 -0500 Subject: [PATCH 7/9] Update resolve/random/RandSketchingCountSketch.hpp Grammar in the comment. Co-authored-by: kswirydo --- resolve/random/RandSketchingCountSketch.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/random/RandSketchingCountSketch.hpp b/resolve/random/RandSketchingCountSketch.hpp index c8238a04..03ae2b04 100644 --- a/resolve/random/RandSketchingCountSketch.hpp +++ b/resolve/random/RandSketchingCountSketch.hpp @@ -32,7 +32,7 @@ namespace ReSolve { private: index_type* h_labels_{nullptr}; ///< label array size _n_, with values from _0_ to _k-1_ assigned by random - index_type* h_flip_{nullptr}; ///< flip array with valyes of 1 and -1 assigned by random + index_type* h_flip_{nullptr}; ///< flip array with values of 1 and -1 assigned by random index_type* d_labels_{nullptr}; ///< h_labels GPU counterpart index_type* d_flip_{nullptr}; ///< h_flip GPU counterpart From 5f3867210811538895b8c4a3d581c9c066991610 Mon Sep 17 00:00:00 2001 From: pelesh Date: Wed, 6 Mar 2024 11:21:21 -0500 Subject: [PATCH 8/9] Update resolve/random/RandSketchingFWHT.cpp Grammar in the comment. Co-authored-by: kswirydo --- resolve/random/RandSketchingFWHT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/random/RandSketchingFWHT.cpp b/resolve/random/RandSketchingFWHT.cpp index 754fdbb2..d0990c88 100644 --- a/resolve/random/RandSketchingFWHT.cpp +++ b/resolve/random/RandSketchingFWHT.cpp @@ -66,7 +66,7 @@ namespace ReSolve /** * @brief Sketching method - it sketches a given vector (shrinks its size) * - * Implements actula sketching process. + * Implements actual sketching process. * * @param[in] input - input vector, size _n_ * @param[out] output - output vector, size _k_ From f6563bfa52418e677b568b20514c030d43c564c7 Mon Sep 17 00:00:00 2001 From: pelesh Date: Wed, 6 Mar 2024 11:21:46 -0500 Subject: [PATCH 9/9] Update resolve/random/RandSketchingManager.hpp Fix comment for accuracy. Co-authored-by: kswirydo --- resolve/random/RandSketchingManager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/random/RandSketchingManager.hpp b/resolve/random/RandSketchingManager.hpp index 3e903aa9..ef7c95ab 100644 --- a/resolve/random/RandSketchingManager.hpp +++ b/resolve/random/RandSketchingManager.hpp @@ -40,7 +40,7 @@ namespace ReSolve protected: index_type n_; ///< size of base vector index_type k_rand_; ///< size of sketched vector - index_type N_; ///< padded n -- generally N_ > n_ + index_type N_; ///< padded n -- generally N_ >= n_ }; } // namespace ReSolve