-
Notifications
You must be signed in to change notification settings - Fork 99
Add new SpGEMM/SpGEAM interface with reuse capabilities #1934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
upsj
wants to merge
8
commits into
develop
Choose a base branch
from
new_spgemm_interface
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8de40b3
add new SpGEMM interface and reuse capabilities
upsj 75a9321
review updates
upsj 4cd37f6
replace uses of old SpGEMM interface
upsj 5e6a15e
fix compilation and handle empty multiply_reuse_info
upsj 2b0e3ca
add spgemm_reuse to sparse_blas benchmark
upsj 001a974
add add_scale and multiply_add functions with reuse
upsj 6d1d93c
add dpcpp kernels
upsj 8d13f9f
update sparse_blas operations, add spgemm_reuse_setup
upsj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,11 +5,13 @@ | |
#include "ginkgo/core/matrix/csr.hpp" | ||
|
||
#include <ginkgo/core/base/array.hpp> | ||
#include <ginkgo/core/base/exception.hpp> | ||
#include <ginkgo/core/base/exception_helpers.hpp> | ||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/index_set.hpp> | ||
#include <ginkgo/core/base/math.hpp> | ||
#include <ginkgo/core/base/precision_dispatch.hpp> | ||
#include <ginkgo/core/base/temporary_clone.hpp> | ||
#include <ginkgo/core/base/utils.hpp> | ||
#include <ginkgo/core/matrix/coo.hpp> | ||
#include <ginkgo/core/matrix/dense.hpp> | ||
|
@@ -45,6 +47,7 @@ GKO_REGISTER_OPERATION(spmv, csr::spmv); | |
GKO_REGISTER_OPERATION(advanced_spmv, csr::advanced_spmv); | ||
GKO_REGISTER_OPERATION(spgemm, csr::spgemm); | ||
GKO_REGISTER_OPERATION(advanced_spgemm, csr::advanced_spgemm); | ||
GKO_REGISTER_OPERATION(spgemm_reuse, csr::spgemm_reuse); | ||
GKO_REGISTER_OPERATION(spgeam, csr::spgeam); | ||
GKO_REGISTER_OPERATION(convert_idxs_to_ptrs, components::convert_idxs_to_ptrs); | ||
GKO_REGISTER_OPERATION(convert_ptrs_to_idxs, components::convert_ptrs_to_idxs); | ||
|
@@ -643,6 +646,108 @@ void Csr<ValueType, IndexType>::write(mat_data& data) const | |
} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
std::unique_ptr<Csr<ValueType, IndexType>> Csr<ValueType, IndexType>::multiply( | ||
ptr_param<const Csr> other) const | ||
{ | ||
GKO_ASSERT_CONFORMANT(this, other); | ||
auto result_size = gko::dim<2>{this->get_size()[0], other->get_size()[1]}; | ||
auto exec = this->get_executor(); | ||
auto local_other = make_temporary_clone(exec, other); | ||
auto result = Csr::create(exec, result_size); | ||
exec->run(csr::make_spgemm(this, local_other.get(), result.get())); | ||
return result; | ||
} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
struct Csr<ValueType, IndexType>::multiply_reuse_info::lookup_data { | ||
dim<2> size1; | ||
dim<2> size2; | ||
dim<2> size_out; | ||
size_type nnz1; | ||
size_type nnz2; | ||
size_type nnz_out; | ||
csr::lookup_data<IndexType> data; | ||
}; | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
Csr<ValueType, IndexType>::multiply_reuse_info::~multiply_reuse_info() = | ||
default; | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
Csr<ValueType, IndexType>::multiply_reuse_info::multiply_reuse_info( | ||
multiply_reuse_info&&) = default; | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
typename Csr<ValueType, IndexType>::multiply_reuse_info& | ||
Csr<ValueType, IndexType>::multiply_reuse_info::operator=( | ||
multiply_reuse_info&&) = default; | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
Csr<ValueType, IndexType>::multiply_reuse_info::multiply_reuse_info() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. =default ? |
||
{} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
Csr<ValueType, IndexType>::multiply_reuse_info::multiply_reuse_info( | ||
std::unique_ptr<lookup_data> data) | ||
: internal{std::move(data)} | ||
{} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
void Csr<ValueType, IndexType>::multiply_reuse_info::update_values( | ||
ptr_param<const Csr> mtx1, ptr_param<const Csr> mtx2, | ||
ptr_param<Csr> out) const | ||
{ | ||
if (!internal) { | ||
throw InvalidStateError{ | ||
__FILE__, __LINE__, __func__, | ||
"Attempting to use uninitialized multiply_reuse_info"}; | ||
} | ||
upsj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
GKO_ASSERT_EQUAL_DIMENSIONS(mtx1, internal->size1); | ||
GKO_ASSERT_EQUAL_DIMENSIONS(mtx2, internal->size2); | ||
GKO_ASSERT_EQUAL_DIMENSIONS(out, internal->size_out); | ||
GKO_ASSERT_EQ(mtx1->get_num_stored_elements(), internal->nnz1); | ||
GKO_ASSERT_EQ(mtx2->get_num_stored_elements(), internal->nnz2); | ||
GKO_ASSERT_EQ(out->get_num_stored_elements(), internal->nnz_out); | ||
auto exec = internal->data.storage.get_executor(); | ||
auto local_mtx1 = make_temporary_clone(exec, mtx1); | ||
auto local_mtx2 = make_temporary_clone(exec, mtx2); | ||
auto local_out = make_temporary_clone(exec, out); | ||
exec->run(csr::make_spgemm_reuse(local_mtx1.get(), local_mtx2.get(), | ||
internal->data, local_out.get())); | ||
} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
std::pair<std::unique_ptr<Csr<ValueType, IndexType>>, | ||
typename Csr<ValueType, IndexType>::multiply_reuse_info> | ||
Csr<ValueType, IndexType>::multiply_reuse(ptr_param<const Csr> other) const | ||
{ | ||
GKO_ASSERT_CONFORMANT(this, other); | ||
auto result_size = gko::dim<2>{this->get_size()[0], other->get_size()[1]}; | ||
auto exec = this->get_executor(); | ||
auto local_other = make_temporary_clone(exec, other); | ||
auto result = Csr::create(exec, result_size); | ||
exec->run(csr::make_spgemm(this, local_other.get(), result.get())); | ||
auto lookup = csr::build_lookup(result.get()); | ||
auto reuse_info = multiply_reuse_info{ | ||
std::make_unique<typename multiply_reuse_info::lookup_data>( | ||
typename multiply_reuse_info::lookup_data{ | ||
this->get_size(), other->get_size(), result_size, | ||
this->get_num_stored_elements(), | ||
other->get_num_stored_elements(), | ||
result->get_num_stored_elements(), std::move(lookup)})}; | ||
return std::make_pair(std::move(result), std::move(reuse_info)); | ||
} | ||
|
||
|
||
template <typename ValueType, typename IndexType, typename TransformClosure> | ||
std::pair<std::unique_ptr<Csr<ValueType, IndexType>>, | ||
typename Csr<ValueType, IndexType>::permuting_reuse_info> | ||
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.