-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathblas.cpp
More file actions
142 lines (128 loc) · 5.74 KB
/
blas.cpp
File metadata and controls
142 lines (128 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <ginkgo/ginkgo.hpp>
#include "benchmark/blas/blas_common.hpp"
#include "benchmark/utils/general.hpp"
#include "benchmark/utils/generator.hpp"
#include "benchmark/utils/types.hpp"
using Generator = DefaultSystemGenerator<>;
std::map<std::string, std::function<std::unique_ptr<BenchmarkOperation>(
std::shared_ptr<const gko::Executor>, dimensions)>>
operation_map{
{"copy",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<CopyOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_x,
dims.stride_y);
}},
{"axpy",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<AxpyOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_x,
dims.stride_y, false);
}},
{"sub_scaled",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<SubScaledOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_x,
dims.stride_y, false);
}},
{"multiaxpy",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<AxpyOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_x,
dims.stride_y, true);
}},
{"scal",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<ScalOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_y, false);
}},
{"multiscal",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<ScalOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_y, true);
}},
{"dot",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<DotOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_x,
dims.stride_y);
}},
{"norm",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<NormOperation<Generator>>(
exec, Generator{}, dims.n, dims.r, dims.stride_y);
}},
{"mm",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<ApplyOperation<Generator>>(
exec, Generator{}, dims.n, dims.k, dims.m, dims.stride_A,
dims.stride_B, dims.stride_C);
}},
{"gemm",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<AdvancedApplyOperation<Generator>>(
exec, Generator{}, dims.n, dims.k, dims.m, dims.stride_A,
dims.stride_B, dims.stride_C);
}},
{"prefix_sum32",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<PrefixSumOperation<gko::int32>>(exec,
dims.n);
}},
{"prefix_sum64",
[](std::shared_ptr<const gko::Executor> exec, dimensions dims) {
return std::make_unique<PrefixSumOperation<gko::int64>>(exec,
dims.n);
}}};
int main(int argc, char* argv[])
{
std::string header = R"("
A benchmark for measuring performance of Ginkgo's BLAS-like "
operations.
Parameters for a benchmark case are:
n: number of rows for vectors and gemm output (required)
r: number of columns for vectors (optional, default 1)
m: number of columns for gemm output (optional, default n)
k: inner dimension of the gemm (optional, default n)
stride: storage stride for both vectors (optional, default r)
stride_x: stride for input vector x (optional, default r)
stride_y: stride for in/out vector y (optional, default r)
stride_A: stride for A matrix in gemm (optional, default k)
stride_B: stride for B matrix in gemm (optional, default m)
stride_C: stride for C matrix in gemm (optional, default m)
The supported operations are defined as:
BLAS algorithms:
copy (y = x),
axpy (y = y + a * x),
sub_scaled (y = y - a * x),
multiaxpy (like axpy, but a has one entry per column),
scal (y = a * y),
multiscal (like scal, but a has one entry per column),
dot (a = x' * y),"
norm (a = sqrt(x' * x)),
mm (C = A * B),
gemm (C = a * A * B + b * C)
Non-numerical algorithms:
prefix_sum32 (x_i <- sum_{j=0}^{i-1} x_i, 32 bit indices)
prefix_sum64 ( 64 bit indices)
where A has dimensions n x k, B has dimensions k x m,
C has dimensions n x m and x and y have dimensions n x r
)";
auto schema =
json::parse(std::ifstream(GKO_ROOT "/benchmark/schema/blas.json"));
initialize_argument_parsing(&argc, &argv, header, schema["examples"]);
std::string extra_information;
auto exec = executor_factory.at(FLAGS_executor)(FLAGS_gpu_timer);
print_general_information(extra_information, exec);
auto test_cases = json::parse(get_input_stream());
auto results = run_test_cases(BlasBenchmark{operation_map}, exec,
get_timer(exec, FLAGS_gpu_timer), schema,
std::move(test_cases));
std::cout << std::setw(4) << results << std::endl;
}