| 392 | } |
| 393 | |
| 394 | std::shared_ptr<phi::DenseTensor> PrepareData( |
| 395 | const Tensor& input, |
| 396 | const phi::TensorArgDef& target_args_def, |
| 397 | const TransformFlag& transform_flag, |
| 398 | bool is_stride_kernel) { |
| 399 | const auto& tensor_in = input.impl(); |
| 400 | if (tensor_in) { |
| 401 | phi::DenseTensor& dense_tensor = |
| 402 | *static_cast<phi::DenseTensor*>(tensor_in.get()); |
| 403 | if (!transform_flag.NeedTransform() || !dense_tensor.initialized() || |
| 404 | (!NeedTransformPlace( |
| 405 | dense_tensor.place(), target_args_def.backend, transform_flag) && |
| 406 | !NeedTransformDataType( |
| 407 | dense_tensor.dtype(), target_args_def.dtype, transform_flag) && |
| 408 | !NeedTransformLayout(dense_tensor.layout(), |
| 409 | target_args_def.layout, |
| 410 | dense_tensor.place(), |
| 411 | transform_flag) && |
| 412 | !NeedTransform2Contiguous(is_stride_kernel, |
| 413 | dense_tensor.meta().is_contiguous()))) { |
| 414 | if (NeedTransform2Contiguous(is_stride_kernel, |
| 415 | dense_tensor.meta().is_contiguous()) && |
| 416 | dense_tensor.initialized()) { |
| 417 | phi::DenseTensor out = dense_tensor; |
| 418 | out = Trans2Contiguous(out); |
| 419 | return std::make_shared<phi::DenseTensor>(std::move(out)); |
| 420 | } |
| 421 | return std::static_pointer_cast<phi::DenseTensor>(tensor_in); |
| 422 | } |
| 423 | phi::DenseTensor out = TransformData( |
| 424 | dense_tensor, target_args_def, transform_flag, is_stride_kernel); |
| 425 | return std::make_shared<phi::DenseTensor>(std::move(out)); |
| 426 | } |
| 427 | return nullptr; |
| 428 | } |
| 429 | |
| 430 | paddle::optional<phi::DenseTensor> PrepareData( |
| 431 | const paddle::optional<Tensor>& input, |
no test coverage detected