Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0447023
Add support for factorization in create_new_algorithm.sh
Oct 21, 2019
cda40b6
fix sellp read
yhmtsai Oct 29, 2019
932fbe1
fix ell error on small mtx and flexble warp_size
yhmtsai Oct 30, 2019
ec4a3ab
Fix small typo in the stencil examples
upsj Nov 13, 2019
4db298c
Improve CSR strategies
Nov 12, 2019
db622a9
Review update
Nov 12, 2019
a942a89
Review update and additional fixes
Nov 13, 2019
29bda33
Review update
Nov 13, 2019
638db8c
Fix GKO_NOT_SUPPORTED, so it behaves as expected
Nov 13, 2019
f0d8e2d
Review update: fix doxygen comment for GKO_NOT_SUPPORTED
Nov 13, 2019
9fe7165
Add `GKO_ASSERT_EQ` assertion.
Nov 27, 2019
6e88654
Throw ValueMismatch instead of BadDimension for `GKO_ASSERT_EQ`.
Nov 27, 2019
2f671da
replace GKO_ENSURE_IN_BOUNDS by GKO_ASSERT_EQ
upsj Nov 18, 2019
8f3c8cb
add tests for GKO_ASSERT_EQ
upsj Nov 18, 2019
65ec1ae
fix dense bounds check
upsj Nov 19, 2019
de97319
revert bounds check changes for dense.hpp
upsj Nov 19, 2019
e308255
Improve update_header script so it does not stop `make`
Nov 15, 2019
89949c7
Further improve the update_ginkgo_header.sh script
Nov 18, 2019
bbcd2e4
Review Update
Nov 18, 2019
ba452f1
update git-cmake-format source repository
upsj Nov 25, 2019
6fce256
Update all versions to v1.1.1.
Nov 27, 2019
cf678b1
Add Changelog
Nov 27, 2019
784aa6e
Create a new macro `GKO_VERSION_STR` to facilitate version bumping.
Nov 27, 2019
d4afd1b
Install Ginkgo and launch `test_install` for all jobs.
Nov 28, 2019
10da811
Fix missing `}` for `SparsityCsr` in `test_install`.
Nov 28, 2019
8f70a7c
Fix some issues pointed by sonarqube.
Nov 28, 2019
2b75262
Fix test_install with PAPI.
Nov 28, 2019
1dbcef9
Fix documentation issues and add a Jacobi documentation group.
Nov 29, 2019
c8ec186
Update changelog with the recent changes done for this PR.
Nov 29, 2019
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
Improve CSR strategies
- All conversions to CSR (except CSR to CSR) now conserve the original
  strategy (test for that are included)
- CSR strategies now try to copy the least amount of data
- Add exception throwing in case the load_balance would not work
  properly (when srow is empty)
  • Loading branch information
Thomas Grützmacher authored and Terry Cojean committed Nov 27, 2019
commit 4db298cd70828f3e736856827dfab78007377247
10 changes: 8 additions & 2 deletions core/matrix/coo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ void Coo<ValueType, IndexType>::convert_to(
Csr<ValueType, IndexType> *result) const
{
auto exec = this->get_executor();
auto tmp = Csr<ValueType, IndexType>::create(exec, this->get_size());
auto tmp = Csr<ValueType, IndexType>::create(
exec, this->get_size(), this->get_num_stored_elements(),
result->get_strategy());
tmp->values_ = this->values_;
tmp->col_idxs_ = this->col_idxs_;
exec->run(coo::make_convert_to_csr(tmp.get(), this));
tmp->make_srow();
tmp->move_to(result);
}

Expand All @@ -120,10 +123,13 @@ template <typename ValueType, typename IndexType>
void Coo<ValueType, IndexType>::move_to(Csr<ValueType, IndexType> *result)
{
auto exec = this->get_executor();
auto tmp = Csr<ValueType, IndexType>::create(exec, this->get_size());
auto tmp = Csr<ValueType, IndexType>::create(
exec, this->get_size(), this->get_num_stored_elements(),
result->get_strategy());
tmp->values_ = std::move(this->values_);
tmp->col_idxs_ = std::move(this->col_idxs_);
exec->run(coo::make_convert_to_csr(tmp.get(), this));
tmp->make_srow();
tmp->move_to(result);
}

Expand Down
5 changes: 3 additions & 2 deletions core/matrix/ell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ void Ell<ValueType, IndexType>::convert_to(
size_type num_stored_elements = 0;
exec->run(ell::make_count_nonzeros(this, &num_stored_elements));

auto tmp = Csr<ValueType, IndexType>::create(exec, this->get_size(),
num_stored_elements);
auto tmp = Csr<ValueType, IndexType>::create(
exec, this->get_size(), num_stored_elements, result->get_strategy());
exec->run(ell::make_convert_to_csr(tmp.get(), this));

tmp->make_srow();
tmp->move_to(result);
}

Expand Down
5 changes: 3 additions & 2 deletions core/matrix/hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ void Hybrid<ValueType, IndexType>::convert_to(
size_type num_stored_elements = 0;
exec->run(hybrid::make_count_nonzeros(this, &num_stored_elements));

auto tmp = Csr<ValueType, IndexType>::create(exec, this->get_size(),
num_stored_elements);
auto tmp = Csr<ValueType, IndexType>::create(
exec, this->get_size(), num_stored_elements, result->get_strategy());
exec->run(hybrid::make_convert_to_csr(tmp.get(), this));

tmp->make_srow();
tmp->move_to(result);
}

Expand Down
5 changes: 3 additions & 2 deletions core/matrix/sellp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ void Sellp<ValueType, IndexType>::convert_to(

size_type num_stored_nonzeros = 0;
exec->run(sellp::make_count_nonzeros(this, &num_stored_nonzeros));
auto tmp = Csr<ValueType, IndexType>::create(exec, this->get_size(),
num_stored_nonzeros);
auto tmp = Csr<ValueType, IndexType>::create(
exec, this->get_size(), num_stored_nonzeros, result->get_strategy());
exec->run(sellp::make_convert_to_csr(tmp.get(), this));
tmp->make_srow();
tmp->move_to(result);
}

Expand Down
3 changes: 3 additions & 0 deletions core/test/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ TEST_F(Csr, CanBeCreatedFromExistingData)
double values[] = {1.0, 2.0, 3.0, 4.0};
gko::int32 col_idxs[] = {0, 1, 1, 0};
gko::int32 row_ptrs[] = {0, 2, 3, 4};

auto mtx = gko::matrix::Csr<>::create(
exec, gko::dim<2>{3, 2}, gko::Array<double>::view(exec, 4, values),
gko::Array<gko::int32>::view(exec, 4, col_idxs),
gko::Array<gko::int32>::view(exec, 4, row_ptrs),
std::make_shared<Mtx::load_balance>(2));

ASSERT_EQ(mtx->get_num_srow_elements(), 1);
ASSERT_EQ(mtx->get_const_values(), values);
ASSERT_EQ(mtx->get_const_col_idxs(), col_idxs);
Expand Down Expand Up @@ -183,6 +185,7 @@ TEST_F(Csr, CanBeCleared)
TEST_F(Csr, CanBeReadFromMatrixData)
{
auto m = Mtx::create(exec, std::make_shared<Mtx::load_balance>(2));

m->read({{2, 3},
{{0, 0, 1.0},
{0, 1, 3.0},
Expand Down
92 changes: 66 additions & 26 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,28 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
auto nwarps = mtx_srow->get_num_elems();

if (nwarps > 0) {
auto exec = mtx_srow->get_executor()->get_master();
Array<index_type> srow_host(exec);
srow_host = *mtx_srow;
auto srow = srow_host.get_data();
Array<index_type> row_ptrs_host(exec);
row_ptrs_host = mtx_row_ptrs;
auto row_ptrs = row_ptrs_host.get_const_data();
auto host_srow_exec = mtx_srow->get_executor()->get_master();
auto host_mtx_exec = mtx_row_ptrs.get_executor()->get_master();
bool is_srow_on_host{host_srow_exec ==
mtx_srow->get_executor()};
bool is_mtx_on_host{host_mtx_exec ==
mtx_row_ptrs.get_executor()};
Array<index_type> row_ptrs_host(host_mtx_exec);
Array<index_type> srow_host(host_srow_exec);
const index_type *row_ptrs{};
index_type *srow{};
if (is_srow_on_host) {
srow = mtx_srow->get_data();
} else {
srow_host = *mtx_srow;
srow = srow_host.get_data();
}
if (is_mtx_on_host) {
row_ptrs = mtx_row_ptrs.get_const_data();
} else {
row_ptrs_host = mtx_row_ptrs;
row_ptrs = row_ptrs_host.get_const_data();
}
for (size_type i = 0; i < nwarps; i++) {
srow[i] = 0;
}
Expand All @@ -207,7 +222,11 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
for (size_type i = 1; i < nwarps; i++) {
srow[i] += srow[i - 1];
}
*mtx_srow = srow_host;
if (!is_srow_on_host) {
*mtx_srow = srow_host;
}
} else {
GKO_NOT_SUPPORTED(nwarps);
}
}

Expand Down Expand Up @@ -249,28 +268,46 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
// if the number of stored elements is larger than 1e6 or
// the maximum number of stored elements per row is larger than
// 64, use load_balance otherwise use classical
auto host_mtx_exec = mtx_row_ptrs.get_executor()->get_master();
bool is_mtx_on_host{host_mtx_exec == mtx_row_ptrs.get_executor()};
Array<index_type> row_ptrs_host(host_mtx_exec);
const index_type *row_ptrs{};
if (is_mtx_on_host) {
row_ptrs = mtx_row_ptrs.get_const_data();
} else {
row_ptrs_host = mtx_row_ptrs;
row_ptrs = row_ptrs_host.get_const_data();
}
const auto num_rows = mtx_row_ptrs.get_num_elems() - 1;
Array<index_type> host_row_ptrs(
mtx_row_ptrs.get_executor()->get_master());
host_row_ptrs = mtx_row_ptrs;
const auto row_val = host_row_ptrs.get_const_data();
if (row_val[num_rows] > static_cast<index_type>(1e6)) {
std::make_shared<load_balance>(nwarps_)->process(host_row_ptrs,
mtx_srow);
this->set_name("load_balance");
if (row_ptrs[num_rows] > static_cast<index_type>(1e6)) {
load_balance actual_strategy(nwarps_);
if (is_mtx_on_host) {
actual_strategy.process(mtx_row_ptrs, mtx_srow);
} else {
actual_strategy.process(row_ptrs_host, mtx_srow);
}
this->set_name(actual_strategy.get_name());
} else {
index_type maxnum = 0;
for (index_type i = 1; i < num_rows + 1; i++) {
maxnum = max(maxnum, row_val[i] - row_val[i - 1]);
maxnum = max(maxnum, row_ptrs[i] - row_ptrs[i - 1]);
}
if (maxnum > 64) {
std::make_shared<load_balance>(nwarps_)->process(
host_row_ptrs, mtx_srow);
this->set_name("load_balance");
load_balance actual_strategy(nwarps_);
if (is_mtx_on_host) {
actual_strategy.process(mtx_row_ptrs, mtx_srow);
} else {
actual_strategy.process(row_ptrs_host, mtx_srow);
}
this->set_name(actual_strategy.get_name());
} else {
std::make_shared<classical>()->process(host_row_ptrs,
mtx_srow);
this->set_name("classical");
classical actual_strategy;
if (is_mtx_on_host) {
actual_strategy.process(mtx_row_ptrs, mtx_srow);
} else {
actual_strategy.process(row_ptrs_host, mtx_srow);
}
this->set_name(actual_strategy.get_name());
}
}
}
Expand Down Expand Up @@ -501,7 +538,6 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
GKO_ENSURE_IN_BOUNDS(values_.get_num_elems() - 1,
col_idxs_.get_num_elems());
GKO_ENSURE_IN_BOUNDS(this->get_size()[0], row_ptrs_.get_num_elems());
srow_.resize_and_reset(strategy_->clac_size(values_.get_num_elems()));
this->make_srow();
}

Expand All @@ -511,9 +547,13 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
LinOp *x) const override;

/**
* Compute srow, it should be run after setting value.
* Computes srow. It should be run after changing any row_ptrs_ value.
*/
void make_srow() { strategy_->process(row_ptrs_, &srow_); }
void make_srow()
{
srow_.resize_and_reset(strategy_->clac_size(values_.get_num_elems()));
strategy_->process(row_ptrs_, &srow_);
}

private:
Array<value_type> values_;
Expand Down
42 changes: 32 additions & 10 deletions reference/test/matrix/coo_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "core/matrix/coo_kernels.hpp"


#include <memory>


#include <gtest/gtest.h>


Expand Down Expand Up @@ -90,21 +93,40 @@ class Coo : public ::testing::Test {

TEST_F(Coo, ConvertsToCsr)
{
auto csr_mtx = gko::matrix::Csr<>::create(mtx->get_executor());

mtx->convert_to(csr_mtx.get());

assert_equal_to_mtx_in_csr_format(csr_mtx.get());
auto csr_s_classical = std::make_shared<gko::matrix::Csr<>::classical>();
auto csr_s_merge = std::make_shared<gko::matrix::Csr<>::merge_path>();
auto csr_mtx_c =
gko::matrix::Csr<>::create(mtx->get_executor(), csr_s_classical);
auto csr_mtx_m =
gko::matrix::Csr<>::create(mtx->get_executor(), csr_s_merge);

mtx->convert_to(csr_mtx_c.get());
mtx->convert_to(csr_mtx_m.get());

assert_equal_to_mtx_in_csr_format(csr_mtx_c.get());
assert_equal_to_mtx_in_csr_format(csr_mtx_m.get());
ASSERT_EQ(csr_mtx_c->get_strategy(), csr_s_classical);
ASSERT_EQ(csr_mtx_m->get_strategy(), csr_s_merge);
}


TEST_F(Coo, MovesToCsr)
{
auto csr_mtx = gko::matrix::Csr<>::create(mtx->get_executor());

mtx->move_to(csr_mtx.get());

assert_equal_to_mtx_in_csr_format(csr_mtx.get());
auto csr_s_classical = std::make_shared<gko::matrix::Csr<>::classical>();
auto csr_s_merge = std::make_shared<gko::matrix::Csr<>::merge_path>();
auto csr_mtx_c =
gko::matrix::Csr<>::create(mtx->get_executor(), csr_s_classical);
auto csr_mtx_m =
gko::matrix::Csr<>::create(mtx->get_executor(), csr_s_merge);
auto mtx_clone = mtx->clone();

mtx->move_to(csr_mtx_c.get());
mtx_clone->move_to(csr_mtx_m.get());

assert_equal_to_mtx_in_csr_format(csr_mtx_c.get());
assert_equal_to_mtx_in_csr_format(csr_mtx_m.get());
ASSERT_EQ(csr_mtx_c->get_strategy(), csr_s_classical);
ASSERT_EQ(csr_mtx_m->get_strategy(), csr_s_merge);
}


Expand Down
56 changes: 38 additions & 18 deletions reference/test/matrix/dense_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include <complex>
#include <memory>
#include <random>


Expand Down Expand Up @@ -333,15 +334,21 @@ TEST_F(Dense, MovesToCoo)

TEST_F(Dense, ConvertsToCsr)
{
auto csr_mtx = gko::matrix::Csr<>::create(mtx4->get_executor());

mtx4->convert_to(csr_mtx.get());
auto v = csr_mtx->get_const_values();
auto c = csr_mtx->get_const_col_idxs();
auto r = csr_mtx->get_const_row_ptrs();

ASSERT_EQ(csr_mtx->get_size(), gko::dim<2>(2, 3));
ASSERT_EQ(csr_mtx->get_num_stored_elements(), 4);
auto csr_s_classical = std::make_shared<gko::matrix::Csr<>::classical>();
auto csr_s_merge = std::make_shared<gko::matrix::Csr<>::merge_path>();
auto csr_mtx_c =
gko::matrix::Csr<>::create(mtx4->get_executor(), csr_s_classical);
auto csr_mtx_m =
gko::matrix::Csr<>::create(mtx4->get_executor(), csr_s_merge);

mtx4->convert_to(csr_mtx_c.get());
mtx4->convert_to(csr_mtx_m.get());

auto v = csr_mtx_c->get_const_values();
auto c = csr_mtx_c->get_const_col_idxs();
auto r = csr_mtx_c->get_const_row_ptrs();
ASSERT_EQ(csr_mtx_c->get_size(), gko::dim<2>(2, 3));
ASSERT_EQ(csr_mtx_c->get_num_stored_elements(), 4);
EXPECT_EQ(r[0], 0);
EXPECT_EQ(r[1], 3);
EXPECT_EQ(r[2], 4);
Expand All @@ -353,20 +360,30 @@ TEST_F(Dense, ConvertsToCsr)
EXPECT_EQ(v[1], 3.0);
EXPECT_EQ(v[2], 2.0);
EXPECT_EQ(v[3], 5.0);
ASSERT_EQ(csr_mtx_c->get_strategy(), csr_s_classical);
GKO_ASSERT_MTX_NEAR(csr_mtx_c.get(), csr_mtx_m.get(), 0.0);
ASSERT_EQ(csr_mtx_m->get_strategy(), csr_s_merge);
}


TEST_F(Dense, MovesToCsr)
{
auto csr_mtx = gko::matrix::Csr<>::create(mtx4->get_executor());

mtx4->move_to(csr_mtx.get());
auto v = csr_mtx->get_const_values();
auto c = csr_mtx->get_const_col_idxs();
auto r = csr_mtx->get_const_row_ptrs();

ASSERT_EQ(csr_mtx->get_size(), gko::dim<2>(2, 3));
ASSERT_EQ(csr_mtx->get_num_stored_elements(), 4);
auto csr_s_classical = std::make_shared<gko::matrix::Csr<>::classical>();
auto csr_s_merge = std::make_shared<gko::matrix::Csr<>::merge_path>();
auto csr_mtx_c =
gko::matrix::Csr<>::create(mtx4->get_executor(), csr_s_classical);
auto csr_mtx_m =
gko::matrix::Csr<>::create(mtx4->get_executor(), csr_s_merge);
auto mtx_clone = mtx4->clone();

mtx4->move_to(csr_mtx_c.get());
mtx_clone->move_to(csr_mtx_m.get());

auto v = csr_mtx_c->get_const_values();
auto c = csr_mtx_c->get_const_col_idxs();
auto r = csr_mtx_c->get_const_row_ptrs();
ASSERT_EQ(csr_mtx_c->get_size(), gko::dim<2>(2, 3));
ASSERT_EQ(csr_mtx_c->get_num_stored_elements(), 4);
EXPECT_EQ(r[0], 0);
EXPECT_EQ(r[1], 3);
EXPECT_EQ(r[2], 4);
Expand All @@ -378,6 +395,9 @@ TEST_F(Dense, MovesToCsr)
EXPECT_EQ(v[1], 3.0);
EXPECT_EQ(v[2], 2.0);
EXPECT_EQ(v[3], 5.0);
ASSERT_EQ(csr_mtx_c->get_strategy(), csr_s_classical);
GKO_ASSERT_MTX_NEAR(csr_mtx_c.get(), csr_mtx_m.get(), 0.0);
ASSERT_EQ(csr_mtx_m->get_strategy(), csr_s_merge);
}


Expand Down
Loading