@@ -13,8 +13,11 @@ See the License for the specific language governing permissions and
1313limitations under the License. */
1414
1515#include " paddle/fluid/distributed/ps/service/brpc_utils.h"
16+
1617#include < arpa/inet.h>
1718#include < netdb.h>
19+
20+ #include " paddle/fluid/framework/convert_utils.h"
1821#include " paddle/fluid/platform/enforce.h"
1922
2023namespace paddle {
@@ -98,25 +101,29 @@ void SerializeLodTensor(framework::Variable* var,
98101 }
99102 }
100103 }
101- var_msg->set_data_type (static_cast <VarMsg::Type>(tensor->type ()));
104+ var_msg->set_data_type (static_cast <VarMsg::Type>(
105+ framework::TransToProtoVarType (tensor->dtype ())));
102106 for (auto & dim : framework::vectorize (tensor->dims ())) {
103107 var_msg->add_dims (dim);
104108 }
105109 // IO Buffer
106110 if (platform::is_cpu_place (tensor->place ())) {
107- auto data_len = tensor->numel () * framework::SizeOfType (tensor->type ());
111+ auto data_len = tensor->numel () * framework::DataTypeSize (tensor->dtype ());
108112 iobuf->append (reinterpret_cast <const char *>(&data_len), 8 );
109113 iobuf->append (reinterpret_cast <const char *>(tensor->data ()), data_len);
110114 } else {
111115#ifdef PADDLE_WITH_CUDA
112- char * temp_ptr = new char [tensor->numel () *
113- framework::SizeOfType (tensor->type ())]; // NOLINT
116+ char * temp_ptr =
117+ new char [tensor->numel () *
118+ framework::DataTypeSize (tensor->dtype ())]; // NOLINT
114119 auto stream =
115120 reinterpret_cast <const platform::CUDADeviceContext&>(ctx).stream ();
116121 memory::Copy (
117122 platform::CPUPlace (), temp_ptr, tensor->place (), tensor->data (),
118- tensor->numel () * framework::SizeOfType (tensor->type ()), stream);
119- auto data_len = tensor->numel () * framework::SizeOfType (tensor->type ());
123+ tensor->numel () * framework::SizeOfType (
124+ framework::TransToProtoVarType (tensor->dtype ())),
125+ stream);
126+ auto data_len = tensor->numel () * framework::DataTypeSize (tensor->dtype ());
120127 iobuf->append (reinterpret_cast <const char *>(&data_len), 8 );
121128 iobuf->append (reinterpret_cast <const char *>(temp_ptr), data_len);
122129 delete[] temp_ptr;
@@ -139,25 +146,29 @@ void SerializeSelectedRows(framework::Variable* var,
139146 var_data->resize (rows->size () * sizeof (int64_t ));
140147 char * data_ptr = const_cast <char *>(var_data->data ());
141148 memcpy (data_ptr, &((*rows)[0 ]), rows->size () * sizeof (int64_t ));
142- var_msg->set_data_type (static_cast <VarMsg::Type>(tensor->type ()));
149+ var_msg->set_data_type (static_cast <VarMsg::Type>(
150+ framework::TransToProtoVarType (tensor->dtype ())));
143151 for (auto & dim : framework::vectorize (tensor->dims ())) {
144152 var_msg->add_dims (dim);
145153 }
146154 // IO Buffer
147155 if (platform::is_cpu_place (tensor->place ())) {
148- auto data_len = tensor->numel () * framework::SizeOfType (tensor->type ());
156+ auto data_len = tensor->numel () * framework::DataTypeSize (tensor->dtype ());
149157 iobuf->append (reinterpret_cast <const char *>(&data_len), 8 );
150158 iobuf->append (reinterpret_cast <const char *>(tensor->data ()), data_len);
151159 } else {
152160#ifdef PADDLE_WITH_CUDA
153- char * temp_ptr = new char [tensor->numel () *
154- framework::SizeOfType (tensor->type ())]; // NOLINT
161+ char * temp_ptr =
162+ new char [tensor->numel () *
163+ framework::DataTypeSize (tensor->dtype ())]; // NOLINT
155164 auto stream =
156165 reinterpret_cast <const platform::CUDADeviceContext&>(ctx).stream ();
157166 memory::Copy (
158167 platform::CPUPlace (), temp_ptr, tensor->place (), tensor->data (),
159- tensor->numel () * framework::SizeOfType (tensor->type ()), stream);
160- auto data_len = tensor->numel () * framework::SizeOfType (tensor->type ());
168+ tensor->numel () * framework::SizeOfType (
169+ framework::TransToProtoVarType (tensor->dtype ())),
170+ stream);
171+ auto data_len = tensor->numel () * framework::DataTypeSize (tensor->dtype ());
161172 iobuf->append (reinterpret_cast <const char *>(&data_len), 8 );
162173 iobuf->append (reinterpret_cast <const char *>(temp_ptr), data_len);
163174 delete[] temp_ptr;
@@ -225,8 +236,9 @@ void DeserializeLodTensor(framework::Variable* var, const VarMsg& msg,
225236 }
226237 tensor->set_lod (lod);
227238
228- void * tensor_data =
229- tensor->mutable_data (place, VarMessageToVarType (msg.data_type ()));
239+ void * tensor_data = tensor->mutable_data (
240+ place,
241+ framework::TransToPtenDataType (VarMessageToVarType (msg.data_type ())));
230242
231243 // IO Buffer
232244 if (platform::is_cpu_place (place)) {
@@ -236,15 +248,16 @@ void DeserializeLodTensor(framework::Variable* var, const VarMsg& msg,
236248 } else if (platform::is_gpu_place (place)) {
237249#ifdef PADDLE_WITH_CUDA
238250 unsigned long data_len; // NOLINT
239- char * temp_ptr = new char [tensor->numel () *
240- framework::SizeOfType (tensor->type ())]; // NOLINT
241- io_buffer_itr.copy_and_forward ((void *)(&data_len), 8 ); // NOLINT
242- io_buffer_itr.copy_and_forward ((void *)temp_ptr, data_len); // NOLINT
251+ char * temp_ptr =
252+ new char [tensor->numel () *
253+ framework::DataTypeSize (tensor->dtype ())]; // NOLINT
254+ io_buffer_itr.copy_and_forward ((void *)(&data_len), 8 ); // NOLINT
255+ io_buffer_itr.copy_and_forward ((void *)temp_ptr, data_len); // NOLINT
243256 auto stream =
244257 reinterpret_cast <const platform::CUDADeviceContext&>(ctx).stream ();
245258 memory::Copy (
246259 place, tensor_data, platform::CPUPlace (), (void *)temp_ptr, // NOLINT
247- tensor->numel () * framework::SizeOfType (tensor->type ()), stream);
260+ tensor->numel () * framework::DataTypeSize (tensor->dtype ()), stream);
248261 delete[] temp_ptr;
249262#endif
250263 }
@@ -266,24 +279,26 @@ void DeserializeSelectedRows(
266279 vec_dim.push_back (x);
267280 }
268281 tensor->Resize (framework::make_ddim (vec_dim));
269- void * tensor_data =
270- tensor->mutable_data (place, VarMessageToVarType (msg.data_type ()));
282+ void * tensor_data = tensor->mutable_data (
283+ place,
284+ framework::TransToPtenDataType (VarMessageToVarType (msg.data_type ())));
271285 // IO Buffer
272286 if (platform::is_cpu_place (place)) {
273287 unsigned long data_len; // NOLINT
274288 io_buffer_itr.copy_and_forward ((void *)(&data_len), 8 ); // NOLINT
275289 io_buffer_itr.copy_and_forward (tensor_data, data_len);
276290 } else if (platform::is_gpu_place (place)) {
277291#ifdef PADDLE_WITH_CUDA
278- char * temp_ptr = new char [tensor->numel () *
279- framework::SizeOfType (tensor->type ())]; // NOLINT
280- unsigned long data_len; // NOLINT
281- io_buffer_itr.copy_and_forward ((void *)(&data_len), 8 ); // NOLINT
292+ char * temp_ptr =
293+ new char [tensor->numel () *
294+ framework::DataTypeSize (tensor->dtype ())]; // NOLINT
295+ unsigned long data_len; // NOLINT
296+ io_buffer_itr.copy_and_forward ((void *)(&data_len), 8 ); // NOLINT
282297 io_buffer_itr.copy_and_forward (temp_ptr, data_len);
283298 auto stream =
284299 reinterpret_cast <const platform::CUDADeviceContext&>(ctx).stream ();
285300 memory::Copy (place, tensor_data, platform::CPUPlace (), temp_ptr,
286- tensor->numel () * framework::SizeOfType (tensor->type ()),
301+ tensor->numel () * framework::DataTypeSize (tensor->dtype ()),
287302 stream);
288303 delete[] temp_ptr;
289304#endif
0 commit comments