diff --git a/paddle/fluid/eager/auto_code_generator/final_state_generator/CMakeLists.txt b/paddle/fluid/eager/auto_code_generator/final_state_generator/CMakeLists.txt index 771351dd4affbb355748c275a59681a6d5ba5577..8e89ea3f19762b339671a8418ed5d192bca846eb 100644 --- a/paddle/fluid/eager/auto_code_generator/final_state_generator/CMakeLists.txt +++ b/paddle/fluid/eager/auto_code_generator/final_state_generator/CMakeLists.txt @@ -8,6 +8,8 @@ set(forwards_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/eage set(forwards_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/eager_generated/forwards/dygraph_functions.h") set(nodes_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/eager_generated/backwards/nodes.cc") set(nodes_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/eager_generated/backwards/nodes.h") +# StringTensor only needs forward api +set(fwd_api_yaml_path "${PADDLE_SOURCE_DIR}/python/paddle/utils/code_gen/strings_api.yaml") message("Final State Eager CodeGen") add_custom_target(eager_final_state_codegen @@ -30,7 +32,7 @@ set(python_c_output_path "${PADDLE_SOURCE_DIR}/paddle/fluid/pybind/eager_final_s add_custom_target(eager_final_state_python_c_codegen COMMAND "${PYTHON_EXECUTABLE}" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py" - "--api_yaml_path=${api_yaml_path}" + "--api_yaml_path=${api_yaml_path},${fwd_api_yaml_path}" "--output_path=${tmp_python_c_output_path}" COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_python_c_output_path} ${python_c_output_path} VERBATIM diff --git a/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py b/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py index 4699fe73552c7e4ba2eda37584b9e1cb2054abd1..89939a68f2abd2804eb18c2b13d78193e8efa4b2 100644 --- a/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py +++ b/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py @@ -421,3 +421,5 @@ class YamlGeneratorBase: api_yaml_path = self.api_yaml_path if "sparse" in api_yaml_path: self.namespace = "sparse::" + elif "strings" in api_yaml_path: + self.namespace = "strings::" diff --git a/paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py b/paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py index 4b557f7f5cfe55067a4a84ca9574bbeea2f0d2ec..797fec9752fab67aa1d8529f2ae4658183d10dc4 100644 --- a/paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py +++ b/paddle/fluid/eager/auto_code_generator/final_state_generator/python_c_gen.py @@ -125,7 +125,7 @@ FUNCTION_NAME_TEMPLATE = \ PYTHON_C_FUNCTION_REG_TEMPLATE = \ """ -{{\"final_state_{}\", (PyCFunction)(void(*)(void)) {}eager_final_state_api_{}, METH_VARARGS | METH_KEYWORDS, \"C++ interface function for {} in dygraph.\"}} +{{\"final_state_{}{}\", (PyCFunction)(void(*)(void)) {}eager_final_state_api_{}, METH_VARARGS | METH_KEYWORDS, \"C++ interface function for {} in dygraph.\"}} """ @@ -142,6 +142,7 @@ PYTHON_C_WRAPPER_TEMPLATE = \ #include "paddle/phi/common/scalar.h" #include "paddle/phi/common/scalar_array.h" #include "paddle/phi/api/include/sparse_api.h" +#include "paddle/phi/api/include/strings_api.h" #include "paddle/fluid/pybind/op_function_common.h" #include "paddle/fluid/eager/api/generated/eager_generated/forwards/dygraph_functions.h" #include "paddle/fluid/pybind/exception.h" @@ -328,9 +329,13 @@ class PythonCSingleFunctionGenerator(FunctionGeneratorBase): get_eager_tensor_str, parse_attributes_str, fwd_function_name, dygraph_function_call_str, return_str) + # Set prefix of forward_api_name to avoid conflicts + prefix = self.namespace.strip("::") + forward_api_name_prefix = "" if prefix == "" else prefix + "_" # Generate Python-C Function Registration self.python_c_function_reg_str = PYTHON_C_FUNCTION_REG_TEMPLATE.format( - forward_api_name, namespace, forward_api_name, forward_api_name) + forward_api_name_prefix, forward_api_name, namespace, + forward_api_name, forward_api_name) if len(inplace_map) > 0: assert len( @@ -361,8 +366,8 @@ class PythonCSingleFunctionGenerator(FunctionGeneratorBase): # Generate Python-C Function Registration self.python_c_function_reg_str += "\n," + PYTHON_C_FUNCTION_REG_TEMPLATE.format( - inplaced_forward_api_name, namespace, inplaced_forward_api_name, - inplaced_forward_api_name) + forward_api_name_prefix, inplaced_forward_api_name, namespace, + inplaced_forward_api_name, inplaced_forward_api_name) def run(self): # Initialized is_forward_only