ps/base/base_client.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <vector> | ||
| 3 | #include <string> | ||
| 4 | #include <tuple> | ||
| 5 | |||
| 6 | #include "base/array.h" | ||
| 7 | #include "base/json.h" | ||
| 8 | #include "base/log.h" | ||
| 9 | |||
| 10 | namespace recstore { | ||
| 11 | struct EmbeddingTableConfig { | ||
| 12 | uint64_t num_embeddings, embedding_dim; | ||
| 13 | |||
| 14 | 20 | std::string Serialize() const { | |
| 15 | nlohmann::json payload{ | ||
| 16 |
5/10✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 20 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 20 times.
✗ Branch 16 not taken.
|
180 | {"num_embeddings", num_embeddings}, {"embedding_dim", embedding_dim}}; |
| 17 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | return payload.dump(); |
| 18 | 20 | } | |
| 19 | }; | ||
| 20 | |||
| 21 | enum class PSCommand { | ||
| 22 | CLEAR_PS, | ||
| 23 | RELOAD_PS, | ||
| 24 | LOAD_FAKE_DATA, | ||
| 25 | DUMP_FAKE_DATA, | ||
| 26 | SAVE_CHECKPOINT, | ||
| 27 | LOAD_CHECKPOINT, | ||
| 28 | }; | ||
| 29 | |||
| 30 | class BasePSClient { | ||
| 31 | json json_config_; | ||
| 32 | |||
| 33 | public: | ||
| 34 | 142 | explicit BasePSClient(json config) : json_config_(config) {} | |
| 35 | 142 | virtual ~BasePSClient() {} | |
| 36 | |||
| 37 | virtual int | ||
| 38 | GetParameter(const base::ConstArray<uint64_t>& keys, float* values) = 0; | ||
| 39 | |||
| 40 | virtual int PutParameter(const base::ConstArray<uint64_t>& keys, | ||
| 41 | const std::vector<std::vector<float>>& values) = 0; | ||
| 42 | virtual int UpdateParameter(const std::string& table_name, | ||
| 43 | const base::ConstArray<uint64_t>& keys, | ||
| 44 | const std::vector<std::vector<float>>* grads) = 0; | ||
| 45 | virtual int UpdateParameterFlat( | ||
| 46 | const std::string& table_name, | ||
| 47 | const base::ConstArray<uint64_t>& keys, | ||
| 48 | const float* grads, | ||
| 49 | int64_t num_rows, | ||
| 50 | int64_t embedding_dim) = 0; | ||
| 51 | |||
| 52 | virtual int InitEmbeddingTable(const std::string& table_name, | ||
| 53 | const EmbeddingTableConfig& config) = 0; | ||
| 54 | virtual int | ||
| 55 | AsyncGetParameter(const base::ConstArray<uint64_t>& keys, float* values) = 0; | ||
| 56 | |||
| 57 | virtual void Command(PSCommand command) = 0; | ||
| 58 | |||
| 59 | virtual bool | ||
| 60 | ✗ | SaveCheckpoint(const std::string& path, const std::string& metadata) { | |
| 61 | (void)path; | ||
| 62 | (void)metadata; | ||
| 63 | ✗ | LOG(ERROR) << "Checkpoint save is unsupported by this PS client"; | |
| 64 | ✗ | return false; | |
| 65 | } | ||
| 66 | virtual bool | ||
| 67 | ✗ | LoadCheckpoint(const std::string& path, const std::string& metadata) { | |
| 68 | (void)path; | ||
| 69 | (void)metadata; | ||
| 70 | ✗ | LOG(ERROR) << "Checkpoint load is unsupported by this PS client"; | |
| 71 | ✗ | return false; | |
| 72 | } | ||
| 73 | |||
| 74 | virtual uint64_t | ||
| 75 | PrefetchParameter(const base::ConstArray<uint64_t>& keys) = 0; | ||
| 76 | virtual bool IsPrefetchDone(uint64_t prefetch_id) = 0; | ||
| 77 | virtual void WaitForPrefetch(uint64_t prefetch_id) = 0; | ||
| 78 | virtual bool GetPrefetchResult(uint64_t prefetch_id, | ||
| 79 | std::vector<std::vector<float>>* values) = 0; | ||
| 80 | virtual bool GetPrefetchResultFlat( | ||
| 81 | uint64_t prefetch_id, | ||
| 82 | std::vector<float>* values, | ||
| 83 | int64_t* num_rows, | ||
| 84 | int64_t embedding_dim) = 0; | ||
| 85 | }; | ||
| 86 | |||
| 87 | } // namespace recstore | ||
| 88 |