From 77da99398abaab21f691e8618bb01ed556344f1c Mon Sep 17 00:00:00 2001 From: Pratik Nayak Date: Tue, 15 Dec 2020 12:17:25 +0100 Subject: [PATCH] Add g2l and l2g kernel base. --- core/base/index_set.cpp | 49 +++++++++++++++++------- core/base/index_set_kernels.hpp | 42 ++++++++++++++------ core/device_hooks/common_kernels.inc.cpp | 12 ++++++ cuda/base/index_set_kernels.cpp | 36 ++++++++++++++--- dpcpp/base/index_set_kernels.dp.cpp | 30 ++++++++++++++- hip/base/index_set_kernels.hip.cpp | 36 ++++++++++++++--- include/ginkgo/core/base/index_set.hpp | 11 ++---- omp/base/index_set_kernels.cpp | 36 ++++++++++++++--- reference/base/index_set_kernels.cpp | 36 ++++++++++++++--- 9 files changed, 234 insertions(+), 54 deletions(-) diff --git a/core/base/index_set.cpp b/core/base/index_set.cpp index 6aa1a2ef574..c2df40c9ebd 100644 --- a/core/base/index_set.cpp +++ b/core/base/index_set.cpp @@ -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 @@ -61,31 +63,50 @@ void IndexSet::populate_subsets(const gko::Array &indices) { auto exec = this->get_executor(); - auto num_indices = static_cast(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 -bool IndexSet::is_element(const IndexType index) const -{} - +Array IndexSet::get_global_indices_from_local( + const Array &local_indices) const +{ + auto exec = this->get_executor(); + auto global_indices = + gko::Array(exec, local_indices.get_num_elems()); -template -void IndexSet::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 -void IndexSet::get_local_index(const IndexType &global_index, - IndexType &local_index) const -{} +Array IndexSet::get_local_indices_from_global( + const Array &global_indices) const +{ + auto exec = this->get_executor(); + auto local_indices = gko::Array(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> diff --git a/core/base/index_set_kernels.hpp b/core/base/index_set_kernels.hpp index 951d2365b61..6756e156311 100644 --- a/core/base/index_set_kernels.hpp +++ b/core/base/index_set_kernels.hpp @@ -44,17 +44,37 @@ namespace gko { namespace kernels { -#define GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) \ - void populate_subsets(std::shared_ptr 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 \ - GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) +#define GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType) \ + void populate_subsets( \ + std::shared_ptr 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 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 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 \ + GKO_DECLARE_INDEX_SET_POPULATE_KERNEL(IndexType); \ + template \ + GKO_DECLARE_INDEX_SET_GLOBAL_TO_LOCAL_KERNEL(IndexType); \ + template \ + GKO_DECLARE_INDEX_SET_LOCAL_TO_GLOBAL_KERNEL(IndexType) namespace omp { diff --git a/core/device_hooks/common_kernels.inc.cpp b/core/device_hooks/common_kernels.inc.cpp index 038f2779611..0640d07463a 100644 --- a/core/device_hooks/common_kernels.inc.cpp +++ b/core/device_hooks/common_kernels.inc.cpp @@ -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 +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 +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 diff --git a/cuda/base/index_set_kernels.cpp b/cuda/base/index_set_kernels.cpp index 8d6a3f9834f..e00a0b75276 100644 --- a/cuda/base/index_set_kernels.cpp +++ b/cuda/base/index_set_kernels.cpp @@ -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. *************************************************************/ -#include "core/base/index_set_kernels.hpp" - - #include #include #include @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/base/index_set_kernels.hpp" + + namespace gko { namespace kernels { /** @@ -61,8 +61,8 @@ namespace index_set { template void populate_subsets(std::shared_ptr 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) {} @@ -70,6 +70,32 @@ void populate_subsets(std::shared_ptr exec, GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL); +template +void global_to_local(std::shared_ptr 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 +void local_to_global(std::shared_ptr 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 diff --git a/dpcpp/base/index_set_kernels.dp.cpp b/dpcpp/base/index_set_kernels.dp.cpp index d28bfcf1be3..b7b698d289b 100644 --- a/dpcpp/base/index_set_kernels.dp.cpp +++ b/dpcpp/base/index_set_kernels.dp.cpp @@ -61,8 +61,8 @@ namespace index_set { template void populate_subsets(std::shared_ptr 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) {} @@ -70,6 +70,32 @@ void populate_subsets(std::shared_ptr exec, GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL); +template +void global_to_local(std::shared_ptr 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 +void local_to_global(std::shared_ptr 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 diff --git a/hip/base/index_set_kernels.hip.cpp b/hip/base/index_set_kernels.hip.cpp index 1317258dfa0..b944b8cee0a 100644 --- a/hip/base/index_set_kernels.hip.cpp +++ b/hip/base/index_set_kernels.hip.cpp @@ -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. *************************************************************/ -#include "core/base/index_set_kernels.hpp" - - #include #include #include @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/base/index_set_kernels.hpp" + + namespace gko { namespace kernels { /** @@ -61,8 +61,8 @@ namespace index_set { template void populate_subsets(std::shared_ptr 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) {} @@ -70,6 +70,32 @@ void populate_subsets(std::shared_ptr exec, GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL); +template +void global_to_local(std::shared_ptr 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 +void local_to_global(std::shared_ptr 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 diff --git a/include/ginkgo/core/base/index_set.hpp b/include/ginkgo/core/base/index_set.hpp index 5c10c76f630..db413074a09 100644 --- a/include/ginkgo/core/base/index_set.hpp +++ b/include/ginkgo/core/base/index_set.hpp @@ -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 get_global_indices_from_local( + const Array &local_indices) const; - void get_local_index(const index_type &global_index, - index_type &local_index) const; + Array get_local_indices_from_global( + const Array &global_indices) const; index_type get_num_subsets() const { diff --git a/omp/base/index_set_kernels.cpp b/omp/base/index_set_kernels.cpp index 0d0fb2b52ab..5d2e72f930d 100644 --- a/omp/base/index_set_kernels.cpp +++ b/omp/base/index_set_kernels.cpp @@ -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. *************************************************************/ -#include "core/base/index_set_kernels.hpp" - - #include #include #include @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/base/index_set_kernels.hpp" + + namespace gko { namespace kernels { /** @@ -61,8 +61,8 @@ namespace index_set { template void populate_subsets(std::shared_ptr 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) {} @@ -70,6 +70,32 @@ void populate_subsets(std::shared_ptr exec, GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL); +template +void global_to_local(std::shared_ptr 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 +void local_to_global(std::shared_ptr 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 omp } // namespace kernels diff --git a/reference/base/index_set_kernels.cpp b/reference/base/index_set_kernels.cpp index 5463efa052f..1bbc9d9133d 100644 --- a/reference/base/index_set_kernels.cpp +++ b/reference/base/index_set_kernels.cpp @@ -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. *************************************************************/ -#include "core/base/index_set_kernels.hpp" - - #include #include #include @@ -43,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "core/base/index_set_kernels.hpp" + + namespace gko { namespace kernels { /** @@ -61,8 +61,8 @@ namespace index_set { template void populate_subsets(std::shared_ptr 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) {} @@ -70,6 +70,32 @@ void populate_subsets(std::shared_ptr exec, GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_INDEX_SET_POPULATE_KERNEL); +template +void global_to_local(std::shared_ptr 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 +void local_to_global(std::shared_ptr 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 reference } // namespace kernels