Skip to content

Commit

Permalink
Add g2l and l2g kernel base.
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikvn committed Dec 15, 2020
1 parent 655d9c7 commit 77da993
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 54 deletions.
49 changes: 35 additions & 14 deletions core/base/index_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace index_set {


GKO_REGISTER_OPERATION(populate_subsets, index_set::populate_subsets);
GKO_REGISTER_OPERATION(global_to_local, index_set::global_to_local);
GKO_REGISTER_OPERATION(local_to_global, index_set::local_to_global);


} // namespace index_set
Expand All @@ -61,31 +63,50 @@ 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());

this->num_stored_indices_ = 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->index_space_size_, indices.get_const_data(),
this->num_stored_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
{}

Array<IndexType> IndexSet<IndexType>::get_global_indices_from_local(
const Array<IndexType> &local_indices) const
{
auto exec = this->get_executor();
auto global_indices =
gko::Array<IndexType>(exec, local_indices.get_num_elems());

template <typename IndexType>
void IndexSet<IndexType>::get_global_index(const IndexType &local_index,
IndexType &global_index) const
{}
GKO_ASSERT(this->get_num_subsets() >= 1);
exec->run(index_set::make_global_to_local(
this->index_space_size_, this->num_stored_indices_,
this->subsets_begin_.get_const_data(),
this->subsets_end_.get_const_data(),
this->superset_cumulative_indices_.get_const_data(),
local_indices.get_const_data(), global_indices.get_data()));
return std::move(global_indices);
}


template <typename IndexType>
void IndexSet<IndexType>::get_local_index(const IndexType &global_index,
IndexType &local_index) const
{}
Array<IndexType> IndexSet<IndexType>::get_local_indices_from_global(
const Array<IndexType> &global_indices) const
{
auto exec = this->get_executor();
auto local_indices = gko::Array<IndexType>(exec);

GKO_ASSERT(this->get_num_subsets() >= 1);
exec->run(index_set::make_local_to_global(
this->index_space_size_, this->num_stored_indices_,
this->subsets_begin_.get_const_data(),
this->subsets_end_.get_const_data(),
this->superset_cumulative_indices_.get_const_data(),
global_indices.get_const_data(), local_indices.get_data()));
return std::move(local_indices);
}


#define GKO_DECLARE_INDEX_SET(_type) class IndexSet<_type>
Expand Down
42 changes: 31 additions & 11 deletions core/base/index_set_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,37 @@ 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)
#define GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) \
void populate_subsets( \
std::shared_ptr<const DefaultExecutor> exec, \
const IndexType index_space_size, const IndexType *indices, \
const IndexType num_indices, IndexType *subset_begin, \
IndexType *subset_end, IndexType *superset_indices)

#define GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL(IndexType) \
void global_to_local( \
std::shared_ptr<const DefaultExecutor> exec, \
const IndexType index_space_size, const IndexType num_indices, \
const IndexType *subset_begin, const IndexType *subset_end, \
const IndexType *superset_indices, const IndexType *local_indices, \
IndexType *global_indices)

#define GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL(IndexType) \
void local_to_global( \
std::shared_ptr<const DefaultExecutor> exec, \
const IndexType index_space_size, const IndexType num_indices, \
const IndexType *subset_begin, const IndexType *subset_end, \
const IndexType *superset_indices, const IndexType *local_indices, \
IndexType *global_indices)


#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename IndexType> \
GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType); \
template <typename IndexType> \
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL(IndexType); \
template <typename IndexType> \
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL(IndexType)


namespace omp {
Expand Down
12 changes: 12 additions & 0 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL);

template <typename IndexType>
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL(IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL);

template <typename IndexType>
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL(IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL);


} // namespace index_set

Expand Down
36 changes: 31 additions & 5 deletions cuda/base/index_set_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

#include "core/base/index_set_kernels.hpp"


#include <algorithm>
#include <iostream>
#include <mutex>
Expand All @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/types.hpp>


#include "core/base/index_set_kernels.hpp"


namespace gko {
namespace kernels {
/**
Expand All @@ -61,15 +61,41 @@ namespace index_set {

template <typename IndexType>
void populate_subsets(std::shared_ptr<const DefaultExecutor> exec,
const IndexType &index_space_size, IndexType &num_elems,
const IndexType *indices, IndexType &num_indices,
const IndexType index_space_size,
const IndexType *indices, const IndexType num_indices,
IndexType *subset_begin, IndexType *subset_end,
IndexType *superset_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL);


template <typename IndexType>
void global_to_local(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *global_indices, IndexType *local_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL);


template <typename IndexType>
void local_to_global(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *local_indices, IndexType *global_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL);


} // namespace index_set
} // namespace cuda
} // namespace kernels
Expand Down
30 changes: 28 additions & 2 deletions dpcpp/base/index_set_kernels.dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,41 @@ namespace index_set {

template <typename IndexType>
void populate_subsets(std::shared_ptr<const DefaultExecutor> exec,
const IndexType &index_space_size, IndexType &num_elems,
const IndexType *indices, IndexType &num_indices,
const IndexType *index_space_size, IndexType *num_elems,
const IndexType *indices, IndexType *num_indices,
IndexType *subset_begin, IndexType *subset_end,
IndexType *superset_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL);


template <typename IndexType>
void global_to_local(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *global_indices, IndexType *local_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL);


template <typename IndexType>
void local_to_global(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *local_indices, IndexType *global_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL);


} // namespace index_set
} // namespace dpcpp
} // namespace kernels
Expand Down
36 changes: 31 additions & 5 deletions hip/base/index_set_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

#include "core/base/index_set_kernels.hpp"


#include <algorithm>
#include <iostream>
#include <mutex>
Expand All @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/types.hpp>


#include "core/base/index_set_kernels.hpp"


namespace gko {
namespace kernels {
/**
Expand All @@ -61,15 +61,41 @@ namespace index_set {

template <typename IndexType>
void populate_subsets(std::shared_ptr<const DefaultExecutor> exec,
const IndexType &index_space_size, IndexType &num_elems,
const IndexType *indices, IndexType &num_indices,
const IndexType index_space_size,
const IndexType *indices, const IndexType num_indices,
IndexType *subset_begin, IndexType *subset_end,
IndexType *superset_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL);


template <typename IndexType>
void global_to_local(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *global_indices, IndexType *local_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL);


template <typename IndexType>
void local_to_global(std::shared_ptr<const DefaultExecutor> exec,
const IndexType index_space_size,
const IndexType num_indices, const IndexType *subset_begin,
const IndexType *subset_end,
const IndexType *superset_indices,
const IndexType *local_indices, IndexType *global_indices)
{}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(
GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL);


} // namespace index_set
} // namespace hip
} // namespace kernels
Expand Down
11 changes: 4 additions & 7 deletions include/ginkgo/core/base/index_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,17 @@ class IndexSet {
return exec_;
}


index_type get_size() const { return this->index_space_size_; }

bool is_element(const index_type index) const;

bool is_contiguous() const { return (this->get_num_subsets() <= 1); }

index_type get_num_elems() const { return this->num_stored_indices_; };

void get_global_index(const index_type &local_index,
index_type &global_index) const;
Array<index_type> get_global_indices_from_local(
const Array<index_type> &local_indices) const;

void get_local_index(const index_type &global_index,
index_type &local_index) const;
Array<index_type> get_local_indices_from_global(
const Array<index_type> &global_indices) const;

index_type get_num_subsets() const
{
Expand Down
Loading

0 comments on commit 77da993

Please sign in to comment.