Caffe2 - C++ API
A deep learning, cross platform ML framework
store_handler.h
1 #pragma once
2 
3 #include <chrono>
4 #include <cstdint>
5 #include <stdexcept>
6 #include <string>
7 #include <vector>
8 
9 namespace caffe2 {
10 
11 class StoreHandler {
12  public:
13  static constexpr std::chrono::milliseconds kDefaultTimeout =
14  std::chrono::seconds(30);
15  static constexpr std::chrono::milliseconds kNoTimeout =
16  std::chrono::milliseconds::zero();
17 
18  virtual ~StoreHandler();
19 
20  /*
21  * Set data for the key if it doesn't exist.
22  * If the key exists the data should be the same as the existing key.
23  */
24  virtual void set(const std::string& name, const std::string& data) = 0;
25 
26  /*
27  * Get the data for the key.
28  * The call should wait until the key is stored with default timeout
29  * and return data if set else fail.
30  */
31  virtual std::string get(const std::string& name) = 0;
32 
33  /*
34  * Does an atomic add operation on the key and returns the latest updated
35  * value.
36  * Note: To access the current value for this counter call with value = 0
37  */
38  virtual int64_t add(const std::string& name, int64_t value) = 0;
39 
40  /*
41  * Check if a keys exist in the store.
42  */
43  virtual bool check(const std::vector<std::string>& names) = 0;
44 
45  /*
46  * Wait for Keys to be stored.
47  */
48  virtual void wait(
49  const std::vector<std::string>& names,
50  const std::chrono::milliseconds& timeout = kDefaultTimeout) = 0;
51 };
52 
53 struct StoreHandlerTimeoutException : public std::runtime_error {
54  StoreHandlerTimeoutException() = default;
55  explicit StoreHandlerTimeoutException(const std::string& msg)
56  : std::runtime_error(msg) {}
57 };
58 
59 #define STORE_HANDLER_TIMEOUT(...) \
60  throw ::caffe2::StoreHandlerTimeoutException( \
61  ::caffe2::MakeString("[", __FILE__, ":", __LINE__, "] ", __VA_ARGS__));
62 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...