Skip to content

Commit

Permalink
Review update.
Browse files Browse the repository at this point in the history
+ Remove old stubs and defines for instantiations
+ Use PolymorphicObject instead.

Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
  • Loading branch information
pratikvn and upsj committed Nov 4, 2021
1 parent ea9bf5a commit 2248355
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 284 deletions.
12 changes: 5 additions & 7 deletions common/unified/base/index_set_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ void compute_validity(std::shared_ptr<const DefaultExecutor> exec,
const Array<IndexType>* local_indices,
Array<bool>* validity_array)
{
auto invalid_idx = invalid_index<IndexType>();
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<IndexType>();
},
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);


Expand Down
6 changes: 3 additions & 3 deletions core/base/index_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Array<IndexType> IndexSet<IndexType>::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;
}


Expand All @@ -134,7 +134,7 @@ Array<IndexType> IndexSet<IndexType>::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;
}


Expand All @@ -151,7 +151,7 @@ Array<IndexType> IndexSet<IndexType>::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;
}


Expand Down
5 changes: 0 additions & 5 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename IndexSizeType> \
_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 <typename ValueType, typename IndexType> \
_macro(ValueType, IndexType) GKO_NOT_COMPILED(GKO_HOOK_MODULE); \
Expand Down
1 change: 0 additions & 1 deletion core/test/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
82 changes: 0 additions & 82 deletions core/test/base/index_set.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions core/test/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ using ComplexValueTypes =


using IndexTypes = ::testing::Types<gko::int32, gko::int64>;
using IndexAndUnsignedTypes =
::testing::Types<gko::int32, gko::int64, gko::uint32, gko::uint64>;

using AllTemplateTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float, std::complex<float>, gko::int32, gko::int64,
gko::uint32, gko::uint64>;
#else
::testing::Types<float, double, std::complex<float>, std::complex<double>,
gko::int32, gko::int64, gko::uint32, gko::uint64>;
#endif


using ValueAndIndexTypes =
Expand Down
1 change: 0 additions & 1 deletion dpcpp/matrix/csr_kernels.dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/matrix/sellp.hpp>


#include "core/base/allocator.hpp"
#include "core/base/utils.hpp"
#include "core/components/fill_array.hpp"
#include "core/components/prefix_sum.hpp"
Expand Down
139 changes: 9 additions & 130 deletions include/ginkgo/core/base/index_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#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>

Expand Down Expand Up @@ -81,33 +82,22 @@ namespace gko {
* @ingroup IndexSet
*/
template <typename IndexType = int32>
class IndexSet {
class IndexSet : public EnablePolymorphicObject<IndexSet<IndexType>> {
friend class EnablePolymorphicObject<IndexSet>;

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<const Executor> 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<const Executor> exec)
: EnablePolymorphicObject<IndexSet>(std::move(exec))
{}

/**
Expand All @@ -123,11 +113,8 @@ class IndexSet {
IndexSet(std::shared_ptr<const gko::Executor> executor,
const index_type size, const gko::Array<index_type>& 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<IndexSet>(std::move(executor)),
index_space_size_(size)
{
GKO_ASSERT(index_space_size_ >= indices.get_num_elems());
this->populate_subsets(indices, is_sorted);
Expand All @@ -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<const Executor> 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<const gko::Executor> get_executor() const noexcept
{
return exec_;
}

/**
* Returns the size of the index set space.
*
Expand Down Expand Up @@ -358,7 +239,7 @@ class IndexSet {
Array<index_type> 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
Expand Down Expand Up @@ -428,8 +309,6 @@ class IndexSet {
void populate_subsets(const gko::Array<index_type>& indices,
const bool is_sorted);

std::shared_ptr<const gko::Executor> exec_;

index_type index_space_size_;
index_type num_stored_indices_;
gko::Array<index_type> subsets_begin_;
Expand Down
Loading

0 comments on commit 2248355

Please sign in to comment.