From 5f2ad112eb80413ae54a01a841d92efb5a50f8c6 Mon Sep 17 00:00:00 2001 From: Mikhail Katliar Date: Thu, 8 Aug 2024 09:36:34 +0200 Subject: [PATCH 1/2] Matrix concept and type traits --- include/blast/math/Matrix.hpp | 62 +++++++++++++++++++ include/blast/math/TypeTraits.hpp | 2 + .../blast/math/dense/DynamicMatrixPointer.hpp | 12 ++-- .../blast/math/expressions/PanelMatrix.hpp | 12 ++-- .../blast/math/panel/DynamicPanelMatrix.hpp | 4 +- .../register_matrix/DynamicRegisterMatrix.hpp | 56 +++++++++-------- .../math/register_matrix/RegisterMatrix.hpp | 34 +++++----- .../blast/math/typetraits/IsDenseMatrix.hpp | 16 +++++ include/blast/math/typetraits/IsStatic.hpp | 11 +++- include/blast/math/typetraits/Matrix.hpp | 23 +++++++ include/blast/util/Types.hpp | 9 +++ test/blast/math/dense/Getf2Test.cpp | 12 ++-- test/blast/math/dense/GetrfTest.cpp | 12 ++-- 13 files changed, 192 insertions(+), 73 deletions(-) create mode 100644 include/blast/math/Matrix.hpp create mode 100644 include/blast/math/typetraits/IsDenseMatrix.hpp create mode 100644 include/blast/math/typetraits/Matrix.hpp create mode 100644 include/blast/util/Types.hpp diff --git a/include/blast/math/Matrix.hpp b/include/blast/math/Matrix.hpp new file mode 100644 index 00000000..83e87654 --- /dev/null +++ b/include/blast/math/Matrix.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2019-2024 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include + + +namespace blast +{ + template + inline void randomize(M& m) noexcept + { + + } + + + template + inline bool operator==(MA const& a, MB const& b) noexcept + { + return false; + } + + + template + inline std::ostream& operator<<(std::ostream& os, M const& m) + { + for (size_t i = 0; i < rows(m); ++i) + { + for (size_t j = 0; j < columns(m); ++j) + os << m(i, j) << "\t"; + os << std::endl; + } + + return os; + } + + + template + requires IsStatic_v && IsDenseMatrix_v + BLAST_ALWAYS_INLINE auto ptr(MT& m, size_t i, size_t j) noexcept + { + return StaticMatrixPointer, spacing(m), StorageOrder_v, AF, IsPadded_v>(data(m), i, j); + } + + + template + requires IsStatic_v && IsDenseMatrix_v + BLAST_ALWAYS_INLINE auto ptr(MT const& m, size_t i, size_t j) noexcept + { + return StaticMatrixPointer const, spacing(m), StorageOrder_v, AF, IsPadded_v>(data(m), i, j); + } +} diff --git a/include/blast/math/TypeTraits.hpp b/include/blast/math/TypeTraits.hpp index a65b0ac3..0a70f009 100644 --- a/include/blast/math/TypeTraits.hpp +++ b/include/blast/math/TypeTraits.hpp @@ -19,7 +19,9 @@ #include #include #include +#include #include #include #include #include +#include diff --git a/include/blast/math/dense/DynamicMatrixPointer.hpp b/include/blast/math/dense/DynamicMatrixPointer.hpp index 5610b1c9..30c7b4e3 100644 --- a/include/blast/math/dense/DynamicMatrixPointer.hpp +++ b/include/blast/math/dense/DynamicMatrixPointer.hpp @@ -10,6 +10,8 @@ #include #include #include +#include + #include @@ -203,7 +205,7 @@ namespace blast template - BLAZE_ALWAYS_INLINE auto trans(DynamicMatrixPointer const& p) noexcept + BLAST_ALWAYS_INLINE auto trans(DynamicMatrixPointer const& p) noexcept { return p.trans(); } @@ -211,7 +213,7 @@ namespace blast template requires (!IsStatic_v) - BLAZE_ALWAYS_INLINE DynamicMatrixPointer, SO, AF, IsPadded_v> + BLAST_ALWAYS_INLINE DynamicMatrixPointer, SO, AF, IsPadded_v> ptr(DenseMatrix& m, size_t i, size_t j) { if constexpr (SO == columnMajor) @@ -223,7 +225,7 @@ namespace blast template requires (!IsStatic_v) - BLAZE_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> + BLAST_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> ptr(DenseMatrix const& m, size_t i, size_t j) { if constexpr (SO == columnMajor) @@ -235,7 +237,7 @@ namespace blast template requires (!IsStatic_v) - BLAZE_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> + BLAST_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> ptr(DMatTransExpr const& m, size_t i, size_t j) { if constexpr (SO == columnMajor) @@ -246,7 +248,7 @@ namespace blast template - BLAZE_ALWAYS_INLINE DynamicMatrixPointer ptr(T * p, size_t spacing) + BLAST_ALWAYS_INLINE DynamicMatrixPointer ptr(T * p, size_t spacing) { return {p, spacing}; } diff --git a/include/blast/math/expressions/PanelMatrix.hpp b/include/blast/math/expressions/PanelMatrix.hpp index d0494887..80de78cf 100644 --- a/include/blast/math/expressions/PanelMatrix.hpp +++ b/include/blast/math/expressions/PanelMatrix.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -21,12 +22,9 @@ namespace blast { - using namespace blaze; - - template struct PanelMatrix - : public Matrix + : public blaze::Matrix { public: using TagType = Group0; @@ -80,14 +78,14 @@ namespace blast template inline auto assign(PanelMatrix& lhs, blaze::DMatTDMatMultExpr const& rhs) - -> blaze::EnableIf_t && IsRowMajorMatrix_v && IsPanelMatrix_v && IsRowMajorMatrix_v> + -> blaze::EnableIf_t && blaze::IsRowMajorMatrix_v && IsPanelMatrix_v && blaze::IsRowMajorMatrix_v> { BLAZE_THROW_LOGIC_ERROR("Not implemented 2"); } template - inline void assign(DenseMatrix& lhs, PanelMatrix const& rhs) + inline void assign(blaze::DenseMatrix& lhs, PanelMatrix const& rhs) { BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" ); BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" ); @@ -176,7 +174,7 @@ namespace blast template - inline void assign(PanelMatrix& lhs, DenseMatrix const& rhs) + inline void assign(PanelMatrix& lhs, blaze::DenseMatrix const& rhs) { size_t const m = (*rhs).rows(); size_t const n = (*rhs).columns(); diff --git a/include/blast/math/panel/DynamicPanelMatrix.hpp b/include/blast/math/panel/DynamicPanelMatrix.hpp index f82e51e6..4dd69d1f 100644 --- a/include/blast/math/panel/DynamicPanelMatrix.hpp +++ b/include/blast/math/panel/DynamicPanelMatrix.hpp @@ -109,7 +109,7 @@ namespace blast template< typename MT // Type of the right-hand side matrix , bool SO2 > // Storage order of the right-hand side matrix - DynamicPanelMatrix& operator=(Matrix const& rhs) + DynamicPanelMatrix& operator=(blaze::Matrix const& rhs) { assign(*this, *rhs); return *this; @@ -238,4 +238,4 @@ namespace blaze { using Type = blast::DynamicPanelMatrix; }; -} \ No newline at end of file +} diff --git a/include/blast/math/register_matrix/DynamicRegisterMatrix.hpp b/include/blast/math/register_matrix/DynamicRegisterMatrix.hpp index 9cd7f826..caa0eeb3 100644 --- a/include/blast/math/register_matrix/DynamicRegisterMatrix.hpp +++ b/include/blast/math/register_matrix/DynamicRegisterMatrix.hpp @@ -6,14 +6,16 @@ #include #include +#include #include #include +#include #include +#include #include #include #include -#include #include #include @@ -31,12 +33,12 @@ namespace blast /// @tparam SO orientation of SIMD registers. template class DynamicRegisterMatrix - : public Matrix, SO> + : public blaze::Matrix, SO> { public: static_assert(SO == columnMajor, "Only column-major register matrices are currently supported"); - using BaseType = Matrix, SO>; + using BaseType = blaze::Matrix, SO>; using BaseType::storageOrder; /// @brief Type of matrix elements @@ -135,7 +137,7 @@ namespace blast /// @brief R(0:m-1, 0:n-1) += beta * A template - requires MatrixPointer && (PA::storageOrder == columnMajor) + requires MatrixPointer && (PA::storageOrder == columnMajor) void axpy(T beta, PA a) noexcept { #pragma unroll @@ -148,25 +150,25 @@ namespace blast /// @brief Load from memory template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) void load(P p) noexcept; /// @brief Load from memory template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) void load(T beta, P p) noexcept; /// @brief Store matrix at location pointed by \a p template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) void store(P p) const noexcept; /// @brief Store lower-triangular part of the matrix at location pointed by \a p. template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) void storeLower(P p) const noexcept; @@ -178,7 +180,7 @@ namespace blast /// @param a pointer to the first element of the first matrix. /// @param b pointer to the first element of the second matrix. template - requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer void ger(T alpha, PA a, PB b) noexcept; @@ -189,7 +191,7 @@ namespace blast /// @param a pointer to the first element of the first matrix. /// @param b pointer to the first element of the second matrix. template - requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer void ger(PA a, PB b) noexcept; @@ -202,7 +204,7 @@ namespace blast /// @brief a pointer to a triangular matrix /// template - requires MatrixPointer + requires MatrixPointer void trsmRightUpper(P a); @@ -222,7 +224,7 @@ namespace blast /// @param b general matrix. /// template - requires MatrixPointer && (P1::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (P1::storageOrder == columnMajor) && MatrixPointer void trmmLeftUpper(T alpha, P1 a, P2 b) noexcept; @@ -242,7 +244,7 @@ namespace blast /// @param b general matrix. /// template - requires MatrixPointer && (P1::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (P1::storageOrder == columnMajor) && MatrixPointer void trmmRightLower(T alpha, P1 a, P2 b) noexcept; @@ -289,7 +291,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void DynamicRegisterMatrix::load(P p) noexcept { #pragma unroll @@ -302,7 +304,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void DynamicRegisterMatrix::load(T beta, P p) noexcept { #pragma unroll @@ -315,7 +317,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void DynamicRegisterMatrix::store(P p) const noexcept { // The compile-time constant size of the j loop in combination with the if() expression @@ -337,7 +339,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void DynamicRegisterMatrix::storeLower(P p) const noexcept { for (size_t j = 0; j < N; ++j) if (j < n_) @@ -393,7 +395,7 @@ namespace blast template template - requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer BLAZE_ALWAYS_INLINE void DynamicRegisterMatrix::ger(T alpha, PA a, PB b) noexcept { SimdVecType ax[RM]; @@ -416,7 +418,7 @@ namespace blast template template - requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer + requires MatrixPointer && (PA::storageOrder == columnMajor) && MatrixPointer BLAZE_ALWAYS_INLINE void DynamicRegisterMatrix::ger(PA a, PB b) noexcept { SimdVecType ax[RM]; @@ -550,23 +552,23 @@ namespace blast // } - template - inline bool operator==(DynamicRegisterMatrix const& rm, Matrix const& m) + template + inline bool operator==(DynamicRegisterMatrix const& rm, MT const& m) { if (rows(m) != rm.rows() || columns(m) != rm.columns()) return false; for (size_t i = 0; i < rm.rows(); ++i) for (size_t j = 0; j < rm.columns(); ++j) - if (rm(i, j) != (*m)(i, j)) + if (rm(i, j) != m(i, j)) return false; return true; } - template - inline bool operator==(Matrix const& m, DynamicRegisterMatrix const& rm) + template + inline bool operator==(MT const& m, DynamicRegisterMatrix const& rm) { return rm == m; } @@ -576,9 +578,9 @@ namespace blast typename T, size_t M, size_t N, bool SO, typename PA, typename PB, typename PC, typename PD > - requires MatrixPointer && (PA::storageOrder == columnMajor) - && MatrixPointer - && MatrixPointer && (PC::storageOrder == columnMajor) + requires MatrixPointer && (PA::storageOrder == columnMajor) + && MatrixPointer + && MatrixPointer && (PC::storageOrder == columnMajor) BLAZE_ALWAYS_INLINE void gemm(DynamicRegisterMatrix& ker, size_t K, T alpha, PA a, PB b, T beta, PC c, PD d) noexcept { diff --git a/include/blast/math/register_matrix/RegisterMatrix.hpp b/include/blast/math/register_matrix/RegisterMatrix.hpp index 631b530d..156031c0 100644 --- a/include/blast/math/register_matrix/RegisterMatrix.hpp +++ b/include/blast/math/register_matrix/RegisterMatrix.hpp @@ -7,9 +7,12 @@ #include #include #include +#include #include #include #include +#include +#include #include #include @@ -22,9 +25,6 @@ namespace blast { - using namespace blaze; - - /// @brief Register-resident matrix /// /// The RegisterMatrix class provides basic linear algebra operations that can be performed @@ -39,12 +39,12 @@ namespace blast /// template class RegisterMatrix - : public Matrix, SO> + : public blaze::Matrix, SO> { public: static_assert(SO == columnMajor, "Only column-major register matrices are currently supported"); - using BaseType = Matrix, SO>; + using BaseType = blaze::Matrix, SO>; using BaseType::storageOrder; /// @brief Type of matrix elements @@ -131,7 +131,7 @@ namespace blast /// @brief R += beta * A template - requires MatrixPointer && (PA::storageOrder == columnMajor) + requires MatrixPointer && (PA::storageOrder == columnMajor) void axpy(T beta, PA a) noexcept { SimdVecType const beta_simd {beta}; @@ -146,7 +146,7 @@ namespace blast /// @brief R(0:m-1, 0:n-1) += beta * A template - requires MatrixPointer && (PA::storageOrder == columnMajor) + requires MatrixPointer && (PA::storageOrder == columnMajor) void axpy(T beta, PA a, size_t m, size_t n) noexcept { SimdVecType const beta_simd {beta}; @@ -191,7 +191,7 @@ namespace blast /// @brief Store lower-triangular part of the matrix at location pointed by \a p. template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) void storeLower(P p) const noexcept; @@ -466,7 +466,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void RegisterMatrix::store(P p) const noexcept { #pragma unroll @@ -479,7 +479,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void RegisterMatrix::store(P p, size_t m, size_t n) const noexcept { // The compile-time constant size of the j loop in combination with the if() expression @@ -501,7 +501,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void RegisterMatrix::storeLower(P p) const noexcept { for (size_t j = 0; j < N; ++j) @@ -524,7 +524,7 @@ namespace blast template template - requires MatrixPointer && (P::storageOrder == columnMajor) + requires MatrixPointer && (P::storageOrder == columnMajor) inline void RegisterMatrix::storeLower(P p, size_t m, size_t n) const noexcept { for (size_t j = 0; j < N; ++j) if (j < n) @@ -802,23 +802,23 @@ namespace blast } - template - inline bool operator==(RegisterMatrix const& rm, Matrix const& m) + template + inline bool operator==(RegisterMatrix const& rm, MT const& m) { if (rows(m) != rm.rows() || columns(m) != rm.columns()) return false; for (size_t i = 0; i < rm.rows(); ++i) for (size_t j = 0; j < rm.columns(); ++j) - if (rm(i, j) != (*m)(i, j)) + if (rm(i, j) != m(i, j)) return false; return true; } - template - inline bool operator==(Matrix const& m, RegisterMatrix const& rm) + template + inline bool operator==(MT const& m, RegisterMatrix const& rm) { return rm == m; } diff --git a/include/blast/math/typetraits/IsDenseMatrix.hpp b/include/blast/math/typetraits/IsDenseMatrix.hpp new file mode 100644 index 00000000..2cf5384e --- /dev/null +++ b/include/blast/math/typetraits/IsDenseMatrix.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +#pragma once + +#include + + +namespace blast +{ + template + struct IsDenseMatrix : std::false_type {}; + + template + bool constexpr IsDenseMatrix_v = IsDenseMatrix::value; +} diff --git a/include/blast/math/typetraits/IsStatic.hpp b/include/blast/math/typetraits/IsStatic.hpp index 0f60867e..ba3f98a9 100644 --- a/include/blast/math/typetraits/IsStatic.hpp +++ b/include/blast/math/typetraits/IsStatic.hpp @@ -14,10 +14,15 @@ #pragma once -#include +#include namespace blast { - using blaze::IsStatic_v; -} \ No newline at end of file + template + struct IsStatic : blaze::IsStatic {}; + + + template + bool constexpr IsStatic_v = IsStatic::value; +} diff --git a/include/blast/math/typetraits/Matrix.hpp b/include/blast/math/typetraits/Matrix.hpp new file mode 100644 index 00000000..c1af9537 --- /dev/null +++ b/include/blast/math/typetraits/Matrix.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2019-2023 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include + + +namespace blast +{ + template > + concept Matrix = requires(M m, T v, T * p, size_t i, size_t j) + { + m; + m(i, j) = v; + v = m(i, j); + i = rows(m); + j = columns(m); + p = data(m); + }; +} diff --git a/include/blast/util/Types.hpp b/include/blast/util/Types.hpp new file mode 100644 index 00000000..f7c82547 --- /dev/null +++ b/include/blast/util/Types.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace blast +{ + using std::size_t; + using std::ptrdiff_t; +} diff --git a/test/blast/math/dense/Getf2Test.cpp b/test/blast/math/dense/Getf2Test.cpp index 80cdab7d..f9d98802 100644 --- a/test/blast/math/dense/Getf2Test.cpp +++ b/test/blast/math/dense/Getf2Test.cpp @@ -23,13 +23,13 @@ namespace blast :: testing using Real = T; template - static DynamicMatrix luRestore(Matrix const& LU, size_t * ipiv) + static blaze::DynamicMatrix luRestore(blaze::Matrix const& LU, size_t * ipiv) { auto const M = rows(LU); auto const N = columns(LU); auto const K = std::min(M, N); - DynamicMatrix L(M, K, 0.); + blaze::DynamicMatrix L(M, K, 0.); for (size_t i = 0; i < M; ++i) { for (size_t j = 0; j < i && j < K; ++j) @@ -39,7 +39,7 @@ namespace blast :: testing L(i, i) = 1.; } - DynamicMatrix U(K, N, 0.); + blaze::DynamicMatrix U(K, N, 0.); for (size_t i = 0; i < K; ++i) { for (size_t j = i; j < N; ++j) @@ -63,9 +63,9 @@ namespace blast :: testing // Init matrices // - DynamicMatrix A(M, N); + blaze::DynamicMatrix A(M, N); randomize(A); - DynamicMatrix A_orig = A; + blaze::DynamicMatrix A_orig = A; // Do getrf std::vector ipiv(K); @@ -105,4 +105,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DenseGetf2Test, double); // INSTANTIATE_TYPED_TEST_SUITE_P(Potrf_float, DensePotrtTest, float); -} \ No newline at end of file +} diff --git a/test/blast/math/dense/GetrfTest.cpp b/test/blast/math/dense/GetrfTest.cpp index 4a1a3732..652dc6f3 100644 --- a/test/blast/math/dense/GetrfTest.cpp +++ b/test/blast/math/dense/GetrfTest.cpp @@ -27,13 +27,13 @@ namespace blast :: testing using Real = T; template - static DynamicMatrix luRestore(Matrix const& LU, size_t * ipiv) + static blaze::DynamicMatrix luRestore(blaze::Matrix const& LU, size_t * ipiv) { auto const M = rows(LU); auto const N = columns(LU); auto const K = std::min(M, N); - DynamicMatrix L(M, K, 0.); + blaze::DynamicMatrix L(M, K, 0.); for (size_t i = 0; i < M; ++i) { for (size_t j = 0; j < i && j < K; ++j) @@ -43,7 +43,7 @@ namespace blast :: testing L(i, i) = 1.; } - DynamicMatrix U(K, N, 0.); + blaze::DynamicMatrix U(K, N, 0.); for (size_t i = 0; i < K; ++i) { for (size_t j = i; j < N; ++j) @@ -67,9 +67,9 @@ namespace blast :: testing // Init matrices // - DynamicMatrix A(M, N); + blaze::DynamicMatrix A(M, N); randomize(A); - DynamicMatrix A_orig = A; + blaze::DynamicMatrix A_orig = A; // Do getrf std::vector ipiv(K); @@ -132,4 +132,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DenseGetrfTest, double); // INSTANTIATE_TYPED_TEST_SUITE_P(Potrf_float, DensePotrtTest, float); -} \ No newline at end of file +} From 480a442473d75d692ea6044d53a67cb608b9ace5 Mon Sep 17 00:00:00 2001 From: Mikhail Katliar Date: Thu, 8 Aug 2024 12:52:30 +0200 Subject: [PATCH 2/2] - Clean ptr mess - Blaze-specific code moved to blast/blaze --- bench/blast/math/dense/DynamicGemm.cpp | 4 +- bench/blast/math/dense/StaticGemm.cpp | 4 +- bench/blast/math/dense/StaticIamax.cpp | 2 +- bench/blast/math/dense/StaticTrmm.cpp | 7 +- bench/blast/math/panel/StaticGemm.cpp | 2 + bench/blast/math/simd/Trmm.cpp | 6 +- include/blast/blaze/Math.hpp | 10 + include/blast/blaze/math/TypeTraits.hpp | 12 + include/blast/blaze/math/Vector.hpp | 38 +++ .../blaze/math/typetraits/IsContiguous.hpp | 41 +++ .../blaze/math/typetraits/IsDenseMatrix.hpp | 23 ++ .../blaze/math/typetraits/IsDenseVector.hpp | 23 ++ .../blast/blaze/math/typetraits/IsStatic.hpp | 24 ++ .../math/typetraits/IsStaticallySpaced.hpp | 44 +++ .../blast/blaze/math/typetraits/Spacing.hpp | 59 ++++ include/blast/math/Matrix.hpp | 73 ++--- include/blast/math/TypeTraits.hpp | 21 +- include/blast/math/Vector.hpp | 45 ++++ .../blast/math/dense/DynamicMatrixPointer.hpp | 50 +--- .../blast/math/dense/DynamicVectorPointer.hpp | 46 +++- include/blast/math/dense/Gemm.hpp | 8 +- include/blast/math/dense/Ger.hpp | 37 +-- include/blast/math/dense/Getf2.hpp | 9 +- include/blast/math/dense/Getrf.hpp | 4 +- include/blast/math/dense/Iamax.hpp | 3 +- include/blast/math/dense/Laswp.hpp | 9 +- include/blast/math/dense/MatrixPointer.hpp | 45 ---- include/blast/math/dense/Potrf.hpp | 36 ++- .../blast/math/dense/StaticMatrixPointer.hpp | 28 +- .../blast/math/dense/StaticVectorPointer.hpp | 43 +++ include/blast/math/dense/Swap.hpp | 5 +- include/blast/math/dense/Syrk.hpp | 71 +++-- include/blast/math/dense/Trmm.hpp | 40 +-- include/blast/math/dense/VectorPointer.hpp | 253 ------------------ .../blast/math/expressions/PMatTransExpr.hpp | 21 ++ .../blast/math/expressions/PanelMatrix.hpp | 11 +- .../math/panel/DynamicPanelMatrixPointer.hpp | 26 +- include/blast/math/panel/Gemm.hpp | 2 +- include/blast/math/panel/MatrixPointer.hpp | 46 ---- .../blast/math/panel/StaticPanelMatrix.hpp | 14 + .../math/panel/StaticPanelMatrixPointer.hpp | 24 +- .../blast/math/typetraits/IsContiguous.hpp | 26 ++ .../blast/math/typetraits/IsDenseMatrix.hpp | 13 +- .../blast/math/typetraits/IsDenseVector.hpp | 28 ++ include/blast/math/typetraits/IsStatic.hpp | 30 +-- .../math/typetraits/IsStaticallySpaced.hpp | 27 ++ include/blast/math/typetraits/Matrix.hpp | 10 +- include/blast/math/typetraits/Spacing.hpp | 32 +++ include/blast/math/typetraits/Vector.hpp | 29 ++ .../math/dense/DynamicVectorPointerTest.cpp | 22 +- test/blast/math/dense/GemmTest.cpp | 4 +- test/blast/math/dense/GerTest.cpp | 6 +- test/blast/math/dense/Getf2Test.cpp | 2 +- test/blast/math/dense/GetrfTest.cpp | 4 +- test/blast/math/dense/Iamax.cpp | 21 +- test/blast/math/dense/MatrixPointerTest.cpp | 16 +- test/blast/math/dense/PotrfTest.cpp | 13 +- .../math/dense/StaticVectorPointerTest.cpp | 5 +- test/blast/math/dense/SyrkTest.cpp | 11 +- test/blast/math/dense/TrmmTest.cpp | 5 +- test/blast/math/panel/PotrfTest.cpp | 3 +- .../math/panel/StaticPanelMatrixTest.cpp | 2 +- .../math/simd/DynamicRegisterMatrixTest.cpp | 5 +- test/blast/math/simd/RegisterMatrixTest.cpp | 18 +- 64 files changed, 869 insertions(+), 732 deletions(-) create mode 100644 include/blast/blaze/Math.hpp create mode 100644 include/blast/blaze/math/TypeTraits.hpp create mode 100644 include/blast/blaze/math/Vector.hpp create mode 100644 include/blast/blaze/math/typetraits/IsContiguous.hpp create mode 100644 include/blast/blaze/math/typetraits/IsDenseMatrix.hpp create mode 100644 include/blast/blaze/math/typetraits/IsDenseVector.hpp create mode 100644 include/blast/blaze/math/typetraits/IsStatic.hpp create mode 100644 include/blast/blaze/math/typetraits/IsStaticallySpaced.hpp create mode 100644 include/blast/blaze/math/typetraits/Spacing.hpp create mode 100644 include/blast/math/Vector.hpp delete mode 100644 include/blast/math/dense/MatrixPointer.hpp delete mode 100644 include/blast/math/dense/VectorPointer.hpp delete mode 100644 include/blast/math/panel/MatrixPointer.hpp create mode 100644 include/blast/math/typetraits/IsContiguous.hpp create mode 100644 include/blast/math/typetraits/IsDenseVector.hpp create mode 100644 include/blast/math/typetraits/IsStaticallySpaced.hpp create mode 100644 include/blast/math/typetraits/Spacing.hpp create mode 100644 include/blast/math/typetraits/Vector.hpp diff --git a/bench/blast/math/dense/DynamicGemm.cpp b/bench/blast/math/dense/DynamicGemm.cpp index e0f78260..9d702760 100644 --- a/bench/blast/math/dense/DynamicGemm.cpp +++ b/bench/blast/math/dense/DynamicGemm.cpp @@ -3,11 +3,11 @@ // license that can be found in the LICENSE file. #include +#include +#include #include -#include - #include diff --git a/bench/blast/math/dense/StaticGemm.cpp b/bench/blast/math/dense/StaticGemm.cpp index 22d6f68e..960c8ae9 100644 --- a/bench/blast/math/dense/StaticGemm.cpp +++ b/bench/blast/math/dense/StaticGemm.cpp @@ -3,11 +3,11 @@ // license that can be found in the LICENSE file. #include +#include +#include #include -#include - #include diff --git a/bench/blast/math/dense/StaticIamax.cpp b/bench/blast/math/dense/StaticIamax.cpp index a3a53101..6fab6a87 100644 --- a/bench/blast/math/dense/StaticIamax.cpp +++ b/bench/blast/math/dense/StaticIamax.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include diff --git a/bench/blast/math/dense/StaticTrmm.cpp b/bench/blast/math/dense/StaticTrmm.cpp index 1365197b..1cc263ad 100644 --- a/bench/blast/math/dense/StaticTrmm.cpp +++ b/bench/blast/math/dense/StaticTrmm.cpp @@ -3,15 +3,12 @@ // license that can be found in the LICENSE file. #include - -#include +#include +#include #include #include -#include -#include - namespace blast :: benchmark { diff --git a/bench/blast/math/panel/StaticGemm.cpp b/bench/blast/math/panel/StaticGemm.cpp index 0d4f4ee2..c515c35e 100644 --- a/bench/blast/math/panel/StaticGemm.cpp +++ b/bench/blast/math/panel/StaticGemm.cpp @@ -3,7 +3,9 @@ // license that can be found in the LICENSE file. #include +#include #include +#include #include diff --git a/bench/blast/math/simd/Trmm.cpp b/bench/blast/math/simd/Trmm.cpp index 9ab4a7c3..5cc29978 100644 --- a/bench/blast/math/simd/Trmm.cpp +++ b/bench/blast/math/simd/Trmm.cpp @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include +#include #include #include #include -#include +#include namespace blast :: benchmark @@ -81,4 +81,4 @@ namespace blast :: benchmark BENCHMARK_TEMPLATE(BM_RegisterMatrix_trmmRightLower, float, 24, 4, columnMajor); BENCHMARK_TEMPLATE(BM_RegisterMatrix_trmmRightLower, float, 16, 5, columnMajor); BENCHMARK_TEMPLATE(BM_RegisterMatrix_trmmRightLower, float, 16, 6, columnMajor); -} \ No newline at end of file +} diff --git a/include/blast/blaze/Math.hpp b/include/blast/blaze/Math.hpp new file mode 100644 index 00000000..48c1c3cc --- /dev/null +++ b/include/blast/blaze/Math.hpp @@ -0,0 +1,10 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include + +#include diff --git a/include/blast/blaze/math/TypeTraits.hpp b/include/blast/blaze/math/TypeTraits.hpp new file mode 100644 index 00000000..40737815 --- /dev/null +++ b/include/blast/blaze/math/TypeTraits.hpp @@ -0,0 +1,12 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include +#include +#include +#include +#include diff --git a/include/blast/blaze/math/Vector.hpp b/include/blast/blaze/math/Vector.hpp new file mode 100644 index 00000000..452cc7d4 --- /dev/null +++ b/include/blast/blaze/math/Vector.hpp @@ -0,0 +1,38 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + +#include +#include + + +namespace blaze +{ + /** + * @brief Memory distance between consecutive elements of a dense Blaze vector + * + * NOTE: The function is declared in blaze namespace s.t. it can be found by ADL. + * + * @tparam VT vector type + * + * @param v vector + * + * @return memory distance between consecutive elements of @a v + */ + template + requires blaze::IsDenseVector_v + inline size_t spacing(VT const& v) noexcept + { + if constexpr (IsContiguous_v) + return 1; + else + if constexpr (blaze::IsView_v) + return spacing(v.operand()); + else + static_assert(false, "Spacing is not defined for a type which is not a view and is not contiguous"); + } +} diff --git a/include/blast/blaze/math/typetraits/IsContiguous.hpp b/include/blast/blaze/math/typetraits/IsContiguous.hpp new file mode 100644 index 00000000..544b4486 --- /dev/null +++ b/include/blast/blaze/math/typetraits/IsContiguous.hpp @@ -0,0 +1,41 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + +#include +#include +#include +#include + +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze vectors which are not transpose expressions + * + * @tparam T type + */ + template + requires blaze::IsVector_v && (!blaze::IsTransExpr_v) + struct IsContiguous : blaze::IsContiguous {}; + + + /** + * @brief Specialization for Blaze vector transpose expressions + * + * The trasnposed vector expression is contiguous iff its operand is contiguous. + * + * This specialization is required to fix this Blaze bug: https://bitbucket.org/blaze-lib/blaze/issues/474 + * + * @tparam T type + */ + template + requires blaze::IsVector_v && blaze::IsTransExpr_v + struct IsContiguous : IsContiguous>> {}; +} diff --git a/include/blast/blaze/math/typetraits/IsDenseMatrix.hpp b/include/blast/blaze/math/typetraits/IsDenseMatrix.hpp new file mode 100644 index 00000000..e03e6c5a --- /dev/null +++ b/include/blast/blaze/math/typetraits/IsDenseMatrix.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + +#include +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze matrices + * + * @tparam T matrix type + */ + template + requires blaze::IsMatrix_v + struct IsDenseMatrix : blaze::IsDenseMatrix {}; +} diff --git a/include/blast/blaze/math/typetraits/IsDenseVector.hpp b/include/blast/blaze/math/typetraits/IsDenseVector.hpp new file mode 100644 index 00000000..eaeae86e --- /dev/null +++ b/include/blast/blaze/math/typetraits/IsDenseVector.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + +#include +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze vectors + * + * @tparam T vector type + */ + template + requires blaze::IsVector_v + struct IsDenseVector : blaze::IsDenseVector {}; +} diff --git a/include/blast/blaze/math/typetraits/IsStatic.hpp b/include/blast/blaze/math/typetraits/IsStatic.hpp new file mode 100644 index 00000000..3b0031ba --- /dev/null +++ b/include/blast/blaze/math/typetraits/IsStatic.hpp @@ -0,0 +1,24 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + +#include +#include +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze matrix and vector types + * + * @tparam T matrix or vector type + */ + template + requires blaze::IsVector_v || blaze::IsMatrix_v + struct IsStatic : blaze::IsStatic {}; +} diff --git a/include/blast/blaze/math/typetraits/IsStaticallySpaced.hpp b/include/blast/blaze/math/typetraits/IsStaticallySpaced.hpp new file mode 100644 index 00000000..4184ab83 --- /dev/null +++ b/include/blast/blaze/math/typetraits/IsStaticallySpaced.hpp @@ -0,0 +1,44 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include + +#include +#include +#include +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze vectors which are not views + * + * Blaze vectors which are not views are statically spaced iff they are contiguous + * + * @tparam VT vector type + */ + template + requires blaze::IsVector_v && (!blaze::IsView_v) + struct IsStaticallySpaced : IsContiguous {}; + + + /** + * @brief Specialization for Blaze vectors which are views + * + * Blaze vectors which are views are statically spaced iff they are contiguous or their viewed type is static + * + * @tparam VT vector type + */ + template + requires blaze::IsVector_v && blaze::IsView_v + struct IsStaticallySpaced + : std::integral_constant || blaze::IsStatic_v> + > + {}; +} diff --git a/include/blast/blaze/math/typetraits/Spacing.hpp b/include/blast/blaze/math/typetraits/Spacing.hpp new file mode 100644 index 00000000..6ead89fc --- /dev/null +++ b/include/blast/blaze/math/typetraits/Spacing.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include + +#include +#include +#include +#include +#include + +#include + + +namespace blast +{ + /** + * @brief Specialization for Blaze dense matrices which are not transpose expressions + * + * @tparam MT matrix type + */ + template + requires blaze::IsDenseMatrix_v && (!blaze::IsTransExpr_v) + struct Spacing : std::integral_constant {}; + + + /** + * @brief Specialization for Blaze dense matrix transpose expressions + * + * @tparam MT matrix type + */ + template + requires blaze::IsDenseMatrix_v && blaze::IsTransExpr_v + struct Spacing : Spacing>> {}; + + + /** + * @brief Specialization for contiguous dense Blaze vectors + * + * @tparam VT vector type + */ + template + requires blaze::IsDenseVector_v && IsContiguous_v + struct Spacing : std::integral_constant {}; + + + /** + * @brief Specialization for non-contiguous dense Blaze vector views + * + * @tparam VT vector type + */ + template + requires blaze::IsDenseVector_v && (!IsContiguous_v) && blaze::IsView_v + struct Spacing : Spacing> {}; +} diff --git a/include/blast/math/Matrix.hpp b/include/blast/math/Matrix.hpp index 83e87654..7002226d 100644 --- a/include/blast/math/Matrix.hpp +++ b/include/blast/math/Matrix.hpp @@ -4,59 +4,44 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include - namespace blast { - template - inline void randomize(M& m) noexcept - { - - } - - - template - inline bool operator==(MA const& a, MB const& b) noexcept - { - return false; - } - - - template - inline std::ostream& operator<<(std::ostream& os, M const& m) - { - for (size_t i = 0; i < rows(m); ++i) - { - for (size_t j = 0; j < columns(m); ++j) - os << m(i, j) << "\t"; - os << std::endl; - } - - return os; - } - - - template - requires IsStatic_v && IsDenseMatrix_v - BLAST_ALWAYS_INLINE auto ptr(MT& m, size_t i, size_t j) noexcept + /** + * @brief Pointer to the first element of a matrix + * + * @tparam MT matrix type + * + * @param m matrix + * + * @return pointer to @a m(0, 0) + */ + template + BLAST_ALWAYS_INLINE auto ptr(MT& m) { - return StaticMatrixPointer, spacing(m), StorageOrder_v, AF, IsPadded_v>(data(m), i, j); + return ptr>(m, 0, 0); } - template - requires IsStatic_v && IsDenseMatrix_v - BLAST_ALWAYS_INLINE auto ptr(MT const& m, size_t i, size_t j) noexcept + /** + * @brief Pointer to the first element of a const matrix + * + * @tparam MT matrix type + * + * @param m matrix + * + * @return pointer to @a m(0, 0) + */ + template + BLAST_ALWAYS_INLINE auto ptr(MT const& m) { - return StaticMatrixPointer const, spacing(m), StorageOrder_v, AF, IsPadded_v>(data(m), i, j); + return ptr>(m, 0, 0); } } diff --git a/include/blast/math/TypeTraits.hpp b/include/blast/math/TypeTraits.hpp index 0a70f009..bff67adc 100644 --- a/include/blast/math/TypeTraits.hpp +++ b/include/blast/math/TypeTraits.hpp @@ -1,27 +1,22 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. #pragma once #include #include #include +#include +#include #include #include +#include #include +#include #include #include #include #include #include +#include diff --git a/include/blast/math/Vector.hpp b/include/blast/math/Vector.hpp new file mode 100644 index 00000000..f1026b29 --- /dev/null +++ b/include/blast/math/Vector.hpp @@ -0,0 +1,45 @@ +// Copyright 2023-2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include +#include +#include + + +namespace blast +{ + /** + * @brief Pointer to the first element of a vector + * + * @tparam VT vector type + * @param v vector + * + * @return pointer to the first element of @a v + */ + template + requires IsDenseVector_v + BLAST_ALWAYS_INLINE auto ptr(VT& v) + { + return ptr>(v, 0); + } + + + /** + * @brief Pointer to the first element of a const vector + * + * @tparam VT vector type + * @param v vector + * + * @return pointer to the first element of @a v + */ + template + requires IsDenseVector_v + BLAST_ALWAYS_INLINE auto ptr(VT const& v) + { + return ptr>(v, 0); + } +} diff --git a/include/blast/math/dense/DynamicMatrixPointer.hpp b/include/blast/math/dense/DynamicMatrixPointer.hpp index 30c7b4e3..b7651373 100644 --- a/include/blast/math/dense/DynamicMatrixPointer.hpp +++ b/include/blast/math/dense/DynamicMatrixPointer.hpp @@ -4,7 +4,6 @@ #pragma once - #include #include #include @@ -12,8 +11,6 @@ #include #include -#include - namespace blast { @@ -211,45 +208,26 @@ namespace blast } - template - requires (!IsStatic_v) - BLAST_ALWAYS_INLINE DynamicMatrixPointer, SO, AF, IsPadded_v> - ptr(DenseMatrix& m, size_t i, size_t j) + template + requires (!IsStatic_v) && IsDenseMatrix_v + BLAST_ALWAYS_INLINE DynamicMatrixPointer, StorageOrder_v, AF, IsPadded_v> + ptr(MT& m, size_t i, size_t j) { - if constexpr (SO == columnMajor) - return {(*m).data() + i + spacing(m) * j, spacing(m)}; + if constexpr (StorageOrder_v == columnMajor) + return {data(m) + i + spacing(m) * j, spacing(m)}; else - return {(*m).data() + spacing(m) * i + j, spacing(m)}; + return {data(m) + spacing(m) * i + j, spacing(m)}; } - template - requires (!IsStatic_v) - BLAST_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> - ptr(DenseMatrix const& m, size_t i, size_t j) + template + requires (!IsStatic_v) && IsDenseMatrix_v + BLAST_ALWAYS_INLINE DynamicMatrixPointer const, StorageOrder_v, AF, IsPadded_v> + ptr(MT const& m, size_t i, size_t j) { - if constexpr (SO == columnMajor) - return {(*m).data() + i + spacing(m) * j, spacing(m)}; + if constexpr (StorageOrder_v == columnMajor) + return {data(m) + i + spacing(m) * j, spacing(m)}; else - return {(*m).data() + spacing(m) * i + j, spacing(m)}; - } - - - template - requires (!IsStatic_v) - BLAST_ALWAYS_INLINE DynamicMatrixPointer const, SO, AF, IsPadded_v> - ptr(DMatTransExpr const& m, size_t i, size_t j) - { - if constexpr (SO == columnMajor) - return {(*m).data() + i + spacing(m) * j, spacing(m)}; - else - return {(*m).data() + spacing(m) * i + j, spacing(m)}; - } - - - template - BLAST_ALWAYS_INLINE DynamicMatrixPointer ptr(T * p, size_t spacing) - { - return {p, spacing}; + return {data(m) + spacing(m) * i + j, spacing(m)}; } } diff --git a/include/blast/math/dense/DynamicVectorPointer.hpp b/include/blast/math/dense/DynamicVectorPointer.hpp index 7638119a..6843925d 100644 --- a/include/blast/math/dense/DynamicVectorPointer.hpp +++ b/include/blast/math/dense/DynamicVectorPointer.hpp @@ -5,7 +5,9 @@ #pragma once #include +#include #include +#include #include @@ -187,8 +189,50 @@ namespace blast template - BLAZE_ALWAYS_INLINE auto trans(DynamicVectorPointer const& p) noexcept + BLAST_ALWAYS_INLINE auto trans(DynamicVectorPointer const& p) noexcept { return p.trans(); } + + + /** + * @brief Pointer to a dynamically spaced vector + * + * @tparam AF true if the pointer is SIMD-aligned + * @tparam VT vector type + * + * @param v vector + * @param i index within @a v + * + * @return vector pointer to @a i -th element of @a v + */ + template + requires (!IsStaticallySpaced_v) + BLAST_ALWAYS_INLINE auto ptr(VT& v, size_t i) noexcept + { + // NOTE: we don't use data(v) here because of this bug: + // https://bitbucket.org/blaze-lib/blaze/issues/457 + return DynamicVectorPointer, VT::transposeFlag, AF, IsPadded_v> {&v[i], spacing(v)}; + } + + + /** + * @brief Pointer to a dynamically spaced const vector + * + * @tparam AF true if the pointer is SIMD-aligned + * @tparam VT vector type + * + * @param v vector + * @param i index within @a v + * + * @return vector pointer to @a i -th element of @a v + */ + template + requires (!IsStaticallySpaced_v) + BLAST_ALWAYS_INLINE auto ptr(VT const& v, size_t i) noexcept + { + // NOTE: we don't use data(v) here because of this bug: + // https://bitbucket.org/blaze-lib/blaze/issues/457 + return DynamicVectorPointer const, VT::transposeFlag, AF, IsPadded_v> {&v[i], spacing(v)}; + } } diff --git a/include/blast/math/dense/Gemm.hpp b/include/blast/math/dense/Gemm.hpp index a386baee..7c6cc40a 100644 --- a/include/blast/math/dense/Gemm.hpp +++ b/include/blast/math/dense/Gemm.hpp @@ -5,13 +5,9 @@ #pragma once #include -#include +#include #include -#include -#include -#include - namespace blast { @@ -80,4 +76,4 @@ namespace blast using ET = ElementType_t; gemm(ET(1.), A, B, ET(1.), C, D); } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Ger.hpp b/include/blast/math/dense/Ger.hpp index 807412c3..c19557bf 100644 --- a/include/blast/math/dense/Ger.hpp +++ b/include/blast/math/dense/Ger.hpp @@ -1,26 +1,14 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright 2023-2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. #pragma once #include - #include #include -#include -#include -#include +#include +#include namespace blast @@ -57,13 +45,9 @@ namespace blast MatrixPointer && (StorageOrder_v == columnMajor) inline void ger(size_t M, size_t N, Scalar alpha, VPX x, VPY y, MPA A, MPB B) { - using ET = ElementType_t; + using ET = Scalar; size_t constexpr TILE_SIZE = TileSize_v; - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - size_t j = 0; // Main part @@ -182,13 +166,6 @@ namespace blast DenseMatrix& B ) { - using ET = ElementType_t; - size_t constexpr TILE_SIZE = TileSize_v; - - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); - size_t const M = size(x); size_t const N = size(y); @@ -319,4 +296,4 @@ namespace blast { ger(alpha, x, y, A, B); } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Getf2.hpp b/include/blast/math/dense/Getf2.hpp index 73614b01..bd359835 100644 --- a/include/blast/math/dense/Getf2.hpp +++ b/include/blast/math/dense/Getf2.hpp @@ -19,10 +19,7 @@ #include #include #include -#include -#include - -#include +#include namespace blast @@ -106,7 +103,7 @@ namespace blast template inline void getf2(DenseMatrix& A, size_t * ipiv) { - getf2(rows(*A), columns(*A), ptr(A), ipiv); + getf2(rows(*A), columns(*A), ptr(*A), ipiv); } @@ -165,4 +162,4 @@ namespace blast ); } } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Getrf.hpp b/include/blast/math/dense/Getrf.hpp index cc94faa0..543a3ae5 100644 --- a/include/blast/math/dense/Getrf.hpp +++ b/include/blast/math/dense/Getrf.hpp @@ -57,7 +57,7 @@ namespace blast size_t const M = rows(A); size_t const N = columns(A); - auto pA = ptr(A); + auto pA = ptr(*A); size_t k = 0; @@ -160,4 +160,4 @@ namespace blast ipiv[k] = k; } } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Iamax.hpp b/include/blast/math/dense/Iamax.hpp index 530df07b..16e2e464 100644 --- a/include/blast/math/dense/Iamax.hpp +++ b/include/blast/math/dense/Iamax.hpp @@ -16,7 +16,8 @@ #include -#include +#include +#include #include #include diff --git a/include/blast/math/dense/Laswp.hpp b/include/blast/math/dense/Laswp.hpp index f363e756..844ec02a 100644 --- a/include/blast/math/dense/Laswp.hpp +++ b/include/blast/math/dense/Laswp.hpp @@ -14,9 +14,10 @@ #pragma once - #include +#include + namespace blast { @@ -34,10 +35,10 @@ namespace blast @a k0 ... @a k1 - 1 of @a ipiv are accessed. ipiv[k] = l implies rows k and l are to be interchanged. */ template - inline void laswp(DenseMatrix& A, size_t k0, size_t k1, size_t * ipiv) + inline void laswp(blaze::DenseMatrix& A, size_t k0, size_t k1, size_t * ipiv) { for (size_t k = k0; k < k1; ++k) if (k != ipiv[k]) - swap(row(*A, k, unchecked), row(*A, ipiv[k], unchecked)); + swap(row(*A, k, blaze::unchecked), row(*A, ipiv[k], blaze::unchecked)); } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/MatrixPointer.hpp b/include/blast/math/dense/MatrixPointer.hpp deleted file mode 100644 index 06372ed9..00000000 --- a/include/blast/math/dense/MatrixPointer.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include - -#include -#include - - -namespace blast -{ - template - BLAZE_ALWAYS_INLINE auto ptr(blaze::DenseMatrix& m) - { - return ptr>(m, 0, 0); - } - - - template - BLAZE_ALWAYS_INLINE auto ptr(blaze::DenseMatrix const& m) - { - return ptr>(m, 0, 0); - } - - - template - BLAZE_ALWAYS_INLINE auto ptr(blaze::DMatTransExpr const& m) - { - return ptr>(m, 0, 0); - } -} \ No newline at end of file diff --git a/include/blast/math/dense/Potrf.hpp b/include/blast/math/dense/Potrf.hpp index 50cfd56d..3b1e1e02 100644 --- a/include/blast/math/dense/Potrf.hpp +++ b/include/blast/math/dense/Potrf.hpp @@ -5,27 +5,23 @@ #pragma once -#include +#include #include #include #include -#include -#include +#include #include namespace blast { - using namespace blaze; - - template BLAZE_ALWAYS_INLINE void potrf_backend(size_t k, size_t i, - DenseMatrix const& A, DenseMatrix& L) + blaze::DenseMatrix const& A, blaze::DenseMatrix& L) { - using ET = ElementType_t; + using ET = blaze::ElementType_t; size_t constexpr TILE_SIZE = TileSize_v; size_t const M = rows(A); @@ -36,10 +32,10 @@ namespace blast RegisterMatrix ker; - ker.load(1., ptr(A, i, k)); + ker.load(1., ptr(*A, i, k)); - auto a = ptr(L, i, 0); - auto b = ptr(L, k, 0); + auto a = ptr(*L, i, 0); + auto b = ptr(*L, k, 0); for (size_t l = 0; l < k; ++l) ker.ger(ET(-1.), column(a(0, l)), row(trans(b)(l, 0))); @@ -50,31 +46,31 @@ namespace blast ker.potrf(); if (k + KN <= N) - ker.storeLower(ptr(L, i, k)); + ker.storeLower(ptr(*L, i, k)); else - ker.storeLower(ptr(L, i, k), std::min(M - i, KM), N - k); + ker.storeLower(ptr(*L, i, k), std::min(M - i, KM), N - k); } else { // Off-diagonal blocks - ker.trsm(Side::Right, UpLo::Upper, ptr(L, k, k).trans()); + ker.trsm(Side::Right, UpLo::Upper, ptr(*L, k, k).trans()); if (k + KN <= N) - ker.store(ptr(L, i, k)); + ker.store(ptr(*L, i, k)); else - ker.store(ptr(L, i, k), std::min(M - i, KM), N - k); + ker.store(ptr(*L, i, k), std::min(M - i, KM), N - k); } } template inline void potrf( - DenseMatrix const& A, DenseMatrix& L) + blaze::DenseMatrix const& A, blaze::DenseMatrix& L) { - using ET = ElementType_t; + using ET = blaze::ElementType_t; size_t constexpr TILE_SIZE = TileSize_v; - BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(ElementType_t, ET); + BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(blaze::ElementType_t, ET); size_t const M = rows(A); size_t const N = columns(A); @@ -108,4 +104,4 @@ namespace blast potrf_backend<1 * TILE_SIZE, KN>(k, i, *A, *L); } } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/StaticMatrixPointer.hpp b/include/blast/math/dense/StaticMatrixPointer.hpp index 961b5e01..bb70c091 100644 --- a/include/blast/math/dense/StaticMatrixPointer.hpp +++ b/include/blast/math/dense/StaticMatrixPointer.hpp @@ -12,10 +12,6 @@ #include #include -#include -#include -#include - namespace blast { @@ -203,26 +199,18 @@ namespace blast } - template - requires IsStatic_v - BLAZE_ALWAYS_INLINE auto ptr(blaze::DenseMatrix& m, size_t i, size_t j) - { - return StaticMatrixPointer, MT::spacing(), SO, AF, IsPadded_v>((*m).data(), i, j); - } - - - template - requires IsStatic_v - BLAZE_ALWAYS_INLINE auto ptr(blaze::DenseMatrix const& m, size_t i, size_t j) + template + requires IsStatic_v && IsDenseMatrix_v + BLAZE_ALWAYS_INLINE auto ptr(MT& m, size_t i, size_t j) { - return StaticMatrixPointer const, MT::spacing(), SO, AF, IsPadded_v>((*m).data(), i, j); + return StaticMatrixPointer, Spacing_v, StorageOrder_v, AF, IsPadded_v>(data(m), i, j); } - template - requires IsStatic_v - BLAZE_ALWAYS_INLINE auto ptr(blaze::DMatTransExpr const& m, size_t i, size_t j) + template + requires IsStatic_v && IsDenseMatrix_v + BLAZE_ALWAYS_INLINE auto ptr(MT const& m, size_t i, size_t j) { - return trans(ptr(m.operand(), j, i)); + return StaticMatrixPointer const, Spacing_v, StorageOrder_v, AF, IsPadded_v>(data(m), i, j); } } diff --git a/include/blast/math/dense/StaticVectorPointer.hpp b/include/blast/math/dense/StaticVectorPointer.hpp index 6017dafa..6f7a0e2e 100644 --- a/include/blast/math/dense/StaticVectorPointer.hpp +++ b/include/blast/math/dense/StaticVectorPointer.hpp @@ -6,6 +6,7 @@ #include +#include #include @@ -213,4 +214,46 @@ namespace blast { return p.trans(); } + + + /** + * @brief Pointer to a statically spaced vector + * + * @tparam AF true if the pointer is SIMD-aligned + * @tparam VT vector type + * + * @param v vector + * @param i index within @a v + * + * @return vector pointer to @a i -th element of @a v + */ + template + requires IsStaticallySpaced_v + BLAST_ALWAYS_INLINE auto ptr(VT& v, size_t i) + { + // NOTE: we don't use data(v) here because of this bug: + // https://bitbucket.org/blaze-lib/blaze/issues/457 + return StaticVectorPointer, Spacing_v, VT::transposeFlag, AF, IsPadded_v> {&v[i]}; + } + + + /** + * @brief Pointer to a statically spaced const vector + * + * @tparam AF true if the pointer is SIMD-aligned + * @tparam VT vector type + * + * @param v vector + * @param i index within @a v + * + * @return vector pointer to @a i -th element of @a v + */ + template + requires IsStaticallySpaced_v + BLAST_ALWAYS_INLINE auto ptr(VT const& v, size_t i) + { + // NOTE: we don't use data(v) here because of this bug: + // https://bitbucket.org/blaze-lib/blaze/issues/457 + return StaticVectorPointer const, Spacing_v, VT::transposeFlag, AF, IsPadded_v> {&v[i]}; + } } diff --git a/include/blast/math/dense/Swap.hpp b/include/blast/math/dense/Swap.hpp index d192e9fe..cf574c59 100644 --- a/include/blast/math/dense/Swap.hpp +++ b/include/blast/math/dense/Swap.hpp @@ -15,8 +15,7 @@ #pragma once #include - -#include +#include #include @@ -69,4 +68,4 @@ namespace blast if (N > 0) swap(N, ptr(*x), ptr(*y)); } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Syrk.hpp b/include/blast/math/dense/Syrk.hpp index 182789eb..a39d47f3 100644 --- a/include/blast/math/dense/Syrk.hpp +++ b/include/blast/math/dense/Syrk.hpp @@ -7,10 +7,7 @@ #include #include #include - -#include -#include -#include +#include namespace blast @@ -48,46 +45,46 @@ namespace blast for (; i + 3 * TILE_SIZE <= M && i + 4 * TILE_SIZE != M; i += 3 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j)); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0))); + ker.load(beta, ptr(*C, i, j)); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0))); if (i == j) - ker.storeLower(ptr(D, i, j)); + ker.storeLower(ptr(*D, i, j)); else - ker.store(ptr(D, i, j)); + ker.store(ptr(*D, i, j)); } for (; i + 2 * TILE_SIZE <= M; i += 2 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j)); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0))); + ker.load(beta, ptr(*C, i, j)); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0))); if (i == j) - ker.storeLower(ptr(D, i, j)); + ker.storeLower(ptr(*D, i, j)); else - ker.store(ptr(D, i, j)); + ker.store(ptr(*D, i, j)); } for (; i + 1 * TILE_SIZE <= M; i += 1 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j)); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0))); + ker.load(beta, ptr(*C, i, j)); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0))); if (i == j) - ker.storeLower(ptr(D, i, j)); + ker.storeLower(ptr(*D, i, j)); else - ker.store(ptr(D, i, j)); + ker.store(ptr(*D, i, j)); } // Bottom side if (i < M) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j), M - i, ker.columns()); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0)), M - i, ker.columns()); + ker.load(beta, ptr(*C, i, j), M - i, ker.columns()); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0)), M - i, ker.columns()); if (i == j) - ker.storeLower(ptr(D, i, j), M - i, ker.columns()); + ker.storeLower(ptr(*D, i, j), M - i, ker.columns()); else - ker.store(ptr(D, i, j), M - i, ker.columns()); + ker.store(ptr(*D, i, j), M - i, ker.columns()); } } @@ -102,48 +99,48 @@ namespace blast for (; i + 3 * TILE_SIZE <= M && i + 4 * TILE_SIZE != M; i += 3 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j), ker.rows(), M - j); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0)), ker.rows(), M - j); + ker.load(beta, ptr(*C, i, j), ker.rows(), M - j); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0)), ker.rows(), M - j); if (i == j) - ker.storeLower(ptr(D, i, j), ker.rows(), M - j); + ker.storeLower(ptr(*D, i, j), ker.rows(), M - j); else - ker.store(ptr(D, i, j), ker.rows(), M - j); + ker.store(ptr(*D, i, j), ker.rows(), M - j); } for (; i + 2 * TILE_SIZE <= M; i += 2 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j), ker.rows(), M - j); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0)), ker.rows(), M - j); + ker.load(beta, ptr(*C, i, j), ker.rows(), M - j); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0)), ker.rows(), M - j); if (i == j) - ker.storeLower(ptr(D, i, j), ker.rows(), M - j); + ker.storeLower(ptr(*D, i, j), ker.rows(), M - j); else - ker.store(ptr(D, i, j), ker.rows(), M - j); + ker.store(ptr(*D, i, j), ker.rows(), M - j); } for (; i + 1 * TILE_SIZE <= M; i += 1 * TILE_SIZE) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j), ker.rows(), M - j); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0)), ker.rows(), M - j); + ker.load(beta, ptr(*C, i, j), ker.rows(), M - j); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0)), ker.rows(), M - j); if (i == j) - ker.storeLower(ptr(D, i, j), ker.rows(), M - j); + ker.storeLower(ptr(*D, i, j), ker.rows(), M - j); else - ker.store(ptr(D, i, j), ker.rows(), M - j); + ker.store(ptr(*D, i, j), ker.rows(), M - j); } // Bottom-right corner if (i < M) { RegisterMatrix ker; - ker.load(beta, ptr(C, i, j), ker.rows(), M - j); - gemm(ker, K, alpha, ptr(A, i, 0), trans(ptr(A, j, 0)), M - i, M - j); + ker.load(beta, ptr(*C, i, j), ker.rows(), M - j); + gemm(ker, K, alpha, ptr(*A, i, 0), trans(ptr(*A, j, 0)), M - i, M - j); if (i == j) - ker.storeLower(ptr(D, i, j), M - i, M - j); + ker.storeLower(ptr(*D, i, j), M - i, M - j); else - ker.store(ptr(D, i, j), M - i, M - j); + ker.store(ptr(*D, i, j), M - i, M - j); } } } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/Trmm.hpp b/include/blast/math/dense/Trmm.hpp index 041159e0..34dc7c4f 100644 --- a/include/blast/math/dense/Trmm.hpp +++ b/include/blast/math/dense/Trmm.hpp @@ -44,15 +44,15 @@ namespace blast // it is more efficient to apply 2 * TILE_SIZE kernel 2 times than 3 * TILE_SIZE + 1 * TILE_SIZE kernel. for (; i + 2 * TILE_SIZE < M && i + 4 * TILE_SIZE != M; i += 3 * TILE_SIZE) trmmLeftUpper_backend<3 * TILE_SIZE, TILE_SIZE>( - M - i, N, alpha, ptr(A, i, i), ptr(B, i, 0), ptr(C, i, 0)); + M - i, N, alpha, ptr(*A, i, i), ptr(*B, i, 0), ptr(*C, i, 0)); for (; i + 1 * TILE_SIZE < M; i += 2 * TILE_SIZE) trmmLeftUpper_backend<2 * TILE_SIZE, TILE_SIZE>( - M - i, N, alpha, ptr(A, i, i), ptr(B, i, 0), ptr(C, i, 0)); + M - i, N, alpha, ptr(*A, i, i), ptr(*B, i, 0), ptr(*C, i, 0)); for (; i + 0 * TILE_SIZE < M; i += 1 * TILE_SIZE) trmmLeftUpper_backend<1 * TILE_SIZE, TILE_SIZE>( - M - i, N, alpha, ptr(A, i, i), ptr(B, i, 0), ptr(C, i, 0)); + M - i, N, alpha, ptr(*A, i, i), ptr(*B, i, 0), ptr(*C, i, 0)); } @@ -92,46 +92,46 @@ namespace blast for (; i + 3 * TILE_SIZE <= M && i + 4 * TILE_SIZE != M; i += 3 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j)); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j)); /* ker.trmmRightLower(alpha, ptr(B, i, j), ptr(A, j, j)); ker.gemm(K, alpha, ptr(B, i, j + TILE_SIZE), ptr(A, j + TILE_SIZE, j)); */ - ker.store(ptr(C, i, j)); + ker.store(ptr(*C, i, j)); } for (; i + 2 * TILE_SIZE <= M; i += 2 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j)); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j)); /* ker.trmmRightLower(alpha, ptr(B, i, j), ptr(A, j, j)); ker.gemm(K, alpha, ptr(B, i, j + TILE_SIZE), ptr(A, j + TILE_SIZE, j)); */ - ker.store(ptr(C, i, j)); + ker.store(ptr(*C, i, j)); } for (; i + 1 * TILE_SIZE <= M; i += 1 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j)); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j)); /* ker.trmmRightLower(alpha, ptr(B, i, j), ptr(A, j, j)); ker.gemm(K, alpha, ptr(B, i, j + TILE_SIZE), ptr(A, j + TILE_SIZE, j)); */ - ker.store(ptr(C, i, j)); + ker.store(ptr(*C, i, j)); } // Bottom side if (i < M) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j), M - i, ker.columns()); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j), M - i, ker.columns()); /* ker.trmmRightLower(alpha, ptr(B, i, j), ptr(A, j, j)); ker.gemm(K, alpha, ptr(B, i, j + TILE_SIZE), ptr(A, j + TILE_SIZE, j), M - i, ker.columns()); */ - ker.store(ptr(C, i, j), M - i, ker.columns()); + ker.store(ptr(*C, i, j), M - i, ker.columns()); } } @@ -146,31 +146,31 @@ namespace blast for (; i + 3 * TILE_SIZE <= M && i + 4 * TILE_SIZE != M; i += 3 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j), ker.rows(), N - j); - ker.store(ptr(C, i, j), ker.rows(), N - j); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j), ker.rows(), N - j); + ker.store(ptr(*C, i, j), ker.rows(), N - j); } for (; i + 2 * TILE_SIZE <= M; i += 2 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j), ker.rows(), N - j); - ker.store(ptr(C, i, j), ker.rows(), N - j); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j), ker.rows(), N - j); + ker.store(ptr(*C, i, j), ker.rows(), N - j); } for (; i + 1 * TILE_SIZE <= M; i += 1 * TILE_SIZE) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j), ker.rows(), N - j); - ker.store(ptr(C, i, j), ker.rows(), N - j); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j), ker.rows(), N - j); + ker.store(ptr(*C, i, j), ker.rows(), N - j); } // Bottom-right corner if (i < M) { RegisterMatrix ker; - gemm(ker, N - j, alpha, ptr(B, i, j), ptr(A, j, j), M - i, N - j); - ker.store(ptr(C, i, j), M - i, N - j); + gemm(ker, N - j, alpha, ptr(*B, i, j), ptr(*A, j, j), M - i, N - j); + ker.store(ptr(*C, i, j), M - i, N - j); } } } -} \ No newline at end of file +} diff --git a/include/blast/math/dense/VectorPointer.hpp b/include/blast/math/dense/VectorPointer.hpp deleted file mode 100644 index 39a4538e..00000000 --- a/include/blast/math/dense/VectorPointer.hpp +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - -namespace blast -{ - /* - ======================================================================================= - - Pointer to static dense vector. - - ======================================================================================= - */ - - template - BLAZE_ALWAYS_INLINE auto ptr(StaticVector& v, size_t i) - { - return StaticVectorPointer {v.data() + i}; - } - - - template - BLAZE_ALWAYS_INLINE auto ptr(StaticVector const& v, size_t i) - { - return StaticVectorPointer {v.data() + i}; - } - - - /* - ======================================================================================= - - Pointer to dynamic dense vector. - - ======================================================================================= - */ - - template - BLAZE_ALWAYS_INLINE auto ptr(DynamicVector& v, size_t i) - { - using VT = DynamicVector; - return StaticVectorPointer> {v.data() + i}; - } - - - template - BLAZE_ALWAYS_INLINE auto ptr(DynamicVector const& v, size_t i) - { - using VT = DynamicVector; - return StaticVectorPointer> {v.data() + i}; - } - - - /* - ======================================================================================= - - Pointer to vector transpose expression. - - ======================================================================================= - */ - - template - requires IsDenseVector_v && IsTransExpr_v - BLAZE_ALWAYS_INLINE auto ptr(VT& v, size_t i) noexcept - { - return trans(ptr(v.operand(), i)); - } - - - template - requires IsDenseVector_v && IsTransExpr_v - BLAZE_ALWAYS_INLINE auto ptr(VT const& v, size_t i) noexcept - { - return trans(ptr(v.operand(), i)); - } - - - /* - ======================================================================================= - - Pointer to row of a matrix. - - ======================================================================================= - */ - - template - requires IsDenseVector_v && IsRow_v - BLAZE_ALWAYS_INLINE auto ptr(VT& v, size_t i) noexcept - { - using MT = ViewedType_t; - using ET = ElementType_t; - - if constexpr (IsRowMajorMatrix_v) - { - return StaticVectorPointer> {&(*v)[i]}; - } - else - { - if constexpr (IsStatic_v) - return StaticVectorPointer> {&(*v)[i]}; - else - return DynamicVectorPointer> {&(*v)[i], v.operand().spacing()}; - } - } - - - template - requires IsDenseVector_v && IsRow_v - BLAZE_ALWAYS_INLINE auto ptr(VT const& v, size_t i) noexcept - { - using MT = ViewedType_t; - using ET = ElementType_t; - - if constexpr (IsRowMajorMatrix_v) - { - return StaticVectorPointer> {&(*v)[i]}; - } - else - { - if constexpr (IsStatic_v) - return StaticVectorPointer> {&(*v)[i]}; - else - return DynamicVectorPointer> {&(*v)[i], v.operand().spacing()}; - } - } - - - /* - ======================================================================================= - - Pointer to column of a matrix. - - ======================================================================================= - */ - - template - requires IsDenseVector_v && IsColumn_v - BLAZE_ALWAYS_INLINE auto ptr(VT& v, size_t i) noexcept - { - using MT = ViewedType_t; - using ET = ElementType_t; - - if constexpr (IsColumnMajorMatrix_v) - { - return StaticVectorPointer> {&(*v)[i]}; - } - else - { - if constexpr (IsStatic_v) - return StaticVectorPointer> {&(*v)[i]}; - else - return DynamicVectorPointer> {&(*v)[i], v.operand().spacing()}; - } - } - - - template - requires IsDenseVector_v && IsColumn_v - BLAZE_ALWAYS_INLINE auto ptr(VT const& v, size_t i) noexcept - { - using MT = ViewedType_t; - using ET = ElementType_t; - - if constexpr (IsColumnMajorMatrix_v) - { - return StaticVectorPointer> {&(*v)[i]}; - } - else - { - if constexpr (IsStatic_v) - return StaticVectorPointer> {&(*v)[i]}; - else - return DynamicVectorPointer> {&(*v)[i], v.operand().spacing()}; - } - } - - - /* - ======================================================================================= - - Pointer to a subvector. - - ======================================================================================= - */ - - template - requires IsDenseVector_v && IsSubvector_v - BLAZE_ALWAYS_INLINE auto ptr(VT& v, size_t i) noexcept - { - return ptr(v.operand(), v.offset() + i); - } - - - template - requires IsDenseVector_v && IsSubvector_v - BLAZE_ALWAYS_INLINE auto ptr(VT const& v, size_t i) noexcept - { - return ptr(v.operand(), v.offset() + i); - } - - - /* - ======================================================================================= - - Pointer to general dense vector. - - ======================================================================================= - */ - template - requires IsDenseVector_v - BLAZE_ALWAYS_INLINE auto ptr(VT& v) - { - return ptr>(v, 0); - } - - - template - requires IsDenseVector_v - BLAZE_ALWAYS_INLINE auto ptr(VT const& v) - { - return ptr>(v, 0); - } -} \ No newline at end of file diff --git a/include/blast/math/expressions/PMatTransExpr.hpp b/include/blast/math/expressions/PMatTransExpr.hpp index 3098741a..ad5b262c 100644 --- a/include/blast/math/expressions/PMatTransExpr.hpp +++ b/include/blast/math/expressions/PMatTransExpr.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -32,6 +33,8 @@ #include #include +#include + namespace blast { @@ -234,4 +237,22 @@ namespace blast using ReturnType = const PMatTransExpr; return ReturnType(*pm); } + + + template + struct IsPanelMatrix> : std::true_type {}; + + + template + struct IsStatic> : IsStatic {}; + + + /** + * @brief Specialization for @a PMatTransExpr + * + * @tparam expression operand type + * @tparam SO storage order + */ + template + struct Spacing> : Spacing {}; } diff --git a/include/blast/math/expressions/PanelMatrix.hpp b/include/blast/math/expressions/PanelMatrix.hpp index 80de78cf..50d12268 100644 --- a/include/blast/math/expressions/PanelMatrix.hpp +++ b/include/blast/math/expressions/PanelMatrix.hpp @@ -10,14 +10,9 @@ #include #include #include -#include -#include - -#include -#include -#include -#include -#include +#include + +#include namespace blast diff --git a/include/blast/math/panel/DynamicPanelMatrixPointer.hpp b/include/blast/math/panel/DynamicPanelMatrixPointer.hpp index 13d23cec..f58dcabf 100644 --- a/include/blast/math/panel/DynamicPanelMatrixPointer.hpp +++ b/include/blast/math/panel/DynamicPanelMatrixPointer.hpp @@ -8,12 +8,8 @@ #include #include #include -#include -#include #include -#include - namespace blast { @@ -252,26 +248,18 @@ namespace blast } - template - requires (!IsStatic_v) - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix& m, size_t i, size_t j) - { - return DynamicPanelMatrixPointer, SO, AF, IsPadded_v>((*m).data(), spacing(m), i, j); - } - - - template - requires (!IsStatic_v) - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix const& m, size_t i, size_t j) + template + requires (!IsStatic_v) && IsPanelMatrix_v + BLAZE_ALWAYS_INLINE auto ptr(MT& m, size_t i, size_t j) { - return DynamicPanelMatrixPointer const, SO, AF, IsPadded_v>((*m).data(), spacing(m), i, j); + return DynamicPanelMatrixPointer, StorageOrder_v, AF, IsPadded_v>(data(m), spacing(m), i, j); } - template + template requires (!IsStatic_v) && IsPanelMatrix_v - BLAZE_ALWAYS_INLINE auto ptr(PMatTransExpr const& m, size_t i, size_t j) + BLAZE_ALWAYS_INLINE auto ptr(MT const& m, size_t i, size_t j) { - return trans(ptr(m.operand(), j, i)); + return DynamicPanelMatrixPointer const, StorageOrder_v, AF, IsPadded_v>(data(m), spacing(m), i, j); } } diff --git a/include/blast/math/panel/Gemm.hpp b/include/blast/math/panel/Gemm.hpp index aaeb9231..531c2801 100644 --- a/include/blast/math/panel/Gemm.hpp +++ b/include/blast/math/panel/Gemm.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include #include diff --git a/include/blast/math/panel/MatrixPointer.hpp b/include/blast/math/panel/MatrixPointer.hpp deleted file mode 100644 index 6caca766..00000000 --- a/include/blast/math/panel/MatrixPointer.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include -#include -#include - - -namespace blast -{ - template - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix& m) - { - return ptr>(*m, 0, 0); - } - - - template - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix const& m) - { - return ptr>(*m, 0, 0); - } - - - template - requires IsPanelMatrix_v - BLAZE_ALWAYS_INLINE auto ptr(blaze::DMatTransExpr const& m) - { - return ptr>(*m, 0, 0); - } -} diff --git a/include/blast/math/panel/StaticPanelMatrix.hpp b/include/blast/math/panel/StaticPanelMatrix.hpp index 585b6f6b..82358689 100644 --- a/include/blast/math/panel/StaticPanelMatrix.hpp +++ b/include/blast/math/panel/StaticPanelMatrix.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,7 @@ #include #include +#include namespace blast @@ -223,6 +225,18 @@ namespace blast return *this; } + + + /** + * @brief Specialization for @a StaticPanelMatrix + * + * @tparam Type element type + * @tparam M number of rows + * @tparam N number of columns + * @tparam SO storage order + */ + template + struct Spacing> : std::integral_constant::spacing()> {}; } namespace blaze diff --git a/include/blast/math/panel/StaticPanelMatrixPointer.hpp b/include/blast/math/panel/StaticPanelMatrixPointer.hpp index 85f3d1ba..da10f069 100644 --- a/include/blast/math/panel/StaticPanelMatrixPointer.hpp +++ b/include/blast/math/panel/StaticPanelMatrixPointer.hpp @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include @@ -244,26 +242,18 @@ namespace blast } - template - requires IsStatic_v - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix& m, size_t i, size_t j) - { - return StaticPanelMatrixPointer, MT::spacing(), SO, AF, IsPadded_v>((*m).data(), i, j); - } - - - template - requires IsStatic_v - BLAZE_ALWAYS_INLINE auto ptr(PanelMatrix const& m, size_t i, size_t j) + template + requires IsStatic_v && IsPanelMatrix_v + BLAZE_ALWAYS_INLINE auto ptr(MT& m, size_t i, size_t j) { - return StaticPanelMatrixPointer const, MT::spacing(), SO, AF, IsPadded_v>((*m).data(), i, j); + return StaticPanelMatrixPointer, Spacing_v, StorageOrder_v, AF, IsPadded_v>(data(m), i, j); } - template + template requires IsStatic_v && IsPanelMatrix_v - BLAZE_ALWAYS_INLINE auto ptr(PMatTransExpr const& m, size_t i, size_t j) + BLAZE_ALWAYS_INLINE auto ptr(MT const& m, size_t i, size_t j) { - return trans(ptr(m.operand(), j, i)); + return StaticPanelMatrixPointer const, Spacing_v, StorageOrder_v, AF, IsPadded_v>(data(m), i, j); } } diff --git a/include/blast/math/typetraits/IsContiguous.hpp b/include/blast/math/typetraits/IsContiguous.hpp new file mode 100644 index 00000000..5a978b7b --- /dev/null +++ b/include/blast/math/typetraits/IsContiguous.hpp @@ -0,0 +1,26 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + + +namespace blast +{ + /** + * @brief Tests whether the elements of a given data type lie contiguous in memory + * + * @tparam T data type + */ + template + struct IsContiguous; + + + /** + * @brief Shortcut for @a IsContiguous::value + * + * @tparam T data type + */ + template + bool constexpr IsContiguous_v = IsContiguous::value; +} diff --git a/include/blast/math/typetraits/IsDenseMatrix.hpp b/include/blast/math/typetraits/IsDenseMatrix.hpp index 2cf5384e..0709f0f8 100644 --- a/include/blast/math/typetraits/IsDenseMatrix.hpp +++ b/include/blast/math/typetraits/IsDenseMatrix.hpp @@ -1,16 +1,27 @@ // Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. + #pragma once #include - namespace blast { + /** + * @brief Tests if the given data type is a dense matrix with column- or row-major storage + * + * @tparam T data type + */ template struct IsDenseMatrix : std::false_type {}; + + /** + * @brief Shortcut for @a IsDenseMatrix::value + * + * @tparam T data type + */ template bool constexpr IsDenseMatrix_v = IsDenseMatrix::value; } diff --git a/include/blast/math/typetraits/IsDenseVector.hpp b/include/blast/math/typetraits/IsDenseVector.hpp new file mode 100644 index 00000000..ae0df964 --- /dev/null +++ b/include/blast/math/typetraits/IsDenseVector.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + + +namespace blast +{ + /** + * @brief Tests if the given data type is a vector with dense storage + * + * @tparam T data type + */ + template + struct IsDenseVector : std::false_type {}; + + + /** + * @brief Shortcut for @a IsDenseVector::value + * + * @tparam T data type + */ + template + bool constexpr IsDenseVector_v = IsDenseVector::value; +} diff --git a/include/blast/math/typetraits/IsStatic.hpp b/include/blast/math/typetraits/IsStatic.hpp index ba3f98a9..a6bb784b 100644 --- a/include/blast/math/typetraits/IsStatic.hpp +++ b/include/blast/math/typetraits/IsStatic.hpp @@ -1,28 +1,26 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. #pragma once -#include - namespace blast { + /** + * @brief Tests if dimensions of the given matrix or vector type are known at compile-time. + * + * @tparam T matrix or vector type + */ template - struct IsStatic : blaze::IsStatic {}; + struct IsStatic; + /** + * @brief Shortcut for @a IsStatic::value + * + * @tparam T matrix or vector type + */ template bool constexpr IsStatic_v = IsStatic::value; } diff --git a/include/blast/math/typetraits/IsStaticallySpaced.hpp b/include/blast/math/typetraits/IsStaticallySpaced.hpp new file mode 100644 index 00000000..97abccc7 --- /dev/null +++ b/include/blast/math/typetraits/IsStaticallySpaced.hpp @@ -0,0 +1,27 @@ +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + + +namespace blast +{ + /** + * @brief Tests if the given vector data type has spacing between elements + * which is known at compile-time. + * + * @tparam VT vector data type + */ + template + struct IsStaticallySpaced; + + + /** + * @brief Shortcut for @a IsStaticallySpaced::value + * + * @tparam VT vector data type + */ + template + bool constexpr IsStaticallySpaced_v = IsStaticallySpaced::value; +} diff --git a/include/blast/math/typetraits/Matrix.hpp b/include/blast/math/typetraits/Matrix.hpp index c1af9537..e263b625 100644 --- a/include/blast/math/typetraits/Matrix.hpp +++ b/include/blast/math/typetraits/Matrix.hpp @@ -10,14 +10,20 @@ namespace blast { + /** + * @brief Matrix concept + * + * @tparam M matrix type + * @tparam T element type + */ template > concept Matrix = requires(M m, T v, T * p, size_t i, size_t j) { m; - m(i, j) = v; + // m(i, j) = v; v = m(i, j); i = rows(m); j = columns(m); - p = data(m); + // p = data(m); }; } diff --git a/include/blast/math/typetraits/Spacing.hpp b/include/blast/math/typetraits/Spacing.hpp new file mode 100644 index 00000000..118da285 --- /dev/null +++ b/include/blast/math/typetraits/Spacing.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include + + +namespace blast +{ + /** + * @brief Deduces memory spacing of the given data type if it is known at compile-time + * - for row-major matrices, deduced to the memory distance between rows + * - for column-major matrices, deduced to the memory distance between columns + * - for panel-major matrices, deduced to memory distance between panels + * - for vectors, deduced to memory distance between consecutive elements + * + * @tparam T data type + */ + template + struct Spacing; + + + /** + * @brief Shortcut for @a Spacing::value + * + * @tparam MT matrix type + */ + template + size_t constexpr Spacing_v = Spacing::value; +} diff --git a/include/blast/math/typetraits/Vector.hpp b/include/blast/math/typetraits/Vector.hpp new file mode 100644 index 00000000..1ebbff20 --- /dev/null +++ b/include/blast/math/typetraits/Vector.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2019-2023 Mikhail Katliar All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#pragma once + +#include +#include + + +namespace blast +{ + /** + * @brief Vector concept + * + * @tparam V vector type + * @tparam T element type + */ + template > + concept Vector = requires(V v, T a, T * p, size_t i) + { + v; + // v[i] = a; + a = v[i]; + i = size(v); + // i = spacing(v); + p = data(v); + }; +} diff --git a/test/blast/math/dense/DynamicVectorPointerTest.cpp b/test/blast/math/dense/DynamicVectorPointerTest.cpp index de9d27db..4ce95ca0 100644 --- a/test/blast/math/dense/DynamicVectorPointerTest.cpp +++ b/test/blast/math/dense/DynamicVectorPointerTest.cpp @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include +#include +#include #include @@ -210,4 +211,21 @@ namespace blast :: testing { this->template testMatrixColumnSubvectorImpl(); } -} \ No newline at end of file + + + TEST(DynamicVectorPointerTest, testSpacing) + { + blaze::DynamicVector dv(10); + ASSERT_EQ(spacing(dv), 1); + + blaze::StaticVector sv; + ASSERT_EQ(spacing(sv), 1); + } + + + TEST(DynamicVectorPointerTest, testStaticallySpaced) + { + ASSERT_TRUE((IsStaticallySpaced_v>)); + ASSERT_TRUE((IsStaticallySpaced_v>)); + } +} diff --git a/test/blast/math/dense/GemmTest.cpp b/test/blast/math/dense/GemmTest.cpp index e19eaca7..82a8b318 100644 --- a/test/blast/math/dense/GemmTest.cpp +++ b/test/blast/math/dense/GemmTest.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace blast :: testing @@ -121,4 +121,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DenseGemmTest, double); -} \ No newline at end of file +} diff --git a/test/blast/math/dense/GerTest.cpp b/test/blast/math/dense/GerTest.cpp index 70576ef1..cbf84913 100644 --- a/test/blast/math/dense/GerTest.cpp +++ b/test/blast/math/dense/GerTest.cpp @@ -6,8 +6,8 @@ #define BLAST_USER_ASSERTION 1 #include - - +#include +#include #include #include @@ -64,4 +64,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DenseGerTest, double); -} \ No newline at end of file +} diff --git a/test/blast/math/dense/Getf2Test.cpp b/test/blast/math/dense/Getf2Test.cpp index f9d98802..9f725701 100644 --- a/test/blast/math/dense/Getf2Test.cpp +++ b/test/blast/math/dense/Getf2Test.cpp @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - #include #include +#include #include #include diff --git a/test/blast/math/dense/GetrfTest.cpp b/test/blast/math/dense/GetrfTest.cpp index 652dc6f3..59eaa7cb 100644 --- a/test/blast/math/dense/GetrfTest.cpp +++ b/test/blast/math/dense/GetrfTest.cpp @@ -2,14 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "blast/math/dense/Laswp.hpp" #include #include #include - #include +#include -#include #include #include #include diff --git a/test/blast/math/dense/Iamax.cpp b/test/blast/math/dense/Iamax.cpp index 7d0cb254..c66134e1 100644 --- a/test/blast/math/dense/Iamax.cpp +++ b/test/blast/math/dense/Iamax.cpp @@ -1,18 +1,9 @@ -// Copyright 2023 Mikhail Katliar -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Copyright 2024 Mikhail Katliar. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. #include +#include #include #include @@ -37,7 +28,7 @@ namespace blast :: testing for (size_t n = 1; n < 50; ++n) { - DynamicVector x(n); + blaze::DynamicVector x(n); randomize(x); size_t const ind = iamax(x); @@ -46,4 +37,4 @@ namespace blast :: testing ASSERT_LE(std::abs(v), x[ind]) << "Error at size " << n; } } -} \ No newline at end of file +} diff --git a/test/blast/math/dense/MatrixPointerTest.cpp b/test/blast/math/dense/MatrixPointerTest.cpp index 5bc45c2f..123a4dc0 100644 --- a/test/blast/math/dense/MatrixPointerTest.cpp +++ b/test/blast/math/dense/MatrixPointerTest.cpp @@ -2,19 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include -#include +#include #include #include -#include -#include -#include #include -#include - -#include +#include namespace blast :: testing @@ -53,7 +47,7 @@ namespace blast :: testing template struct MatrixType> { - using type = blaze::DynamicPanelMatrix; + using type = DynamicPanelMatrix; }; @@ -67,7 +61,7 @@ namespace blast :: testing static size_t constexpr N = SO == columnMajor ? S / SimdSize_v : defaultColumns; public: - using type = blaze::StaticPanelMatrix; + using type = StaticPanelMatrix; static_assert(type::spacing() == S); }; @@ -245,4 +239,4 @@ namespace blast :: testing EXPECT_EQ(p_trans.storageOrder, !p.storageOrder); } } -} \ No newline at end of file +} diff --git a/test/blast/math/dense/PotrfTest.cpp b/test/blast/math/dense/PotrfTest.cpp index 0e8def7a..f8fa24d4 100644 --- a/test/blast/math/dense/PotrfTest.cpp +++ b/test/blast/math/dense/PotrfTest.cpp @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - #include #include #include #include +#include + namespace blast :: testing { @@ -30,7 +31,7 @@ namespace blast :: testing { // Init matrices // - DynamicMatrix A(M, M), L(M, M); + blaze::DynamicMatrix A(M, M), L(M, M); makePositiveDefinite(A); reset(L); @@ -51,7 +52,7 @@ namespace blast :: testing // Init matrices // - StaticMatrix A, L; + blaze::StaticMatrix A, L; makePositiveDefinite(A); reset(L); @@ -71,10 +72,10 @@ namespace blast :: testing // Init matrices // - StaticMatrix A_orig; + blaze::StaticMatrix A_orig; makePositiveDefinite(A_orig); - StaticMatrix A = A_orig; + blaze::StaticMatrix A = A_orig; for (size_t i = 0; i < M; ++i) for (size_t j = i + 1; j < M; ++j) reset(A(i, j)); @@ -96,4 +97,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DensePotrtTest, double); // INSTANTIATE_TYPED_TEST_SUITE_P(Potrf_float, DensePotrtTest, float); -} \ No newline at end of file +} diff --git a/test/blast/math/dense/StaticVectorPointerTest.cpp b/test/blast/math/dense/StaticVectorPointerTest.cpp index c25d3a43..a8050c8f 100644 --- a/test/blast/math/dense/StaticVectorPointerTest.cpp +++ b/test/blast/math/dense/StaticVectorPointerTest.cpp @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include +#include +#include #include @@ -114,4 +115,4 @@ namespace blast :: testing { this->template testMatrixRowSubvectorImpl(); } -} \ No newline at end of file +} diff --git a/test/blast/math/dense/SyrkTest.cpp b/test/blast/math/dense/SyrkTest.cpp index 7a2334ae..897b4d34 100644 --- a/test/blast/math/dense/SyrkTest.cpp +++ b/test/blast/math/dense/SyrkTest.cpp @@ -6,11 +6,12 @@ #include - - #include #include +#include + + namespace blast :: testing { template @@ -32,8 +33,8 @@ namespace blast :: testing { // Init Blaze matrices // - DynamicMatrix A(m, k); - DynamicMatrix C(m, m), D(m, m); + blaze::DynamicMatrix A(m, k); + blaze::DynamicMatrix C(m, m), D(m, m); randomize(A); makeSymmetric(C); // for (size_t i = 0; i < m; ++i) @@ -71,4 +72,4 @@ namespace blast :: testing INSTANTIATE_TYPED_TEST_SUITE_P(double, DenseSyrkTest, double); -} \ No newline at end of file +} diff --git a/test/blast/math/dense/TrmmTest.cpp b/test/blast/math/dense/TrmmTest.cpp index e5c08041..a61e3c4c 100644 --- a/test/blast/math/dense/TrmmTest.cpp +++ b/test/blast/math/dense/TrmmTest.cpp @@ -4,8 +4,7 @@ #include #include - - +#include #include #include @@ -70,4 +69,4 @@ namespace blast :: testing << "trmm error at size m,n=" << m << "," << n; } } -} \ No newline at end of file +} diff --git a/test/blast/math/panel/PotrfTest.cpp b/test/blast/math/panel/PotrfTest.cpp index 28c27115..d0c267cd 100644 --- a/test/blast/math/panel/PotrfTest.cpp +++ b/test/blast/math/panel/PotrfTest.cpp @@ -5,8 +5,7 @@ #include #include #include - -#include +#include #include #include diff --git a/test/blast/math/panel/StaticPanelMatrixTest.cpp b/test/blast/math/panel/StaticPanelMatrixTest.cpp index c319a422..486b61c8 100644 --- a/test/blast/math/panel/StaticPanelMatrixTest.cpp +++ b/test/blast/math/panel/StaticPanelMatrixTest.cpp @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. #include -#include +#include #include #include diff --git a/test/blast/math/simd/DynamicRegisterMatrixTest.cpp b/test/blast/math/simd/DynamicRegisterMatrixTest.cpp index ae1f91fb..45908e9b 100644 --- a/test/blast/math/simd/DynamicRegisterMatrixTest.cpp +++ b/test/blast/math/simd/DynamicRegisterMatrixTest.cpp @@ -4,8 +4,9 @@ #include #include -#include +#include #include +#include #include #include @@ -223,4 +224,4 @@ namespace blast :: testing // std::clog << "DynamicRegisterMatrixTest.testPotrf not implemented for kernels with columns more than rows!" << std::endl; // } // } -} \ No newline at end of file +} diff --git a/test/blast/math/simd/RegisterMatrixTest.cpp b/test/blast/math/simd/RegisterMatrixTest.cpp index a09865f1..2ad3866a 100644 --- a/test/blast/math/simd/RegisterMatrixTest.cpp +++ b/test/blast/math/simd/RegisterMatrixTest.cpp @@ -4,17 +4,15 @@ #include #include -#include -#include -#include +#include +#include #include +#include #include #include #include -#include - namespace blast :: testing { @@ -376,7 +374,7 @@ namespace blast :: testing blaze::randomize(alpha); TypeParam ker; - ker.load(1., ptr(C)); + ker.load(1., ptr(*C)); ker.ger(alpha, ptr(a), ptr(b)); BLAST_EXPECT_APPROX_EQ(ker, evaluate(C + alpha * a * b), absTol(), relTol()); @@ -445,7 +443,7 @@ namespace blast :: testing for (size_t n = 0; n <= columns(C); ++n) { TypeParam ker; - ker.load(1., ptr(C)); + ker.load(1., ptr(*C)); ker.ger(ET(1.), ptr(a), ptr(trans(b)), m, n); for (size_t i = 0; i < m; ++i) @@ -473,9 +471,9 @@ namespace blast :: testing randomize(C); TypeParam ker; - ker.load(1., ptr(C)); + ker.load(1., ptr(*C)); ker.ger(ET(1.), ptr(a), ptr(trans(b))); - ker.store(ptr(D)); + ker.store(ptr(*D)); BLAST_EXPECT_EQ(D, evaluate(C + a * trans(b))); } @@ -643,4 +641,4 @@ namespace blast :: testing // TODO: should be strictly equal? BLAST_ASSERT_APPROX_EQ(ker, alpha * B * A, absTol(), relTol()); } -} \ No newline at end of file +}