-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge: Reverse Cuthill-McKee reordering
This PR adds a reordering framework and the RCM algorithm for reordering a matrix. + All reordering is done on the CPU and if reordering is called on the GPU, it is copied to the host and the reordering is copied back to the GPU. Related PR: #500
- Loading branch information
Showing
35 changed files
with
5,669 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2020, the Ginkgo authors | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
#include <ginkgo/core/reorder/rcm.hpp> | ||
|
||
|
||
#include <memory> | ||
|
||
|
||
#include <ginkgo/core/base/array.hpp> | ||
#include <ginkgo/core/base/exception_helpers.hpp> | ||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/polymorphic_object.hpp> | ||
#include <ginkgo/core/base/types.hpp> | ||
#include <ginkgo/core/base/utils.hpp> | ||
#include <ginkgo/core/matrix/csr.hpp> | ||
#include <ginkgo/core/matrix/permutation.hpp> | ||
#include <ginkgo/core/matrix/sparsity_csr.hpp> | ||
|
||
|
||
#include "core/matrix/csr_kernels.hpp" | ||
#include "core/reorder/rcm_kernels.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace reorder { | ||
namespace rcm { | ||
|
||
|
||
GKO_REGISTER_OPERATION(get_permutation, rcm::get_permutation); | ||
GKO_REGISTER_OPERATION(get_degree_of_nodes, rcm::get_degree_of_nodes); | ||
|
||
|
||
} // namespace rcm | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
void Rcm<ValueType, IndexType>::generate( | ||
std::shared_ptr<const Executor> &exec, | ||
std::unique_ptr<SparsityMatrix> adjacency_matrix) const | ||
{ | ||
const IndexType num_rows = adjacency_matrix->get_size()[0]; | ||
const auto mtx = adjacency_matrix.get(); | ||
auto degrees = Array<IndexType>(exec, num_rows); | ||
// RCM is only valid for symmetric matrices. Need to add an expensive check | ||
// for symmetricity here ? | ||
exec->run(rcm::make_get_degree_of_nodes(num_rows, mtx->get_const_row_ptrs(), | ||
degrees.get_data())); | ||
exec->run(rcm::make_get_permutation( | ||
num_rows, mtx->get_const_row_ptrs(), mtx->get_const_col_idxs(), | ||
degrees.get_const_data(), permutation_->get_permutation(), | ||
inv_permutation_.get() ? inv_permutation_->get_permutation() : nullptr, | ||
parameters_.strategy)); | ||
} | ||
|
||
|
||
#define GKO_DECLARE_RCM(ValueType, IndexType) class Rcm<ValueType, IndexType> | ||
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_RCM); | ||
|
||
|
||
} // namespace reorder | ||
} // namespace gko |
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,117 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2020, the Ginkgo authors | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
#ifndef GKO_CORE_REORDER_RCM_KERNELS_HPP_ | ||
#define GKO_CORE_REORDER_RCM_KERNELS_HPP_ | ||
|
||
|
||
#include <ginkgo/core/reorder/rcm.hpp> | ||
|
||
|
||
#include <memory> | ||
|
||
|
||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/lin_op.hpp> | ||
#include <ginkgo/core/base/types.hpp> | ||
#include <ginkgo/core/matrix/csr.hpp> | ||
#include <ginkgo/core/matrix/permutation.hpp> | ||
#include <ginkgo/core/matrix/sparsity_csr.hpp> | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
|
||
|
||
#define GKO_DECLARE_RCM_GET_PERMUTATION_KERNEL(IndexType) \ | ||
void get_permutation(std::shared_ptr<const DefaultExecutor> exec, \ | ||
IndexType num_vertices, const IndexType *row_ptrs, \ | ||
const IndexType *col_idxs, const IndexType *degrees, \ | ||
IndexType *permutation, IndexType *inv_permutation, \ | ||
gko::reorder::starting_strategy strategy) | ||
|
||
#define GKO_DECLARE_RCM_GET_DEGREE_OF_NODES_KERNEL(IndexType) \ | ||
void get_degree_of_nodes(std::shared_ptr<const DefaultExecutor> exec, \ | ||
IndexType num_vertices, \ | ||
const IndexType *row_ptrs, IndexType *degrees) | ||
|
||
#define GKO_DECLARE_ALL_AS_TEMPLATES \ | ||
template <typename IndexType> \ | ||
GKO_DECLARE_RCM_GET_DEGREE_OF_NODES_KERNEL(IndexType); \ | ||
template <typename IndexType> \ | ||
GKO_DECLARE_RCM_GET_PERMUTATION_KERNEL(IndexType) | ||
|
||
|
||
namespace omp { | ||
namespace rcm { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace rcm | ||
} // namespace omp | ||
|
||
|
||
namespace cuda { | ||
namespace rcm { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace rcm | ||
} // namespace cuda | ||
|
||
|
||
namespace hip { | ||
namespace rcm { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace rcm | ||
} // namespace hip | ||
|
||
|
||
namespace reference { | ||
namespace rcm { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace rcm | ||
} // namespace reference | ||
|
||
|
||
#undef GKO_DECLARE_ALL_AS_TEMPLATES | ||
|
||
|
||
} // namespace kernels | ||
} // namespace gko | ||
|
||
|
||
#endif // GKO_CORE_REORDER_RCM_KERNELS_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
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 @@ | ||
ginkgo_create_test(rcm) |
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,70 @@ | ||
/*******************************<GINKGO LICENSE>****************************** | ||
Copyright (c) 2017-2019, the Ginkgo authors | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
******************************<GINKGO LICENSE>*******************************/ | ||
|
||
#include <ginkgo/core/reorder/rcm.hpp> | ||
|
||
|
||
#include <memory> | ||
|
||
|
||
#include <gtest/gtest.h> | ||
|
||
|
||
#include <ginkgo/core/base/executor.hpp> | ||
|
||
|
||
#include "core/test/utils.hpp" | ||
|
||
|
||
namespace { | ||
|
||
class Rcm : public ::testing::Test { | ||
protected: | ||
using v_type = double; | ||
using i_type = int; | ||
using reorder_type = gko::reorder::Rcm<v_type, i_type>; | ||
|
||
Rcm() | ||
: exec(gko::ReferenceExecutor::create()), | ||
rcm_factory(reorder_type::build().on(exec)) | ||
{} | ||
|
||
std::shared_ptr<const gko::Executor> exec; | ||
std::unique_ptr<reorder_type::Factory> rcm_factory; | ||
}; | ||
|
||
TEST_F(Rcm, RcmFactoryKnowsItsExecutor) | ||
{ | ||
ASSERT_EQ(this->rcm_factory->get_executor(), this->exec); | ||
} | ||
|
||
} // namespace |
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.