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
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
#include "memory.hpp"
#include <cstdlib>
#include <trans_table/trans_table.hpp>
// After moving ThreadData ownership into SolverContext, Memory no longer
// holds per-thread ThreadData pointers. Keep a minimal implementation that
// tracks configured thread sizes (S/L) and exposes lightweight queries.
Memory::Memory()
{
}
Memory::~Memory()
{
// Clear configured thread sizes
Resize(0, DDS_TT_SMALL, 0, 0);
}
void Memory::ReturnThread(const unsigned /*thrId*/)
{
// No-op: ThreadData is now owned by SolverContext instances. Returning
// per-thread TT memory requires a SolverContext with the appropriate
// ThreadData pointer; call sites should perform that via their
// SolverContext instances.
}
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
void Memory::Resize(
const unsigned n,
const TTmemory flag,
const int /*memDefault_MB*/,
const int /*memMaximum_MB*/) // NOLINT(bugprone-easily-swappable-parameters)
{
// Resize the lightweight thread size vector. Each entry is a short
// diagnostic token: "S" = small TT, "L" = large TT.
threadSizes.resize(n);
for (unsigned i = 0; i < n; ++i)
threadSizes[i] = (flag == DDS_TT_SMALL ? "S" : "L");
}
unsigned Memory::NumThreads() const
{
return static_cast<unsigned>(threadSizes.size());
}
double Memory::MemoryInUseMB(const unsigned /*thrId*/) const
{
// We can only account for the static RelRanksType footprint here. Any
// transposition table memory is owned by SolverContext/transposition
// table instances and must be queried via those contexts when available.
return 8192. * sizeof(RelRanksType) / static_cast<double>(1024.);
}
std::string Memory::ThreadSize(const unsigned thrId) const
{
if (thrId >= threadSizes.size()) return std::string();
return threadSizes[thrId];
}