-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_pigo.cpp
164 lines (129 loc) · 5.23 KB
/
bench_pigo.cpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright (C) 2023 Adam Lugowski. All rights reserved.
// Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file.
// SPDX-License-Identifier: BSD-2-Clause
#include "common.hpp"
#include "pigo.hpp"
// PIGO memory maps the input file. Multiple iterations
// can mean that the second and following iterations are on a warm cache.
// Both cold and warm caches are valid benchmark options, but default to cold.
//#define PIGO_iterations num_iterations
#define PIGO_iterations 1
// PIGO's types
// User warning! pigo::COO is unweighted by default!
using pigo_COO = pigo::COO<
INDEX_TYPE, // class Label=uint32_t,
INDEX_TYPE, // class Ordinal=Label,
INDEX_TYPE*, // class Storage=Label*,
false, // bool symmetric=false,
false, // bool keep_upper_triangle_only=false,
false, // bool remove_self_loops=false,
true, // bool weighted=false,
VALUE_TYPE // class Weight=float,
>;
using pigo_COO_pattern = pigo::COO<
INDEX_TYPE, // class Label=uint32_t,
INDEX_TYPE, // class Ordinal=Label,
INDEX_TYPE*, // class Storage=Label*,
false, // bool symmetric=false,
false, // bool keep_upper_triangle_only=false,
false, // bool remove_self_loops=false,
false // bool weighted=false,
>;
/**
* Read MatrixMarket with PIGO.
*/
static void PIGO_read(benchmark::State& state) {
problem& prob = get_problem((int)state.range(0));
int num_threads = (int)state.range(1);
omp_set_num_threads(num_threads);
std::size_t num_bytes = 0;
for ([[maybe_unused]] auto _ : state) {
pigo_COO c {prob.mm_path};
benchmark::DoNotOptimize(c);
num_bytes += std::filesystem::file_size(prob.mm_path);
benchmark::ClobberMemory();
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(PIGO_read)->Name("op:read/impl:PIGO/format:MatrixMarket")->UseRealTime()->Iterations(PIGO_iterations)->Apply(BenchmarkArgument);
/**
* Write an ASCII file with PIGO.
*/
static void PIGO_write_binary(benchmark::State& state) {
std::size_t num_bytes = 0;
problem& prob = get_problem((int)state.range(0));
int num_threads = (int)state.range(1);
// load the problem to be written later
omp_set_num_threads(0);
pigo_COO c {prob.mm_path};
omp_set_num_threads(num_threads);
auto out_path = temporary_write_dir / ("write_" + prob.name + ".bin");
for ([[maybe_unused]] auto _ : state) {
c.save(out_path);
num_bytes += std::filesystem::file_size(out_path);
benchmark::ClobberMemory();
}
if (delete_written_files_on_finish) {
std::filesystem::remove(out_path);
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
BENCHMARK(PIGO_write_binary)->Name("op:write/impl:PIGO/format:binary")->UseRealTime()->Iterations(PIGO_iterations)->Apply(BenchmarkArgument);
/**
* Write an ASCII file with PIGO.
*/
static void PIGO_write_ascii(benchmark::State& state) {
std::size_t num_bytes = 0;
problem& prob = get_problem((int)state.range(0));
int num_threads = (int)state.range(1);
// load the problem to be written later
omp_set_num_threads(0);
pigo_COO c {prob.mm_path};
omp_set_num_threads(num_threads);
auto out_path = temporary_write_dir / ("write_" + prob.name + ".txt");
for ([[maybe_unused]] auto _ : state) {
c.write(out_path);
num_bytes += std::filesystem::file_size(out_path);
benchmark::ClobberMemory();
}
if (delete_written_files_on_finish) {
std::filesystem::remove(out_path);
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
// pigo::COO::write uses std::to_string to write values. This method does not paralellize, so this
// benchmark is very slow on large datasets.
#if ENABLE_SLOW_BENCHMARKS
BENCHMARK(PIGO_write_ascii)->Name("op:write/impl:PIGO/format:ASCII(MatrixMarket_body_only)")->UseRealTime()->Iterations(PIGO_iterations)->Apply(BenchmarkArgument);
#endif
/**
* Write an ASCII file with PIGO (pattern).
*/
static void PIGO_write_ascii_pattern(benchmark::State& state) {
std::size_t num_bytes = 0;
problem& prob = get_problem((int)state.range(0));
int num_threads = (int)state.range(1);
// load the problem to be written later
omp_set_num_threads(0);
pigo_COO_pattern c {prob.mm_path};
omp_set_num_threads(num_threads);
auto out_path = temporary_write_dir / ("write_" + prob.name + ".txt");
for ([[maybe_unused]] auto _ : state) {
c.write(out_path);
num_bytes += std::filesystem::file_size(out_path);
benchmark::ClobberMemory();
}
if (delete_written_files_on_finish) {
std::filesystem::remove(out_path);
}
state.SetBytesProcessed((int64_t)num_bytes);
state.SetLabel("problem_name=" + prob.name);
}
// pigo::COO::write uses std::to_string to write values. This method does not paralellize, so this
// benchmark is very slow on large datasets.
#if ENABLE_SLOW_BENCHMARKS
BENCHMARK(PIGO_write_ascii_pattern)->Name("op:write/impl:PIGO/format:ASCII(MatrixMarket_body_only(pattern))")->UseRealTime()->Iterations(PIGO_iterations)->Apply(BenchmarkArgument);
#endif