-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an IndexSet class and basic functions.
- Loading branch information
Showing
21 changed files
with
1,002 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*******************************<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/base/index_set.hpp> | ||
|
||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <mutex> | ||
#include <vector> | ||
|
||
|
||
#include <ginkgo/core/base/exception_helpers.hpp> | ||
#include <ginkgo/core/base/types.hpp> | ||
|
||
|
||
#include "core/base/index_set_kernels.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace index_set { | ||
|
||
|
||
GKO_REGISTER_OPERATION(populate_subsets, index_set::populate_subsets); | ||
|
||
|
||
} // namespace index_set | ||
|
||
|
||
template <typename IndexType> | ||
void IndexSet<IndexType>::populate_subsets(const gko::Array<IndexType> &indices) | ||
{ | ||
auto exec = this->get_executor(); | ||
|
||
auto num_indices = static_cast<IndexType>(indices.get_num_elems()); | ||
|
||
exec->run(index_set::make_populate_subsets( | ||
this->index_space_size_, this->num_stored_indices_, | ||
indices.get_const_data(), num_indices, this->subsets_begin_.get_data(), | ||
this->subsets_end_.get_data(), | ||
this->superset_cumulative_indices_.get_data())); | ||
} | ||
|
||
|
||
template <typename IndexType> | ||
bool IndexSet<IndexType>::is_element(const IndexType index) const | ||
{} | ||
|
||
|
||
template <typename IndexType> | ||
void IndexSet<IndexType>::get_global_index(const IndexType &local_index, | ||
IndexType &global_index) const | ||
{} | ||
|
||
|
||
template <typename IndexType> | ||
void IndexSet<IndexType>::get_local_index(const IndexType &global_index, | ||
IndexType &local_index) const | ||
{} | ||
|
||
|
||
#define GKO_DECLARE_INDEX_SET(_type) class IndexSet<_type> | ||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET); | ||
|
||
|
||
} // 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,111 @@ | ||
/*******************************<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_BASE_INDEX_SET_KERNELS_HPP_ | ||
#define GKO_CORE_BASE_INDEX_SET_KERNELS_HPP_ | ||
|
||
|
||
#include <ginkgo/core/base/index_set.hpp> | ||
|
||
|
||
#include <memory> | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
|
||
|
||
#define GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) \ | ||
void populate_subsets(std::shared_ptr<const DefaultExecutor> exec, \ | ||
const IndexType &index_space_size, \ | ||
IndexType &num_elems, const IndexType *indices, \ | ||
IndexType &num_indices, IndexType *subset_begin, \ | ||
IndexType *subset_end, IndexType *superset_indices) | ||
|
||
|
||
#define GKO_DECLARE_ALL_AS_TEMPLATES \ | ||
template <typename IndexType> \ | ||
GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) | ||
|
||
|
||
namespace omp { | ||
namespace index_set { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace index_set | ||
} // namespace omp | ||
|
||
|
||
namespace cuda { | ||
namespace index_set { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace index_set | ||
} // namespace cuda | ||
|
||
|
||
namespace reference { | ||
namespace index_set { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace index_set | ||
} // namespace reference | ||
|
||
|
||
namespace hip { | ||
namespace index_set { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace index_set | ||
} // namespace hip | ||
|
||
|
||
namespace dpcpp { | ||
namespace index_set { | ||
|
||
GKO_DECLARE_ALL_AS_TEMPLATES; | ||
|
||
} // namespace index_set | ||
} // namespace dpcpp | ||
|
||
|
||
#undef GKO_DECLARE_ALL_AS_TEMPLATES | ||
|
||
|
||
} // namespace kernels | ||
} // namespace gko | ||
|
||
#endif // GKO_CORE_BASE_INDEX_SET_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
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,143 @@ | ||
/*******************************<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/base/index_set.hpp> | ||
|
||
|
||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/range.hpp> | ||
#include <ginkgo/core/matrix/dense.hpp> | ||
|
||
|
||
#include "core/test/utils.hpp" | ||
|
||
|
||
namespace { | ||
|
||
|
||
template <typename T> | ||
class IndexSet : public ::testing::Test { | ||
protected: | ||
using value_type = T; | ||
IndexSet() : exec(gko::ReferenceExecutor::create()) {} | ||
|
||
void TearDown() | ||
{ | ||
if (exec != nullptr) { | ||
// ensure that previous calls finished and didn't throw an error | ||
ASSERT_NO_THROW(exec->synchronize()); | ||
} | ||
} | ||
|
||
static void assert_equal_to_original(gko::IndexSet<T> &a) | ||
{ | ||
ASSERT_EQ(a.get_size(), 10); | ||
} | ||
|
||
static void assert_equal_index_sets(gko::IndexSet<T> &a, | ||
gko::IndexSet<T> &b) | ||
{ | ||
ASSERT_EQ(a.get_size(), b.get_size()); | ||
ASSERT_EQ(a.get_num_subsets(), b.get_num_subsets()); | ||
if (a.get_num_subsets() > 0) { | ||
for (auto i = 0; i < a.get_num_subsets(); ++i) { | ||
ASSERT_EQ(a.get_subsets_begin()[i], b.get_subsets_begin()[i]); | ||
ASSERT_EQ(a.get_subsets_end()[i], b.get_subsets_end()[i]); | ||
ASSERT_EQ(a.get_superset_indices()[i], | ||
b.get_superset_indices()[i]); | ||
} | ||
} | ||
} | ||
|
||
|
||
std::shared_ptr<const gko::Executor> exec; | ||
}; | ||
|
||
TYPED_TEST_SUITE(IndexSet, gko::test::IndexTypes); | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeEmpty) | ||
{ | ||
auto empty = gko::IndexSet<TypeParam>{}; | ||
ASSERT_EQ(empty.get_size(), 0); | ||
ASSERT_EQ(empty.get_num_subsets(), 0); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeConstructedWithSize) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
ASSERT_EQ(idx_set.get_size(), 10); | ||
ASSERT_EQ(idx_set.get_num_subsets(), 0); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeCopyConstructed) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
auto idx_set2(idx_set); | ||
this->assert_equal_index_sets(idx_set2, idx_set); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeMoveConstructed) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
auto idx_set2(std::move(idx_set)); | ||
this->assert_equal_to_original(idx_set2); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeCopyAssigned) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
auto idx_set2 = idx_set; | ||
this->assert_equal_index_sets(idx_set2, idx_set); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, CanBeMoveAssigned) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
auto idx_set2 = std::move(idx_set); | ||
this->assert_equal_to_original(idx_set2); | ||
} | ||
|
||
|
||
TYPED_TEST(IndexSet, KnowsItsSize) | ||
{ | ||
auto idx_set = gko::IndexSet<TypeParam>{this->exec, 10}; | ||
ASSERT_EQ(idx_set.get_size(), 10); | ||
} | ||
|
||
|
||
} // namespace |
Oops, something went wrong.