Skip to content

Commit 74c05ce

Browse files
committed
Merge branch 'remove-boost-timer' into 'develop'
Remove boost timer See merge request correaa/boost-multi!1925
2 parents 7ac311a + 6682466 commit 74c05ce

7 files changed

Lines changed: 143 additions & 51 deletions

File tree

benchmark/array_ref_timing.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
#ifdef COMPILATION_INSTRUCTIONS
2-
clang++ -O3 -Ofast -std=c++14 -DNDEBUG -Wall -Wextra -Wpedantic -Werror $0 -o $0.x -lboost_timer && time $0.x $@ && rm -f $0.x; exit
2+
clang++ -O3 -Ofast -std=c++14 -DNDEBUG -Wall -Wextra -Wpedantic -Werror $0 -o $0.x && time $0.x $@ && rm -f $0.x; exit
33
#endif
44

55
#include "../array_ref.hpp"
66

7-
#include <boost/timer/timer.hpp>
8-
7+
#include<chrono>
98
#include<iostream>
109
#include<numeric>
10+
#include<string>
11+
#include<utility> // move
1112
#include<vector>
12-
#include<numeric>
1313

1414
using std::cout; using std::cerr;
1515
namespace multi = boost::multi;
1616

17+
namespace {
18+
// minimal RAII wall-clock timer (replaces boost::timer::auto_cpu_timer)
19+
class auto_timer {
20+
std::string label_;
21+
std::chrono::steady_clock::time_point start_ = std::chrono::steady_clock::now();
22+
23+
public:
24+
explicit auto_timer(std::string label = {}) : label_{std::move(label)} {}
25+
auto_timer(auto_timer const&) = delete;
26+
auto_timer(auto_timer&&) = delete;
27+
auto operator=(auto_timer const&) -> auto_timer& = delete;
28+
auto operator=(auto_timer&&) -> auto_timer& = delete;
29+
~auto_timer() {
30+
std::cerr << label_ << std::chrono::duration<double>(std::chrono::steady_clock::now() - start_).count() << " s (wall)\n";
31+
}
32+
};
33+
} // namespace
34+
1735
int main(){
1836

1937
assert(0); // check that NDEBUG is off
@@ -31,15 +49,15 @@ int main(){
3149
double sum_raw;
3250
{
3351
double sum = 0.0;
34-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: raw %t seconds\n"};
52+
auto_timer t{"sum: raw: "};
3553
for(auto const& e : data) sum += e;
3654
sum_raw = sum;
3755
}
3856
iota(begin(data), end(data), 1.2); iota(begin(data), end(data), 202.2); data[1234] = 399.1;
3957
double sum_2D;
4058
{
4159
double sum = 0.0;
42-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 2D %t seconds\n"};
60+
auto_timer t{"sum: 2D: "};
4361
auto ext = extensions(data2D_cref);
4462
for(auto i : std::get<0>(ext)){
4563
for(auto j : std::get<1>(ext)) sum += data2D_cref(i, j);
@@ -50,7 +68,7 @@ int main(){
5068
double sum_2D_acc;
5169
{
5270
double sum = 0.0;
53-
boost::timer::auto_cpu_timer t{cerr, 3, "sum: 2D acc %t seconds\n"};
71+
auto_timer t{"sum: 2D acc: "};
5472
sum = std::accumulate(
5573
begin(data2D_cref), end(data2D_cref), 0.0,
5674
[](auto const& a, auto const& b){return a + std::accumulate(begin(b), end(b), 0.0);}
@@ -60,7 +78,7 @@ int main(){
6078
iota(begin(data), end(data), 1.2); iota(begin(data), end(data), 2.15); data[1234] = 3419.1;
6179
double sum_2Dwrong_acc;
6280
{
63-
boost::timer::auto_cpu_timer t{cerr, 3, "sum: 2Dwrong acc %t seconds\n"};
81+
auto_timer t{"sum: 2Dwrong acc: "};
6482
sum_2Dwrong_acc = std::accumulate(
6583
begin(rotated(data2D_cref)), end(rotated(data2D_cref)), 0.0,
6684
[](auto const& a, auto const& b){return a + std::accumulate(begin(b), end(b), 0.0);}
@@ -70,7 +88,7 @@ int main(){
7088
double sum_2Dwrong;
7189
{
7290
double sum = 0.0;
73-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 2Dwrong sum %t seconds\n"};
91+
auto_timer t{"sum: 2Dwrong sum: "};
7492
auto const [is, js] = extensions(data2D_cref);
7593
for(auto j : js){
7694
for(auto i : is){
@@ -83,14 +101,14 @@ int main(){
83101
double sum_raw2;
84102
{
85103
double sum = 0.0;
86-
boost::timer::auto_cpu_timer t{cerr, 3, "sum: raw %t seconds\n"};
104+
auto_timer t{"sum: raw: "};
87105
for(auto const& e : data) sum += e;
88106
sum_raw2 = sum;
89107
}
90108
iota(begin(data), end(data), 1.2); iota(begin(data), end(data), 33.112); data[1234] = 1199.1;
91109
double sum_raw_acc;
92110
{
93-
boost::timer::auto_cpu_timer t{cerr, 3, "sum: raw acc %t seconds\n"};
111+
auto_timer t{"sum: raw acc: "};
94112
sum_raw_acc = std::accumulate(data.data(), data.data() + data.size(), 0.);
95113
}
96114
cout<< sum_2D + sum_2D_acc + sum_2Dwrong_acc + sum_2Dwrong + sum_raw + sum_raw2 + sum_raw_acc <<std::endl;
@@ -109,14 +127,14 @@ cout<<'\n';
109127
assert( num_elements(v3D_cref) == std::ptrdiff_t(v.size()) );
110128
{
111129
double sum = 0.0;
112-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 3D raw %t seconds\n"};
130+
auto_timer t{"sum: 3D raw: "};
113131
for(auto const& e : v) sum += e;
114132
cout << sum << '\n';
115133
}
116134
iota(begin(v), end(v), 1.2);
117135
{
118136
double sum = 0.0;
119-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 3D indexed %t seconds\n"};
137+
auto_timer t{"sum: 3D indexed: "};
120138
auto const [is, js, ks] = extensions(v3D_cref);
121139
for(auto i : is) {
122140
auto const& v3D_crefi = v3D_cref[i];
@@ -132,7 +150,7 @@ cout<<'\n';
132150
iota(begin(v), end(v), 4444.5);
133151
{
134152
double sum = 0.0;
135-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 3Dwrong indexed %t seconds\n"};
153+
auto_timer t{"sum: 3Dwrong indexed: "};
136154
for(auto k : v3D_cref.extension(2)) // TODO(correaa) this doesn't work anymore
137155
for(auto j : v3D_cref.extension(1))
138156
for(auto i : v3D_cref.extension(0))
@@ -153,14 +171,14 @@ cout<<'\n';
153171
iota(begin(v), end(v), 0.1);
154172
{
155173
double sum = 0.0;
156-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 4D raw %t seconds\n"};
174+
auto_timer t{"sum: 4D raw: "};
157175
for(auto const& e : v) sum += e;
158176
cout<< sum <<'\n';
159177
}
160178
iota(begin(v), end(v), 1222.1);
161179
{
162180
double sum = 0.0;
163-
boost::timer::auto_cpu_timer t{std::cerr, 3, "sum: 4D indexed %t seconds\n"};
181+
auto_timer t{"sum: 4D indexed: "};
164182
auto const [is, js, ks, ls] = extensions(v4D_cref);
165183
for(auto i : is) {
166184
// auto const& v4D_crefi = v4D_cref[i]; // not necessary in clang or gcc

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include_directories(../include)
1212
#...
1313
#target_link_library(my_target PUBLIC multi)
1414

15-
find_package(Boost REQUIRED COMPONENTS iostreams serialization unit_test_framework timer)
15+
find_package(Boost REQUIRED COMPONENTS iostreams serialization unit_test_framework)
1616
add_subdirectory("../" multi-bin)
1717

1818
set(CMAKE_CXX_STANDARD_REQUIRED ON)

examples/gj_solve.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#ifdef COMPILATION// -*-indent-tabs-mode:t;c-basic-offset:4;tab-width:4-*-
2-
$CXX -DNDEBUG $0 -o $0x -lboost_timer&&$0x&&rm $0x;exit
2+
$CXX -DNDEBUG $0 -o $0x&&$0x&&rm $0x;exit
33
#endif
44
// Copyright 2019-2023 Alfredo A. Correa
55

66
#include <multi/array.hpp>
77

8+
#include<algorithm>
9+
#include<chrono>
810
#include<iostream>
9-
#include<vector>
1011
#include<numeric> // iota
11-
#include<algorithm>
12+
#include<string>
13+
#include<utility> // move
14+
#include<vector>
1215

1316
namespace multi = boost::multi;
1417
using std::cout;
@@ -63,7 +66,23 @@ auto gj_solve2(Matrix&& A, Vector&& y) -> decltype(y[0] /= A[0][0], y) {
6366
return y;
6467
}
6568

66-
#include <boost/timer/timer.hpp>
69+
namespace {
70+
// minimal RAII wall-clock timer (replaces boost::timer::auto_cpu_timer)
71+
class auto_timer {
72+
std::string label_;
73+
std::chrono::steady_clock::time_point start_ = std::chrono::steady_clock::now();
74+
75+
public:
76+
explicit auto_timer(std::string label = {}) : label_{std::move(label)} {}
77+
auto_timer(auto_timer const&) = delete;
78+
auto_timer(auto_timer&&) = delete;
79+
auto operator=(auto_timer const&) -> auto_timer& = delete;
80+
auto operator=(auto_timer&&) -> auto_timer& = delete;
81+
~auto_timer() {
82+
std::cerr << label_ << std::chrono::duration<double>(std::chrono::steady_clock::now() - start_).count() << " s (wall)\n";
83+
}
84+
};
85+
} // namespace
6786

6887
int main(){
6988
{
@@ -83,7 +102,7 @@ int main(){
83102
std::vector<double> y(3000);
84103
std::iota(y.begin(), y.end(), 0.2);
85104
{
86-
boost::timer::auto_cpu_timer t;
105+
auto_timer t;
87106
gj_solve(A({1000, 4000}, {0, 3000}), y);
88107
}
89108
cout << y[45] << std::endl;
@@ -95,7 +114,7 @@ int main(){
95114
std::vector<double> y(3000);
96115
std::iota(y.begin(), y.end(), 0.2);
97116
{
98-
boost::timer::auto_cpu_timer t;
117+
auto_timer t;
99118
gj_solve2(A({1000, 4000}, {0, 3000}), y);
100119
}
101120
cout << y[45] << std::endl;

examples/lu_fact.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
#ifdef COMPILATION // -*-indent-tabs-mode:t;c-basic-offset:4;tab-width:4;-*-
2-
$CXX $0 - std = c++ 17 - o $0x - lboost_timer `pkg - config-- libs tbb` && $0x && rm $0x;
2+
$CXX $0 - std = c++ 17 - o $0x `pkg - config-- libs tbb` && $0x && rm $0x;
33
exit
44
#endif
55
// Copyright 2018-2024 Alfredo A. Correa
66

77
#include <boost/multi/array.hpp>
88

9-
#include <boost/timer/timer.hpp>
10-
119
#include <algorithm> // transform
10+
#include <chrono>
1211
#include <iostream>
1312
#include <numeric> // iota
13+
#include <string>
1414
#include <tuple>
15+
#include <utility> // move
1516

1617
namespace multi = boost::multi;
1718

19+
namespace {
20+
// minimal RAII wall-clock timer (replaces boost::timer::auto_cpu_timer)
21+
class auto_timer {
22+
std::string label_;
23+
std::chrono::steady_clock::time_point start_ = std::chrono::steady_clock::now();
24+
25+
public:
26+
explicit auto_timer(std::string label = {}) : label_{std::move(label)} {}
27+
auto_timer(auto_timer const&) = delete;
28+
auto_timer(auto_timer&&) = delete;
29+
auto operator=(auto_timer const&) -> auto_timer& = delete;
30+
auto operator=(auto_timer&&) -> auto_timer& = delete;
31+
~auto_timer() {
32+
std::cerr << label_ << std::chrono::duration<double>(std::chrono::steady_clock::now() - start_).count() << " s (wall)\n";
33+
}
34+
};
35+
} // namespace
36+
1837
template<class Matrix>
1938
Matrix&& lu_fact(Matrix&& A) {
2039
using multi::size;
@@ -93,7 +112,7 @@ int main() {
93112
std::iota(A.elements().begin(), A.elements().end(), 0.1);
94113
std::transform(A.elements().begin(), A.elements().begin() + A.num_elements(), A.elements().begin(), [](auto x) { return x /= 2.0e6; });
95114
{
96-
boost::timer::auto_cpu_timer t;
115+
auto_timer t;
97116
lu_fact(A({3000, 6000}, {0, 4000}));
98117
cout << A[456][123] << std::endl;
99118
}

include/boost/multi/adaptors/blas/cuda/tests/gemm.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,42 @@
33
// https://www.boost.org/LICENSE_1_0.txt
44

55
// #include <boost/test/unit_test.hpp> // TODO(correaa) convert into lightweight test
6-
#include <boost/timer/timer.hpp>
76

87
#include <boost/multi/adaptors/cuda/cublas.hpp>
98
#include <boost/multi/array.hpp>
109

1110
#include <boost/multi/adaptors/cuda.hpp>
1211
#include <boost/multi/adaptors/blas.hpp>
1312

13+
#include <chrono>
1414
#include <cmath> // for abs // IWYU pragma: keep
1515
// IWYU pragma: no_include <cstdlib> // for abs
1616
#include <exception> // for exception
17+
#include <iostream>
1718
#include <random>
19+
#include <string>
20+
#include <utility> // move
1821

1922
namespace multi = boost::multi;
2023

24+
namespace {
25+
// minimal RAII wall-clock timer (replaces boost::timer::auto_cpu_timer)
26+
class auto_timer {
27+
std::string label_;
28+
std::chrono::steady_clock::time_point start_ = std::chrono::steady_clock::now();
29+
30+
public:
31+
explicit auto_timer(std::string label = {}) : label_{std::move(label)} {}
32+
auto_timer(auto_timer const&) = delete;
33+
auto_timer(auto_timer&&) = delete;
34+
auto operator=(auto_timer const&) -> auto_timer& = delete;
35+
auto operator=(auto_timer&&) -> auto_timer& = delete;
36+
~auto_timer() {
37+
std::cerr << label_ << std::chrono::duration<double>(std::chrono::steady_clock::now() - start_).count() << " s (wall)\n";
38+
}
39+
};
40+
} // namespace
41+
2142
BOOST_AUTO_TEST_CASE(const multi_adaptors_blas_cuda_gemm_complex_3x2_3x2){
2243
using complex = std::complex<double>; complex const I{0, 1};
2344
namespace blas = multi::blas;
@@ -134,7 +155,7 @@ BOOST_AUTO_TEST_CASE(const multi_adaptors_blas_cuda_gemm_context_timing){
134155
}
135156
namespace blas = multi::blas;
136157
{
137-
boost::timer::auto_cpu_timer t; // 2.398206s
158+
auto_timer t; // 2.398206s
138159
for(auto i = 0; i != 10; ++i){
139160
blas::context ctx;
140161
blas::gemm(ctx, 1.0, A, B, 0.0, C);
@@ -144,7 +165,7 @@ BOOST_AUTO_TEST_CASE(const multi_adaptors_blas_cuda_gemm_context_timing){
144165
{
145166
device_array A_gpu = A, B_gpu = B, C_gpu({size(A), size(~B)});
146167

147-
boost::timer::auto_cpu_timer t; // 0.707426s
168+
auto_timer t; // 0.707426s
148169
for(auto i = 0; i != 10; ++i){
149170
multi::cublas::context ctx;
150171
blas::gemm(ctx, 1.0, A_gpu, B_gpu, 0.0, C_gpu);
@@ -153,7 +174,7 @@ BOOST_AUTO_TEST_CASE(const multi_adaptors_blas_cuda_gemm_context_timing){
153174
{
154175
device_array A_gpu = A, B_gpu = B, C_gpu({size(A), size(~B)});
155176

156-
boost::timer::auto_cpu_timer t; // 0.613534s
177+
auto_timer t; // 0.613534s
157178
multi::cublas::context ctx;
158179
for(auto i = 0; i != 10; ++i) blas::gemm(ctx, 1.0, A_gpu, B_gpu, 0.0, C_gpu);
159180
}

0 commit comments

Comments
 (0)