Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring randomized solvers #146

Merged
merged 9 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions examples/r_randGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/Csc.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/matrix/io.hpp>
#include <resolve/matrix/MatrixHandler.hpp>
#include <resolve/vector/VectorHandler.hpp>
#include <resolve/LinSolverDirectKLU.hpp>
#include <resolve/GramSchmidt.hpp>
#include <resolve/LinSolverDirectRocSparseILU0.hpp>
#include <resolve/LinSolverIterativeRandFGMRES.hpp>
#include <resolve/workspace/LinAlgWorkspace.hpp>
Expand Down
3 changes: 1 addition & 2 deletions examples/r_randGMRES_CUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/Csc.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/matrix/io.hpp>
#include <resolve/matrix/MatrixHandler.hpp>
#include <resolve/vector/VectorHandler.hpp>
#include <resolve/LinSolverDirectKLU.hpp>
#include <resolve/GramSchmidt.hpp>
#include <resolve/LinSolverDirectCuSparseILU0.hpp>
#include <resolve/LinSolverIterativeRandFGMRES.hpp>
#include <resolve/workspace/LinAlgWorkspace.hpp>
Expand Down
3 changes: 1 addition & 2 deletions examples/r_randGMRES_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/Csc.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/matrix/io.hpp>
#include <resolve/matrix/MatrixHandler.hpp>
#include <resolve/vector/VectorHandler.hpp>
#include <resolve/LinSolverDirectKLU.hpp>
#include <resolve/LinSolverDirectSerialILU0.hpp>
#include <resolve/GramSchmidt.hpp>
#include <resolve/LinSolverIterativeRandFGMRES.hpp>
#include <resolve/workspace/LinAlgWorkspace.hpp>
#include <cmath>
Expand Down
25 changes: 11 additions & 14 deletions resolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ set(ReSolve_SRC
LinSolverIterativeFGMRES.cpp
LinSolverDirectCpuILU0.cpp
LinSolverIterativeRandFGMRES.cpp
RandSketchingManager.cpp
RandSketchingCountSketch.cpp
RandSketchingFWHT.cpp
LinSolverDirectSerialILU0.cpp
SystemSolver.cpp
)

set(ReSolve_KLU_SRC
LinSolverDirectKLU.cpp
SystemSolver.cpp
)

# C++ code that links to CUDA SDK libraries
Expand All @@ -33,11 +30,12 @@ set(ReSolve_CUDASDK_SRC
LinSolverDirectCuSparseILU0.cpp
)

# HIP files
# C++ code that links to ROCm libraries
set(ReSolve_ROCM_SRC
LinSolverDirectRocSolverRf.cpp
LinSolverDirectRocSparseILU0.cpp
)

# Header files to be installed
set(ReSolve_HEADER_INSTALL
Common.hpp
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -86,6 +82,7 @@ endif()
set(ReSolve_Targets_List
resolve_matrix
resolve_vector
resolve_random
resolve_logger
resolve_tpl
resolve_workspace
Expand All @@ -96,6 +93,12 @@ set(ReSolve_Object_List
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)
add_subdirectory(cuda)
Expand All @@ -114,12 +117,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)

Expand Down
7 changes: 5 additions & 2 deletions resolve/LinSolverIterativeRandFGMRES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#include <cstring>

#include <resolve/utilities/logger/Logger.hpp>
#include <resolve/matrix/Sparse.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/GramSchmidt.hpp>
#include <resolve/matrix/MatrixHandler.hpp>
#include "LinSolverIterativeRandFGMRES.hpp"
#include <resolve/RandSketchingCountSketch.hpp>
#include <resolve/RandSketchingFWHT.hpp>
#include <resolve/random/RandSketchingCountSketch.hpp>
#include <resolve/random/RandSketchingFWHT.hpp>

namespace ReSolve
{
Expand Down
16 changes: 12 additions & 4 deletions resolve/LinSolverIterativeRandFGMRES.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#pragma once
#include "Common.hpp"
#include <resolve/matrix/Sparse.hpp>
#include <resolve/vector/Vector.hpp>
#include "LinSolver.hpp"
#include "GramSchmidt.hpp"
#include "RandSketchingManager.hpp"

namespace ReSolve
{
// Forward declarations
class RandSketchingManager;
class GramSchmidt;
namespace matrix
{
class Sparse;
}
namespace vector
{
class Vector;
}

/**
* @brief Randomized (F)GMRES
*
Expand Down
2 changes: 1 addition & 1 deletion resolve/MemoryUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace ReSolve
template <typename I, typename T>
int copyArrayHostToHost(T* dst, const T* src, I n)
{
size_t nelements = static_cast<size_t>(n);
std::size_t nelements = static_cast<std::size_t>(n);
memcpy(dst, src, nelements * sizeof(T));
return 0;
}
Expand Down
56 changes: 0 additions & 56 deletions resolve/RandSketchingManager.cpp

This file was deleted.

Loading