Skip to content

Commit

Permalink
WIP: can compile but three tests are still failed
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Apr 20, 2024
1 parent 7efe4ca commit aba0afc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 44 deletions.
21 changes: 21 additions & 0 deletions core/matrix/batch_csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,27 @@ void Csr<ValueType, IndexType>::move_to(
}


#if GINKGO_ENABLE_HALF
template <typename ValueType, typename IndexType>
void Csr<ValueType, IndexType>::convert_to(
Csr<next_precision<next_precision<ValueType>>, IndexType>* result) const
{
result->values_ = this->values_;
result->col_idxs_ = this->col_idxs_;
result->row_ptrs_ = this->row_ptrs_;
result->set_size(this->get_size());
}


template <typename ValueType, typename IndexType>
void Csr<ValueType, IndexType>::move_to(
Csr<next_precision<next_precision<ValueType>>, IndexType>* result)
{
this->convert_to(result);
}
#endif


#define GKO_DECLARE_BATCH_CSR_MATRIX(ValueType) class Csr<ValueType, int32>
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_BATCH_CSR_MATRIX);

Expand Down
5 changes: 3 additions & 2 deletions core/matrix/permutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ void dispatch_dense(const LinOp* op, Functor fn)
{
using matrix::Dense;
using std::complex;
run<const Dense<double>*, const Dense<float>*,
const Dense<complex<double>>*, const Dense<complex<float>>*>(op, fn);
run<const Dense<double>*, const Dense<float>*, const Dense<half>*,
const Dense<complex<double>>*, const Dense<complex<float>>*,
const Dense<complex<half>>*>(op, fn);
}


Expand Down
2 changes: 1 addition & 1 deletion core/test/utils/batch_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::unique_ptr<MatrixType> generate_diag_dominant_batch_matrix(
static_cast<size_type>(num_cols)},
{}};
auto engine = std::default_random_engine(42);
auto rand_diag_dist = std::normal_distribution<real_type>(8.0, 1.0);
auto rand_diag_dist = std::normal_distribution<>(8.0, 1.0);
for (int row = 0; row < num_rows; ++row) {
std::uniform_int_distribution<index_type> rand_nnz_dist{1, row + 1};
const auto k = rand_nnz_dist(engine);
Expand Down
36 changes: 4 additions & 32 deletions include/ginkgo/core/base/half.hpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2023, the Ginkgo authors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#ifndef GKO_PUBLIC_CORE_BASE_HALF_HPP_
#define GKO_PUBLIC_CORE_BASE_HALF_HPP_
Expand Down Expand Up @@ -326,7 +298,7 @@ struct precision_converter<SourceType, ResultType, false> {
*/
class half {
public:
// TODO: NVHPC (host side) may not use zero initialzation for the data
// TODO: NVHPC (host side) may not use zero initialization for the data
// member by default constructor in some cases. Not sure whether it is
// caused by something else in jacobi or isai.
GKO_ATTRIBUTES half() noexcept : data_(0){};
Expand Down
21 changes: 20 additions & 1 deletion include/ginkgo/core/matrix/batch_csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ namespace matrix {
template <typename ValueType = default_precision, typename IndexType = int32>
class Csr final
: public EnableBatchLinOp<Csr<ValueType, IndexType>>,
#if GINKGO_ENABLE_HALF
public ConvertibleTo<
Csr<next_precision<next_precision<ValueType>>, IndexType>>,
#endif
public ConvertibleTo<Csr<next_precision<ValueType>, IndexType>> {
friend class EnablePolymorphicObject<Csr, BatchLinOp>;
friend class Csr<to_complex<ValueType>, IndexType>;
friend class Csr<next_precision<ValueType>, IndexType>;
friend class Csr<previous_precision<ValueType>, IndexType>;
static_assert(std::is_same<IndexType, int32>::value,
"IndexType must be a 32 bit integer");

Expand All @@ -69,6 +73,21 @@ class Csr final

void move_to(Csr<next_precision<ValueType>, IndexType>* result) override;

#if GINKGO_ENABLE_HALF
friend class Csr<previous_precision<previous_precision<ValueType>>,
IndexType>;
using ConvertibleTo<
Csr<next_precision<next_precision<ValueType>>, IndexType>>::convert_to;
using ConvertibleTo<
Csr<next_precision<next_precision<ValueType>>, IndexType>>::move_to;

void convert_to(Csr<next_precision<next_precision<ValueType>>, IndexType>*
result) const override;

void move_to(Csr<next_precision<next_precision<ValueType>>, IndexType>*
result) override;
#endif

/**
* Creates a mutable view (of matrix::Csr type) of one item of the
* batch::matrix::Csr<value_type> object. Does not perform any deep
Expand Down
2 changes: 1 addition & 1 deletion reference/test/factorization/lu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ TYPED_TEST(Lu, FactorizeNonsymmetricWorks)

GKO_ASSERT_MTX_EQ_SPARSITY(lu->get_combined(), this->mtx_lu);
GKO_ASSERT_MTX_NEAR(lu->get_combined(), this->mtx_lu,
15 * r<value_type>::value);
30 * r<value_type>::value);
ASSERT_EQ(lu->get_storage_type(),
gko::experimental::factorization::storage_type::combined_lu);
ASSERT_EQ(lu->get_lower_factor(), nullptr);
Expand Down
3 changes: 1 addition & 2 deletions reference/test/matrix/scaled_permutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ TYPED_TEST(ScaledPermutation, CombineWithInverse)
using index_type = typename TestFixture::index_type;
const gko::size_type size = 20;
auto rng = std::default_random_engine{3754};
auto dist = std::uniform_real_distribution<gko::remove_complex<value_type>>{
1.0, 2.0};
auto dist = std::uniform_real_distribution<>{1.0, 2.0};
auto perm = gko::matrix::ScaledPermutation<value_type, index_type>::create(
this->exec, size);
std::iota(perm->get_permutation(), perm->get_permutation() + size, 0);
Expand Down
2 changes: 1 addition & 1 deletion reference/test/reorder/mc64_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Mc64 : public ::testing::Test {
0., 2., 3., 0.}},
final_dual_u{ref, I<real_type>{0., 1., -1., -2., 0., 0.}},
final_distance{ref, I<real_type>{inf(), inf(), 1., 0., inf(), 1.}},
zero_tol{1e-14}
zero_tol{1e-4}
{}

std::pair<std::shared_ptr<const perm_type>,
Expand Down
6 changes: 4 additions & 2 deletions reference/test/stop/residual_norm_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ TYPED_TEST(ResidualNorm, CheckIfResZeroConverges)
for (auto baseline :
{mode::rhs_norm, mode::initial_resnorm, mode::absolute}) {
gko::remove_complex<T> factor =
(baseline == mode::absolute) ? 0.0 : r<T>::value;
(baseline == mode::absolute) ? gko::zero<gko::remove_complex<T>>()
: r<T>::value;
auto criterion = gko::stop::ResidualNorm<T>::build()
.with_reduction_factor(factor)
.with_baseline(baseline)
Expand Down Expand Up @@ -843,7 +844,8 @@ TYPED_TEST(ImplicitResidualNorm, CheckIfResZeroConverges)
for (auto baseline :
{mode::rhs_norm, mode::initial_resnorm, mode::absolute}) {
gko::remove_complex<T> factor =
(baseline == mode::absolute) ? 0.0 : r<T>::value;
(baseline == mode::absolute) ? gko::zero<gko::remove_complex<T>>()
: r<T>::value;
auto criterion = gko::stop::ImplicitResidualNorm<T>::build()
.with_reduction_factor(factor)
.with_baseline(baseline)
Expand Down
6 changes: 4 additions & 2 deletions test/stop/residual_norm_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ TYPED_TEST(ResidualNorm, CheckIfResZeroConverges)
for (auto baseline :
{mode::rhs_norm, mode::initial_resnorm, mode::absolute}) {
gko::remove_complex<T> factor =
(baseline == mode::absolute) ? 0.0 : r<T>::value;
(baseline == mode::absolute) ? gko::zero<gko::remove_complex<T>>()
: r<T>::value;
auto criterion = gko::stop::ResidualNorm<T>::build()
.with_reduction_factor(factor)
.with_baseline(baseline)
Expand Down Expand Up @@ -560,7 +561,8 @@ TYPED_TEST(ImplicitResidualNorm, CheckIfResZeroConverges)
for (auto baseline :
{mode::rhs_norm, mode::initial_resnorm, mode::absolute}) {
gko::remove_complex<T> factor =
(baseline == mode::absolute) ? 0.0 : r<T>::value;
(baseline == mode::absolute) ? gko::zero<gko::remove_complex<T>>()
: r<T>::value;
auto criterion = gko::stop::ImplicitResidualNorm<T>::build()
.with_reduction_factor(factor)
.with_baseline(baseline)
Expand Down

0 comments on commit aba0afc

Please sign in to comment.