Phase-parallel tape search: 22 minutes down to 2.7
The sequential search is memory bound on its hash table, so the split that
works is inside a Dial bucket, not across the graph:
* the table is read only for the whole bucket, so threads probe it with no
locking -- 99.7% of the work, since only about one edge in four hundred
lands on an unseen state
* misses and dist improvements are buffered per thread and applied by one
serial pass after the bucket
Cost order is untouched, so the answer is identical. Measured at limit 60:
threads wall states
1 12.40s 7,671,626
8 2.68s 7,671,626
16 2.20s 7,671,626
32 2.14s 7,671,626
and at the full limit 82 (the run that used to take 1350s): 162s, 414,631,673
states, cost 75 in 6 blocks -- the same program.
%synth now uses this by default. examples/full_add.r8asm assembles in 166s
instead of ~23 minutes and still produces the 90 character tape, checked on the
machine for all eight combinations.
The earlier attempt -- one worker per possible first block -- stays in
r8veritas.hh behind opt.threads but off by default; it duplicated the middle of
the graph and cost three to four times the work.
This commit is contained in:
1 parent
5b492b4ef5
commit
0bc5f1e6b8
5 files changed
+462
-5
No files matched your search
+12
-5
@@ -1,4 +1,5 @@
|
||||
#include "r8forge/r8asm.hh"
|
||||
#include "r8forge/r8veritas_phase_tt.hh"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
@@ -139,8 +140,14 @@ r8asm_synth_run(const std::vector<int> &in, const std::vector<int> &out,
|
||||
}
|
||||
copt.max_cost = bound;
|
||||
|
||||
std::array<int, P> addr{};
|
||||
for (int i = 0; i < P; i++)
|
||||
addr[size_t(i)] = copt.addr[size_t(i)];
|
||||
|
||||
const unsigned threads = std::thread::hardware_concurrency();
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
const auto tape = v.solve_cost(tt, copt);
|
||||
const auto tape =
|
||||
r8par::search_tt<P>(tt, addr, bound, threads, copt.max_states);
|
||||
const double tape_seconds =
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - t0)
|
||||
.count();
|
||||
@@ -153,10 +160,10 @@ r8asm_synth_run(const std::vector<int> &in, const std::vector<int> &out,
|
||||
return out_ins;
|
||||
}
|
||||
std::cerr << "r8asm: %synth " << name << ": tape cost " << tape.cost << " in "
|
||||
<< tape.program.size() << " blocks (layer answer was " << bound
|
||||
<< "), " << tape.states << " states, " << tape_seconds << "s\n";
|
||||
for (const auto &i : tape.program)
|
||||
out_ins.push_back({int(i.sacrifice), int(i.mask), int(i.or_mode)});
|
||||
<< tape.prog.size() << " blocks (layer answer was " << bound << "), "
|
||||
<< tape.states << " states, " << tape_seconds << "s\n";
|
||||
for (const auto &i : tape.prog)
|
||||
out_ins.push_back({i[0], i[1], i[2]});
|
||||
write_cache(out_ins);
|
||||
return out_ins;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user