@@ -1434,7 +1434,8 @@ static PyObject* tensor_method_set_underline_tensor(TensorObject* self,
14341434 static_cast <phi::DenseTensor*>(self->tensor .impl ().get ());
14351435 if (self->tensor .has_allocation () && self->tensor .initialized () &&
14361436 (!dst_tensor->meta ().is_contiguous () ||
1437- !src_tensor->meta ().is_contiguous ())) {
1437+ !src_tensor->meta ().is_contiguous ()) &&
1438+ dst_tensor->place ().GetType () == src_tensor->place ().GetType ()) {
14381439 VLOG (8 ) << " set_tensor() method , src or dst tensor is not contiguous " ;
14391440 if (!FLAGS_use_stride_kernel) {
14401441 PADDLE_THROW (common::errors::Fatal (
@@ -1451,6 +1452,17 @@ static PyObject* tensor_method_set_underline_tensor(TensorObject* self,
14511452 dst_tensor);
14521453 }));
14531454 } else {
1455+ if (!dst_tensor->meta ().is_contiguous ()) {
1456+ PADDLE_THROW (common::errors::Fatal (
1457+ " dst_tensor is not contiguous and src_tesnor has different place "
1458+ " with dst_tensor, so Strided kernel "
1459+ " can't be called, please change src_tensor'place as same as "
1460+ " dst_tensor'place or change dst_tensor to be contiguous" ));
1461+ } else if (!src_tensor->meta ().is_contiguous ()) {
1462+ VLOG (6 ) << " src_tensor is not contiguous, so dst_tensor will be not "
1463+ " contiguous after set_value " ;
1464+ }
1465+
14541466 if (dst_tensor->place ().GetType () != phi::AllocationType::UNDEFINED) {
14551467 framework::TensorCopy (*src_tensor, dst_tensor->place (), dst_tensor);
14561468 } else if (src_tensor->place ().GetType () !=
0 commit comments