Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
utils.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Distributed under BSD 3-Clause license. *
3  * Copyright by The HDF Group. *
4  * Copyright by the Illinois Institute of Technology. *
5  * All rights reserved. *
6  * *
7  * This file is part of Hermes. The full Hermes copyright notice, including *
8  * terms governing use, modification, and redistribution, is contained in *
9  * the COPYING file, which can be found at the top directory. If you do not *
10  * have access to the file, you may request a copy from help@hdfgroup.org. *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 #ifndef HERMES_UTILS_H_
14 #define HERMES_UTILS_H_
15 
16 #include <assert.h>
17 
18 #include <chrono>
19 #include <map>
20 
21 #include "hermes_types.h"
22 
29 #if HERMES_ENABLE_TIMING
30 
31 #define HERMES_BEGIN_TIMED_BLOCK(func_name) \
32  auto hermes_timed_block_start_ = std::chrono::high_resolution_clock::now(); \
33  const char *hermes_timed_block_func_name_ = (func_name);
34 
35 // TODO(chogan): Probably want to prepend rank to output
36 #define HERMES_END_TIMED_BLOCK() \
37  auto hermes_timed_block_end_ = std::chrono::high_resolution_clock::now(); \
38  auto hermes_timed_block_elapsed_ = \
39  hermes_timed_block_end_ - hermes_timed_block_start_; \
40  double hermes_timed_block_seconds_ = \
41  std::chrono::duration<double>(hermes_timed_block_elapsed_).count(); \
42  VLOG(1) << hermes_timed_block_func_name_ << " took " \
43  << hermes_timed_block_seconds_ << " seconds\n";
44 
45 #else
46 #define HERMES_BEGIN_TIMED_BLOCK(func_name)
47 #define HERMES_END_TIMED_BLOCK()
48 #endif // HERMES_ENABLE_TIMING
49 
50 namespace hermes {
51 
68 size_t RoundUpToMultiple(size_t val, size_t multiple);
69 
86 size_t RoundDownToMultiple(size_t val, size_t multiple);
87 
93 void InitDefaultConfig(Config *config);
94 
95 void FailedLibraryCall(std::string func);
96 
97 namespace testing {
101 enum class BlobSizeRange {
102  kSmall,
103  kMedium,
104  kLarge,
105  kXLarge,
106  kHuge,
107 };
108 
113  std::vector<hermes::u64> bytes_capacity;
114  std::vector<hermes::u64> bytes_available;
115  std::vector<hermes::f32> bandwidth;
117 };
118 
128 TargetViewState InitDeviceState(u64 total_target = 4, bool homo_dist = true);
129 
140 u64 UpdateDeviceState(PlacementSchema &schema, TargetViewState &node_state);
141 
147 void PrintNodeState(TargetViewState &node_state);
148 
156 std::vector<TargetID> GetDefaultTargets(size_t n);
157 
167 std::vector<size_t> GenFixedTotalBlobSize(size_t total_size,
168  BlobSizeRange range);
169 
170 } // namespace testing
171 } // namespace hermes
172 #endif // HERMES_UTILS_H_
Definition: adapter_utils.cc:35
size_t RoundUpToMultiple(size_t val, size_t multiple)
Definition: utils.cc:22
void FailedLibraryCall(std::string func)
Definition: utils.cc:132
size_t RoundDownToMultiple(size_t val, size_t multiple)
Definition: utils.cc:37
std::vector< std::pair< size_t, TargetID > > PlacementSchema
Definition: hermes_types.h:226
void InitDefaultConfig(Config *config)
Definition: utils.cc:49
uint64_t u64
Definition: hermes_types.h:43
Definition: utils.h:112
std::vector< hermes::u64 > bytes_available
Definition: utils.h:114
int num_devices
Definition: utils.h:116
std::vector< hermes::f32 > bandwidth
Definition: utils.h:115
std::vector< hermes::u64 > bytes_capacity
Definition: utils.h:113
BlobSizeRange
Definition: utils.h:101