Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple RegisterMatrix from Blaze #49

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bench/blast/math/simd/Ger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_ger_nt(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see this now, but technically a 'kernel' is the operation, i.e. dgemm, not the data you're operating on.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. This wording remains for histerical reasons.

using Traits = RegisterMatrixTraits<Kernel>;
using ET = ElementType_t<Kernel>;
size_t constexpr K = 100;

DynamicPanelMatrix<ET> a(Traits::rows, K);
DynamicPanelMatrix<ET> b(Traits::columns, K);
DynamicPanelMatrix<ET> c(Traits::rows, Traits::columns);
DynamicPanelMatrix<ET> a(Kernel::rows(), K);
DynamicPanelMatrix<ET> b(Kernel::columns(), K);
DynamicPanelMatrix<ET> c(Kernel::rows(), Kernel::columns());

randomize(a);
randomize(b);
Expand Down
23 changes: 6 additions & 17 deletions bench/blast/math/simd/Load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@

#include <blast/math/algorithm/Randomize.hpp>

#include <blaze/Math.h>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_load_dynamic_panel(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

DynamicPanelMatrix<double> c(ker.rows(), ker.columns());
randomize(c);
Expand All @@ -37,13 +32,10 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_load_dynamic_dense(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

DynamicMatrix<double, SO> c(ker.rows(), ker.columns());
randomize(c);
Expand All @@ -58,13 +50,10 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_load_static_dense(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

StaticMatrix<double, M, N, SO> c;
randomize(c);
Expand Down
11 changes: 5 additions & 6 deletions bench/blast/math/simd/PartialGemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
#include <blast/math/DynamicPanelMatrix.hpp>
#include <blast/math/RegisterMatrix.hpp>
#include <blast/math/dense/StaticMatrixPointer.hpp>
#include <blast/math/dense/StaticMatrix.hpp>

#include <bench/Benchmark.hpp>

#include <blast/math/algorithm/Randomize.hpp>

#include <blaze/math/StaticMatrix.h>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO, size_t MM, size_t NN>
template <typename T, size_t M, size_t N, StorageOrder SO, size_t MM, size_t NN>
static void BM_RegisterMatrix_partialGemm_static(State& state)
{
size_t constexpr K = 5;

blaze::StaticMatrix<T, M, K, SO> A;
blaze::StaticMatrix<T, K, N, SO> B;
blaze::StaticMatrix<T, M, N, SO> C, D;
StaticMatrix<T, M, K, SO> A;
StaticMatrix<T, K, N, SO> B;
StaticMatrix<T, M, N, SO> C, D;

randomize(A);
randomize(B);
Expand Down
5 changes: 2 additions & 3 deletions bench/blast/math/simd/PartialLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
#include <blast/math/DynamicPanelMatrix.hpp>
#include <blast/math/RegisterMatrix.hpp>
#include <blast/math/dense/StaticMatrixPointer.hpp>
#include <blast/math/dense/StaticMatrix.hpp>

#include <bench/Benchmark.hpp>

#include <blast/math/algorithm/Randomize.hpp>

#include <blaze/Math.h>

#include <functional>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_partialLoad_static_dense(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
Expand Down
11 changes: 5 additions & 6 deletions bench/blast/math/simd/PartialStore.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// Copyright (c) 2019-2020 Mikhail Katliar All rights reserved.
// 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.

#include <blast/math/DynamicPanelMatrix.hpp>
#include <blast/math/RegisterMatrix.hpp>
#include <blast/math/dense/StaticMatrixPointer.hpp>
#include <blast/math/dense/StaticMatrix.hpp>

#include <bench/Benchmark.hpp>

#include <blast/math/algorithm/Randomize.hpp>

#include <blaze/math/StaticMatrix.h>

#include <functional>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_partialStore_panel(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
Expand All @@ -44,7 +43,7 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_partialStore(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
Expand All @@ -71,7 +70,7 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO, size_t MM, size_t NN>
template <typename T, size_t M, size_t N, StorageOrder SO, size_t MM, size_t NN>
static void BM_RegisterMatrix_partialStore_static(State& state)
{
RegisterMatrix<T, M, N, SO> ker;
Expand Down
15 changes: 5 additions & 10 deletions bench/blast/math/simd/Potrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@

namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_potrf(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;
size_t constexpr m = Traits::rows;
size_t constexpr n = Traits::columns;

DynamicPanelMatrix<T> a(m, n);
DynamicPanelMatrix<T> a(M, N);
randomize(a);

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;
ker.load(ptr(a));

for (auto _ : state)
Expand All @@ -34,8 +29,8 @@ namespace blast :: benchmark
DoNotOptimize(ker);
}

if (m >= n)
setCounters(state.counters, complexityPotrf(m, n));
if (M >= N)
setCounters(state.counters, complexityPotrf(M, N));
}


Expand Down
23 changes: 6 additions & 17 deletions bench/blast/math/simd/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@

#include <blast/math/algorithm/Randomize.hpp>

#include <blaze/Math.h>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_store_dynamic_panel(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

DynamicPanelMatrix<double> c(ker.rows(), ker.columns()), d(ker.rows(), ker.columns());
randomize(c);
Expand All @@ -39,13 +34,10 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_store_dynamic_dense(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

DynamicMatrix<double, SO> c(ker.rows(), ker.columns()), d(ker.rows(), ker.columns());
randomize(c);
Expand All @@ -62,13 +54,10 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_store_static_dense(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

StaticMatrix<double, M, N, SO> c, d;
randomize(c);
Expand Down
21 changes: 9 additions & 12 deletions bench/blast/math/simd/Trmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@

#include <blast/math/Matrix.hpp>
#include <blast/math/RegisterMatrix.hpp>
#include <blast/math/dense/StaticMatrix.hpp>

#include <bench/Benchmark.hpp>

#include <blast/math/algorithm/Randomize.hpp>

#include <blast/blaze/Math.hpp>


namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO, UpLo UPLO>
template <typename T, size_t M, size_t N, StorageOrder SO, UpLo UPLO>
static void BM_RegisterMatrix_trmmLeft(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
size_t constexpr K = 100;

blaze::StaticMatrix<T, Kernel::rows(), Kernel::rows(), SO> A;
blaze::StaticMatrix<T, Kernel::rows(), Kernel::columns(), columnMajor> B;
StaticMatrix<T, M, M, SO> A;
StaticMatrix<T, M, N, columnMajor> B;

randomize(A);
randomize(B);

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

for (auto _ : state)
{
Expand All @@ -38,19 +36,18 @@ namespace blast :: benchmark
}


template <typename T, size_t M, size_t N, bool SO, UpLo UPLO>
template <typename T, size_t M, size_t N, StorageOrder SO, UpLo UPLO>
static void BM_RegisterMatrix_trmmRight(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
size_t constexpr K = 100;

blaze::StaticMatrix<T, Kernel::columns(), Kernel::columns(), SO> A;
blaze::StaticMatrix<T, Kernel::rows(), Kernel::columns(), columnMajor> B;
StaticMatrix<T, N, N, SO> A;
StaticMatrix<T, M, N, columnMajor> B;

randomize(A);
randomize(B);

Kernel ker;
RegisterMatrix<T, M, N, SO> ker;

for (auto _ : state)
{
Expand Down
11 changes: 4 additions & 7 deletions bench/blast/math/simd/Trsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@

namespace blast :: benchmark
{
template <typename T, size_t M, size_t N, bool SO>
template <typename T, size_t M, size_t N, StorageOrder SO>
static void BM_RegisterMatrix_trsm(State& state)
{
using Kernel = RegisterMatrix<T, M, N, SO>;
using Traits = RegisterMatrixTraits<Kernel>;
size_t constexpr m = Traits::rows;
size_t constexpr n = Traits::columns;

StaticPanelMatrix<double, m, n, columnMajor> L;
StaticPanelMatrix<double, M, N, columnMajor> L;
randomize(L);

StaticPanelMatrix<double, m, n, columnMajor> A;
StaticPanelMatrix<double, M, N, columnMajor> A;
randomize(A);

Kernel ker;
Expand All @@ -36,7 +33,7 @@ namespace blast :: benchmark
DoNotOptimize(ker);
}

setCounters(state.counters, complexity(trsmTag, false, m, n));
setCounters(state.counters, complexity(trsmTag, false, M, N));
}


Expand Down
24 changes: 6 additions & 18 deletions include/blast/math/StorageOrder.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
// 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 <blaze/math/StorageOrder.h>


namespace blast
{
enum StorageOrder : bool
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool? will there never be more StorageOrders than two?

Copy link
Owner Author

@mkatliar mkatliar Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The StorageOrder term was borrowed from Blaze, where it meant only row-major or column-major. Now I think that it could be a more complex thing, that would include panel-based and possible other storages. It could be a class that defines how to calculate memory offset given row and column indices, similar to LayoutPolicy in std::mdspan. Then we would not need special classes for panel matrices, because the StorageOrder parameter of the matrix class would handle accessing the elements. Implementing it would also solve #6 . Doing it in one step though would be a too big change, so I just decoupled StorageOrder from Blaze for now.

rowMajor = blaze::rowMajor,
columnMajor = blaze::columnMajor
rowMajor = false,
columnMajor = true
};


inline constexpr StorageOrder operator!(StorageOrder so)
{
return so == rowMajor ? columnMajor : rowMajor;
}
}
}
Loading
Loading