-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathutils_internal.hpp
More file actions
82 lines (62 loc) · 1.81 KB
/
utils_internal.hpp
File metadata and controls
82 lines (62 loc) · 1.81 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
// Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
// Modifications Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#ifndef MSCCLPP_UTILS_INTERNAL_HPP_
#define MSCCLPP_UTILS_INTERNAL_HPP_
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <mscclpp/utils.hpp>
namespace mscclpp {
struct Timer {
std::chrono::steady_clock::time_point start_;
int timeout_;
Timer(int timeout = -1);
~Timer();
/// Returns the elapsed time in microseconds.
int64_t elapsed() const;
void set(int timeout);
void reset();
void print(const std::string& name);
};
// PCI Bus ID <-> int64 conversion functions
std::string int64ToBusId(int64_t id);
int64_t busIdToInt64(const std::string busId);
uint64_t getHash(const char* string, int n);
uint64_t getHostHash();
uint64_t getPidHash();
void getRandomData(void* buffer, size_t bytes);
struct netIf {
char prefix[64];
int port;
};
int parseStringList(const char* string, struct netIf* ifList, int maxList);
bool matchIfList(const char* string, int port, struct netIf* ifList, int listSize, bool matchExact);
template <class T>
inline void hashCombine(std::size_t& hash, const T& v) {
std::hash<T> hasher;
hash ^= hasher(v) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
}
struct PairHash {
public:
template <typename T, typename U>
std::size_t operator()(const std::pair<T, U>& x) const {
std::size_t hash = 0;
hashCombine(hash, x.first);
hashCombine(hash, x.second);
return hash;
}
};
class TokenPool : public std::enable_shared_from_this<TokenPool> {
public:
TokenPool(size_t nTokens);
std::shared_ptr<uint64_t> getToken();
private:
size_t nToken_;
uint64_t* baseAddr_;
uint64_t tailMask_;
std::shared_ptr<uint64_t> tokens_;
std::vector<uint64_t> allocationMap_;
};
} // namespace mscclpp
#endif