File: store_handler.h

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (90 lines) | stat: -rw-r--r-- 2,522 bytes parent folder | download
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
83
84
85
86
87
88
89
90
#pragma once

#include <chrono>
#include <cstdint>
#include <stdexcept>
#include <string>
#include <vector>

#include "caffe2/core/common.h"

namespace caffe2 {

class TORCH_API StoreHandler {
 public:
  static constexpr std::chrono::milliseconds kDefaultTimeout =
      std::chrono::seconds(30);
  static constexpr std::chrono::milliseconds kNoTimeout =
      std::chrono::milliseconds::zero();

  virtual ~StoreHandler();

  /*
   * Set data for the key if it doesn't exist.
   * If the key exists the data should be the same as the existing key.
   */
  virtual void set(const std::string& name, const std::string& data) = 0;

  /*
   * Get the data for the key.
   * The call should wait until the key is stored with specified timeout
   * and return data if set else fail.
   */
  virtual std::string get(
      const std::string& name,
      const std::chrono::milliseconds& timeout = kDefaultTimeout) = 0;

  /*
   * Does an atomic add operation on the key and returns the latest updated
   * value.
   * Note: To access the current value for this counter call with value = 0
   */
  virtual int64_t add(const std::string& name, int64_t value) = 0;

  /*
   * Returns the number of keys in this store.
   */
  virtual int64_t getNumKeys() = 0;

  /*
   * Removes the specified key from the store.
   */
  virtual bool deleteKey(const std::string& key) = 0;

  /*
   * Check if a keys exist in the store.
   */
  virtual bool check(const std::vector<std::string>& names) = 0;

  /*
   * Wait for Keys to be stored.
   */
  virtual void wait(
      const std::vector<std::string>& names,
      const std::chrono::milliseconds& timeout = kDefaultTimeout) = 0;
};

/*
 * The backing store is no longer available. It may have been deleted.
 */
struct TORCH_API StoreHandlerNotAvailableException : public std::runtime_error {
  explicit StoreHandlerNotAvailableException(const std::string& msg)
      : std::runtime_error(msg) {}
};

#define STORE_HANDLER_NOT_AVAILABLE(...)             \
  throw ::caffe2::StoreHandlerNotAvailableException( \
      ::c10::str("[", __FILE__, ":", __LINE__, "] ", __VA_ARGS__));

/*
 * Timeout accessing the store.
 */
struct TORCH_API StoreHandlerTimeoutException : public std::runtime_error {
  explicit StoreHandlerTimeoutException(const std::string& msg)
      : std::runtime_error(msg) {}
};

#define STORE_HANDLER_TIMEOUT(...)              \
  throw ::caffe2::StoreHandlerTimeoutException( \
      ::c10::str("[", __FILE__, ":", __LINE__, "] ", __VA_ARGS__));
} // namespace caffe2