-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine the generation process of swig's python wrapper #1099
Changes from 6 commits
4cafb6d
8c3a9e6
bd1f6a7
a355493
d44f5e9
336334c
29f9c0d
ee628a4
c1d9300
4cacbd1
8a09b2e
c0d6317
62acf32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
FUNCTION(generate_python_api target_name) | ||
ADD_CUSTOM_COMMAND(OUTPUT ${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py | ||
${PROJ_ROOT}/paddle/Paddle_wrap.cxx | ||
${PROJ_ROOT}/paddle/Paddle_wrap.h | ||
COMMAND ${SWIG_EXECUTABLE} -python -c++ -outcurrentdir -I../ api/Paddle.swig | ||
&& mv ${PROJ_ROOT}/paddle/swig_paddle.py ${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py | ||
DEPENDS ${PROJ_ROOT}/paddle/api/Paddle.swig | ||
${PROJ_ROOT}/paddle/api/PaddleAPI.h | ||
${external_project_dependencies} | ||
WORKING_DIRECTORY ${PROJ_ROOT}/paddle | ||
COMMENT "Generate Python API from swig") | ||
ADD_CUSTOM_TARGET(${target_name} ALL DEPENDS | ||
${PROJ_ROOT}/paddle/Paddle_wrap.cxx | ||
${PROJ_ROOT}/paddle/Paddle_wrap.h | ||
${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py | ||
${external_project_dependencies}) | ||
ENDFUNCTION(generate_python_api) | ||
|
||
set(API_SOURCES | ||
Arguments.cpp | ||
ConfigParser.cpp | ||
|
@@ -33,65 +15,85 @@ set(API_HEADER | |
PaddleAPI.h | ||
Internal.h) | ||
|
||
add_library(paddle_api STATIC | ||
${API_SOURCES}) | ||
add_library(paddle_api STATIC ${API_SOURCES}) | ||
add_dependencies(paddle_api gen_proto_cpp) | ||
|
||
list(LENGTH "${GFLAGS_LIBRARIES}" GFLAGS_LIBRARIES_LENGTH) | ||
INCLUDE(${SWIG_USE_FILE}) | ||
INCLUDE_DIRECTORIES(${PROJ_ROOT}/paddle) | ||
|
||
if(${GFLAGS_LIBRARIES_LENGTH} EQUAL 0 AND TARGET "${GFLAGS_LIBRARIES}") | ||
# Because gflags compiled by cmake, so it is imported by cmake target, | ||
# not a real library path. Get the real library path here. | ||
message(STATUS "GFLAGS Libraries is ${GFLAGS_LIBRARIES}") | ||
get_target_property(GFLAGS_LOCATION ${GFLAGS_LIBRARIES} LOCATION) | ||
message(STATUS "GFLAGS Target location is ${GFLAGS_LOCATION}") | ||
else() | ||
set(GFLAGS_LOCATION ${GFLAGS_LIBRARIES}) | ||
endif() | ||
FILE(GLOB PY_PADDLE_PYTHON_FILES ${PROJ_ROOT}/paddle/py_paddle/*.py) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GLOB => GLOB_RECURSE 因为我们可能会在这个包里面加一些其他的子目录,子目录下面也有PY文件。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 删掉了 好像这里没起什么作用 以后新增的py,直接在https://github.com/PaddlePaddle/Paddle/pull/1099/files#diff-409abc2eda4ed1dba2c69defc807748dR22 里面加,直观一些。 |
||
|
||
SET_SOURCE_FILES_PROPERTIES(Paddle.i PROPERTIES CPLUSPLUS ON) | ||
|
||
configure_file( | ||
paddle_api_config.py.in | ||
${PROJ_ROOT}/paddle/api/paddle_api_config.py | ||
SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
SET(CMAKE_CXX_FLAGS "-std=c++11 -fPIC -Wall") | ||
IF(WITH_COVERAGE) | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") | ||
ENDIF(WITH_COVERAGE) | ||
|
||
SET(SWIG_MODULE_swig_paddle_EXTRA_DEPS | ||
paddle_parameter | ||
paddle_function | ||
paddle_math | ||
paddle_utils | ||
paddle_gserver | ||
paddle_pserver | ||
paddle_api | ||
paddle_cuda | ||
paddle_trainer_lib | ||
paddle_network | ||
paddle_proto | ||
${PY_PADDLE_PYTHON_FILES} | ||
${external_project_dependencies} | ||
) | ||
|
||
generate_python_api(python_swig_sources) | ||
IF(APPLE) | ||
SET(ARCHIVE_START "-undefined dynamic_lookup -Wl,-all_load") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 记得 -all_load 不太等于ARCHIVE_START... |
||
ELSE(APPLE) | ||
SET(START_GROUP "-Xlinker -start-group") | ||
SET(END_GROUP "-Xlinker -end-group") | ||
SET(ARCHIVE_START "-Wl,--whole-archive") | ||
SET(ARCHIVE_END "-Wl,--no-whole-archive") | ||
ENDIF(APPLE) | ||
|
||
file(GLOB PY_PADDLE_PYTHON_FILES ${PROJ_ROOT}/paddle/py_paddle/*.py) | ||
SWIG_ADD_MODULE(swig_paddle python Paddle.i) | ||
SWIG_LINK_LIBRARIES(swig_paddle | ||
${START_GROUP} | ||
${ARCHIVE_START} | ||
paddle_gserver | ||
paddle_function | ||
${METRIC_LIBS} | ||
${ARCHIVE_END} | ||
paddle_pserver | ||
paddle_trainer_lib | ||
paddle_network | ||
paddle_parameter | ||
paddle_math | ||
paddle_utils | ||
paddle_proto | ||
paddle_cuda | ||
paddle_api | ||
${CMAKE_DL_LIBS} | ||
${EXTERNAL_LIBS} | ||
${CMAKE_THREAD_LIBS_INIT} | ||
${RDMA_LD_FLAGS} | ||
${RDMA_LIBS} | ||
${START_END} | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这个事情其实还是没有fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert 了 |
||
# TODO(yuyang18) : make wheel name calculated by cmake | ||
add_custom_command(OUTPUT ${PROJ_ROOT}/paddle/dist/.timestamp | ||
COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/swig_paddle.py ${PROJ_ROOT}/paddle/py_paddle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个可以重新搞一下。 1、应该用cp而不是用 mv,否则,${CMAKE_CURRENT_BINARY_DIR}/swig_paddle.py 会永远不存在,然后每次make的时候都会编译。 2、之前用timestamp来标记这个OUTPUT其实是个trick
|
||
&& mv ${CMAKE_CURRENT_BINARY_DIR}/_swig_paddle.so ${PROJ_ROOT}/paddle/py_paddle | ||
COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel | ||
COMMAND ${CMAKE_COMMAND} -E touch dist/.timestamp | ||
COMMAND rm -rf py_paddle.egg-info build | ||
WORKING_DIRECTORY ${PROJ_ROOT}/paddle | ||
DEPENDS python_swig_sources | ||
paddle_parameter | ||
paddle_function | ||
paddle_math | ||
paddle_utils | ||
paddle_gserver | ||
paddle_pserver | ||
paddle_trainer | ||
paddle_api | ||
paddle_cuda | ||
${PY_PADDLE_PYTHON_FILES} | ||
DEPENDS _swig_paddle | ||
) | ||
|
||
install(DIRECTORY ${PROJ_ROOT}/paddle/dist/ | ||
DESTINATION opt/paddle/share/wheels | ||
) | ||
add_custom_target(python_api_wheel ALL DEPENDS ${PROJ_ROOT}/paddle/dist/.timestamp) | ||
|
||
add_custom_target(python_api_wheel ALL DEPENDS | ||
${PROJ_ROOT}/paddle/dist/.timestamp) | ||
add_dependencies(python_api_wheel python_swig_sources | ||
paddle_parameter | ||
paddle_math | ||
paddle_utils | ||
paddle_gserver | ||
paddle_pserver | ||
paddle_trainer | ||
paddle_api | ||
paddle_cuda) | ||
install(DIRECTORY ${PROJ_ROOT}/paddle/dist/ DESTINATION opt/paddle/share/wheels) | ||
|
||
if(WITH_TESTING) | ||
IF(NOT PY_PIP_FOUND) | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重复