diff --git a/common/unified/base/index_set_kernels.cpp b/common/unified/base/index_set_kernels.cpp index d5ff4ae498e..d20316ada35 100644 --- a/common/unified/base/index_set_kernels.cpp +++ b/common/unified/base/index_set_kernels.cpp @@ -55,18 +55,16 @@ void compute_validity(std::shared_ptr exec, const Array* local_indices, Array* validity_array) { - auto invalid_idx = invalid_index(); run_kernel( exec, - [invalid_idx] GKO_KERNEL(auto elem, auto local_indices, - auto validity_array) { - validity_array[elem] = local_indices[elem] != invalid_idx; + [] GKO_KERNEL(auto elem, auto local_indices, auto validity_array) { + validity_array[elem] = + local_indices[elem] != invalid_index(); }, - local_indices->get_num_elems(), local_indices->get_const_data(), - validity_array->get_data()); + local_indices->get_num_elems(), *local_indices, *validity_array); } -GKO_INSTANTIATE_FOR_EACH_INDEX_AND_SIZE_TYPE( +GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE( GKO_DECLARE_INDEX_SET_COMPUTE_VALIDITY_KERNEL); diff --git a/core/base/index_set.cpp b/core/base/index_set.cpp index c691020119e..a35510f375f 100644 --- a/core/base/index_set.cpp +++ b/core/base/index_set.cpp @@ -117,7 +117,7 @@ Array IndexSet::to_global_indices() const this->index_space_size_, &this->subsets_begin_, &this->subsets_end_, &this->superset_cumulative_indices_, &decomp_indices)); - return std::move(decomp_indices); + return decomp_indices; } @@ -134,7 +134,7 @@ Array IndexSet::map_local_to_global( this->index_space_size_, &this->subsets_begin_, &this->subsets_end_, &this->superset_cumulative_indices_, &local_indices, &global_indices, is_sorted)); - return std::move(global_indices); + return global_indices; } @@ -151,7 +151,7 @@ Array IndexSet::map_global_to_local( this->index_space_size_, &this->subsets_begin_, &this->subsets_end_, &this->superset_cumulative_indices_, &global_indices, &local_indices, is_sorted)); - return std::move(local_indices); + return local_indices; } diff --git a/core/device_hooks/common_kernels.inc.cpp b/core/device_hooks/common_kernels.inc.cpp index 92cb2ea3698..5d55806c8ee 100644 --- a/core/device_hooks/common_kernels.inc.cpp +++ b/core/device_hooks/common_kernels.inc.cpp @@ -110,11 +110,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. _macro(IndexType) GKO_NOT_COMPILED(GKO_HOOK_MODULE); \ GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) -#define GKO_STUB_INDEX_AND_SIZE_TYPE(_macro) \ - template \ - _macro(IndexSizeType) GKO_NOT_COMPILED(GKO_HOOK_MODULE); \ - GKO_INSTANTIATE_FOR_EACH_INDEX_AND_SIZE_TYPE(_macro) - #define GKO_STUB_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \ template \ _macro(ValueType, IndexType) GKO_NOT_COMPILED(GKO_HOOK_MODULE); \ diff --git a/core/test/base/CMakeLists.txt b/core/test/base/CMakeLists.txt index 636c4d161b7..6f8c7291165 100644 --- a/core/test/base/CMakeLists.txt +++ b/core/test/base/CMakeLists.txt @@ -8,7 +8,6 @@ ginkgo_create_test(exception) ginkgo_create_test(exception_helpers) ginkgo_create_test(extended_float) ginkgo_create_test(executor) -ginkgo_create_test(index_set) ginkgo_create_test(iterator_factory) ginkgo_create_test(lin_op) ginkgo_create_test(math) diff --git a/core/test/base/index_set.cpp b/core/test/base/index_set.cpp deleted file mode 100644 index a944038062e..00000000000 --- a/core/test/base/index_set.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/************************************************************* -Copyright (c) 2017-2021, 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. -*************************************************************/ - -#include - - -#include -#include - - -#include - - -#include -#include - - -#include "core/test/utils.hpp" - - -namespace { - - -template -class IndexSet : public ::testing::Test { -protected: - using index_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()); - } - } - - std::shared_ptr exec; -}; - -TYPED_TEST_SUITE(IndexSet, gko::test::IndexTypes, TypenameNameGenerator); - - -TYPED_TEST(IndexSet, CanBeEmpty) -{ - auto empty = gko::IndexSet{}; - - ASSERT_EQ(empty.get_size(), 0); - ASSERT_EQ(empty.get_num_subsets(), 0); -} - - -} // namespace diff --git a/core/test/utils.hpp b/core/test/utils.hpp index 1ec2fad2def..c1c82d12b00 100644 --- a/core/test/utils.hpp +++ b/core/test/utils.hpp @@ -77,17 +77,6 @@ using ComplexValueTypes = using IndexTypes = ::testing::Types; -using IndexAndUnsignedTypes = - ::testing::Types; - -using AllTemplateTypes = -#if GINKGO_DPCPP_SINGLE_MODE - ::testing::Types, gko::int32, gko::int64, - gko::uint32, gko::uint64>; -#else - ::testing::Types, std::complex, - gko::int32, gko::int64, gko::uint32, gko::uint64>; -#endif using ValueAndIndexTypes = diff --git a/dpcpp/matrix/csr_kernels.dp.cpp b/dpcpp/matrix/csr_kernels.dp.cpp index 6b681ec39cd..7435ff35221 100644 --- a/dpcpp/matrix/csr_kernels.dp.cpp +++ b/dpcpp/matrix/csr_kernels.dp.cpp @@ -50,7 +50,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include "core/base/allocator.hpp" #include "core/base/utils.hpp" #include "core/components/fill_array.hpp" #include "core/components/prefix_sum.hpp" diff --git a/include/ginkgo/core/base/index_set.hpp b/include/ginkgo/core/base/index_set.hpp index 12032a7087c..2f88be5ca28 100644 --- a/include/ginkgo/core/base/index_set.hpp +++ b/include/ginkgo/core/base/index_set.hpp @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -81,33 +82,22 @@ namespace gko { * @ingroup IndexSet */ template -class IndexSet { +class IndexSet : public EnablePolymorphicObject> { + friend class EnablePolymorphicObject; + public: /** * The type of elements stored in the index set. */ using index_type = IndexType; - /** - * Creates an index set not tied to any executor. - * - * This can only be empty. - */ - IndexSet() noexcept = default; - /** * Creates an empty IndexSet tied to the specified Executor. * * @param exec the Executor where the IndexSet data is allocated */ - explicit IndexSet(std::shared_ptr exec) noexcept - : exec_(std::move(exec)), - index_space_size_(0), - num_stored_indices_(0), - subsets_begin_(exec_), - subsets_end_(exec_), - superset_cumulative_indices_(exec_) - + IndexSet(std::shared_ptr exec) + : EnablePolymorphicObject(std::move(exec)) {} /** @@ -123,11 +113,8 @@ class IndexSet { IndexSet(std::shared_ptr executor, const index_type size, const gko::Array& indices, const bool is_sorted = false) - : index_space_size_(size), - exec_(std::move(executor)), - subsets_begin_(exec_), - subsets_end_(exec_), - superset_cumulative_indices_(exec_) + : EnablePolymorphicObject(std::move(executor)), + index_space_size_(size) { GKO_ASSERT(index_space_size_ >= indices.get_num_elems()); this->populate_subsets(indices, is_sorted); @@ -145,112 +132,6 @@ class IndexSet { *this = other; } - /** - * Copies data from another IndexSet - * - * The executor of this is preserved. In case this does not have an assigned - * executor, it will inherit the executor of other. - * - * @param other the IndexSet to copy from - * - * @return this - */ - IndexSet& operator=(const IndexSet& other) - { - if (&other == this) { - return *this; - } - if (exec_ == nullptr) { - exec_ = other.get_executor(); - } - if (other.get_executor() == nullptr) { - this->clear(); - return *this; - } - index_space_size_ = other.index_space_size_; - num_stored_indices_ = other.num_stored_indices_; - subsets_begin_ = other.subsets_begin_; - subsets_end_ = other.subsets_end_; - superset_cumulative_indices_ = other.superset_cumulative_indices_; - - return *this; - } - - /** - * Moves data from another IndexSet. If the data is on another device, it is - * copied over. If it is on the same device, then the data from the other - * IndexSet is moved over and the other IndexSet is cleared. - * - * @param other the IndexSet to move data from - * - * @return this - */ - IndexSet& operator=(IndexSet&& other) - { - if (&other == this) { - return *this; - } - if (exec_ == nullptr) { - exec_ = other.get_executor(); - } - if (other.get_executor() == nullptr) { - this->clear(); - return *this; - } - if (exec_ == other.get_executor()) { - // same device - index_space_size_ = other.index_space_size_; - num_stored_indices_ = other.num_stored_indices_; - subsets_begin_ = std::move(other.subsets_begin_); - subsets_end_ = std::move(other.subsets_end_); - superset_cumulative_indices_ = - std::move(other.superset_cumulative_indices_); - other.clear(); - } else { - // different device, copy the data - *this = other; - } - return *this; - } - - /** - * Creates a copy of another IndexSet. - * - * @param other the IndexSet to copy from - */ - IndexSet(const IndexSet& other) : IndexSet(other.get_executor(), other) {} - - /** - * Moves another IndexSet to a different executor. - * - * @param exec the executor where the new IndexSet will be moved - * @param other the IndexSet to move - */ - IndexSet(std::shared_ptr exec, IndexSet&& other) - : IndexSet(exec) - { - *this = std::move(other); - } - - void clear() noexcept - { - index_space_size_ = 0; - num_stored_indices_ = 0; - subsets_begin_.clear(); - subsets_end_.clear(); - superset_cumulative_indices_.clear(); - } - - /** - * Returns the Executor associated with the index set. - * - * @return the Executor associated with the index set - */ - std::shared_ptr get_executor() const noexcept - { - return exec_; - } - /** * Returns the size of the index set space. * @@ -358,7 +239,7 @@ class IndexSet { Array to_global_indices() const; /** - * Checks if the global index exists in the index set. + * Checks if the individual global indeices exist in the index set. * * @param global_indices the indices to check. * @param is_sorted a parameter that specifies if the query array is sorted @@ -428,8 +309,6 @@ class IndexSet { void populate_subsets(const gko::Array& indices, const bool is_sorted); - std::shared_ptr exec_; - index_type index_space_size_; index_type num_stored_indices_; gko::Array subsets_begin_; diff --git a/include/ginkgo/core/base/types.hpp b/include/ginkgo/core/base/types.hpp index 9c9f10d6ce5..9c6827c4a11 100644 --- a/include/ginkgo/core/base/types.hpp +++ b/include/ginkgo/core/base/types.hpp @@ -532,20 +532,6 @@ GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x, #endif -/** - * Instantiates a template for each index and size type compiled by Ginkgo. - * - * @param _macro A macro which expands the template instantiation - * (not including the leading `template` specifier). - * Should take one argument, which is replaced by the - * value type. - */ -#define GKO_INSTANTIATE_FOR_EACH_INDEX_AND_SIZE_TYPE(_macro) \ - GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \ - template _macro(uint32); \ - template _macro(uint64) - - /** * Instantiates a template for each value and index type compiled by Ginkgo. * @@ -640,44 +626,21 @@ GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x, */ #define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \ GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \ - GKO_INSTANTIATE_FOR_EACH_INDEX_AND_SIZE_TYPE(_macro) + GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \ + template _macro(gko::size_type) /** * Value for an invalid signed index type. */ template -inline IndexType invalid_index() +inline constexpr GKO_ATTRIBUTES IndexType invalid_index() { static_assert(std::is_signed::value, "IndexType needs to be signed"); return static_cast(-1); } -#define GKO_DECLARE_INVALID_TYPES(_itype) _itype invalid_index() - -GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INVALID_TYPES); - - -/** - * Value for an invalid unsigned int. - */ -template <> -inline uint32 invalid_index() -{ - return std::numeric_limits::max(); -} - - -/** - * Value for an invalid unsigned long. - */ -template <> -inline uint64 invalid_index() -{ - return std::numeric_limits::max(); -} - } // namespace gko diff --git a/omp/test/components/fill_array.cpp b/omp/test/components/fill_array.cpp index 4d29271a7da..7b8a4f18a10 100644 --- a/omp/test/components/fill_array.cpp +++ b/omp/test/components/fill_array.cpp @@ -74,7 +74,8 @@ class FillArray : public ::testing::Test { gko::Array seqs; }; -TYPED_TEST_SUITE(FillArray, gko::test::AllTemplateTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(FillArray, gko::test::ValueAndIndexTypes, + TypenameNameGenerator); TYPED_TEST(FillArray, EqualsReference) diff --git a/omp/test/components/reduce_array.cpp b/omp/test/components/reduce_array.cpp index 7ab0979b1f0..9f17af287e0 100644 --- a/omp/test/components/reduce_array.cpp +++ b/omp/test/components/reduce_array.cpp @@ -74,7 +74,7 @@ class ReduceArray : public ::testing::Test { gko::Array dvals; }; -TYPED_TEST_SUITE(ReduceArray, gko::test::AllTemplateTypes, +TYPED_TEST_SUITE(ReduceArray, gko::test::ValueAndIndexTypes, TypenameNameGenerator); diff --git a/reference/test/base/array.cpp b/reference/test/base/array.cpp index 9bb79d44c17..a8647c59391 100644 --- a/reference/test/base/array.cpp +++ b/reference/test/base/array.cpp @@ -61,7 +61,7 @@ class Array : public ::testing::Test { gko::Array x; }; -TYPED_TEST_SUITE(Array, gko::test::AllTemplateTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(Array, gko::test::ValueAndIndexTypes, TypenameNameGenerator); TYPED_TEST(Array, CanBeFilledWithValue) diff --git a/reference/test/components/fill_array.cpp b/reference/test/components/fill_array.cpp index 0c66b94dbdf..9c88cbbbf11 100644 --- a/reference/test/components/fill_array.cpp +++ b/reference/test/components/fill_array.cpp @@ -72,7 +72,8 @@ class FillArray : public ::testing::Test { gko::Array seqs; }; -TYPED_TEST_SUITE(FillArray, gko::test::AllTemplateTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(FillArray, gko::test::ValueAndIndexTypes, + TypenameNameGenerator); TYPED_TEST(FillArray, EqualsReference)