From bd1f6a79293be03266e5daec08be96226acb6977 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 9 Jan 2017 15:55:43 +0800 Subject: [PATCH] Fix swig on linux and clean cmake --- CMakeLists.txt | 9 ++++++++- cmake/external/python.cmake | 4 ---- cmake/util.cmake | 20 -------------------- paddle/api/CMakeLists.txt | 11 ++++++++--- paddle/api/test/run_tests.sh | 8 ++++++-- paddle/setup.py.in | 16 ++++++++-------- 6 files changed, 30 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abe7b5228..5d3ff0657 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,14 +72,21 @@ include_directories("${PROJ_ROOT}/paddle/cuda/include") include_directories("${CMAKE_CURRENT_BINARY_DIR}/proto") set(EXTERNAL_LIBS - # have not include gtest here. ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES} ${CBLAS_LIBRARIES} ${PROTOBUF_LIBRARY} ${ZLIB_LIBRARIES} + ${PYTHON_LIBRARIES} ) +if(WITH_GPU) + list(APPEND EXTERNAL_LIB ${CUDA_LIBRARIES} ${CUDA_rt_LIBRARY}) + if(NOT WITH_DSO) + list(APPEND EXTERNAL_LIB ${CUDNN_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY}) + endif(NOT WITH_DSO) +endif(WITH_GPU) + add_subdirectory(proto) add_subdirectory(paddle) add_subdirectory(python) diff --git a/cmake/external/python.cmake b/cmake/external/python.cmake index cbb694022..2f86ab390 100644 --- a/cmake/external/python.cmake +++ b/cmake/external/python.cmake @@ -216,7 +216,3 @@ ENDIF(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR}) - -MESSAGE("[Paddle] Python Executable: ${PYTHON_EXECUTABLE}") -MESSAGE("[Paddle] Python Include: ${PYTHON_INCLUDE_DIRS}") -MESSAGE("[Paddle] Python Libraries: ${PYTHON_LIBRARIES}") diff --git a/cmake/util.cmake b/cmake/util.cmake index 7da52bb75..29f5128f6 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -95,32 +95,12 @@ function(link_paddle_exe TARGET_NAME) paddle_parameter paddle_proto paddle_cuda - ${METRIC_LIBS} ${EXTERNAL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} ${RDMA_LD_FLAGS} ${RDMA_LIBS}) - if(WITH_PYTHON) - target_link_libraries(${TARGET_NAME} - ${PYTHON_LIBRARIES} util) - endif() - - if(WITH_GPU) - if(NOT WITH_DSO OR WITH_METRIC) - target_link_libraries(${TARGET_NAME} - ${CUDNN_LIBRARY} - ${CUDA_curand_LIBRARY}) - CUDA_ADD_CUBLAS_TO_TARGET(${TARGET_NAME}) - endif() - - check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME ) - if(HAVE_CLOCK_GETTIME) - target_link_libraries(${TARGET_NAME} rt) - endif() - endif() - add_dependencies(${TARGET_NAME} ${external_project_dependencies}) endfunction() diff --git a/paddle/api/CMakeLists.txt b/paddle/api/CMakeLists.txt index 0caa5d38a..88d6b7169 100644 --- a/paddle/api/CMakeLists.txt +++ b/paddle/api/CMakeLists.txt @@ -45,6 +45,9 @@ SET(SWIG_MODULE_swig_paddle_EXTRA_DEPS IF(APPLE) SET(CMAKE_LINK_FLAGS "-undefined dynamic_lookup -Wl,-all_load") +ELSE(APPLE) + SET(ARCHIVE_START "-Wl,--whole-archive") + SET(ARCHIVE_END "-Wl,--no-whole-archive") ENDIF(APPLE) SWIG_ADD_MODULE(swig_paddle python Paddle.i) @@ -52,21 +55,23 @@ SWIG_LINK_LIBRARIES(swig_paddle ${CMAKE_LINK_FLAGS} ${CMAKE_DL_LIBS} ${EXTERNAL_LIBS} - ${PYTHON_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${RDMA_LD_FLAGS} ${RDMA_LIBS} paddle_parameter - paddle_function paddle_math paddle_utils - paddle_gserver paddle_pserver paddle_api paddle_cuda paddle_trainer_lib paddle_network paddle_proto + ARCHIVE_START + paddle_gserver + paddle_function + ${METRIC_LIBS} + ARCHIVE_END ) add_custom_command(OUTPUT ${PROJ_ROOT}/paddle/dist/.timestamp diff --git a/paddle/api/test/run_tests.sh b/paddle/api/test/run_tests.sh index bcf06afa8..d3b74fb97 100755 --- a/paddle/api/test/run_tests.sh +++ b/paddle/api/test/run_tests.sh @@ -20,7 +20,11 @@ popd > /dev/null cd $SCRIPTPATH -$1 -m pip install ../../dist/*.whl +rm -rf .test_env +virtualenv .test_env +source .test_env/bin/activate + +python -m pip install ../../dist/*.whl test_list="testArguments.py testGradientMachine.py testMatrix.py testVector.py testTrain.py testTrainer.py" @@ -29,7 +33,7 @@ export PYTHONPATH=$PWD/../../../python/ for fn in $test_list do echo "test $fn" - $1 $fn + python $fn if [ $? -ne 0 ]; then exit 1 fi diff --git a/paddle/setup.py.in b/paddle/setup.py.in index 3f60261ef..8cfa485bd 100644 --- a/paddle/setup.py.in +++ b/paddle/setup.py.in @@ -16,12 +16,12 @@ from setuptools import setup, Extension setup(name="py_paddle", - version="@PADDLE_VERSION@", - packages=['py_paddle'], - include_package_data=True, - package_data={'py_paddle':['*.py','_swig_paddle.so']}, - install_requires = [ - 'numpy>=1.8.0', # The numpy is required. - 'protobuf>=2.4.1' # The paddle protobuf version - ], + version="@PADDLE_VERSION@", + packages=['py_paddle'], + include_package_data=True, + package_data={'py_paddle':['*.py','_swig_paddle.so']}, + install_requires = [ + 'numpy>=1.8.0', # The numpy is required. + 'protobuf>=2.4.1' # The paddle protobuf version + ], ) -- GitLab