-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathenv.cpp
More file actions
104 lines (82 loc) · 3.28 KB
/
Copy pathenv.cpp
File metadata and controls
104 lines (82 loc) · 3.28 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* This file is a part of TiledArray.
* Copyright (C) 2021 Virginia Tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Chong Peng
* Department of Chemistry, Virginia Tech
* July 23, 2018
*
*/
#include <TiledArray/host/env.h>
#include <TiledArray/error.h>
#include <umpire/strategy/QuickPool.hpp>
#include <umpire/strategy/SizeLimiter.hpp>
namespace TiledArray {
namespace detail {
umpire::Allocator& get_host_allocator::operator()() {
return TiledArray::host::Env::instance()->host_allocator();
}
} // namespace detail
namespace host {
std::unique_ptr<Env>& Env::instance() {
if (!instance_accessor()) {
initialize();
}
return instance_accessor();
}
void Env::initialize(World& world, const std::uint64_t host_alloc_limit,
const std::uint64_t page_size) {
static std::mutex mtx; // to make initialize() reentrant
std::scoped_lock lock{mtx};
// only the winner of the lock race gets to initialize
if (instance_accessor() == nullptr) {
// uncomment to debug umpire ops
//
// umpire::util::Logger::getActiveLogger()->setLoggingMsgLevel(
// umpire::util::message::Debug);
// make thread-safe size-limited pool of host memory
auto& rm = umpire::ResourceManager::getInstance();
// N.B. we don't rely on Umpire introspection (even for profiling)
constexpr auto introspect = false;
// use QuickPool for host memory allocation, with min grain of 1 page
auto host_size_limited_alloc =
rm.makeAllocator<umpire::strategy::SizeLimiter, introspect>(
"SizeLimited_HOST", rm.getAllocator("HOST"), host_alloc_limit);
auto host_dynamic_pool =
rm.makeAllocator<umpire::strategy::QuickPool, introspect>(
"QuickPool_SizeLimited_HOST", host_size_limited_alloc, page_size,
page_size, /* alignment */ TILEDARRAY_ALIGN_SIZE);
auto host_env = std::unique_ptr<Env>(new Env(world, host_dynamic_pool));
instance_accessor() = std::move(host_env);
}
}
World& Env::world() const { return *world_; }
umpire::Allocator& Env::host_allocator() { return host_allocator_; }
std::size_t Env::host_allocator_getActualHighWatermark() {
TA_ASSERT(dynamic_cast<umpire::strategy::QuickPool*>(
host_allocator_.getAllocationStrategy()) != nullptr);
return dynamic_cast<umpire::strategy::QuickPool*>(
host_allocator_.getAllocationStrategy())
->getActualHighwaterMark();
}
Env::Env(World& world, umpire::Allocator host_alloc)
: world_(&world), host_allocator_(host_alloc) {}
std::unique_ptr<Env>& Env::instance_accessor() {
static std::unique_ptr<Env> instance_{nullptr};
return instance_;
}
} // namespace host
} // namespace TiledArray