Skip to content
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

Sparsity format Reference and OpenMP kernels #350

Merged
merged 8 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename Sparsity to SparsityCsr.
  • Loading branch information
pratikvn committed Oct 2, 2019
commit b8bd4773d90d4bed7b2ef588f8a8c93085e1e989
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_sources(ginkgo
matrix/hybrid.cpp
matrix/identity.cpp
matrix/sellp.cpp
matrix/sparsity.cpp
matrix/sparsity_csr.cpp
preconditioner/jacobi.cpp
solver/bicgstab.cpp
solver/cg.cpp
Expand Down
40 changes: 21 additions & 19 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "core/matrix/ell_kernels.hpp"
#include "core/matrix/hybrid_kernels.hpp"
#include "core/matrix/sellp_kernels.hpp"
#include "core/matrix/sparsity_kernels.hpp"
#include "core/matrix/sparsity_csr_kernels.hpp"
#include "core/preconditioner/jacobi_kernels.hpp"
#include "core/solver/bicgstab_kernels.hpp"
#include "core/solver/cg_kernels.hpp"
Expand Down Expand Up @@ -126,10 +126,10 @@ GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_DENSE_CONVERT_TO_SELLP_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_KERNEL(ValueType, IndexType)
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_CSR_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_KERNEL);
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_CSR_KERNEL);

template <typename ValueType>
GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(ValueType)
Expand Down Expand Up @@ -358,52 +358,54 @@ GKO_NOT_COMPILED(GKO_HOOK_MODULE);
} // namespace ir


namespace sparsity {
namespace sparsity_csr {


template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_SPMV_KERNEL(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_SPMV_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_SPARSITY_SPMV_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_CSR_SPMV_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_ADVANCED_SPMV_KERNEL(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_ADVANCED_SPMV_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_ADVANCED_SPMV_KERNEL);
GKO_DECLARE_SPARSITY_CSR_ADVANCED_SPMV_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_COUNT_NUM_DIAGONAL_ELEMENTS_KERNEL(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_COUNT_NUM_DIAGONAL_ELEMENTS_KERNEL(ValueType,
IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_COUNT_NUM_DIAGONAL_ELEMENTS_KERNEL);
GKO_DECLARE_SPARSITY_CSR_COUNT_NUM_DIAGONAL_ELEMENTS_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_REMOVE_DIAGONAL_ELEMENTS_KERNEL(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_REMOVE_DIAGONAL_ELEMENTS_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_REMOVE_DIAGONAL_ELEMENTS_KERNEL);
GKO_DECLARE_SPARSITY_CSR_REMOVE_DIAGONAL_ELEMENTS_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_TRANSPOSE_KERNEL(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_TRANSPOSE_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_TRANSPOSE_KERNEL);
GKO_DECLARE_SPARSITY_CSR_TRANSPOSE_KERNEL);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_SORT_BY_COLUMN_INDEX(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_SORT_BY_COLUMN_INDEX(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_SORT_BY_COLUMN_INDEX);
GKO_DECLARE_SPARSITY_CSR_SORT_BY_COLUMN_INDEX);

template <typename ValueType, typename IndexType>
GKO_DECLARE_SPARSITY_IS_SORTED_BY_COLUMN_INDEX(ValueType, IndexType)
GKO_DECLARE_SPARSITY_CSR_IS_SORTED_BY_COLUMN_INDEX(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_SPARSITY_IS_SORTED_BY_COLUMN_INDEX);
GKO_DECLARE_SPARSITY_CSR_IS_SORTED_BY_COLUMN_INDEX);


} // namespace sparsity
} // namespace sparsity_csr


namespace csr {
Expand Down
9 changes: 5 additions & 4 deletions core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>


#include "core/matrix/csr_kernels.hpp"
Expand Down Expand Up @@ -190,10 +190,10 @@ void Csr<ValueType, IndexType>::move_to(Sellp<ValueType, IndexType> *result)

template <typename ValueType, typename IndexType>
void Csr<ValueType, IndexType>::convert_to(
Sparsity<ValueType, IndexType> *result) const
SparsityCsr<ValueType, IndexType> *result) const
{
auto exec = this->get_executor();
auto tmp = Sparsity<ValueType, IndexType>::create(
auto tmp = SparsityCsr<ValueType, IndexType>::create(
exec, this->get_size(), this->get_num_stored_elements());
yhmtsai marked this conversation as resolved.
Show resolved Hide resolved
tmp->col_idxs_ = this->col_idxs_;
tmp->row_ptrs_ = this->row_ptrs_;
Expand All @@ -203,7 +203,8 @@ void Csr<ValueType, IndexType>::convert_to(


template <typename ValueType, typename IndexType>
void Csr<ValueType, IndexType>::move_to(Sparsity<ValueType, IndexType> *result)
void Csr<ValueType, IndexType>::move_to(
SparsityCsr<ValueType, IndexType> *result)
{
this->convert_to(result);
}
Expand Down
2 changes: 1 addition & 1 deletion core/matrix/csr_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>


namespace gko {
Expand Down
16 changes: 8 additions & 8 deletions core/matrix/dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>


#include "core/matrix/dense_kernels.hpp"
Expand Down Expand Up @@ -185,15 +185,15 @@ inline void conversion_helper(Sellp<ValueType, IndexType> *result,

template <typename ValueType, typename IndexType, typename MatrixType,
typename OperationType>
inline void conversion_helper(Sparsity<ValueType, IndexType> *result,
inline void conversion_helper(SparsityCsr<ValueType, IndexType> *result,
MatrixType *source, const OperationType &op)
{
auto exec = source->get_executor();

size_type num_stored_nonzeros = 0;
exec->run(dense::make_count_nonzeros(source, &num_stored_nonzeros));
auto tmp = Sparsity<ValueType, IndexType>::create(exec, source->get_size(),
num_stored_nonzeros);
auto tmp = SparsityCsr<ValueType, IndexType>::create(
exec, source->get_size(), num_stored_nonzeros);
exec->run(op(tmp.get(), source));
tmp->move_to(result);
}
Expand Down Expand Up @@ -442,7 +442,7 @@ void Dense<ValueType>::move_to(Sellp<ValueType, int64> *result)


template <typename ValueType>
void Dense<ValueType>::convert_to(Sparsity<ValueType, int32> *result) const
void Dense<ValueType>::convert_to(SparsityCsr<ValueType, int32> *result) const
{
conversion_helper(
result, this,
Expand All @@ -452,14 +452,14 @@ void Dense<ValueType>::convert_to(Sparsity<ValueType, int32> *result) const


template <typename ValueType>
void Dense<ValueType>::move_to(Sparsity<ValueType, int32> *result)
void Dense<ValueType>::move_to(SparsityCsr<ValueType, int32> *result)
{
this->convert_to(result);
}


template <typename ValueType>
void Dense<ValueType>::convert_to(Sparsity<ValueType, int64> *result) const
void Dense<ValueType>::convert_to(SparsityCsr<ValueType, int64> *result) const
{
conversion_helper(
result, this,
Expand All @@ -469,7 +469,7 @@ void Dense<ValueType>::convert_to(Sparsity<ValueType, int64> *result) const


template <typename ValueType>
void Dense<ValueType>::move_to(Sparsity<ValueType, int64> *result)
void Dense<ValueType>::move_to(SparsityCsr<ValueType, int64> *result)
{
this->convert_to(result);
}
pratikvn marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
76 changes: 38 additions & 38 deletions core/matrix/dense_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ namespace kernels {
matrix::Sellp<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_KERNEL(_type, _prec) \
#define GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_CSR_KERNEL(_type, _prec) \
void convert_to_sparsity(std::shared_ptr<const DefaultExecutor> exec, \
thoasm marked this conversation as resolved.
Show resolved Hide resolved
matrix::Sparsity<_type, _prec> *other, \
matrix::SparsityCsr<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(_type) \
Expand Down Expand Up @@ -133,42 +133,42 @@ namespace kernels {
matrix::Dense<_type> *trans, \
const matrix::Dense<_type> *orig)

#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename ValueType> \
GKO_DECLARE_DENSE_SIMPLE_APPLY_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_APPLY_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_SCALE_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_ADD_SCALED_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COMPUTE_DOT_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COMPUTE_NORM2_KERNEL(ValueType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_COO_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_ELL_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_HYBRID_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_KERNEL(ValueType, IndexType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_MAX_NNZ_PER_ROW_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_NONZEROS_PER_ROW_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_TOTAL_COLS_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_TRANSPOSE_KERNEL(ValueType); \
template <typename ValueType> \
#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename ValueType> \
GKO_DECLARE_DENSE_SIMPLE_APPLY_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_APPLY_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_SCALE_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_ADD_SCALED_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COMPUTE_DOT_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COMPUTE_NORM2_KERNEL(ValueType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_COO_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_ELL_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_HYBRID_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_SPARSITY_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_MAX_NNZ_PER_ROW_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_NONZEROS_PER_ROW_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_CALCULATE_TOTAL_COLS_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_TRANSPOSE_KERNEL(ValueType); \
template <typename ValueType> \
GKO_DECLARE_CONJ_TRANSPOSE_KERNEL(ValueType)


Expand Down
Loading