Skip to content

Commit

Permalink
update operator generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfeiyu committed May 10, 2022
1 parent 12a788d commit 761be90
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 339 deletions.
1 change: 0 additions & 1 deletion paddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
38 changes: 36 additions & 2 deletions paddle/phi/api/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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}
Expand Down
11 changes: 0 additions & 11 deletions paddle/phi/infermeta/ternary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
7 changes: 0 additions & 7 deletions paddle/phi/infermeta/ternary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 0 additions & 30 deletions paddle/phi/kernels/cpu/linear_grad_kernel.cc

This file was deleted.

30 changes: 0 additions & 30 deletions paddle/phi/kernels/cpu/linear_kernel.cc

This file was deleted.

30 changes: 0 additions & 30 deletions paddle/phi/kernels/gpu/linear_grad_kernel.cu

This file was deleted.

30 changes: 0 additions & 30 deletions paddle/phi/kernels/gpu/linear_kernel.cu

This file was deleted.

45 changes: 0 additions & 45 deletions paddle/phi/kernels/impl/linear_grad_kernel_impl.h

This file was deleted.

49 changes: 0 additions & 49 deletions paddle/phi/kernels/impl/linear_kernel_impl.h

This file was deleted.

36 changes: 0 additions & 36 deletions paddle/phi/kernels/linear_grad_kernel.h

This file was deleted.

Loading

0 comments on commit 761be90

Please sign in to comment.