diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 8e614faa248faccd1385ea29e0cd0950f08c481d..e589f059f522bb32b0f46e41f143874ce2ed7636 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -1972,6 +1972,9 @@ Scope* OperatorWithKernel::PreparePtenData( continue; } + if (in_def.backend == phi::Backend::ALL_BACKEND) { + continue; + } auto expected_place = phi::TransToPtenPlace(in_def.backend); if (platform::is_same_place(tensor_in->place(), expected_place)) { continue; diff --git a/paddle/fluid/imperative/prepared_operator.h b/paddle/fluid/imperative/prepared_operator.h index 714e429798662b9a5846f7f0f6bb23f1b43b0d4a..879b3ec3e68a25141c239d00e25fab92914ef068 100644 --- a/paddle/fluid/imperative/prepared_operator.h +++ b/paddle/fluid/imperative/prepared_operator.h @@ -479,6 +479,9 @@ void PreparePtenData(const phi::Kernel& pt_kernel, auto var = ins_vector[offset]; const auto* tensor_in = GetTensorFromVar(var->Var()); if (tensor_in && tensor_in->IsInitialized()) { + if (in_def.backend == phi::Backend::ALL_BACKEND) { + continue; + } auto expected_place = phi::TransToPtenPlace(in_def.backend); if (platform::is_same_place(tensor_in->place(), expected_place)) { continue; diff --git a/paddle/fluid/operators/fill_any_like_op.cc b/paddle/fluid/operators/fill_any_like_op.cc index ed68bd7b7c2a5fd2aa9cd05c006d91c96b5b8625..e6de430a78c1a38439cbc78f4e930a7bbe1bc463 100644 --- a/paddle/fluid/operators/fill_any_like_op.cc +++ b/paddle/fluid/operators/fill_any_like_op.cc @@ -12,9 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/fluid/operators/fill_any_like_op.h" #include +#include "paddle/fluid/framework/op_registry.h" + namespace paddle { namespace operators { @@ -91,14 +92,3 @@ REGISTER_OPERATOR( ::paddle::framework::EmptyGradOpMaker, ::paddle::framework::EmptyGradOpMaker, ops::FillAnyLikeVarTypeInference) - -REGISTER_OP_CPU_KERNEL( - fill_any_like, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel); diff --git a/paddle/fluid/operators/fill_any_like_op.cu b/paddle/fluid/operators/fill_any_like_op.cu deleted file mode 100644 index 3ebc0ad7c8ec53b5c3de68823d9ba943e49bd364..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/fill_any_like_op.cu +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/operators/fill_any_like_op.h" -#include "paddle/fluid/platform/float16.h" - -namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL( - fill_any_like, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel, - ops::FillAnyLikeKernel); diff --git a/paddle/fluid/operators/fill_any_like_op.h b/paddle/fluid/operators/fill_any_like_op.h deleted file mode 100644 index 36b56394b6f1b1198c65cb7a6a6046d223b31922..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/fill_any_like_op.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#pragma once -#include -#include -#include -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/framework/pten_utils.h" - -#include "paddle/phi/kernels/full_kernel.h" - -namespace paddle { -namespace operators { - -template -class FillAnyLikeKernel : public framework::OpKernel { - public: - using CommonType = typename std::common_type< - float, - typename std::conditional::value, - float, T>::type>::type; - - void Compute(const framework::ExecutionContext& context) const override { - auto* x = context.Input("X"); - auto* out = context.Output("Out"); - out->mutable_data(context.GetPlace()); - - // TODO(fangzeyang): Once context.Attribute supports double dtype, this - // kernel should be updated to support double dtype, too. - float value = context.Attr("value"); - - auto common_type_value = static_cast(value); - - PADDLE_ENFORCE_EQ( - (common_type_value >= - static_cast(std::numeric_limits::lowest())) && - (common_type_value <= - static_cast(std::numeric_limits::max())), - true, - platform::errors::InvalidArgument( - "The filled value is out of range for target type, " - "current kernel type is %s, the range should between %f " - "and %f, but now value is %f.", - typeid(T).name(), - static_cast(std::numeric_limits::lowest()), - static_cast(std::numeric_limits::max()), value)); - - PADDLE_ENFORCE_EQ( - std::isnan(value), false, - platform::errors::InvalidArgument("The filled value is NaN.")); - - const auto& dev_ctx = context.template device_context(); - // call new kernel - phi::FullLikeKernel( - static_cast::TYPE&>(dev_ctx), - *x, value, phi::DataType::UNDEFINED, out); - } -}; - -} // namespace operators -} // namespace paddle diff --git a/paddle/fluid/operators/fill_any_like_op_npu.cc b/paddle/fluid/operators/fill_any_like_op_npu.cc index a584c1341dc0f280d483d5677ef2276b43c003d2..2a914ff2ebd33024d80f8d88fde97f70a2f203a7 100644 --- a/paddle/fluid/operators/fill_any_like_op_npu.cc +++ b/paddle/fluid/operators/fill_any_like_op_npu.cc @@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/fluid/operators/fill_any_like_op.h" +#include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/platform/device/npu/npu_op_runner.h" namespace paddle { diff --git a/paddle/fluid/operators/fill_any_like_op_xpu.cc b/paddle/fluid/operators/fill_any_like_op_xpu.cc index 693d4431b2ec8e0546dfe125d3d7bd00f70993c9..896310cd0918b118db003d784daca87c49c5ab32 100644 --- a/paddle/fluid/operators/fill_any_like_op_xpu.cc +++ b/paddle/fluid/operators/fill_any_like_op_xpu.cc @@ -14,7 +14,7 @@ limitations under the License. */ #ifdef PADDLE_WITH_XPU -#include "paddle/fluid/operators/fill_any_like_op.h" +#include "paddle/fluid/framework/op_registry.h" #include "paddle/phi/kernels/full_kernel.h" diff --git a/paddle/phi/api/lib/CMakeLists.txt b/paddle/phi/api/lib/CMakeLists.txt index 720c6f54bb075dade92c40eecc1d8752f55f9848..1ebddc3d3cd1baefcfcb362806d522fe2b3bcb72 100644 --- a/paddle/phi/api/lib/CMakeLists.txt +++ b/paddle/phi/api/lib/CMakeLists.txt @@ -91,8 +91,9 @@ cc_library(pten_tensor SRCS tensor_method.cc DEPS pten_tensor_raw pten_function_ cc_library(op_meta_info SRCS op_meta_info.cc DEPS pten_tensor) +cc_library(wrapped_infermeta SRCS ${wrapped_infermeta_source_file} DEPS pten) + cc_library(sparse_api SRCS sparse_api.cc DEPS pten_tensor pten kernel_dispatch pten_data_transform) -cc_library(pten_function_api SRCS ${api_source_file} DEPS pten_tensor pten kernel_dispatch pten_data_transform) +cc_library(pten_function_api SRCS ${api_source_file} DEPS pten_tensor pten kernel_dispatch pten_data_transform wrapped_infermeta) cc_library(pten_dygraph_api SRCS ${dygraph_api_source_file} DEPS pten_tensor pten kernel_dispatch pten_data_transform) cc_library(pten_bw_function_api SRCS ${bw_api_source_file} DEPS pten_tensor pten kernel_dispatch backward_infermeta pten_data_transform pten_function_api) -cc_library(wrapped_infermeta SRCS ${wrapped_infermeta_source_file} DEPS pten) diff --git a/paddle/phi/common/scalar.h b/paddle/phi/common/scalar.h index 9a5a3fbf921d07951873a1ee1c1d4d73b1a003db..72cef89d300c8d60811bde7cf667275b37fedc6f 100644 --- a/paddle/phi/common/scalar.h +++ b/paddle/phi/common/scalar.h @@ -25,7 +25,6 @@ namespace experimental { template class ScalarBase { public: - bool FromTensor() const { return is_from_tensor_; } // Constructor support implicit ScalarBase(double val) : dtype_(DataType::FLOAT64) { // NOLINT data_.f64 = val; @@ -157,6 +156,10 @@ class ScalarBase { CopyScalar(other, this); } + bool FromTensor() const { return is_from_tensor_; } + + void SetFromTensor(bool from_tensor) { is_from_tensor_ = from_tensor; } + template inline RT to() const { switch (dtype_) { diff --git a/paddle/phi/kernels/cpu/full_kernel.cc b/paddle/phi/kernels/cpu/full_kernel.cc index 84d7f56d3361c6e5d4382e8ea45e9b31a8eb60bd..6b0183d31c6ec3dc3e6712043f27678c3f3a6bb2 100644 --- a/paddle/phi/kernels/cpu/full_kernel.cc +++ b/paddle/phi/kernels/cpu/full_kernel.cc @@ -99,4 +99,6 @@ PD_REGISTER_KERNEL(full_like, int, int64_t, bool, - phi::dtype::float16) {} + phi::dtype::float16) { + kernel->InputAt(0).SetBackend(phi::Backend::ALL_BACKEND); +} diff --git a/paddle/phi/kernels/gpu/full_kernel.cu b/paddle/phi/kernels/gpu/full_kernel.cu index d5cb1575b71817be445311d1081a7185e80e49ed..48b26540331ef54c971d3f0cf5ee9ef9fc185f1d 100644 --- a/paddle/phi/kernels/gpu/full_kernel.cu +++ b/paddle/phi/kernels/gpu/full_kernel.cu @@ -123,4 +123,6 @@ PD_REGISTER_KERNEL(full_like, int, int64_t, bool, - phi::dtype::float16) {} + phi::dtype::float16) { + kernel->InputAt(0).SetBackend(phi::Backend::ALL_BACKEND); +} diff --git a/paddle/phi/kernels/xpu/full_kernel.cc b/paddle/phi/kernels/xpu/full_kernel.cc index b514425cc54da2fe004fdda2319f5d3c1e488afe..574f4e991a260e8ebc250fe3f8461736dc3eb7f8 100644 --- a/paddle/phi/kernels/xpu/full_kernel.cc +++ b/paddle/phi/kernels/xpu/full_kernel.cc @@ -139,4 +139,6 @@ PD_REGISTER_KERNEL(full_like, float, int, int64_t, - phi::dtype::float16) {} + phi::dtype::float16) { + kernel->InputAt(0).SetBackend(phi::Backend::ALL_BACKEND); +}