From 761be90350e09406cb229e3eb8ab9bae44aa9326 Mon Sep 17 00:00:00 2001 From: chenfeiyu Date: Tue, 10 May 2022 03:41:43 +0000 Subject: [PATCH] update operator generation code --- paddle/CMakeLists.txt | 1 - paddle/phi/api/lib/CMakeLists.txt | 38 +++++++++++++- paddle/phi/infermeta/ternary.cc | 11 ----- paddle/phi/infermeta/ternary.h | 7 --- paddle/phi/kernels/cpu/linear_grad_kernel.cc | 30 ------------ paddle/phi/kernels/cpu/linear_kernel.cc | 30 ------------ paddle/phi/kernels/gpu/linear_grad_kernel.cu | 30 ------------ paddle/phi/kernels/gpu/linear_kernel.cu | 30 ------------ .../kernels/impl/linear_grad_kernel_impl.h | 45 ----------------- paddle/phi/kernels/impl/linear_kernel_impl.h | 49 ------------------- paddle/phi/kernels/linear_grad_kernel.h | 36 -------------- paddle/phi/kernels/linear_kernel.h | 34 ------------- python/paddle/utils/code_gen/filters.py | 11 +++-- python/paddle/utils/code_gen/generate_op.py | 11 +++-- python/paddle/utils/code_gen/new_api.yaml | 9 ---- .../paddle/utils/code_gen/new_backward.yaml | 10 ---- .../paddle/utils/code_gen/templates/ks.c.j2 | 4 ++ .../paddle/utils/code_gen/templates/op.c.j2 | 1 + .../code_gen/templates/operator_utils.c.j2 | 10 ++-- python/paddle/utils/code_gen/type_mapping.py | 4 +- 20 files changed, 62 insertions(+), 339 deletions(-) delete mode 100644 paddle/phi/kernels/cpu/linear_grad_kernel.cc delete mode 100644 paddle/phi/kernels/cpu/linear_kernel.cc delete mode 100644 paddle/phi/kernels/gpu/linear_grad_kernel.cu delete mode 100644 paddle/phi/kernels/gpu/linear_kernel.cu delete mode 100644 paddle/phi/kernels/impl/linear_grad_kernel_impl.h delete mode 100644 paddle/phi/kernels/impl/linear_kernel_impl.h delete mode 100644 paddle/phi/kernels/linear_grad_kernel.h delete mode 100644 paddle/phi/kernels/linear_kernel.h diff --git a/paddle/CMakeLists.txt b/paddle/CMakeLists.txt index bba4d19926b1a..9d801c9e224a9 100644 --- a/paddle/CMakeLists.txt +++ b/paddle/CMakeLists.txt @@ -2,7 +2,6 @@ add_subdirectory(utils) add_subdirectory(scripts) add_subdirectory(testing) set(PYTHON_TESTS_DIR ${PADDLE_BINARY_DIR}/python/paddle/fluid/tests CACHE INTERNAL "python tests directory") - add_subdirectory(phi) add_subdirectory(infrt) add_subdirectory(fluid) diff --git a/paddle/phi/api/lib/CMakeLists.txt b/paddle/phi/api/lib/CMakeLists.txt index 5917719602e54..d88f937a8b875 100644 --- a/paddle/phi/api/lib/CMakeLists.txt +++ b/paddle/phi/api/lib/CMakeLists.txt @@ -77,6 +77,11 @@ execute_process( set(parsed_api_dir ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/parsed_apis) set(generated_op_path ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generated_op.cc) set(generated_argument_mapping_path ${CMAKE_SOURCE_DIR}/paddle/phi/ops/compat/generated_sig.cc) +message("parse api yamls: +- ${api_yaml_file} +- ${new_api_yaml_file} +- ${bw_api_yaml_file} +- ${new_bw_api_yaml_file}") execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_api_dir} @@ -103,6 +108,9 @@ foreach(_result in ${_results}) endforeach() # validation of api yamls +message("validate api yaml: +- ${parsed_api_dir}/new_api.parsed.yaml +- ${parsed_api_dir}/new_backward_api.parsed.yaml") execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen COMMAND ${PYTHON_EXECUTABLE} cross_validate.py @@ -115,19 +123,45 @@ if (${_result}) endif() # code generation for op, op makers, and argument mapping functions +message("create or remove auto-geneated operators: ${generated_op_path}.tmp +create or remove auto-geneated argument mappings: ${generated_argument_mapping_path}.tmp") execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen COMMAND ${PYTHON_EXECUTABLE} generate_op.py --api_yaml_path ./parsed_apis/new_api.parsed.yaml --backward_api_yaml_path ./parsed_apis/new_backward_api.parsed.yaml - --output_op_path "${generated_op_path}" - --output_arg_map_path "${generated_argument_mapping_path}" + --output_op_path "${generated_op_path}.tmp" + --output_arg_map_path "${generated_argument_mapping_path}.tmp" RESULT_VARIABLE _result ) if (${_result}) message(FATAL_ERROR "operator codegen failed, exiting." ) endif() + +if(EXISTS "${generated_op_path}.tmp" AND EXISTS "${generated_op_path}") + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${generated_op_path}.tmp" "${generated_op_path}") + message("copy if different ${generated_op_path}.tmp ${generated_op_path}") +elseif(EXISTS "${generated_op_path}.tmp") + execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${generated_op_path}.tmp" "${generated_op_path}") + message("copy ${generated_op_path}.tmp ${generated_op_path}") +else() + execute_process(COMMAND ${CMAKE_COMMAND} -E rm -f "${generated_op_path}") + message("remove ${generated_op_path}") +endif() + + +if(EXISTS "${generated_argument_mapping_path}.tmp" AND EXISTS "${generated_argument_mapping_path}") + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${generated_argument_mapping_path}.tmp" "${generated_argument_mapping_path}") + message("copy if different ${generated_argument_mapping_path}.tmp ${generated_argument_mapping_path}") +elseif(EXISTS "${generated_argument_mapping_path}.tmp") + execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${generated_argument_mapping_path}.tmp" "${generated_argument_mapping_path}") + message("copy ${generated_argument_mapping_path}.tmp ${generated_argument_mapping_path}") +else() + execute_process(COMMAND ${CMAKE_COMMAND} -E rm -f "${generated_argument_mapping_path}") + message("remove ${generated_argument_mapping_path}") +endif() + # generate forward api add_custom_command( OUTPUT ${api_header_file} ${api_source_file} diff --git a/paddle/phi/infermeta/ternary.cc b/paddle/phi/infermeta/ternary.cc index f72b88cc3f729..ae8c7dd61c3bb 100644 --- a/paddle/phi/infermeta/ternary.cc +++ b/paddle/phi/infermeta/ternary.cc @@ -14,7 +14,6 @@ limitations under the License. */ #include "paddle/phi/infermeta/ternary.h" #include "paddle/phi/core/ddim.h" -#include "paddle/phi/infermeta/binary.h" #include "paddle/phi/kernels/funcs/common_shape.h" namespace phi { @@ -803,14 +802,4 @@ void ViterbiDecodeInferMeta(const MetaTensor& input, scores->set_dtype(length.dtype()); } -void LinearInferMeta(const MetaTensor& x, - const MetaTensor& y, - const MetaTensor& b, - bool trans_x, - bool trans_y, - MetaTensor* out, - MetaTensor* mm) { - MatmulInferMeta(x, y, trans_x, trans_y, mm); - ElementwiseInferMeta(*mm, b, out); -} } // namespace phi diff --git a/paddle/phi/infermeta/ternary.h b/paddle/phi/infermeta/ternary.h index ed58b798e1503..4f561e0adf19d 100644 --- a/paddle/phi/infermeta/ternary.h +++ b/paddle/phi/infermeta/ternary.h @@ -149,11 +149,4 @@ void ViterbiDecodeInferMeta(const MetaTensor& input, MetaTensor* path, MetaConfig config = MetaConfig()); -void LinearInferMeta(const MetaTensor& x, - const MetaTensor& y, - const MetaTensor& b, - bool trans_x, - bool trans_y, - MetaTensor* out, - MetaTensor* mm); } // namespace phi diff --git a/paddle/phi/kernels/cpu/linear_grad_kernel.cc b/paddle/phi/kernels/cpu/linear_grad_kernel.cc deleted file mode 100644 index 2c6065f6699c5..0000000000000 --- a/paddle/phi/kernels/cpu/linear_grad_kernel.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2021 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/phi/kernels/linear_grad_kernel.h" - -#include "paddle/phi/backends/cpu/cpu_context.h" -#include "paddle/phi/core/kernel_registry.h" - -#include "paddle/phi/common/complex.h" -#include "paddle/phi/kernels/impl/linear_grad_kernel_impl.h" - -PD_REGISTER_KERNEL(linear_grad, - CPU, - ALL_LAYOUT, - phi::LinearGradKernel, - float, - double, - phi::dtype::complex, - phi::dtype::complex) {} diff --git a/paddle/phi/kernels/cpu/linear_kernel.cc b/paddle/phi/kernels/cpu/linear_kernel.cc deleted file mode 100644 index 4bcbec394ae78..0000000000000 --- a/paddle/phi/kernels/cpu/linear_kernel.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2021 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/phi/kernels/linear_kernel.h" - -#include "paddle/phi/backends/cpu/cpu_context.h" -#include "paddle/phi/core/kernel_registry.h" - -#include "paddle/phi/common/complex.h" -#include "paddle/phi/kernels/impl/linear_kernel_impl.h" - -PD_REGISTER_KERNEL(linear, - CPU, - ALL_LAYOUT, - phi::LinearKernel, - float, - double, - phi::dtype::complex, - phi::dtype::complex) {} diff --git a/paddle/phi/kernels/gpu/linear_grad_kernel.cu b/paddle/phi/kernels/gpu/linear_grad_kernel.cu deleted file mode 100644 index ae6d35d58f4c8..0000000000000 --- a/paddle/phi/kernels/gpu/linear_grad_kernel.cu +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2021 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/phi/kernels/linear_grad_kernel.h" - -#include "paddle/phi/backends/gpu/gpu_context.h" -#include "paddle/phi/core/kernel_registry.h" - -#include "paddle/phi/common/complex.h" -#include "paddle/phi/kernels/impl/linear_grad_kernel_impl.h" - -PD_REGISTER_KERNEL(linear_grad, - GPU, - ALL_LAYOUT, - phi::LinearGradKernel, - float, - double, - phi::dtype::complex, - phi::dtype::complex) {} diff --git a/paddle/phi/kernels/gpu/linear_kernel.cu b/paddle/phi/kernels/gpu/linear_kernel.cu deleted file mode 100644 index 22bf8cf82efce..0000000000000 --- a/paddle/phi/kernels/gpu/linear_kernel.cu +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2021 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/phi/kernels/linear_kernel.h" - -#include "paddle/phi/backends/gpu/gpu_context.h" -#include "paddle/phi/core/kernel_registry.h" - -#include "paddle/phi/common/complex.h" -#include "paddle/phi/kernels/impl/linear_kernel_impl.h" - -PD_REGISTER_KERNEL(linear, - GPU, - ALL_LAYOUT, - phi::LinearKernel, - float, - double, - phi::dtype::complex, - phi::dtype::complex) {} diff --git a/paddle/phi/kernels/impl/linear_grad_kernel_impl.h b/paddle/phi/kernels/impl/linear_grad_kernel_impl.h deleted file mode 100644 index fc99ceb8f3914..0000000000000 --- a/paddle/phi/kernels/impl/linear_grad_kernel_impl.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (c) 2022 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 "paddle/phi/kernels/elementwise_grad_kernel.h" -#include "paddle/phi/kernels/empty_kernel.h" -#include "paddle/phi/kernels/matmul_grad_kernel.h" - -#include "paddle/phi/backends/cpu/cpu_context.h" -#include "paddle/phi/backends/gpu/gpu_context.h" - -namespace phi { -template -void LinearGradKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& b, - const DenseTensor& out, - const DenseTensor& mm, - const DenseTensor& out_grad, - bool transpose_x, - bool transpose_y, - DenseTensor* dx, - DenseTensor* dy, - DenseTensor* db) { - DenseTensor dmm; - EmptyLikeKernel(dev_ctx, mm, mm.type(), &dmm); - AddGradKernel(dev_ctx, mm, b, out_grad, -1, &dmm, db); - MatmulGradKernel( - dev_ctx, x, y, dmm, transpose_x, transpose_y, dx, dy); -} - -} // namespace phi diff --git a/paddle/phi/kernels/impl/linear_kernel_impl.h b/paddle/phi/kernels/impl/linear_kernel_impl.h deleted file mode 100644 index 6931267c935b7..0000000000000 --- a/paddle/phi/kernels/impl/linear_kernel_impl.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (c) 2021 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 "paddle/phi/kernels/elementwise_kernel.h" -#include "paddle/phi/kernels/funcs/blas/blas.h" -#include "paddle/phi/kernels/funcs/complex_functors.h" -#include "paddle/phi/kernels/matmul_kernel.h" - -#include "paddle/phi/core/dense_tensor.h" - -namespace phi { - -template -void LinearKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& b, - bool transpose_x, - bool transpose_y, - DenseTensor* out, - DenseTensor* mm) { - PADDLE_ENFORCE_NE( - phi::product(x.dims()), - 0, - phi::errors::InvalidArgument("The Input(X) dims size must not be equal 0," - " but reviced dims size is 0. ")); - PADDLE_ENFORCE_NE( - phi::product(y.dims()), - 0, - phi::errors::InvalidArgument("The Input(Y) dims size must not be equal 0," - " but reviced dims size is 0. ")); - MatmulKernel(dev_ctx, x, y, transpose_x, transpose_y, mm); - AddKernel(dev_ctx, *mm, b, out); -} - -} // namespace phi diff --git a/paddle/phi/kernels/linear_grad_kernel.h b/paddle/phi/kernels/linear_grad_kernel.h deleted file mode 100644 index 0f10916bbbe8f..0000000000000 --- a/paddle/phi/kernels/linear_grad_kernel.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2022 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 "paddle/phi/core/dense_tensor.h" -#include "paddle/utils/optional.h" - -namespace phi { - -template -void LinearGradKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& b, - const DenseTensor& out, - const DenseTensor& mm, - const DenseTensor& dout, - bool transpose_x, - bool transpose_y, - DenseTensor* dx, - DenseTensor* dy, - DenseTensor* db); - -} // namespace phi diff --git a/paddle/phi/kernels/linear_kernel.h b/paddle/phi/kernels/linear_kernel.h deleted file mode 100644 index 136e3d658fab5..0000000000000 --- a/paddle/phi/kernels/linear_kernel.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2021 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 "paddle/phi/core/dense_tensor.h" -#include "paddle/phi/infermeta/binary.h" - -#include "paddle/phi/kernels/elementwise_kernel.h" -#include "paddle/phi/kernels/empty_kernel.h" - -namespace phi { - -template -void LinearKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& b, - bool transpose_x, - bool transpose_y, - DenseTensor* out, - DenseTensor* mm); -} // namespace phi diff --git a/python/paddle/utils/code_gen/filters.py b/python/paddle/utils/code_gen/filters.py index 1f164deb21aca..d37403adcba36 100644 --- a/python/paddle/utils/code_gen/filters.py +++ b/python/paddle/utils/code_gen/filters.py @@ -80,6 +80,13 @@ def to_opmaker_name(s): return '"{}"'.format(to_pascal_case(s)) +def to_opmaker_name_cstr(s): + if s.endswith("_grad"): + return '"{}@GRAD"'.format(to_pascal_case(s.removesuffix("_grad"))) + else: + return '"{}"'.format(to_pascal_case(s)) + + def to_pascal_case(s): words = s.split("_") return "".join([word.capitalize() for word in words]) @@ -98,7 +105,3 @@ def to_input_name(s): match = re.match(r"(d\d*)(\w+)", s) assert (match.group(1) != ""), "it should be a grad style name." return match.group(2) - - -def to_grad_name(s): - return 'GradVarName("{}")'.format(to_pascal_case(s)) diff --git a/python/paddle/utils/code_gen/generate_op.py b/python/paddle/utils/code_gen/generate_op.py index 01f7f8610b865..0b314e4a11cb3 100644 --- a/python/paddle/utils/code_gen/generate_op.py +++ b/python/paddle/utils/code_gen/generate_op.py @@ -13,15 +13,16 @@ # limitations under the License. import argparse +import os from itertools import chain from pathlib import Path import yaml from jinja2 import Environment, FileSystemLoader, StrictUndefined -from filters import to_op_attr_type, to_opmaker_name, to_pascal_case +from filters import to_op_attr_type, to_opmaker_name, to_opmaker_name_cstr, to_pascal_case from tests import is_base_api, is_vec, is_scalar, is_initializer_list, supports_inplace, supports_no_need_buffer -from filters import to_input_name, to_grad_name +from filters import to_input_name from parse_utils import to_named_dict file_loader = FileSystemLoader(Path(__file__).parent / "templates") @@ -36,7 +37,7 @@ env.filters["to_opmaker_name"] = to_opmaker_name env.filters["to_pascal_case"] = to_pascal_case env.filters["to_input_name"] = to_input_name -env.filters["to_grad_name"] = to_grad_name +env.filters["to_opmaker_name_cstr"] = to_opmaker_name_cstr env.tests["base_api"] = is_base_api env.tests["vec"] = is_vec env.tests["scalar"] = is_scalar @@ -73,6 +74,10 @@ def main(api_yaml_path, backward_yaml_path, output_op_path, api_dict.update(backward_api_dict) if len(apis) == 0 and len(backward_apis) == 0: + if os.path.isfile(output_op_path): + os.remove(output_op_path) + if os.path.isfile(output_arg_map_path): + os.remove(output_arg_map_path) return op_template = env.get_template('op.c.j2') diff --git a/python/paddle/utils/code_gen/new_api.yaml b/python/paddle/utils/code_gen/new_api.yaml index f0ccbcb4f52a8..e69de29bb2d1d 100644 --- a/python/paddle/utils/code_gen/new_api.yaml +++ b/python/paddle/utils/code_gen/new_api.yaml @@ -1,9 +0,0 @@ -- api : linear - args : (Tensor x, Tensor y, Tensor b, bool transpose_x = false, bool transpose_y = false) - output : Tensor(out), Tensor(mm) - infer_meta : - func : LinearInferMeta - kernel : - func : linear - intermediate: mm - backward : linear_grad diff --git a/python/paddle/utils/code_gen/new_backward.yaml b/python/paddle/utils/code_gen/new_backward.yaml index d809ed9838431..e69de29bb2d1d 100644 --- a/python/paddle/utils/code_gen/new_backward.yaml +++ b/python/paddle/utils/code_gen/new_backward.yaml @@ -1,10 +0,0 @@ -- backward_api : linear_grad - forward : linear (Tensor x, Tensor y, Tensor b, bool transpose_x=false, bool transpose_y=false) -> Tensor(out), Tensor(mm) - args : (Tensor x, Tensor y, Tensor b, Tensor out, Tensor mm, Tensor out_grad, bool transpose_x=false, bool transpose_y=false) - output : Tensor(x_grad), Tensor(y_grad), Tensor(b_grad) - infer_meta : - func : GeneralTernaryGradInferMeta - param : [x, y, b] - kernel : - func : linear_grad - no_need_buffer: b, mm, out diff --git a/python/paddle/utils/code_gen/templates/ks.c.j2 b/python/paddle/utils/code_gen/templates/ks.c.j2 index d4485e68419c8..1848513b878e5 100644 --- a/python/paddle/utils/code_gen/templates/ks.c.j2 +++ b/python/paddle/utils/code_gen/templates/ks.c.j2 @@ -1,9 +1,13 @@ {% from "operator_utils.c.j2" import name_map, register_name_map %} +// this file is generated by python/paddle/utils/code_gen/generate_op.py, do not edit. #include "paddle/phi/core/compat/op_utils.h" +#include "paddle/fluid/framework/operator.h" #include "paddle/utils/small_vector.h" namespace phi { +using paddle::framework::GradVarName; + {% for api in apis %} {% if api is base_api %} {{name_map(api)}} diff --git a/python/paddle/utils/code_gen/templates/op.c.j2 b/python/paddle/utils/code_gen/templates/op.c.j2 index bc562a8231885..d4fd293ae460a 100644 --- a/python/paddle/utils/code_gen/templates/op.c.j2 +++ b/python/paddle/utils/code_gen/templates/op.c.j2 @@ -1,4 +1,5 @@ {% from "operator_utils.c.j2" import op_maker, backward_op_maker, operator, register_op_with_components %} +// this file is generated by python/paddle/utils/code_gen/generate_op.py, do not edit. #include #include "paddle/fluid/framework/infershape_utils.h" #include "paddle/fluid/framework/op_registry.h" diff --git a/python/paddle/utils/code_gen/templates/operator_utils.c.j2 b/python/paddle/utils/code_gen/templates/operator_utils.c.j2 index 1a266f574b6ca..2771833d5a335 100644 --- a/python/paddle/utils/code_gen/templates/operator_utils.c.j2 +++ b/python/paddle/utils/code_gen/templates/operator_utils.c.j2 @@ -95,7 +95,7 @@ static_cast(phi::Place({{"phi::" if not default_value is initializer_list}} KernelSignature {{api["name"] | to_pascal_case }}OpArgumentMapping(const ArgumentMappingContext& ctx) { {% set kernel_args = api["kernel"]["param"] %} {{get_input_list(api["inputs"], kernel_args)}}; - paddle::SmallVector attrs; + paddle::small_vector attrs; {% for attr in api["attrs"]%} {% filter indent(2)%} {{get_an_attr(attr)}}; @@ -112,10 +112,10 @@ PD_REGISTER_ARG_MAPPING_FN({{api["name"]}}, phi::{{api["name"] | to_pascal_case} {%- endmacro %} {% macro get_input_list(inputs, kernel_args) %}{# inline #} -paddle::SmallVector inputs { +paddle::small_vector inputs { {%- for input in inputs %} {%- if input["name"] in kernel_args %} -{{input["name"] | to_opmaker_name}}{{", " if not loop.last}} +{{input["name"] | to_opmaker_name_cstr}}{{", " if not loop.last}} {%- endif %} {%- endfor %} } @@ -144,9 +144,9 @@ attrs.emplace_back("{{name}}") {%- endmacro %} {% macro get_output_list(outputs, kernel_args) %}{# inline #} -paddle::SmallVector outputs { +paddle::small_vector outputs { {%- for output in outputs %} -{{output["name"] | to_opmaker_name}}{{", " if not loop.last}} +{{output["name"] | to_opmaker_name_cstr}}{{", " if not loop.last}} {%- endfor %} } {%- endmacro %} diff --git a/python/paddle/utils/code_gen/type_mapping.py b/python/paddle/utils/code_gen/type_mapping.py index 21b98a072aaf8..ecbd1f494c2ee 100644 --- a/python/paddle/utils/code_gen/type_mapping.py +++ b/python/paddle/utils/code_gen/type_mapping.py @@ -31,7 +31,6 @@ 'Scalar(int)': 'const Scalar&', 'Scalar(int64_t)': 'const Scalar&', 'Scalar(float)': 'const Scalar&', - 'Backend': 'Backend', 'Place': 'Place', 'DataLayout': 'DataLayout', 'DataType': 'DataType', @@ -59,7 +58,6 @@ 'Scalar(int)': 'int', 'Scalar(int64_t)': 'int64_t', 'Scalar(float)': 'float', - 'Backend': 'int', 'Place': 'int', 'DataLayout': 'int', 'DataType': 'int', @@ -84,7 +82,7 @@ #------------------------------ phi attr ------------------------------ phi_attr_types_map = attr_types_map.copy() phi_attr_types_map.update({ - 'ScalarArray': 'const phi::IntArray&', + 'IntArray': 'const phi::IntArray&', 'Scalar': 'const phi::Scalar&' })