/
export_AdcMemory.cc
85 lines (78 loc) · 3.85 KB
/
export_AdcMemory.cc
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
//
// Copyright (C) 2018 by the adcc authors
//
// This file is part of adcc.
//
// adcc is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// adcc is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with adcc. If not, see <http://www.gnu.org/licenses/>.
//
#include <adcc/AdcMemory.hh>
#include <memory>
#include <pybind11/pybind11.h>
#include <sstream>
namespace adcc {
namespace py_iface {
namespace py = pybind11;
static std::string AdcMemory___repr__(const AdcMemory& self) {
std::stringstream ss;
ss << "AdcMemory(allocator=" << self.allocator() << ", ";
if (self.allocator() != "standard") {
double mem_mb = static_cast<double>(self.max_memory()) / 1024. / 1024.;
ss << "max_memory=" << mem_mb << "MiB, ";
}
ss << "tensor_block_size=" << self.tbs_param()
<< ", pagefile_directory=" << self.pagefile_directory()
<< ", contraction_batch_size=" << self.contraction_batch_size() << ")";
return ss.str();
}
/** Export adcc/AdcMemory.hh */
void export_AdcMemory(py::module& m) {
// boost::noncopyable
py::class_<AdcMemory, std::shared_ptr<AdcMemory>>(
m, "AdcMemory",
"Class controlling the memory allocations for adcc ADC calculations.")
.def(py::init<>())
.def_property_readonly("allocator", &AdcMemory::allocator,
"Return the allocator to which the class is initialised.")
.def_property_readonly("max_memory", &AdcMemory::max_memory,
"Return the max_memory parameter value to which the class "
"was initialised.\nNote: This value is only a meaningful "
"upper bound if allocator != \"standard\"")
.def_property_readonly("pagefile_directory", &AdcMemory::pagefile_directory,
"Return the pagefile_directory value:\nNote: This value "
"is only meaningful if allocator != \"standard\"")
.def_property_readonly("tensor_block_size", &AdcMemory::tbs_param,
"Return the tensor_block_size parameter.")
.def_property("contraction_batch_size", &AdcMemory::contraction_batch_size,
&AdcMemory::set_contraction_batch_size,
"Get or set the batch size for contraction, i.e. the number of "
"blocks handled simultaneously in a tensor contraction.")
.def("initialise", &AdcMemory::initialise,
"Initialise the adcc memory management.\n\n"
"@param max_memory Estimate for the maximally employed memory\n"
"@param tensor_block_size This parameter roughly has the meaning\n"
" of how many indices are handled together\n"
" on operations. A good value is 16 for most\n"
" nowaday CPU cachelines.\n"
"@param pagefile_prefix Directory prefix for storing temporary\n"
" cache files.\n"
"@param allocator The allocator to be used. Valid values are \"libxm\",\n"
" \"libvmm\", \"standard\" and \"default\", where "
"\"default\"\n"
" uses a default chosen from the first three.")
.def("__repr__", &AdcMemory___repr__)
//
;
}
} // namespace py_iface
} // namespace adcc