Skip to content
Open
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
60 changes: 39 additions & 21 deletions src/Algorithm/LinearSolvers/IpReSolveSolverInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ReSolveSolverInterface::ReSolveSolverInterface() : val_(NULL)
printf("Resolve with GPU.\n");
# if RESOLVE_WITH_CUDA
printf("Resolve with CUDA.\n");
NVMLHelper::getAvailableGPUMemory();
# else
printf("Resolve with HIP.\n");
# endif
Expand All @@ -39,10 +38,6 @@ ReSolveSolverInterface::ReSolveSolverInterface() : val_(NULL)

ReSolveSolverInterface::~ReSolveSolverInterface()
{

// printf("Begin of Destructor\n");
// NVMLHelper::getAvailableGPUMemory();

DBG_START_METH("ReSolveSolverInterface::~ReSolveSolverInterface()", dbg_verbosity);
delete[] val_;

Expand Down Expand Up @@ -74,8 +69,6 @@ ReSolveSolverInterface::~ReSolveSolverInterface()
delete vec_rhs_;
delete vec_x_;
delete A_;

// printf("End of Destructor\n");
}

void ReSolveSolverInterface::RegisterOptions(SmartPtr<RegisteredOptions> roptions)
Expand Down Expand Up @@ -203,12 +196,14 @@ ESymSolverStatus ReSolveSolverInterface::InitializeStructure(Index dim, Index no

if (method_ == resolve_klu)
{
printf("Resolve::KLU Setup\n");
workspace_CPU_ = new ReSolve::LinAlgWorkspaceCpu();
matrix_handler_ = new ReSolve::MatrixHandler(workspace_CPU_);
vector_handler_ = new ReSolve::VectorHandler(workspace_CPU_);
}

#if RESOLVE_WITH_GPU
printf("Resolve::GPU Setup\n");
workspace_GPU_ = new workspace_type();
workspace_GPU_->initializeHandles();

Expand All @@ -218,17 +213,20 @@ ESymSolverStatus ReSolveSolverInterface::InitializeStructure(Index dim, Index no

if (method_ == resolve_rf || method_ == resolve_rf_fgmres)
{
printf("Resolve::RF Setup\n");
resolve_Rf_ = new rf_solver(workspace_GPU_);
}
# if RESOLVE_WITH_CUDA
else if (method_ == resolve_glu)
{
printf("Resolve::GLU Setup\n");
resolve_GLU_ = new ReSolve::LinSolverDirectCuSolverGLU(workspace_GPU_);
}
# endif

if (method_ == resolve_rf_fgmres)
{
printf("Resolve::FGMRES Setup\n");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use Ipopt's output and not hard-wire these print statements.

GS_ = new ReSolve::GramSchmidt(vector_handler_, ReSolve::GramSchmidt::CGS2);
resolve_FGMRES_ = new ReSolve::LinSolverIterativeFGMRES(matrix_handler_, vector_handler_, GS_);
}
Expand Down Expand Up @@ -258,7 +256,6 @@ ESymSolverStatus ReSolveSolverInterface::InitializeStructure(Index dim, Index no
vec_x_ = new ReSolve::vector::Vector(A_->getNumRows());

vec_x_->allocate(ReSolve::memory::HOST); // for KLU
// vec_x_->allocate(ReSolve::memory::DEVICE);
}

factorize_ = true;
Expand All @@ -267,9 +264,6 @@ ESymSolverStatus ReSolveSolverInterface::InitializeStructure(Index dim, Index no
initialized_ = true;
pivtol_changed_ = false;

// printf("After Initialize\n");
// NVMLHelper::getAvailableGPUMemory();

return retval;
}

Expand All @@ -283,7 +277,20 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
bool full_factor_done = false;

// Get Data from CPU and update the A Matrix
A_->copyDataFrom(A_->getRowData(ReSolve::memory::HOST), A_->getColData(ReSolve::memory::HOST), A_->getValues(ReSolve::memory::HOST), ReSolve::memory::HOST, ReSolve::memory::DEVICE);

A_->setDataPointers(const_cast<int*>(ia), const_cast<int*>(ja), const_cast<Number*>(A_->getValues(ReSolve::memory::HOST)), ReSolve::memory::HOST);

#if RESOLVE_WITH_GPU
#if RESOLVE_WITH_CUDA
if (method_ == resolve_rf || method_ == resolve_rf_fgmres || method_ == resolve_glu) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to just check if it's not glu, in case we add another refactorization method.

A_->syncData(ReSolve::memory::DEVICE);
}
#else
if (method_ == resolve_rf || method_ == resolve_rf_fgmres) {
A_->syncData(ReSolve::memory::DEVICE);
}
#endif
#endif

// FACTORIZE

Expand All @@ -294,10 +301,8 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
// re_factorize_ = true;
}

if (factorize_ && (new_matrix || re_factorize_))
{
// printf("Iteration: %d: Performing KLU Factorization\n", n_iteration_);

if( n_iteration_ == 0){
printf("First Iteration: %d: Performing KLU Factorization\n", n_iteration_);
// Symbolic Factorization
Comment on lines +305 to 306

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace hard-wired print statement with Ipopt output function.

if (HaveIpData())
{
Expand All @@ -314,6 +319,11 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
{
IpData().TimingStats().LinearSystemSymbolicFactorization().End();
}
}

if (factorize_ && (new_matrix || re_factorize_))
{
// printf("Iteration: %d: Performing KLU Factorization\n", n_iteration_);

// perform the factorization
if (HaveIpData())
Expand All @@ -322,7 +332,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
}

// First Factorization is always done by KLU
std::cout << "%" << n_iteration_ << "%" << "FULL FACTORIZATIOM" << std::endl;
// std::cout << "%" << n_iteration_ << "%" << "KLU FULL FACTORIZATION" << std::endl;
status = resolve_KLU_->factorize();
Comment on lines +335 to 336

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code from the PR.

full_factor_done = true;

Expand Down Expand Up @@ -397,6 +407,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
// Actual Refactorize
if (method_ == resolve_glu)
{
//std::cout << "%" << n_iteration_ << "%" << "GLU->refactorize()" << std::endl;
status = resolve_GLU_->refactorize();
if (status != 0)
{
Expand All @@ -405,6 +416,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
}
else if (method_ == resolve_rf || method_ == resolve_rf_fgmres)
{
//std::cout << "%" << n_iteration_ << "%" << "RF->refactorize()" << std::endl;
status_refactor = resolve_Rf_->refactorize();
if (status != 0)
{
Expand All @@ -414,6 +426,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
# else
if (method_ == resolve_rf || method_ == resolve_rf_fgmres)
{
//std::cout << "%" << n_iteration_ << "%" << "RF->refactorize()" << std::endl;
int status = resolve_Rf_->refactorize();
if (status != 0)
{
Expand All @@ -424,7 +437,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index

if (method_ == resolve_klu)
{
std::cout << "%" << n_iteration_ << "%" << "RE-FACTORIZATIOM" << std::endl;
//std::cout << "%" << n_iteration_ << "%" << "KLU->refactorize()" << std::endl;
status = resolve_KLU_->refactorize();
if (status != 0)
{
Expand Down Expand Up @@ -452,7 +465,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
if (use_rcond_)
{
Number rcond_val = resolve_KLU_->getMatrixConditionNumber();
printf("RCond: %12.8e\n", rcond_val);
//printf("RCond: %12.8e\n", rcond_val);
if (rcond_val < rcond_val_)
{
if (full_factor_done)
Expand All @@ -476,6 +489,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
// Copy rhs_vals to vec_rhs
vec_rhs_->copyDataFrom(rhs_vals, ReSolve::memory::HOST, ReSolve::memory::HOST);
status = resolve_KLU_->solve(vec_rhs_, vec_x_);
//printf("Solving using KLU!\n");
if (status != 0)
{
std::cout << "KLU solve status: " << status << std::endl;
Expand All @@ -488,11 +502,14 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
# if RESOLVE_WITH_CUDA
if (method_ == resolve_rf || method_ == resolve_rf_fgmres)
{
printf("Iteration: %d: Setting up %s\n", n_iteration_, method_.c_str());
printf("CUDA: Iteration: %d: Setting up %s\n", n_iteration_, method_.c_str());

ReSolve::matrix::Csc* L_csc = (ReSolve::matrix::Csc*)resolve_KLU_->getLFactor();
ReSolve::matrix::Csc* U_csc = (ReSolve::matrix::Csc*)resolve_KLU_->getUFactor();
ReSolve::matrix::Csr* L = new ReSolve::matrix::Csr(L_csc->getNumRows(), L_csc->getNumColumns(), L_csc->getNnz());
ReSolve::matrix::Csr* U = new ReSolve::matrix::Csr(U_csc->getNumRows(), U_csc->getNumColumns(), U_csc->getNnz());
L_csc->syncData(ReSolve::memory::DEVICE);
U_csc->syncData(ReSolve::memory::DEVICE);
matrix_handler_->csc2csr(L_csc, L, ReSolve::memory::DEVICE);
matrix_handler_->csc2csr(U_csc, U, ReSolve::memory::DEVICE);
if (L == nullptr)
Expand All @@ -516,6 +533,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index

if (method_ == resolve_rf || method_ == resolve_rf_fgmres)
{
printf("HIP: Iteration: %d: Setting up %s\n", n_iteration_, method_.c_str());
ReSolve::matrix::Csc* L = (ReSolve::matrix::Csc*)resolve_KLU_->getLFactor();
ReSolve::matrix::Csc* U = (ReSolve::matrix::Csc*)resolve_KLU_->getUFactor();
ReSolve::index_type* P = resolve_KLU_->getPOrdering();
Expand Down Expand Up @@ -615,7 +633,7 @@ ESymSolverStatus ReSolveSolverInterface::MultiSolve(bool new_matrix, const Index
if (use_rcond_)
{
Number rcond_val = resolve_KLU_->getMatrixConditionNumber();
printf("RCond: %12.8e\n", rcond_val);
//printf("RCond: %12.8e\n", rcond_val);
if (rcond_val < rcond_val_)
{
if (full_factor_done)
Expand Down
5 changes: 1 addition & 4 deletions src/Algorithm/LinearSolvers/IpReSolveSolverInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@

#include "IpoptConfig.h"

#if RESOLVE_WITH_CUDA
#include "NVMLHelper.hpp"
#endif

#include <resolve/matrix/Coo.hpp>
#include <resolve/matrix/Csc.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/MatrixHandler.hpp>
#include <resolve/matrix/io.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/vector/VectorHandler.hpp>
#include <resolve/GramSchmidt.hpp>

#include <resolve/LinSolverDirectKLU.hpp>
#include <resolve/workspace/LinAlgWorkspace.hpp>
Expand Down
70 changes: 0 additions & 70 deletions src/Algorithm/LinearSolvers/NVMLHelper.hpp

This file was deleted.