diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b6a80ca43cf131c6886455cb5a86a61246ac17c..5762baa2579396e42f9aacbe21287a597a1a4f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ option(WITH_COVERAGE "Compile PaddlePaddle with code coverage" OFF) option(COVERALLS_UPLOAD "Package code coverage data to coveralls" OFF) option(ON_TRAVIS "Exclude special unit test on Travis CI" OFF) option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF) +option(WITH_Go "Compile PaddlePaddle with Go)" OFF) # CMAKE_BUILD_TYPE if(NOT CMAKE_BUILD_TYPE) @@ -107,6 +108,7 @@ include(configure) # add paddle env configuration include_directories("${PROJ_ROOT}") include_directories("${PROJ_ROOT}/paddle/cuda/include") include_directories("${CMAKE_CURRENT_BINARY_DIR}/proto") +include_directories("${CMAKE_BINARY_DIR}/go/pserver/cclient") set(EXTERNAL_LIBS ${GFLAGS_LIBRARIES} @@ -126,9 +128,12 @@ endif(WITH_GPU) add_subdirectory(proto) add_subdirectory(paddle) -add_subdirectory(go/master/c) add_subdirectory(python) -add_subdirectory(go/pserver/cclient) + +if(WITH_Go) + #add_subdirectory(go/pserver/cclient) + add_subdirectory(go/master/c) +endif(WITH_Go) if(WITH_DOC) add_subdirectory(doc) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index 5e507e78f74eee885922f502f35e3c15fafb622d..44c86bc4797e6615728e7981f4e481507b803202 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -40,6 +40,10 @@ if(NOT CMAKE_CROSSCOMPILING) endif() endif() +if(NOT WITH_Go) + add_definitions(-DPADDLE_WITHOUT_GO) +endif() + if(NOT WITH_GPU) add_definitions(-DPADDLE_ONLY_CPU) add_definitions(-DHPPL_STUB_FUNC) diff --git a/go/cmake/golang.cmake b/go/cmake/golang.cmake index a5a43886f887e495500fa26b3c26fa69c63eded0..446f930f38b3c2493600d2731a284204c6b3fc04 100644 --- a/go/cmake/golang.cmake +++ b/go/cmake/golang.cmake @@ -10,7 +10,8 @@ function(GO_LIBRARY NAME BUILD_TYPE) else() set(BUILD_MODE -buildmode=c-shared) if(APPLE) - set(LIB_NAME "lib${NAME}.dylib") +# set(LIB_NAME "lib${NAME}.dylib") + set(LIB_NAME "lib${NAME}.so") else() set(LIB_NAME "lib${NAME}.so") endif() diff --git a/go/pserver/cclient/CMakeLists.txt b/go/pserver/cclient/CMakeLists.txt index 7967af51ee9a94c9e40bf6403fe819ff462d9219..fff7ae78582732c1b7af7a757c340804e91316d6 100644 --- a/go/pserver/cclient/CMakeLists.txt +++ b/go/pserver/cclient/CMakeLists.txt @@ -11,13 +11,4 @@ include(flags) go_library(paddle_pserver_cclient STATIC) -if(PROJ_ROOT) - add_custom_command(OUTPUT ${PROJ_ROOT}/paddle/trainer/libpaddle_pserver_cclient.a - COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/libpaddle_pserver_cclient.h ${PROJ_ROOT}/paddle/trainer/ - COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/libpaddle_pserver_cclient.a ${PROJ_ROOT}/paddle/trainer/ - WORKING_DIRECTORY ${PROJ_ROOT}/paddle - DEPENDS paddle_pserver_cclient) - add_custom_target(paddle_pserver_cclient_lib ALL DEPENDS ${PROJ_ROOT}/paddle/trainer/libpaddle_pserver_cclient.a) -endif(PROJ_ROOT) - add_subdirectory(test) diff --git a/go/pserver/cclient/test/test_mnist.py b/go/pserver/cclient/test/test_mnist.py index c3a3af55e2812fa0c965d22ddaba198f43f3c4ad..d6fecc81b976d42d9be749eb0055a169f389f12e 100644 --- a/go/pserver/cclient/test/test_mnist.py +++ b/go/pserver/cclient/test/test_mnist.py @@ -81,7 +81,7 @@ def main(): trainer = paddle.trainer.SGD(cost=cost, parameters=parameters, update_equation=optimizer, - is_local=False, + is_local=True, pserver_spec="localhost:3000") lists = [] diff --git a/paddle/api/CMakeLists.txt b/paddle/api/CMakeLists.txt index c9433a38de4d005ebe229c55916401a5f82e9ef3..f2315e31cc06d8b5fea7a9fd203a697bac603a90 100644 --- a/paddle/api/CMakeLists.txt +++ b/paddle/api/CMakeLists.txt @@ -16,7 +16,7 @@ set(API_HEADER Internal.h) add_library(paddle_api STATIC ${API_SOURCES}) -add_dependencies(paddle_api gen_proto_cpp paddle_pserver_cclient_lib) +add_dependencies(paddle_api gen_proto_cpp paddle_trainer_lib) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${PROJ_ROOT}/paddle) diff --git a/paddle/api/PaddleAPI.h b/paddle/api/PaddleAPI.h index 7565ea51fe3e71bf81a28e6e4b5a2bbdd085798c..d4b80fccbd7936f591f9b40410101bee4baf6030 100644 --- a/paddle/api/PaddleAPI.h +++ b/paddle/api/PaddleAPI.h @@ -842,7 +842,7 @@ public: int passCount, bool useSparseUpdater); static ParameterUpdater* createNewRemoteUpdater( - OptimizationConfig* config, const std::string pserverSpec); + OptimizationConfig* config, const std::string pserverSpec) throw(UnsupportError); ~ParameterUpdater(); /** diff --git a/paddle/api/ParameterUpdater.cpp b/paddle/api/ParameterUpdater.cpp index eaf8518ae2beaa93bc40ee944c984d142d2bb951..7eb860cffc31b6cd69645d3eabfc52c371cfe822 100644 --- a/paddle/api/ParameterUpdater.cpp +++ b/paddle/api/ParameterUpdater.cpp @@ -15,7 +15,9 @@ limitations under the License. */ #include "PaddleAPI.h" #include "PaddleAPIPrivate.h" +#ifndef PADDLE_WITHOUT_GO #include "paddle/trainer/NewRemoteParameterUpdater.h" +#endif #include "paddle/trainer/RemoteParameterUpdater.h" #include "paddle/trainer/ThreadParameterUpdater.h" @@ -29,12 +31,17 @@ ParameterUpdater *ParameterUpdater::createLocalUpdater( return updater; } -ParameterUpdater *ParameterUpdater::createNewRemoteUpdater( - OptimizationConfig *config, const std::string pserverSpec) { +ParameterUpdater *ParameterUpdater::createNewRemoteUpdater ( + OptimizationConfig *config, const std::string pserverSpec) +throw(UnsupportError) { +#ifndef PADDLE_WITHOUT_GO auto updater = new ParameterUpdater(); updater->m->updater.reset(new paddle::NewRemoteParameterUpdater( config->m->getConfig(), pserverSpec)); return updater; +#else + throw UnsupportError(); +#endif } ParameterUpdater *ParameterUpdater::createRemoteUpdater( diff --git a/paddle/optimizer/CMakeLists.txt b/paddle/optimizer/CMakeLists.txt index 791be95efa9e8063a2f4b9632d86db2f5bc751e6..4536f62ec7c2c3423d91e309dee993d4212160fe 100644 --- a/paddle/optimizer/CMakeLists.txt +++ b/paddle/optimizer/CMakeLists.txt @@ -12,5 +12,7 @@ set(OPITMIZER_SRCS add_library(paddle_optimizer STATIC ${OPITMIZER_SRCS}) add_dependencies(paddle_optimizer gen_proto_cpp) -add_simple_unittest(serialization_test) -add_simple_unittest(parameter_optimizer_test) +if(WITH_TESTING) + add_simple_unittest(serialization_test) + add_simple_unittest(parameter_optimizer_test) +endif() diff --git a/paddle/trainer/CMakeLists.txt b/paddle/trainer/CMakeLists.txt index 9d246b6690134d96e9a262c6ac64d998536128a9..1072e3d5080222cc8d5b745c38dc095c6af895f5 100644 --- a/paddle/trainer/CMakeLists.txt +++ b/paddle/trainer/CMakeLists.txt @@ -26,6 +26,13 @@ set(TRAINER_HEADERS ThreadParameterUpdater.h TrainerConfigHelper.h) +if(NOT WITH_Go) + list(REMOVE_ITEM TRAINER_SOURCES + NewRemoteParameterUpdater.cpp) + list(REMOVE_ITEM TRAINER_HEADERS + NewRemoteParameterUpdater.h) +endif() + add_library(paddle_trainer_lib STATIC ${TRAINER_SOURCES}) @@ -34,7 +41,7 @@ add_style_check_target(paddle_trainer_lib add_style_check_target(paddle_trainer_lib ${TRAINER_HEADERS}) add_dependencies(paddle_trainer_lib - gen_proto_cpp paddle_pserver_cclient_lib) + gen_proto_cpp) macro(add_paddle_exe TARGET_NAME) add_executable(${TARGET_NAME} ${ARGN}) @@ -63,5 +70,8 @@ if(APPLE) set(CMAKE_EXE_LINKER_FLAGS "-framework CoreFoundation -framework Security") endif() -target_link_libraries(paddle_trainer ${CMAKE_CURRENT_SOURCE_DIR}/libpaddle_pserver_cclient.a) -target_link_libraries(paddle_trainer_lib ${CMAKE_CURRENT_SOURCE_DIR}/libpaddle_pserver_cclient.a) +if(WITH_Go) + add_dependencies(paddle_trainer_lib paddle_pserver_cclient) + target_link_libraries(paddle_trainer ${CMAKE_BINARY_DIR}/go/pserver/cclient/libpaddle_pserver_cclient.a) + target_link_libraries(paddle_trainer_lib ${CMAKE_BINARY_DIR}/go/pserver/cclient/libpaddle_pserver_cclient.a) +endif(WITH_Go) diff --git a/proto/CMakeLists.txt b/proto/CMakeLists.txt index 9b98dd3fde4d141a35d93c0981acb287831c3eaf..c942620990765832f21c887d30f85a2d211a5f32 100644 --- a/proto/CMakeLists.txt +++ b/proto/CMakeLists.txt @@ -36,10 +36,8 @@ foreach(filename ${proto_filenames}) DEPENDS ${filename} ${external_project_dependencies}) endforeach() -include_directories(${CMAKE_CURRENT_BINARY_DIR}/proto) - add_custom_target(gen_proto_cpp ALL DEPENDS ${PROTO_GEN}) add_custom_target(gen_proto_py ALL DEPENDS ${PROTO_GEN_PY}) -add_library(paddle_proto STATIC - ${PROTO_GEN}) + +add_library(paddle_proto STATIC ${PROTO_GEN}) target_include_directories(paddle_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0e17c42d34f147db190ac5e5ccd5339360cc35bb..3640dd3a75ea212a84255ea7f6369b63606482ab 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -18,7 +18,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in add_custom_command(OUTPUT ${OUTPUT_DIR}/.timestamp COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT_DIR}/.timestamp - DEPENDS gen_proto_py ${PY_FILES} ${external_project_dependencies} paddle_master_shared) + DEPENDS gen_proto_py ${PY_FILES} ${external_project_dependencies}) add_custom_target(paddle_python ALL DEPENDS ${OUTPUT_DIR}/.timestamp)