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

Sparse solver on GPU #600

Merged
merged 10 commits into from
Mar 14, 2023
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
4 changes: 2 additions & 2 deletions src/Drivers/MDS/NlpMdsRajaEx1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class MdsEx1 : public hiop::hiopInterfaceMDS
* Returns the sizes and number of nonzeros of the sparse and dense blocks within MDS
*
* @param[out] nx_sparse number of sparse variables
* @param[out] nx_ense number of dense variables
* @param[out] nx_dense number of dense variables
* @param[out] nnz_sparse_Jace number of nonzeros in the Jacobian of the equalities w.r.t.
* sparse variables
* @param[out] nnz_sparse_Jaci number of nonzeros in the Jacobian of the inequalities w.r.t.
Expand Down Expand Up @@ -233,7 +233,7 @@ class MdsEx1 : public hiop::hiopInterfaceMDS
* @param[in] x array with the optimization variables or point at which to evaluate
* (managed by Umpire)
* @param[in] new_x indicates whether any of the other eval functions have been evaluated
* previously (false) or not (true) at x
* previously (false) or not (true) at x
* @param[out] gradf array with the values of the gradient (managed by Umpire)
*/
bool eval_grad_f(const size_type& n, const double* x, bool new_x, double* gradf);
Expand Down
19 changes: 19 additions & 0 deletions src/Drivers/Sparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ target_link_libraries(NlpSparseEx2.exe HiOp::HiOp)
add_executable(NlpSparseEx3.exe NlpSparseEx3.cpp NlpSparseEx3Driver.cpp)
target_link_libraries(NlpSparseEx3.exe HiOp::HiOp)

if(HIOP_USE_RAJA)
if(HIOP_USE_GPU AND HIOP_USE_CUDA)
set_source_files_properties(
NlpSparseRajaEx2.cpp
NlpSparseRajaEx2Driver.cpp
PROPERTIES LANGUAGE CUDA
)

add_executable(NlpSparseRajaEx2.exe NlpSparseRajaEx2Driver.cpp NlpSparseRajaEx2.cpp)
target_link_libraries(NlpSparseRajaEx2.exe HiOp::HiOp)
install(TARGETS NlpSparseRajaEx2.exe DESTINATION bin)
endif()
endif()

if(HIOP_BUILD_SHARED)
add_executable(NlpSparseCEx1.exe NlpSparseCEx1.c)
target_link_libraries(NlpSparseCEx1.exe HiOp::HiOp)
Expand Down Expand Up @@ -52,6 +66,11 @@ if(HIOP_USE_GINKGO)
add_test(NAME NlpSparse2_6 COMMAND ${RUNCMD} "$<TARGET_FILE:NlpSparseEx2.exe>" "500" "-ginkgo_hip" "-inertiafree" "-selfcheck")
endif(HIOP_USE_HIP)
endif(HIOP_USE_GINKGO)

if(HIOP_USE_RAJA AND HIOP_USE_GPU AND HIOP_USE_CUDA)
add_test(NAME NlpSparseRaja2_1 COMMAND ${RUNCMD} bash -c "$<TARGET_FILE:NlpSparseRajaEx2.exe> 500 -selfcheck ")
endif()

add_test(NAME NlpSparse3_1 COMMAND ${RUNCMD} "$<TARGET_FILE:NlpSparseEx3.exe>" "500" "-selfcheck")
if(HIOP_BUILD_SHARED AND NOT HIOP_USE_GPU)
add_test(NAME NlpSparseCinterface COMMAND ${RUNCMD} "$<TARGET_FILE:NlpSparseCEx1.exe>")
Expand Down
3 changes: 1 addition & 2 deletions src/Drivers/Sparse/NlpSparseEx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ bool SparseEx2::eval_cons(const size_type& n,
return false;
}

/* Four constraints no matter how large n is */
bool SparseEx2::eval_cons(const size_type& n, const size_type& m, const double* x, bool new_x, double* cons)
{
assert(n==n_vars); assert(m==n_cons);
Expand All @@ -170,7 +169,7 @@ bool SparseEx2::eval_cons(const size_type& n, const size_type& m, const double*
// --- constraint 2 body ---> 2*x_1 + x_3
cons[conidx++] += 2*x[0] + 1*x[2];

// --- constraint 3 body ---> 2*x_1 + 0.5*x_i, for i>=4
// --- constraint 3 body ---> 2*x_1 + 0.5*x_i, for i>=4
for(auto i=3; i<n; i++) {
cons[conidx++] += 2*x[0] + 0.5*x[i];
}
Expand Down
Loading