network.h 2.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*!
 *  Copyright (c) 2018 by Contributors
 * \file graph/network.h
 * \brief DGL networking related APIs
 */
#ifndef DGL_GRAPH_NETWORK_H_
#define DGL_GRAPH_NETWORK_H_

#include <dmlc/logging.h>
10
11
12
13
14
15
16
17
18
#include <dgl/runtime/ndarray.h>

#include <string.h>
#include <vector>

#include "../c_api_common.h"
#include "./network/msg_queue.h"

using dgl::runtime::NDArray;
19
20
21
22

namespace dgl {
namespace network {

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
91
92
93
94
95
96
97
98
99
100
// Max size of message queue for communicator is 200 MB
// TODO(chao): Make this number configurable
const int64_t kQueueSize = 200 * 1024 * 1024;

/*!
 * \brief Message type for DGL distributed training
 */
enum MessageType {
 /*!
  * \brief Message for send/recv NodeFlow
  */
  kNodeFlowMsg = 0,
 /*!
  * \brief Message for end-signal
  */
  kEndMsg = 1
};

/*!
 * \brief Meta data for communicator message
 */
class MsgMeta {
 public:
  /*!
   * \brief MsgMeta constructor.
   * \param msg_type type of message
   */
  explicit MsgMeta(int msg_type)
  : msg_type_(msg_type), ndarray_count_(0) {}

  /*!
   * \brief Construct MsgMeta from binary data buffer.
   * \param buffer data buffer
   * \param size data size
   */
  MsgMeta(char* buffer, int64_t size) {
    CHECK_NOTNULL(buffer);
    this->Deserialize(buffer, size);
  }

  /*!
   * \return message type
   */
  inline int msg_type() const {
    return msg_type_;
  }

  /*!
   * \return count of ndarray
   */
  inline int ndarray_count() const {
    return ndarray_count_;
  }

  /*!
   * \brief Add NDArray meta data to MsgMeta
   * \param array DGL NDArray
   */
  void AddArray(const NDArray& array);

  /*!
   * \brief Serialize MsgMeta to data buffer
   * \param size size of serialized message
   * \return pointer of data buffer
   */
  char* Serialize(int64_t* size);

  /*!
   * \brief Deserialize MsgMeta from data buffer
   * \param buffer data buffer
   * \param size size of data buffer
   */
  void Deserialize(char* buffer, int64_t size);

  /*!
   * \brief type of message
   */
  int msg_type_;
101

102
103
104
105
  /*!
   * \brief count of ndarray in MetaMsg
   */
  int ndarray_count_;
106

107
108
109
110
111
112
  /*!
   * \brief We first write the ndim to data_shape_ 
   * and then write the data shape. 
   */
  std::vector<int64_t> data_shape_;
};
113

114

115
116
117
118
}  // namespace network
}  // namespace dgl

#endif  // DGL_GRAPH_NETWORK_H_