Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzgoebel committed Jun 26, 2020
1 parent 1b479b6 commit 5fd70a5
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 126 deletions.
9 changes: 4 additions & 5 deletions core/stop/residual_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ bool ResidualNorm<ValueType>::check_impl(uint8 stoppingId, bool setFinalized,
dense_tau = as<NormVector>(updater.residual_norm_);
} else if (updater.residual_ != nullptr) {
auto *dense_r = as<Vector>(updater.residual_);
dense_r->compute_norm2(this->u_dense_tau_.get());
dense_tau = this->u_dense_tau_.get();
dense_r->compute_norm2(u_dense_tau_.get());
dense_tau = u_dense_tau_.get();
} else {
GKO_NOT_SUPPORTED(nullptr);
}
bool all_converged = true;

this->get_executor()->run(residual_norm::make_residual_norm(
dense_tau, this->starting_tau_.get(), this->tolerance_, stoppingId,
setFinalized, stop_status, &this->device_storage_, &all_converged,
one_changed));
dense_tau, starting_tau_.get(), tolerance_, stoppingId, setFinalized,
stop_status, &device_storage_, &all_converged, one_changed));

return all_converged;
}
Expand Down
76 changes: 42 additions & 34 deletions cuda/test/stop/residual_norm_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ class ResidualNormReduction : public ::testing::Test {

TEST_F(ResidualNormReduction, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
auto d_scalar = Mtx::create(cuda_);
d_scalar->copy_from(scalar.get());
auto criterion =
factory_->generate(nullptr, nullptr, nullptr, d_scalar.get());
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(cuda_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(cuda_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -79,25 +81,25 @@ TEST_F(ResidualNormReduction, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+2;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(cuda_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+1;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down Expand Up @@ -167,10 +169,13 @@ class RelativeResidualNorm : public ::testing::Test {

TEST_F(RelativeResidualNorm, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
std::shared_ptr<gko::LinOp> d_scalar = Mtx::create(cuda_);
d_scalar->copy_from(scalar.get());
auto criterion = factory_->generate(nullptr, d_scalar, nullptr, nullptr);
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(cuda_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(cuda_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -179,25 +184,25 @@ TEST_F(RelativeResidualNorm, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+1;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(cuda_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down Expand Up @@ -267,10 +272,13 @@ class AbsoluteResidualNorm : public ::testing::Test {

TEST_F(AbsoluteResidualNorm, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
std::shared_ptr<gko::LinOp> d_scalar = Mtx::create(cuda_);
d_scalar->copy_from(scalar.get());
auto criterion = factory_->generate(nullptr, d_scalar, nullptr, nullptr);
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(cuda_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(cuda_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -279,25 +287,25 @@ TEST_F(AbsoluteResidualNorm, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(cuda_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e-1;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down
76 changes: 42 additions & 34 deletions hip/test/stop/residual_norm_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ class ResidualNormReduction : public ::testing::Test {

TEST_F(ResidualNormReduction, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
auto d_scalar = Mtx::create(hip_);
d_scalar->copy_from(scalar.get());
auto criterion =
factory_->generate(nullptr, nullptr, nullptr, d_scalar.get());
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(hip_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(hip_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -79,25 +81,25 @@ TEST_F(ResidualNormReduction, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+2;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(hip_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+1;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down Expand Up @@ -167,10 +169,13 @@ class RelativeResidualNorm : public ::testing::Test {

TEST_F(RelativeResidualNorm, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
std::shared_ptr<gko::LinOp> d_scalar = Mtx::create(hip_);
d_scalar->copy_from(scalar.get());
auto criterion = factory_->generate(nullptr, d_scalar, nullptr, nullptr);
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(hip_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(hip_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -179,25 +184,25 @@ TEST_F(RelativeResidualNorm, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e+1;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(hip_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down Expand Up @@ -267,10 +272,13 @@ class AbsoluteResidualNorm : public ::testing::Test {

TEST_F(AbsoluteResidualNorm, WaitsTillResidualGoal)
{
auto scalar = gko::initialize<Mtx>({1.0}, ref_);
std::shared_ptr<gko::LinOp> d_scalar = Mtx::create(hip_);
d_scalar->copy_from(scalar.get());
auto criterion = factory_->generate(nullptr, d_scalar, nullptr, nullptr);
auto res = gko::initialize<Mtx>({100.0}, ref_);
auto d_res = Mtx::create(hip_);
d_res->copy_from(res.get());
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, ref_);
std::shared_ptr<gko::LinOp> d_rhs = Mtx::create(hip_);
d_rhs->copy_from(rhs.get());
auto criterion = factory_->generate(nullptr, d_rhs, nullptr, d_res.get());
bool one_changed{};
constexpr gko::uint8 RelativeStoppingId{1};
gko::Array<gko::stopping_status> stop_status(ref_, 1);
Expand All @@ -279,25 +287,25 @@ TEST_F(AbsoluteResidualNorm, WaitsTillResidualGoal)

ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));

scalar->at(0) = tol * 1.0e+2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol;
d_res->copy_from(res.get());
ASSERT_FALSE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_FALSE(stop_status.get_data()[0].has_converged());
stop_status.set_executor(hip_);
ASSERT_FALSE(one_changed);

scalar->at(0) = tol * 1.0e-2;
d_scalar->copy_from(scalar.get());
res->at(0) = tol * 1.0e-1;
d_res->copy_from(res.get());
ASSERT_TRUE(
criterion->update()
.residual_norm(d_scalar.get())
.residual_norm(d_res.get())
.check(RelativeStoppingId, true, &stop_status, &one_changed));
stop_status.set_executor(ref_);
ASSERT_TRUE(stop_status.get_data()[0].has_converged());
Expand Down
2 changes: 1 addition & 1 deletion include/ginkgo/core/stop/residual_norm_reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

// This file is deprecated and will be removed in a later release.
#warning This file is deprecated and will be removed in a later major release.
#include <ginkgo/core/stop/residual_norm.hpp>
Loading

0 comments on commit 5fd70a5

Please sign in to comment.