-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from Exawind/remove_dense_constraints
Removed use of a dense matrix for constraint assembly in favor of a more memory efficient structure
- Loading branch information
Showing
8 changed files
with
136 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/restruct_poc/solver/copy_constraints_to_sparse_matrix.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <KokkosSparse.hpp> | ||
#include <Kokkos_Core.hpp> | ||
|
||
namespace openturbine { | ||
template <typename CrsMatrixType> | ||
struct CopyConstraintsToSparseMatrix { | ||
using RowDataType = typename CrsMatrixType::values_type::non_const_type; | ||
using ColIdxType = typename CrsMatrixType::staticcrsgraph_type::entries_type::non_const_type; | ||
Kokkos::View<Constraints::DeviceData*>::const_type data; | ||
CrsMatrixType sparse; | ||
Kokkos::View<const double* [6][12]> dense; | ||
|
||
KOKKOS_FUNCTION | ||
void operator()(Kokkos::TeamPolicy<>::member_type member) const { | ||
auto i_constraint = member.league_rank(); | ||
auto& cd = data(i_constraint); | ||
auto start_row = cd.row_range.first; | ||
auto end_row = cd.row_range.second; | ||
Kokkos::parallel_for(Kokkos::TeamThreadRange(member, start_row, end_row), [&](int i) { | ||
auto row_number = i - start_row; | ||
auto row = sparse.row(i); | ||
auto row_map = sparse.graph.row_map; | ||
auto cols = sparse.graph.entries; | ||
auto row_data_data = Kokkos::Array<typename RowDataType::value_type, 12>{}; | ||
auto col_idx_data = Kokkos::Array<typename ColIdxType::value_type, 12>{}; | ||
auto row_data = RowDataType(row_data_data.data(), row.length); | ||
auto col_idx = ColIdxType(col_idx_data.data(), row.length); | ||
for (int entry = 0; entry < row.length; ++entry) { | ||
col_idx(entry) = cols(row_map(i) + entry); | ||
row_data(entry) = dense(i_constraint, row_number, entry); | ||
} | ||
sparse.replaceValues(i, col_idx.data(), row.length, row_data.data()); | ||
}); | ||
} | ||
}; | ||
} // namespace openturbine |
28 changes: 28 additions & 0 deletions
28
src/restruct_poc/solver/copy_sparse_values_to_transpose.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <KokkosSparse.hpp> | ||
#include <Kokkos_Core.hpp> | ||
|
||
namespace openturbine { | ||
template <typename CrsMatrixType> | ||
struct CopySparseValuesToTranspose { | ||
using RowMapType = typename CrsMatrixType::staticcrsgraph_type::row_map_type::non_const_type; | ||
CrsMatrixType input; | ||
RowMapType tmp; | ||
CrsMatrixType transpose; | ||
|
||
KOKKOS_FUNCTION | ||
void operator()(Kokkos::TeamPolicy<>::member_type member) const { | ||
int row_index = member.league_rank(); | ||
int col_begin = input.graph.row_map(row_index); | ||
int col_end = input.graph.row_map(row_index + 1); | ||
Kokkos::parallel_for(Kokkos::TeamThreadRange(member, col_begin, col_end), [&](int in_index) { | ||
int col_index = input.graph.entries(in_index); | ||
using atomic_incr_type = typename std::remove_reference<decltype(tmp(0))>::type; | ||
int pos = Kokkos::atomic_fetch_add(&(tmp(col_index)), atomic_incr_type{1}); | ||
transpose.graph.entries(pos) = row_index; | ||
transpose.values(pos) = input.values(in_index); | ||
}); | ||
} | ||
}; | ||
} // namespace openturbine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.