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