Skip to content

Commit

Permalink
Removed move_to_XXX kernels and COO::transpose
Browse files Browse the repository at this point in the history
Removed unused `move_to_XXX` kernels from Dense and Csr. All calls to
`move_to(Mtx *)`, which previously used the mentioned kernels, now use
`convert_to_XXX` kernels.

Since we did not implement any transpose functionality in Coo, the
inheritance from `Transposable` and all related kernels were removed.

Additionally, the tests for Coo, Csr & Dense were modified as follows:
- Made include order compliant to guidelines
- Newlines in the tests are also according to guidelines
- Added MoveTo tests where they were not present
- Added tests for Dense conversions (used already generated variables)

The conversion from Dense to Hybrid with OpenMP was also slightly
improved.
  • Loading branch information
Thomas Grützmacher committed Apr 4, 2019
1 parent 414bee7 commit c027ab3
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 481 deletions.
42 changes: 0 additions & 42 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,49 +103,24 @@ GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_DENSE_CONVERT_TO_CSR_KERNEL);

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


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

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

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

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

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

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

template <typename ValueType>
GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(ValueType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
Expand Down Expand Up @@ -349,12 +324,6 @@ GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CONVERT_TO_COO_KERNEL);

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

template <typename ValueType, typename IndexType>
GKO_DECLARE_CSR_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType)
GKO_NOT_COMPILED(GKO_HOOK_MODULE);
Expand Down Expand Up @@ -431,17 +400,6 @@ GKO_NOT_COMPILED(GKO_HOOK_MODULE);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_COO_CONVERT_TO_DENSE_KERNEL);

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

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


} // namespace coo

Expand Down
26 changes: 0 additions & 26 deletions core/matrix/coo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ GKO_REGISTER_OPERATION(spmv2, coo::spmv2);
GKO_REGISTER_OPERATION(advanced_spmv2, coo::advanced_spmv2);
GKO_REGISTER_OPERATION(convert_to_csr, coo::convert_to_csr);
GKO_REGISTER_OPERATION(convert_to_dense, coo::convert_to_dense);
GKO_REGISTER_OPERATION(transpose, coo::transpose);
GKO_REGISTER_OPERATION(conj_transpose, coo::conj_transpose);


} // namespace coo
Expand Down Expand Up @@ -192,30 +190,6 @@ void Coo<ValueType, IndexType>::write(mat_data &data) const
}


template <typename ValueType, typename IndexType>
std::unique_ptr<LinOp> Coo<ValueType, IndexType>::transpose() const
{
auto exec = this->get_executor();
auto trans_cpy = Coo::create(exec, gko::transpose(this->get_size()),
this->get_num_stored_elements());

exec->run(coo::make_transpose(trans_cpy.get(), this));
return std::move(trans_cpy);
}


template <typename ValueType, typename IndexType>
std::unique_ptr<LinOp> Coo<ValueType, IndexType>::conj_transpose() const
{
auto exec = this->get_executor();
auto trans_cpy = Coo::create(exec, gko::transpose(this->get_size()),
this->get_num_stored_elements());

exec->run(coo::make_conj_transpose(trans_cpy.get(), this));
return std::move(trans_cpy);
}


#define GKO_DECLARE_COO_MATRIX(ValueType, IndexType) \
class Coo<ValueType, IndexType>
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_COO_MATRIX);
Expand Down
40 changes: 13 additions & 27 deletions core/matrix/coo_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,19 @@ namespace kernels {
matrix::Csr<ValueType, IndexType> *result, \
const matrix::Coo<ValueType, IndexType> *source)

#define GKO_DECLARE_COO_TRANSPOSE_KERNEL(ValueType, IndexType) \
void transpose(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Coo<ValueType, IndexType> *trans, \
const matrix::Coo<ValueType, IndexType> *orig)

#define GKO_DECLARE_COO_CONJ_TRANSPOSE_KERNEL(ValueType, IndexType) \
void conj_transpose(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Coo<ValueType, IndexType> *trans, \
const matrix::Coo<ValueType, IndexType> *orig)

#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_SPMV_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_ADVANCED_SPMV_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_SPMV2_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_ADVANCED_SPMV2_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_CONVERT_TO_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_CONVERT_TO_DENSE_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_TRANSPOSE_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_CONJ_TRANSPOSE_KERNEL(ValueType, IndexType)
#define GKO_DECLARE_ALL_AS_TEMPLATES \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_SPMV_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_ADVANCED_SPMV_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_SPMV2_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_ADVANCED_SPMV2_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_CONVERT_TO_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_COO_CONVERT_TO_DENSE_KERNEL(ValueType, IndexType)


namespace omp {
Expand Down
3 changes: 1 addition & 2 deletions core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ GKO_REGISTER_OPERATION(spmv, csr::spmv);
GKO_REGISTER_OPERATION(advanced_spmv, csr::advanced_spmv);
GKO_REGISTER_OPERATION(convert_to_coo, csr::convert_to_coo);
GKO_REGISTER_OPERATION(convert_to_dense, csr::convert_to_dense);
GKO_REGISTER_OPERATION(move_to_dense, csr::move_to_dense);
GKO_REGISTER_OPERATION(convert_to_sellp, csr::convert_to_sellp);
GKO_REGISTER_OPERATION(calculate_total_cols, csr::calculate_total_cols);
GKO_REGISTER_OPERATION(convert_to_ell, csr::convert_to_ell);
Expand Down Expand Up @@ -128,7 +127,7 @@ void Csr<ValueType, IndexType>::move_to(Dense<ValueType> *result)
{
auto exec = this->get_executor();
auto tmp = Dense<ValueType>::create(exec, this->get_size());
exec->run(csr::make_move_to_dense(tmp.get(), this));
exec->run(csr::make_convert_to_dense(tmp.get(), this));
tmp->move_to(result);
}

Expand Down
7 changes: 0 additions & 7 deletions core/matrix/csr_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ namespace kernels {
matrix::Dense<ValueType> *result, \
const matrix::Csr<ValueType, IndexType> *source)

#define GKO_DECLARE_CSR_MOVE_TO_DENSE_KERNEL(ValueType, IndexType) \
void move_to_dense(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Dense<ValueType> *result, \
matrix::Csr<ValueType, IndexType> *source)

#define GKO_DECLARE_CSR_CONVERT_TO_COO_KERNEL(ValueType, IndexType) \
void convert_to_coo(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Coo<ValueType, IndexType> *result, \
Expand Down Expand Up @@ -113,8 +108,6 @@ namespace kernels {
template <typename ValueType, typename IndexType> \
GKO_DECLARE_CSR_CONVERT_TO_DENSE_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_CSR_MOVE_TO_DENSE_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_CSR_CONVERT_TO_COO_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_CSR_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType); \
Expand Down
48 changes: 24 additions & 24 deletions core/matrix/dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ GKO_REGISTER_OPERATION(transpose, dense::transpose);
GKO_REGISTER_OPERATION(conj_transpose, dense::conj_transpose);
GKO_REGISTER_OPERATION(convert_to_coo, dense::convert_to_coo);
GKO_REGISTER_OPERATION(convert_to_csr, dense::convert_to_csr);
GKO_REGISTER_OPERATION(move_to_csr, dense::move_to_csr);
GKO_REGISTER_OPERATION(convert_to_ell, dense::convert_to_ell);
GKO_REGISTER_OPERATION(move_to_ell, dense::move_to_ell);
GKO_REGISTER_OPERATION(convert_to_hybrid, dense::convert_to_hybrid);
GKO_REGISTER_OPERATION(move_to_hybrid, dense::move_to_hybrid);
GKO_REGISTER_OPERATION(convert_to_sellp, dense::convert_to_sellp);
GKO_REGISTER_OPERATION(move_to_sellp, dense::move_to_sellp);


} // namespace dense
Expand Down Expand Up @@ -308,8 +304,8 @@ template <typename ValueType>
void Dense<ValueType>::move_to(Csr<ValueType, int32> *result)
{
conversion_helper(result, this,
dense::template make_move_to_csr<decltype(result),
Dense<ValueType> *&>);
dense::template make_convert_to_csr<decltype(result),
Dense<ValueType> *&>);
result->make_srow();
}

Expand All @@ -329,8 +325,8 @@ template <typename ValueType>
void Dense<ValueType>::move_to(Csr<ValueType, int64> *result)
{
conversion_helper(result, this,
dense::template make_move_to_csr<decltype(result),
Dense<ValueType> *&>);
dense::template make_convert_to_csr<decltype(result),
Dense<ValueType> *&>);
result->make_srow();
}

Expand All @@ -349,8 +345,8 @@ template <typename ValueType>
void Dense<ValueType>::move_to(Ell<ValueType, int32> *result)
{
conversion_helper(result, this,
dense::template make_move_to_ell<decltype(result),
Dense<ValueType> *&>);
dense::template make_convert_to_ell<decltype(result),
Dense<ValueType> *&>);
}


Expand All @@ -368,8 +364,8 @@ template <typename ValueType>
void Dense<ValueType>::move_to(Ell<ValueType, int64> *result)
{
conversion_helper(result, this,
dense::template make_move_to_ell<decltype(result),
Dense<ValueType> *&>);
dense::template make_convert_to_ell<decltype(result),
Dense<ValueType> *&>);
}


Expand All @@ -386,9 +382,10 @@ void Dense<ValueType>::convert_to(Hybrid<ValueType, int32> *result) const
template <typename ValueType>
void Dense<ValueType>::move_to(Hybrid<ValueType, int32> *result)
{
conversion_helper(result, this,
dense::template make_move_to_hybrid<decltype(result),
Dense<ValueType> *&>);
conversion_helper(
result, this,
dense::template make_convert_to_hybrid<decltype(result),
Dense<ValueType> *&>);
}


Expand All @@ -405,9 +402,10 @@ void Dense<ValueType>::convert_to(Hybrid<ValueType, int64> *result) const
template <typename ValueType>
void Dense<ValueType>::move_to(Hybrid<ValueType, int64> *result)
{
conversion_helper(result, this,
dense::template make_move_to_hybrid<decltype(result),
Dense<ValueType> *&>);
conversion_helper(
result, this,
dense::template make_convert_to_hybrid<decltype(result),
Dense<ValueType> *&>);
}


Expand All @@ -424,9 +422,10 @@ void Dense<ValueType>::convert_to(Sellp<ValueType, int32> *result) const
template <typename ValueType>
void Dense<ValueType>::move_to(Sellp<ValueType, int32> *result)
{
conversion_helper(result, this,
dense::template make_move_to_sellp<decltype(result),
Dense<ValueType> *&>);
conversion_helper(
result, this,
dense::template make_convert_to_sellp<decltype(result),
Dense<ValueType> *&>);
}


Expand All @@ -443,9 +442,10 @@ void Dense<ValueType>::convert_to(Sellp<ValueType, int64> *result) const
template <typename ValueType>
void Dense<ValueType>::move_to(Sellp<ValueType, int64> *result)
{
conversion_helper(result, this,
dense::template make_move_to_sellp<decltype(result),
Dense<ValueType> *&>);
conversion_helper(
result, this,
dense::template make_convert_to_sellp<decltype(result),
Dense<ValueType> *&>);
}


Expand Down
28 changes: 0 additions & 28 deletions core/matrix/dense_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,41 +83,21 @@ namespace kernels {
matrix::Csr<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_MOVE_TO_CSR_KERNEL(_type, _prec) \
void move_to_csr(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Csr<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_CONVERT_TO_ELL_KERNEL(_type, _prec) \
void convert_to_ell(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Ell<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_MOVE_TO_ELL_KERNEL(_type, _prec) \
void move_to_ell(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Ell<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_CONVERT_TO_HYBRID_KERNEL(_type, _prec) \
void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Hybrid<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_MOVE_TO_HYBRID_KERNEL(_type, _prec) \
void move_to_hybrid(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Hybrid<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_CONVERT_TO_SELLP_KERNEL(_type, _prec) \
void convert_to_sellp(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Sellp<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_MOVE_TO_SELLP_KERNEL(_type, _prec) \
void move_to_sellp(std::shared_ptr<const DefaultExecutor> exec, \
matrix::Sellp<_type, _prec> *other, \
const matrix::Dense<_type> *source)

#define GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(_type) \
void count_nonzeros(std::shared_ptr<const DefaultExecutor> exec, \
const matrix::Dense<_type> *source, size_type *result)
Expand Down Expand Up @@ -166,19 +146,11 @@ namespace kernels {
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_CONVERT_TO_CSR_KERNEL(ValueType, IndexType); \
template <typename ValueType, typename IndexType> \
GKO_DECLARE_DENSE_MOVE_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_MOVE_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_MOVE_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_MOVE_TO_SELLP_KERNEL(ValueType, IndexType); \
template <typename ValueType> \
GKO_DECLARE_DENSE_COUNT_NONZEROS_KERNEL(ValueType); \
template <typename ValueType> \
Expand Down
Loading

0 comments on commit c027ab3

Please sign in to comment.