未验证 提交 ad78a21e 编写于 作者: Z Zhanlue Yang 提交者: GitHub

Added copy_if_different for eager code generator (#38562)

上级 ecb8c184
...@@ -16,6 +16,15 @@ execute_process( ...@@ -16,6 +16,15 @@ execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/auto_code_generator/generate_file_structures.py" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/" COMMAND "${PYTHON_EXECUTABLE}" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/auto_code_generator/generate_file_structures.py" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/"
) )
set(tmp_dygraph_forward_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/dygraph_forward_api.tmp.h")
set(tmp_dygraph_forward_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions.tmp.cc")
set(tmp_dygraph_node_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes.tmp.h")
set(tmp_dygraph_node_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes.tmp.cc")
set(dygraph_forward_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/dygraph_forward_api.h")
set(dygraph_forward_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions.cc")
set(dygraph_node_h_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes.h")
set(dygraph_node_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes.cc")
if(WIN32) if(WIN32)
set(EAGER_CODEGEN_DEPS eager_generator) set(EAGER_CODEGEN_DEPS eager_generator)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja") if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
...@@ -48,6 +57,14 @@ if(WIN32) ...@@ -48,6 +57,14 @@ if(WIN32)
add_custom_target(eager_codegen add_custom_target(eager_codegen
COMMAND "${eager_generator_path}/eager_generator.exe" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated" COMMAND "${eager_generator_path}/eager_generator.exe" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_forward_h_path} ${dygraph_forward_h_path}
COMMENT "copy_if_different ${tmp_dygraph_forward_h_path} to ${dygraph_forward_h_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_forward_cc_path} ${dygraph_forward_cc_path}
COMMENT "copy_if_different ${tmp_dygraph_forward_cc_path} to ${dygraph_forward_cc_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_node_h_path} ${dygraph_node_h_path}
COMMENT "copy_if_different ${tmp_dygraph_node_h_path} to ${dygraph_node_h_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_node_cc_path} ${dygraph_node_cc_path}
COMMENT "copy_if_different ${tmp_dygraph_node_cc_path} to ${dygraph_node_cc_path}"
DEPENDS ${EAGER_CODEGEN_DEPS} DEPENDS ${EAGER_CODEGEN_DEPS}
VERBATIM) VERBATIM)
else() else()
...@@ -55,6 +72,14 @@ else() ...@@ -55,6 +72,14 @@ else()
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_CURRENT_BINARY_DIR}/../../pybind" COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_CURRENT_BINARY_DIR}/../../pybind"
"${CMAKE_CURRENT_BINARY_DIR}/eager_generator" "${CMAKE_CURRENT_BINARY_DIR}/eager_generator"
"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_forward_h_path} ${dygraph_forward_h_path}
COMMENT "copy_if_different ${tmp_dygraph_forward_h_path} to ${dygraph_forward_h_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_forward_cc_path} ${dygraph_forward_cc_path}
COMMENT "copy_if_different ${tmp_dygraph_forward_cc_path} to ${dygraph_forward_cc_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_node_h_path} ${dygraph_node_h_path}
COMMENT "copy_if_different ${tmp_dygraph_node_h_path} to ${dygraph_node_h_path}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_dygraph_node_cc_path} ${dygraph_node_cc_path}
COMMENT "copy_if_different ${tmp_dygraph_node_cc_path} to ${dygraph_node_cc_path}"
DEPENDS eager_generator DEPENDS eager_generator
VERBATIM) VERBATIM)
endif() endif()
...@@ -1847,19 +1847,15 @@ static std::string GenerateDygraphHFileIncludes() { ...@@ -1847,19 +1847,15 @@ static std::string GenerateDygraphHFileIncludes() {
return dygraph_forward_api_includes_str; return dygraph_forward_api_includes_str;
} }
static void GenerateForwardHFile(const std::string& output_dir, static void GenerateForwardHFile(const std::string& dygraph_forward_api_path,
const std::string& dygraph_forward_api_str) { const std::string& dygraph_forward_api_str) {
std::string dygraph_forward_api_path = output_dir + "/dygraph_forward_api.h";
std::ofstream forward_header_stream(dygraph_forward_api_path, std::ios::out); std::ofstream forward_header_stream(dygraph_forward_api_path, std::ios::out);
forward_header_stream << dygraph_forward_api_str; forward_header_stream << dygraph_forward_api_str;
forward_header_stream.close(); forward_header_stream.close();
} }
static void GenerateForwardDygraphFile(const std::string& output_dir, static void GenerateForwardDygraphFile(const std::string& forward_cc_path,
const std::string& fwd_function_str) { const std::string& fwd_function_str) {
std::string forwards_dir = output_dir + "/forwards/";
std::string forward_cc_filename = "dygraph_forward_functions.cc";
std::string forward_cc_path = forwards_dir + forward_cc_filename;
const char* FORWARD_INCLUDE_TEMPLATE = const char* FORWARD_INCLUDE_TEMPLATE =
"#include " "#include "
"\"paddle/fluid/eager/api/generated/fluid_generated/" "\"paddle/fluid/eager/api/generated/fluid_generated/"
...@@ -1876,11 +1872,8 @@ static void GenerateForwardDygraphFile(const std::string& output_dir, ...@@ -1876,11 +1872,8 @@ static void GenerateForwardDygraphFile(const std::string& output_dir,
forward_cc_stream.close(); forward_cc_stream.close();
} }
static void GenerateNodeHFile(const std::string& output_dir, static void GenerateNodeHFile(const std::string& node_h_path,
const std::string& grad_node_str) { const std::string& grad_node_str) {
std::string nodes_dir = output_dir + "/nodes/";
std::string node_h_filename = "nodes.h";
std::string node_h_path = nodes_dir + node_h_filename;
std::string node_h_include_str = std::string node_h_include_str =
"#pragma once\n" "#pragma once\n"
"#include \"paddle/fluid/eager/tensor_wrapper.h\"\n" "#include \"paddle/fluid/eager/tensor_wrapper.h\"\n"
...@@ -1892,11 +1885,8 @@ static void GenerateNodeHFile(const std::string& output_dir, ...@@ -1892,11 +1885,8 @@ static void GenerateNodeHFile(const std::string& output_dir,
node_h_stream.close(); node_h_stream.close();
} }
static void GenerateNodeCCFile(const std::string& output_dir, static void GenerateNodeCCFile(const std::string& node_cc_path,
const std::string& grad_function_str) { const std::string& grad_function_str) {
std::string nodes_dir = output_dir + "/nodes/";
std::string node_cc_filename = "nodes.cc";
std::string node_cc_path = nodes_dir + node_cc_filename;
const char* NODE_CC_INCLUDE_TEMPLATE = const char* NODE_CC_INCLUDE_TEMPLATE =
"#include \"glog/logging.h\"\n" "#include \"glog/logging.h\"\n"
"#include \"paddle/pten/api/all.h\"\n" "#include \"paddle/pten/api/all.h\"\n"
...@@ -2026,18 +2016,24 @@ static void DygraphCodeGeneration(const std::string& output_dir) { ...@@ -2026,18 +2016,24 @@ static void DygraphCodeGeneration(const std::string& output_dir) {
} }
VLOG(6) << "-------- GenerateDygraphForwardCCFile -------"; VLOG(6) << "-------- GenerateDygraphForwardCCFile -------";
std::string forward_cc_path =
output_dir + "/forwards/dygraph_forward_functions.tmp.cc";
fwd_function_str += "\n"; fwd_function_str += "\n";
fwd_function_str += GenerateCoreOpsReturnsInfo(); fwd_function_str += GenerateCoreOpsReturnsInfo();
GenerateForwardDygraphFile(output_dir, fwd_function_str); GenerateForwardDygraphFile(forward_cc_path, fwd_function_str);
VLOG(6) << "-------- GenerateForwardHFile -------"; VLOG(6) << "-------- GenerateForwardHFile -------";
GenerateForwardHFile(output_dir, dygraph_forward_api_str); std::string dygraph_forward_api_path =
output_dir + "/dygraph_forward_api.tmp.h";
GenerateForwardHFile(dygraph_forward_api_path, dygraph_forward_api_str);
VLOG(6) << "-------- GenerateNodeHFile -------"; VLOG(6) << "-------- GenerateNodeHFile -------";
GenerateNodeHFile(output_dir, grad_node_h_str); std::string node_h_path = output_dir + "/nodes/nodes.tmp.h";
GenerateNodeHFile(node_h_path, grad_node_h_str);
VLOG(6) << "-------- GenerateNodeCCFile -------"; VLOG(6) << "-------- GenerateNodeCCFile -------";
GenerateNodeCCFile(output_dir, grad_node_cc_str); std::string node_cc_path = output_dir + "/nodes/nodes.tmp.cc";
GenerateNodeCCFile(node_cc_path, grad_node_cc_str);
} }
static void PrepareAttrMapForOps() { static void PrepareAttrMapForOps() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册