1 | #include <torch/csrc/distributed/rpc/python_resp.h> |
---|---|
2 | |
3 | #include <c10/util/C++17.h> |
4 | |
5 | namespace torch { |
6 | namespace distributed { |
7 | namespace rpc { |
8 | |
9 | PythonResp::PythonResp(SerializedPyObj&& serializedPyObj) |
10 | : serializedPyObj_(std::move(serializedPyObj)) {} |
11 | |
12 | c10::intrusive_ptr<Message> PythonResp::toMessageImpl() && { |
13 | auto payload = std::vector<char>( |
14 | serializedPyObj_.payload_.begin(), serializedPyObj_.payload_.end()); |
15 | return c10::make_intrusive<Message>( |
16 | std::move(payload), |
17 | std::move(serializedPyObj_.tensors_), |
18 | MessageType::PYTHON_RET); |
19 | } |
20 | |
21 | std::unique_ptr<PythonResp> PythonResp::fromMessage(const Message& message) { |
22 | std::string payload(message.payload().begin(), message.payload().end()); |
23 | std::vector<Tensor> tensors = message.tensors(); |
24 | SerializedPyObj serializedPyObj(std::move(payload), std::move(tensors)); |
25 | return std::make_unique<PythonResp>(std::move(serializedPyObj)); |
26 | } |
27 | |
28 | const SerializedPyObj& PythonResp::serializedPyObj() const { |
29 | return serializedPyObj_; |
30 | } |
31 | |
32 | } // namespace rpc |
33 | } // namespace distributed |
34 | } // namespace torch |
35 |