Skip to content

Commit

Permalink
Adopt the CB-GMRES to the accessor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Grützmacher committed Feb 22, 2021
1 parent 12ce643 commit 799d5ce
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
23 changes: 12 additions & 11 deletions core/solver/cb_gmres_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/dim.hpp>
#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/base/range.hpp>
#include <ginkgo/core/base/std_extensions.hpp>
#include <ginkgo/core/base/types.hpp>


#include "core/base/accessors.hpp"
#include "accessor/range.hpp"
#include "accessor/reduced_row_major.hpp"
#include "accessor/scaled_reduced_row_major.hpp"


namespace gko {
Expand All @@ -65,7 +66,7 @@ struct has_3d_scaled_accessor : public std::false_type {};

template <typename T1, typename T2, size_type mask>
struct has_3d_scaled_accessor<
range<accessor::scaled_reduced_row_major<3, T1, T2, mask>>>
acc::range<acc::scaled_reduced_row_major<3, T1, T2, mask>>>
: public std::true_type {};

template <typename StorageType, bool = std::is_integral<StorageType>::value>
Expand All @@ -90,13 +91,13 @@ template <typename ValueType, typename StorageType>
class Range3dHelper<ValueType, StorageType, true> {
public:
using Accessor =
accessor::scaled_reduced_row_major<3, ValueType, StorageType, 0b101>;
using Range = range<Accessor>;
acc::scaled_reduced_row_major<3, ValueType, StorageType, 0b101>;
using Range = acc::range<Accessor>;

Range3dHelper() = default;

Range3dHelper(std::shared_ptr<const Executor> exec, dim<3> krylov_dim)
: krylov_dim_{krylov_dim},
: krylov_dim_{{krylov_dim[0], krylov_dim[1], krylov_dim[2]}},
bases_{exec, krylov_dim_[0] * krylov_dim_[1] * krylov_dim_[2]},
scale_{exec, krylov_dim_[0] * krylov_dim_[2]}
{
Expand All @@ -116,7 +117,7 @@ class Range3dHelper<ValueType, StorageType, true> {
gko::Array<StorageType> &get_bases() { return bases_; }

private:
dim<3> krylov_dim_;
std::array<size_type, 3> krylov_dim_;
Array<StorageType> bases_;
Array<ValueType> scale_;
};
Expand All @@ -125,13 +126,13 @@ class Range3dHelper<ValueType, StorageType, true> {
template <typename ValueType, typename StorageType>
class Range3dHelper<ValueType, StorageType, false> {
public:
using Accessor = accessor::reduced_row_major<3, ValueType, StorageType>;
using Range = range<Accessor>;
using Accessor = acc::reduced_row_major<3, ValueType, StorageType>;
using Range = acc::range<Accessor>;

Range3dHelper() = default;

Range3dHelper(std::shared_ptr<const Executor> exec, dim<3> krylov_dim)
: krylov_dim_{krylov_dim},
: krylov_dim_{{krylov_dim[0], krylov_dim[1], krylov_dim[2]}},
bases_{std::move(exec),
krylov_dim_[0] * krylov_dim_[1] * krylov_dim_[2]}
{}
Expand All @@ -141,7 +142,7 @@ class Range3dHelper<ValueType, StorageType, false> {
gko::Array<StorageType> &get_bases() { return bases_; }

private:
dim<3> krylov_dim_;
std::array<size_type, 3> krylov_dim_;
Array<StorageType> bases_;
};

Expand Down
29 changes: 15 additions & 14 deletions core/solver/cb_gmres_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/matrix/dense.hpp>


#include "core/base/accessors.hpp"
#include "accessor/reduced_row_major.hpp"
#include "accessor/scaled_reduced_row_major.hpp"
#include "core/base/extended_float.hpp"


Expand All @@ -64,52 +65,52 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template _macro( \
double, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, double, _const double>>)); \
acc::range<acc::reduced_row_major<3, double, _const double>>)); \
template _macro( \
double, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, double, _const float>>)); \
acc::range<acc::reduced_row_major<3, double, _const float>>)); \
template _macro( \
double, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, double, _const half>>)); \
acc::range<acc::reduced_row_major<3, double, _const half>>)); \
template _macro(double, \
GKO_UNPACK(range<accessor::scaled_reduced_row_major< \
GKO_UNPACK(acc::range<acc::scaled_reduced_row_major< \
3, double, _const int64, 0b101>>)); \
template _macro(double, \
GKO_UNPACK(range<accessor::scaled_reduced_row_major< \
GKO_UNPACK(acc::range<acc::scaled_reduced_row_major< \
3, double, _const int32, 0b101>>)); \
template _macro(double, \
GKO_UNPACK(range<accessor::scaled_reduced_row_major< \
GKO_UNPACK(acc::range<acc::scaled_reduced_row_major< \
3, double, _const int16, 0b101>>)); \
template _macro( \
float, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, float, _const float>>)); \
acc::range<acc::reduced_row_major<3, float, _const float>>)); \
template _macro( \
float, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, float, _const half>>)); \
acc::range<acc::reduced_row_major<3, float, _const half>>)); \
template _macro(float, \
GKO_UNPACK(range<accessor::scaled_reduced_row_major< \
GKO_UNPACK(acc::range<acc::scaled_reduced_row_major< \
3, float, _const int32, 0b101>>)); \
template _macro(float, \
GKO_UNPACK(range<accessor::scaled_reduced_row_major< \
GKO_UNPACK(acc::range<acc::scaled_reduced_row_major< \
3, float, _const int16, 0b101>>)); \
template _macro( \
std::complex<double>, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, std::complex<double>, \
acc::range<acc::reduced_row_major<3, std::complex<double>, \
_const std::complex<double>>>)); \
template _macro( \
std::complex<double>, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, std::complex<double>, \
acc::range<acc::reduced_row_major<3, std::complex<double>, \
_const std::complex<float>>>)); \
template _macro( \
std::complex<float>, \
GKO_UNPACK( \
range<accessor::reduced_row_major<3, std::complex<float>, \
acc::range<acc::reduced_row_major<3, std::complex<float>, \
_const std::complex<float>>>))

#define GKO_INSTANTIATE_FOR_EACH_CB_GMRES_TYPE(_macro) \
Expand Down
14 changes: 8 additions & 6 deletions cuda/solver/cb_gmres_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/stop/stopping_status.hpp>


#include "core/base/accessors.hpp"
#include "accessor/range.hpp"
#include "accessor/reduced_row_major.hpp"
#include "accessor/scaled_reduced_row_major.hpp"
#include "core/components/fill_array.hpp"
#include "core/matrix/dense_kernels.hpp"
#include "core/solver/cb_gmres_accessor.hpp"
Expand Down Expand Up @@ -78,21 +80,21 @@ constexpr int default_dot_size = default_dot_dim * default_dot_dim;
// Specialization, so the Accessor can use the same function as regular pointers
template <int dim, typename Type1, typename Type2>
GKO_INLINE auto as_cuda_accessor(
const range<accessor::reduced_row_major<dim, Type1, Type2>> &acc)
const acc::range<acc::reduced_row_major<dim, Type1, Type2>> &acc)
{
return range<
accessor::reduced_row_major<dim, cuda_type<Type1>, cuda_type<Type2>>>(
return acc::range<
acc::reduced_row_major<dim, cuda_type<Type1>, cuda_type<Type2>>>(
acc.get_accessor().get_size(),
as_cuda_type(acc.get_accessor().get_stored_data()),
acc.get_accessor().get_stride());
}

template <int dim, typename Type1, typename Type2, size_type mask>
GKO_INLINE auto as_cuda_accessor(
const range<accessor::scaled_reduced_row_major<dim, Type1, Type2, mask>>
const acc::range<acc::scaled_reduced_row_major<dim, Type1, Type2, mask>>
&acc)
{
return range<accessor::scaled_reduced_row_major<dim, cuda_type<Type1>,
return acc::range<acc::scaled_reduced_row_major<dim, cuda_type<Type1>,
cuda_type<Type2>, mask>>(
acc.get_accessor().get_size(),
as_cuda_type(acc.get_accessor().get_stored_data()),
Expand Down
13 changes: 8 additions & 5 deletions hip/solver/cb_gmres_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/stop/stopping_status.hpp>


#include "accessor/range.hpp"
#include "accessor/reduced_row_major.hpp"
#include "accessor/scaled_reduced_row_major.hpp"
#include "core/components/fill_array.hpp"
#include "core/matrix/dense_kernels.hpp"
#include "core/solver/cb_gmres_accessor.hpp"
Expand Down Expand Up @@ -79,21 +82,21 @@ constexpr int default_dot_size = default_dot_dim * default_dot_dim;
// Specialization, so the Accessor can use the same function as regular pointers
template <int dim, typename Type1, typename Type2>
GKO_INLINE auto as_hip_accessor(
const range<accessor::reduced_row_major<dim, Type1, Type2>> &acc)
const acc::range<acc::reduced_row_major<dim, Type1, Type2>> &acc)
{
return range<
accessor::reduced_row_major<dim, hip_type<Type1>, hip_type<Type2>>>(
return acc::range<
acc::reduced_row_major<dim, hip_type<Type1>, hip_type<Type2>>>(
acc.get_accessor().get_size(),
as_hip_type(acc.get_accessor().get_stored_data()),
acc.get_accessor().get_stride());
}

template <int dim, typename Type1, typename Type2, size_type mask>
GKO_INLINE auto as_hip_accessor(
const range<accessor::scaled_reduced_row_major<dim, Type1, Type2, mask>>
const acc::range<acc::scaled_reduced_row_major<dim, Type1, Type2, mask>>
&acc)
{
return range<accessor::scaled_reduced_row_major<dim, hip_type<Type1>,
return acc::range<acc::scaled_reduced_row_major<dim, hip_type<Type1>,
hip_type<Type2>, mask>>(
acc.get_accessor().get_size(),
as_hip_type(acc.get_accessor().get_stored_data()),
Expand Down

0 comments on commit 799d5ce

Please sign in to comment.