Skip to content

Commit

Permalink
rename compute_elim_forest to compute_elimination_forest
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jan 11, 2025
1 parent 039133f commit fce1842
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion benchmark/test/reference/sparse_blas.reordered.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bandwidth": 1.0,
"repetitions": 10,
"components": {
"compute_elim_forest": 1.0,
"compute_elimination_forest": 1.0,
"allocate": 1.0,
"free": 1.0,
"components::fill_array": 1.0,
Expand Down
47 changes: 24 additions & 23 deletions core/factorization/elimination_forest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand All @@ -13,10 +13,9 @@ namespace {


template <typename IndexType>
void compute_elim_forest_parent_impl(std::shared_ptr<const Executor> host_exec,
const IndexType* row_ptrs,
const IndexType* cols, IndexType num_rows,
IndexType* parent)
void compute_elimination_forest_parent_impl(
std::shared_ptr<const Executor> host_exec, const IndexType* row_ptrs,
const IndexType* cols, IndexType num_rows, IndexType* parent)
{
disjoint_sets<IndexType> subtrees{host_exec, num_rows};
array<IndexType> subtree_root_array{host_exec,
Expand Down Expand Up @@ -50,8 +49,10 @@ void compute_elim_forest_parent_impl(std::shared_ptr<const Executor> host_exec,


template <typename IndexType>
void compute_elim_forest_children_impl(const IndexType* parent, IndexType size,
IndexType* child_ptr, IndexType* child)
void compute_elimination_forest_children_impl(const IndexType* parent,
IndexType size,
IndexType* child_ptr,
IndexType* child)
{
// count how many times each parent occurs, excluding pseudo-root at
// parent == size
Expand All @@ -74,7 +75,7 @@ void compute_elim_forest_children_impl(const IndexType* parent, IndexType size,


template <typename IndexType>
void compute_elim_forest_postorder_impl(
void compute_elimination_forest_postorder_impl(
std::shared_ptr<const Executor> host_exec, const IndexType* parent,
const IndexType* child_ptr, const IndexType* child, IndexType size,
IndexType* postorder, IndexType* inv_postorder)
Expand Down Expand Up @@ -111,10 +112,9 @@ void compute_elim_forest_postorder_impl(


template <typename IndexType>
void compute_elim_forest_postorder_parent_impl(const IndexType* parent,
const IndexType* inv_postorder,
IndexType size,
IndexType* postorder_parent)
void compute_elimination_forest_postorder_parent_impl(
const IndexType* parent, const IndexType* inv_postorder, IndexType size,
IndexType* postorder_parent)
{
for (IndexType row = 0; row < size; row++) {
postorder_parent[inv_postorder[row]] =
Expand All @@ -140,26 +140,27 @@ void elimination_forest<IndexType>::set_executor(


template <typename ValueType, typename IndexType>
void compute_elim_forest(const matrix::Csr<ValueType, IndexType>* mtx,
std::unique_ptr<elimination_forest<IndexType>>& forest)
void compute_elimination_forest(
const matrix::Csr<ValueType, IndexType>* mtx,
std::unique_ptr<elimination_forest<IndexType>>& forest)
{
const auto host_exec = mtx->get_executor()->get_master();
const auto host_mtx = make_temporary_clone(host_exec, mtx);
const auto num_rows = static_cast<IndexType>(host_mtx->get_size()[0]);
forest =
std::make_unique<elimination_forest<IndexType>>(host_exec, num_rows);
compute_elim_forest_parent_impl(host_exec, host_mtx->get_const_row_ptrs(),
host_mtx->get_const_col_idxs(), num_rows,
forest->parents.get_data());
compute_elim_forest_children_impl(forest->parents.get_const_data(),
num_rows, forest->child_ptrs.get_data(),
forest->children.get_data());
compute_elim_forest_postorder_impl(
compute_elimination_forest_parent_impl(
host_exec, host_mtx->get_const_row_ptrs(),
host_mtx->get_const_col_idxs(), num_rows, forest->parents.get_data());
compute_elimination_forest_children_impl(
forest->parents.get_const_data(), num_rows,
forest->child_ptrs.get_data(), forest->children.get_data());
compute_elimination_forest_postorder_impl(
host_exec, forest->parents.get_const_data(),
forest->child_ptrs.get_const_data(), forest->children.get_const_data(),
num_rows, forest->postorder.get_data(),
forest->inv_postorder.get_data());
compute_elim_forest_postorder_parent_impl(
compute_elimination_forest_postorder_parent_impl(
forest->parents.get_const_data(),
forest->inv_postorder.get_const_data(), num_rows,
forest->postorder_parents.get_data());
Expand All @@ -169,7 +170,7 @@ void compute_elim_forest(const matrix::Csr<ValueType, IndexType>* mtx,


#define GKO_DECLARE_COMPUTE_ELIM_FOREST(ValueType, IndexType) \
void compute_elim_forest( \
void compute_elimination_forest( \
const matrix::Csr<ValueType, IndexType>* mtx, \
std::unique_ptr<elimination_forest<IndexType>>& forest)

Expand Down
4 changes: 2 additions & 2 deletions core/factorization/elimination_forest.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -41,7 +41,7 @@ struct elimination_forest {


template <typename ValueType, typename IndexType>
void compute_elim_forest(
void compute_elimination_forest(
const matrix::Csr<ValueType, IndexType>* mtx,
std::unique_ptr<elimination_forest<IndexType>>& forest);

Expand Down
7 changes: 4 additions & 3 deletions core/factorization/symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ GKO_REGISTER_OPERATION(symbolic_factorize_simple,
lu_factorization::symbolic_factorize_simple);
GKO_REGISTER_OPERATION(symbolic_factorize_simple_finalize,
lu_factorization::symbolic_factorize_simple_finalize);
GKO_REGISTER_HOST_OPERATION(compute_elim_forest, compute_elim_forest);
GKO_REGISTER_HOST_OPERATION(compute_elimination_forest,
compute_elimination_forest);


} // namespace
Expand All @@ -54,7 +55,7 @@ void symbolic_cholesky(
GKO_ASSERT_IS_SQUARE_MATRIX(mtx);
const auto exec = mtx->get_executor();
const auto host_exec = exec->get_master();
exec->run(make_compute_elim_forest(mtx, forest));
exec->run(make_compute_elimination_forest(mtx, forest));
const auto num_rows = mtx->get_size()[0];
array<IndexType> row_ptrs{exec, num_rows + 1};
array<IndexType> tmp{exec};
Expand Down Expand Up @@ -103,7 +104,7 @@ void symbolic_cholesky_device(
exec->run(make_compute_skeleton_tree(
mtx->get_const_row_ptrs(), mtx->get_const_col_idxs(), num_rows,
skeleton->get_row_ptrs(), skeleton->get_col_idxs()));
exec->run(make_compute_elim_forest(skeleton.get(), forest));
exec->run(make_compute_elimination_forest(skeleton.get(), forest));
}
array<IndexType> row_ptrs{exec, num_rows + 1};
array<IndexType> tmp{exec};
Expand Down
12 changes: 6 additions & 6 deletions core/test/factorization/elimination_forest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -55,7 +55,7 @@ TYPED_TEST(EliminationForest, WorksForExample)
this->ref);

std::unique_ptr<gko::factorization::elimination_forest<index_type>> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);

GKO_ASSERT_ARRAY_EQ(forest->parents,
I<index_type>({2, 4, 6, 8, 8, 6, 7, 8, 9, 10}));
Expand Down Expand Up @@ -92,7 +92,7 @@ TYPED_TEST(EliminationForest, WorksForSeparable)
this->ref);

std::unique_ptr<gko::factorization::elimination_forest<index_type>> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);

GKO_ASSERT_ARRAY_EQ(forest->parents,
I<index_type>({2, 2, 10, 4, 5, 9, 7, 9, 9, 10}));
Expand Down Expand Up @@ -128,7 +128,7 @@ TYPED_TEST(EliminationForest, WorksForPostOrderNotSelfInverse)
},
this->ref);
std::unique_ptr<gko::factorization::elimination_forest<index_type>> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);
GKO_ASSERT_ARRAY_EQ(forest->parents,
I<index_type>({2, 4, 6, 8, 5, 6, 7, 8, 9, 10}));
GKO_ASSERT_ARRAY_EQ(forest->child_ptrs,
Expand All @@ -152,7 +152,7 @@ TYPED_TEST(EliminationForest, WorksForAni1)
auto mtx = gko::read<matrix_type>(stream, this->ref);

std::unique_ptr<gko::factorization::elimination_forest<index_type>> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);

// the elimination tree is a path
gko::array<index_type> iota_arr{this->ref, 36};
Expand All @@ -178,7 +178,7 @@ TYPED_TEST(EliminationForest, WorksForAni1Amd)
auto mtx = gko::read<matrix_type>(stream, this->ref);

std::unique_ptr<gko::factorization::elimination_forest<index_type>> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);

GKO_ASSERT_ARRAY_EQ(
forest->parents,
Expand Down
23 changes: 12 additions & 11 deletions reference/test/factorization/cholesky_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class Cholesky : public ::testing::Test {
l_factor_ref->get_num_stored_elements());
combined = matrix_type::create(ref, combined_ref->get_size(),
combined_ref->get_num_stored_elements());
gko::factorization::compute_elim_forest(l_factor_ref.get(), forest);
gko::factorization::compute_elimination_forest(l_factor_ref.get(),
forest);
// init sparsity lookup
ref->copy(num_rows + 1, l_factor_ref->get_const_row_ptrs(),
l_factor->get_row_ptrs());
Expand Down Expand Up @@ -262,18 +263,18 @@ TYPED_TEST(Cholesky, KernelComputeSkeletonTreeIsEquivalentToOriginalMatrix)
auto skeleton = matrix_type::create(
this->ref, this->mtx->get_size(), this->mtx->get_size()[0]);
std::unique_ptr<elimination_forest> skeleton_forest;
gko::factorization::compute_elim_forest(this->mtx.get(),
this->forest);
gko::factorization::compute_elimination_forest(this->mtx.get(),
this->forest);

gko::kernels::reference::elimination_forest::compute_skeleton_tree(
this->ref, this->mtx->get_const_row_ptrs(),
this->mtx->get_const_col_idxs(), this->mtx->get_size()[0],
skeleton->get_row_ptrs(), skeleton->get_col_idxs());

gko::factorization::compute_elim_forest(this->mtx.get(),
this->forest);
gko::factorization::compute_elim_forest(skeleton.get(),
skeleton_forest);
gko::factorization::compute_elimination_forest(this->mtx.get(),
this->forest);
gko::factorization::compute_elimination_forest(skeleton.get(),
skeleton_forest);

this->assert_equal_forests(*skeleton_forest, *this->forest);
},
Expand All @@ -289,8 +290,8 @@ TYPED_TEST(Cholesky, KernelSymbolicCount)
using index_type = typename TestFixture::index_type;
this->forall_matrices(
[this] {
gko::factorization::compute_elim_forest(this->mtx.get(),
this->forest);
gko::factorization::compute_elimination_forest(this->mtx.get(),
this->forest);
gko::array<index_type> row_nnz{this->ref, this->num_rows};

gko::kernels::reference::cholesky::symbolic_count(
Expand All @@ -311,8 +312,8 @@ TYPED_TEST(Cholesky, KernelSymbolicFactorize)
using index_type = typename TestFixture::index_type;
this->forall_matrices(
[this] {
gko::factorization::compute_elim_forest(this->mtx.get(),
this->forest);
gko::factorization::compute_elimination_forest(this->mtx.get(),
this->forest);
gko::kernels::reference::cholesky::symbolic_count(
this->ref, this->mtx.get(), *this->forest,
this->l_factor->get_row_ptrs(), this->tmp);
Expand Down
23 changes: 12 additions & 11 deletions test/factorization/cholesky_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ TYPED_TEST(CholeskySymbolic, KernelComputeSkeletonTree)
std::unique_ptr<elimination_forest> forest;
std::unique_ptr<elimination_forest> skeleton_forest;
std::unique_ptr<elimination_forest> dskeleton_forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elim_forest(skeleton.get(),
skeleton_forest);
gko::factorization::compute_elim_forest(dskeleton.get(),
dskeleton_forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(skeleton.get(),
skeleton_forest);
gko::factorization::compute_elimination_forest(dskeleton.get(),
dskeleton_forest);
// the parents array fully determines the elimination forest
GKO_ASSERT_ARRAY_EQ(forest->parents, skeleton_forest->parents);
GKO_ASSERT_ARRAY_EQ(skeleton_forest->parents,
Expand All @@ -215,8 +215,8 @@ TYPED_TEST(CholeskySymbolic, KernelSymbolicCount)
const auto dmtx = gko::clone(this->exec, mtx);
std::unique_ptr<elimination_forest> forest;
std::unique_ptr<elimination_forest> dforest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elim_forest(dmtx.get(), dforest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(dmtx.get(), dforest);
gko::array<index_type> row_nnz{this->ref, mtx->get_size()[0]};
gko::array<index_type> drow_nnz{this->exec, mtx->get_size()[0]};

Expand All @@ -242,7 +242,7 @@ TYPED_TEST(CholeskySymbolic, KernelSymbolicFactorize)
const auto dmtx = gko::clone(this->exec, mtx);
const auto num_rows = mtx->get_size()[0];
std::unique_ptr<elimination_forest> forest;
gko::factorization::compute_elim_forest(mtx.get(), forest);
gko::factorization::compute_elimination_forest(mtx.get(), forest);
gko::array<index_type> row_ptrs{this->ref, num_rows + 1};
gko::kernels::reference::cholesky::symbolic_count(
this->ref, mtx.get(), *forest, row_ptrs.get_data(), this->tmp);
Expand All @@ -259,7 +259,7 @@ TYPED_TEST(CholeskySymbolic, KernelSymbolicFactorize)
gko::array<index_type>{this->exec, nnz}, row_ptrs);
// need to call the device kernels to initialize dtmp
std::unique_ptr<elimination_forest> dforest;
gko::factorization::compute_elim_forest(dmtx.get(), dforest);
gko::factorization::compute_elimination_forest(dmtx.get(), dforest);
gko::array<index_type> dtmp_ptrs{this->exec, num_rows + 1};
gko::kernels::GKO_DEVICE_NAMESPACE::cholesky::symbolic_count(
this->exec, dmtx.get(), *dforest, dtmp_ptrs.get_data(), this->dtmp);
Expand Down Expand Up @@ -380,8 +380,9 @@ class Cholesky : public CommonTestFixture {
mtx_chol_sparsity->copy_from(mtx_chol.get());
dmtx_chol_sparsity = sparsity_pattern_type::create(exec);
dmtx_chol_sparsity->copy_from(mtx_chol_sparsity.get());
gko::factorization::compute_elim_forest(mtx_chol.get(), forest);
gko::factorization::compute_elim_forest(dmtx_chol.get(), dforest);
gko::factorization::compute_elimination_forest(mtx_chol.get(), forest);
gko::factorization::compute_elimination_forest(dmtx_chol.get(),
dforest);
}

void forall_matrices(std::function<void()> fn)
Expand Down

0 comments on commit fce1842

Please sign in to comment.