Skip to content

Commit b90d21b

Browse files
committed
tmc uts
1 parent 89ee428 commit b90d21b

File tree

3 files changed

+102
-18
lines changed

3 files changed

+102
-18
lines changed

bench/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ endif()
100100
target_compile_definitions(benchmark PRIVATE TMC_WORK_ITEM=CORO)
101101
target_compile_definitions(benchmark PRIVATE TMC_PRIORITY_COUNT=1)
102102
target_compile_definitions(benchmark PRIVATE TMC_USE_HWLOC)
103-
target_compile_definitions(benchmark PRIVATE TMC_TRIVIAL_TASK)
103+
104+
# TMC_TRIVIAL_TASK causes asserts to fail in debug builds...
105+
106+
# target_compile_definitions(benchmark PRIVATE TMC_TRIVIAL_TASK)
104107

105108
target_include_directories(benchmark PRIVATE ${tmc_SOURCE_DIR}/include)
106109

bench/source/uts/config.hpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DD1EB460_E250_4A8C_B35B_C99A803E5301
22
#define DD1EB460_E250_4A8C_B35B_C99A803E5301
33

4+
#include <exception>
5+
#include <iostream>
46
#include <stdexcept>
57

68
#include "../util.hpp"
@@ -198,31 +200,25 @@ inline void setup_tree(int i) {
198200

199201
inline auto result_tree(int i) -> result {
200202

201-
return {0, 0, 0};
202-
203203
switch (i) {
204-
case 1:
204+
case 11:
205205
return {10, 4130071, 3305118};
206-
case 2:
207-
return {81, 4117769, 2342762};
208-
case 3:
209-
return {1572, 4112897, 3599034};
210-
case 4:
211-
return {134, 4132453, 3108986};
212-
case 5:
213-
return {20, 4147582, 2181318};
214-
case 6:
206+
case 12:
215207
return {13, 102181082, 81746377};
216-
case 7:
217-
return {67, 96793510, 53791152};
218-
case 8:
208+
case 13:
209+
// TODO: what is the result?
210+
return {0, 0, 0};
211+
case 31:
212+
return {1572, 4112897, 3599034};
213+
case 32:
219214
return {17844, 111345631, 89076904};
220-
case 9:
215+
case 33:
216+
// TODO: what is the result?
221217
return {0, 0, 0};
222218
default:
223219
assert(false && "Invalid tree id");
224-
break;
225220
}
221+
std::terminate();
226222
}
227223

228224
#define MAKE_UTS_FOR(some_type) \

bench/source/uts/tmc.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <optional>
4+
#include <span>
5+
6+
#include <benchmark/benchmark.h>
7+
8+
#include "tmc/all_headers.hpp"
9+
10+
#include "../util.hpp"
11+
#include "config.hpp"
12+
#include "external/uts.h"
13+
14+
namespace {
15+
16+
using namespace tmc;
17+
18+
auto uts(int depth, Node *parent) -> task<result> {
19+
//
20+
result r(depth, 1, 0);
21+
22+
int num_children = uts_numChildren(parent);
23+
int child_type = uts_childType(parent);
24+
25+
parent->numChildren = num_children;
26+
27+
if (num_children > 0) {
28+
29+
std::vector<Node> cs(num_children);
30+
std::vector<task<result>> tsk(num_children);
31+
32+
for (int i = 0; i < num_children; i++) {
33+
34+
cs[i].type = child_type;
35+
cs[i].height = parent->height + 1;
36+
cs[i].numChildren = -1; // not yet determined
37+
38+
for (int j = 0; j < computeGranularity; j++) {
39+
rng_spawn(parent->state.state, cs[i].state.state, i);
40+
}
41+
42+
tsk[i] = uts(depth + 1, &cs[i]);
43+
}
44+
45+
auto results = co_await spawn_many(tsk.data(), num_children);
46+
47+
for (auto &&res : results) {
48+
r.maxdepth = max(r.maxdepth, res.maxdepth);
49+
r.size += res.size;
50+
r.leaves += res.leaves;
51+
}
52+
} else {
53+
r.leaves = 1;
54+
}
55+
co_return r;
56+
};
57+
58+
void uts_tmc(benchmark::State &state, int tree) {
59+
60+
state.counters["green_threads"] = state.range(0);
61+
62+
setup_tree(tree);
63+
64+
volatile int depth = 0;
65+
Node root;
66+
67+
result r;
68+
69+
tmc::cpu_executor().set_thread_count(state.range(0)).init();
70+
71+
for (auto _ : state) {
72+
uts_initRoot(&root, type);
73+
r = tmc::post_waitable(tmc::cpu_executor(), uts(depth, &root), 0).get();
74+
}
75+
76+
tmc::cpu_executor().teardown();
77+
78+
if (r != result_tree(tree)) {
79+
std::cerr << "lf uts " << tree << " failed" << std::endl;
80+
}
81+
}
82+
83+
} // namespace
84+
85+
MAKE_UTS_FOR(uts_tmc);

0 commit comments

Comments
 (0)