-
Notifications
You must be signed in to change notification settings - Fork 4
/
care.cpp
152 lines (127 loc) · 6.16 KB
/
care.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2020-24, Lawrence Livermore National Security, LLC and CARE
// project contributors. See the CARE LICENSE file for details.
//
// SPDX-License-Identifier: BSD-3-Clause
//////////////////////////////////////////////////////////////////////////////
// CARE config header
#include "care/config.h"
// Other CARE headers
#include "care/Setup.h"
// Other library headers
#include "chai/ArrayManager.hpp"
#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/strategy/QuickPool.hpp"
namespace care {
///
/// @brief Initializes a pool using umpire's default strategy
///
void initialize_pool(
const std::string& resource, ///< The name of the umpire resource this pool will be built on
const std::string& poolname, ///< The (application specific) name of the pool to be created
chai::ExecutionSpace space, ///< The CHAI Execution space associated with this pool
std::size_t initial_size, ///< The initial size in bytes
std::size_t min_block_size, ///< The minimum block size in bytes
bool /* grows */)
{
#if !defined(CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
auto& rm = umpire::ResourceManager::getInstance();
auto allocator = rm.getAllocator(resource);
auto pooled_allocator =
rm.makeAllocator<umpire::strategy::QuickPool>(poolname,
allocator,
initial_size, /* default = 512Mb*/
min_block_size); /* default = 1Mb */
chai::ArrayManager * am = chai::ArrayManager::getInstance();
am->setAllocator(space, pooled_allocator);
#endif
}
///
/// @brief Initializes a pool using a block heuristic
///
void initialize_pool_block_heuristic(
const std::string& resource, ///< The name of the umpire resource this pool will be built on
const std::string& poolname, ///< The (application specific) name of the pool to be created
chai::ExecutionSpace space, ///< The CHAI Execution space associated with this pool
std::size_t initial_size, ///< The initial size in bytes
std::size_t min_block_size, ///< The minimum block size in bytes
std::size_t block_coalesce_heuristic, ///< The number of blocks that should be releasable to trigger coalescing
bool /* grows */)
{
#if !defined(CHAI_DISABLE_RM) || defined (CHAI_THIN_GPU_ALLOCATE)
auto& rm = umpire::ResourceManager::getInstance();
auto allocator = rm.getAllocator(resource);
auto pooled_allocator =
rm.makeAllocator<umpire::strategy::QuickPool>(poolname,
allocator,
initial_size, /* default = 512Mb*/
min_block_size, /* default = 1Mb */
16, /* default alignment */
umpire::strategy::QuickPool::blocks_releasable(block_coalesce_heuristic));
chai::ArrayManager * am = chai::ArrayManager::getInstance();
am->setAllocator(space, pooled_allocator);
#endif
}
///
/// @brief Initializes a pool using a percent heuristic
///
void initialize_pool_percent_heuristic(
const std::string& resource, ///< The name of the umpire resource this pool will be built on
const std::string& poolname, ///< The (application specific) name of the pool to be created
chai::ExecutionSpace space, ///< The CHAI Execution space associated with this pool
std::size_t initial_size, ///< The initial size in bytes
std::size_t min_block_size, ///< The minimum block size in bytes
std::size_t percent_coalesce_heuristic, ///< The percentage of blocks that should be releasable to trigger coalescing
bool /* grows */)
{
#if !defined(CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
auto& rm = umpire::ResourceManager::getInstance();
auto allocator = rm.getAllocator(resource);
auto pooled_allocator =
rm.makeAllocator<umpire::strategy::QuickPool>(poolname,
allocator,
initial_size, /* default = 512Mb*/
min_block_size, /* default = 1Mb */
16, /* default alignment */
umpire::strategy::QuickPool::percent_releasable(percent_coalesce_heuristic));
chai::ArrayManager * am = chai::ArrayManager::getInstance();
am->setAllocator(space, pooled_allocator);
#endif
}
void dump_memory_statistics() {
auto& resourceManager = umpire::ResourceManager::getInstance();
chai::ArrayManager* arrayManager = chai::ArrayManager::getInstance();
for (int space = chai::ExecutionSpace::CPU; space < chai::ExecutionSpace::NUM_EXECUTION_SPACES; ++space) {
chai::ExecutionSpace executionSpace = (chai::ExecutionSpace) space;
auto allocatorId = arrayManager->getAllocatorId(executionSpace);
auto allocator = resourceManager.getAllocator(allocatorId);
printf("\n");
printf("Execution space: %s\n", allocator.getName().c_str());
printf("Currently used: %lu bytes\n", allocator.getCurrentSize());
printf("Currently allocated: %lu bytes\n", allocator.getActualSize());
printf("High watermark: %lu bytes\n", allocator.getHighWatermark());
}
}
bool syncIfNeeded() {
return chai::ArrayManager::getInstance()->syncIfNeeded();
}
}
// TODO: Fix conflicting requirement on _WIN32
#if !defined(_WIN32)
#if !defined(CARE_DISABLE_RAJAPLUGIN)
#if defined(_WIN32) && !defined(CARESTATICLIB)
#if defined(CARE_EXPORTS)
#include "RAJA/util/PluginStrategy.hpp"
RAJA_INSTANTIATE_REGISTRY(RAJA::util::PluginRegistry);
namespace RAJA
{
namespace util
{
PluginStrategy::PluginStrategy() = default;
}
} // namespace RAJA
#endif
#endif
#endif
#endif