ps/rdma/rdma_common.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <atomic> | ||
| 4 | #include <chrono> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <cstdlib> | ||
| 7 | #include <string> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include <folly/portability/GFlags.h> | ||
| 11 | |||
| 12 | DECLARE_string(rdma_rc_namespace); | ||
| 13 | |||
| 14 | namespace petps { | ||
| 15 | |||
| 16 | ✗ | inline std::uint64_t NowNs() { | |
| 17 | return static_cast<std::uint64_t>( | ||
| 18 | ✗ | std::chrono::duration_cast<std::chrono::nanoseconds>( | |
| 19 | ✗ | std::chrono::steady_clock::now().time_since_epoch()) | |
| 20 | ✗ | .count()); | |
| 21 | } | ||
| 22 | |||
| 23 | ✗ | inline std::uint64_t Exchange(std::atomic<std::uint64_t>* value) { | |
| 24 | ✗ | return value->exchange(0, std::memory_order_relaxed); | |
| 25 | } | ||
| 26 | |||
| 27 | ✗ | inline std::string NamespaceToken() { | |
| 28 | ✗ | if (!FLAGS_rdma_rc_namespace.empty()) { | |
| 29 | ✗ | return FLAGS_rdma_rc_namespace; | |
| 30 | } | ||
| 31 | ✗ | return "default"; | |
| 32 | } | ||
| 33 | |||
| 34 | inline const std::int32_t* FixedSlotStatusWord( | ||
| 35 | const void* buffer, std::size_t key_count, std::size_t value_size) { | ||
| 36 | return reinterpret_cast<const std::int32_t*>( | ||
| 37 | reinterpret_cast<const char*>(buffer) + | ||
| 38 | key_count * static_cast<std::size_t>(value_size)); | ||
| 39 | } | ||
| 40 | |||
| 41 | 20 | inline std::int32_t* FixedSlotStatusWord( | |
| 42 | void* buffer, std::size_t key_count, std::size_t value_size) { | ||
| 43 | return reinterpret_cast<std::int32_t*>( | ||
| 44 | reinterpret_cast<char*>(buffer) + | ||
| 45 | 20 | key_count * static_cast<std::size_t>(value_size)); | |
| 46 | } | ||
| 47 | |||
| 48 | ✗ | inline void CopyFlatRowsToVectors( | |
| 49 | const float* flat, | ||
| 50 | std::size_t row_count, | ||
| 51 | std::size_t embedding_dim, | ||
| 52 | std::vector<std::vector<float>>* values) { | ||
| 53 | ✗ | if (values == nullptr) { | |
| 54 | ✗ | return; | |
| 55 | } | ||
| 56 | ✗ | values->clear(); | |
| 57 | ✗ | values->reserve(row_count); | |
| 58 | ✗ | for (std::size_t row = 0; row < row_count; ++row) { | |
| 59 | ✗ | values->emplace_back( | |
| 60 | ✗ | flat + row * embedding_dim, flat + (row + 1) * embedding_dim); | |
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | } // namespace petps | ||
| 65 |