From 20cda7bd23195da38dec324f8a7b4ac698fec1f4 Mon Sep 17 00:00:00 2001 From: liaogang Date: Thu, 4 May 2017 17:27:05 +0800 Subject: [PATCH 01/30] auto check lapack libs --- cmake/cblas.cmake | 4 +++- cmake/external/openblas.cmake | 1 + paddle/math/MathFunctions.cpp | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index 0918e6cc63..91663a16ba 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -33,7 +33,6 @@ find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS ${MKL_ROOT}/lib ${MKL_ROOT}/lib/intel64) - if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) set(CBLAS_PROVIDER MKL) set(CBLAS_INC_DIR ${MKL_INC_DIR}) @@ -41,6 +40,7 @@ if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) ${MKL_SEQUENTIAL_LIB} ${MKL_CORE_LIB}) add_definitions(-DPADDLE_USE_MKL) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found MKL (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(${MKL_LAPACK_INC_DIR}) @@ -76,6 +76,7 @@ if(ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_LIB AND NOT CBLAS_FOUND) set(CBLAS_INC_DIR ${ATLAS_INC_DIR}) set(CBLAS_LIBRARIES ${ATLAS_LIB} ${ATLAS_CBLAS_LIB}) add_definitions(-DPADDLE_USE_ATLAS) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found ATLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(ATLAS_CLAPACK_INC_DIR) @@ -110,6 +111,7 @@ if(OPENBLAS_INC_DIR AND OPENBLAS_LIB) set(CBLAS_PROVIDER OPENBLAS) set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR}) set(CBLAS_LIBRARIES ${OPENBLAS_LIB}) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found OpenBLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(OPENBLAS_LAPACKE_INC_DIR) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 46398b22c2..86cb473c38 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -15,6 +15,7 @@ INCLUDE(cblas) IF(NOT ${CBLAS_FOUND}) + SET(LAPACK_FOUND OFF) INCLUDE(ExternalProject) SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas) diff --git a/paddle/math/MathFunctions.cpp b/paddle/math/MathFunctions.cpp index 802a56a0d1..1a3bb432bf 100644 --- a/paddle/math/MathFunctions.cpp +++ b/paddle/math/MathFunctions.cpp @@ -34,6 +34,9 @@ void* lapack_dso_handle = nullptr; // We have to use two levels of macro to do the expansion. // See https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html #define STR(x) #x + +// clang-format off +#ifndef LAPACK_FOUND #define DYNAMIC_LOAD_LAPACK_WRAP(__name) \ struct DynLoad__##__name { \ template \ @@ -46,8 +49,16 @@ void* lapack_dso_handle = nullptr; return reinterpret_cast(p_##__name)(args...); \ } \ } __name; // struct DynLoad__##__name +#else +#define DYNAMIC_LOAD_LAPACK_WRAP(__name) \ + struct DynLoad__##__name { \ + template \ + auto operator()(Args... args) -> decltype(__name(args...)) { \ + return __name(args...); \ + } \ + } __name; // struct DynLoad__##__name +#endif -// clang-format off #ifdef PADDLE_USE_ATLAS #define PADDLE_SGETRF clapack_sgetrf #define PADDLE_DGETRF clapack_dgetrf From c1cb483a6c5cdd10956a2659dc76214004e75bb1 Mon Sep 17 00:00:00 2001 From: "yi.wu" Date: Thu, 4 May 2017 22:34:35 +0800 Subject: [PATCH 02/30] paddle.init default use env --- python/paddle/v2/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 7c8f6ea62f..7a9d3a73f4 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import optimizer import layer import activation @@ -42,6 +43,12 @@ __all__ = [ def init(**kwargs): args = [] + # NOTE: append arguments if they are in ENV + for ek, ev in os.environ.iteritems(): + if ek.startswith("PADDLE_"): + args.append('--%s=%s' % (ek.replace("PADDLE_", "").lower(), str(ev))) + + # NOTE: overwrite arguments from ENV if it is in kwargs for key in kwargs.keys(): args.append('--%s=%s' % (key, str(kwargs[key]))) From f9e36971f3346cd3274bb9d67c4d9b39ea5ee732 Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 5 May 2017 10:29:14 +0800 Subject: [PATCH 03/30] Add Lapack warning --- cmake/external/openblas.cmake | 1 - paddle/math/tests/test_matrixCompare.cpp | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 86cb473c38..46398b22c2 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -15,7 +15,6 @@ INCLUDE(cblas) IF(NOT ${CBLAS_FOUND}) - SET(LAPACK_FOUND OFF) INCLUDE(ExternalProject) SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas) diff --git a/paddle/math/tests/test_matrixCompare.cpp b/paddle/math/tests/test_matrixCompare.cpp index 782a9613d8..05adec6370 100644 --- a/paddle/math/tests/test_matrixCompare.cpp +++ b/paddle/math/tests/test_matrixCompare.cpp @@ -236,8 +236,16 @@ TEST(Matrix, unary) { testMatrixTranspose(height, width); testMatrixRotate(height, width); } + #ifdef LAPACK_FOUND // inverse matrix testMatrixInverse(height); + #else + LOG(WARNING) << "Cannot run Matrix Inverse Unit Test.\n" + << "Failed to find lapack library in current system.\n" + << "To address this issue, Please adopt one of the following approaches: \n" + << "1. Simply issue `sudo apt-get install liblapacke-dev` to avoid re-build source code. \n" + << "2. Install MKL/Openblas/ATLAS and re-build PaddlePaddle source code." + #endif } } From 81195c877e809fda705f7f9d854bfcd196b184b3 Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 5 May 2017 10:30:38 +0800 Subject: [PATCH 04/30] remove lapack header in openblas --- cmake/external/openblas.cmake | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 46398b22c2..5b042fec01 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -40,16 +40,6 @@ IF(NOT ${CBLAS_FOUND}) UPDATE_COMMAND "" CONFIGURE_COMMAND "" ) - - ExternalProject_Add_Step( - openblas lapacke_install - COMMAND ${CMAKE_COMMAND} -E copy "${CBLAS_SOURCES_DIR}/src/openblas/lapack-netlib/LAPACKE/include/lapacke_mangling_with_flags.h" "${CBLAS_INSTALL_DIR}/include/lapacke_mangling.h" - COMMAND ${CMAKE_COMMAND} -E copy "${CBLAS_SOURCES_DIR}/src/openblas/lapack-netlib/LAPACKE/include/lapacke.h" "${CBLAS_INSTALL_DIR}/include/lapacke.h" - COMMAND ${CMAKE_COMMAND} -E copy "${CBLAS_SOURCES_DIR}/src/openblas/lapack-netlib/LAPACKE/include/lapacke_config.h" "${CBLAS_INSTALL_DIR}/include/lapacke_config.h" - COMMAND ${CMAKE_COMMAND} -E copy "${CBLAS_SOURCES_DIR}/src/openblas/lapack-netlib/LAPACKE/include/lapacke_utils.h" "${CBLAS_INSTALL_DIR}/include/lapacke_utils.h" - DEPENDEES install - ) - LIST(APPEND external_project_dependencies openblas) ENDIF(NOT ${CBLAS_FOUND}) From 47b13a409ab6f030b3c193d09ee852662c89ed54 Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 5 May 2017 13:30:19 +0800 Subject: [PATCH 05/30] clang format code --- paddle/math/tests/test_matrixCompare.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/paddle/math/tests/test_matrixCompare.cpp b/paddle/math/tests/test_matrixCompare.cpp index 05adec6370..2bdcab4d86 100644 --- a/paddle/math/tests/test_matrixCompare.cpp +++ b/paddle/math/tests/test_matrixCompare.cpp @@ -236,16 +236,19 @@ TEST(Matrix, unary) { testMatrixTranspose(height, width); testMatrixRotate(height, width); } - #ifdef LAPACK_FOUND +#ifdef LAPACK_FOUND // inverse matrix testMatrixInverse(height); - #else +#else LOG(WARNING) << "Cannot run Matrix Inverse Unit Test.\n" << "Failed to find lapack library in current system.\n" - << "To address this issue, Please adopt one of the following approaches: \n" - << "1. Simply issue `sudo apt-get install liblapacke-dev` to avoid re-build source code. \n" - << "2. Install MKL/Openblas/ATLAS and re-build PaddlePaddle source code." - #endif + << "To address this issue, Please adopt one of the following " + "approaches: \n" + << "1. Simply issue `sudo apt-get install liblapacke-dev` to " + "avoid re-build source code. \n" + << "2. Install MKL/Openblas/ATLAS and re-build PaddlePaddle " + "source code." +#endif } } From 444c4638c21167e138e945f9b91d6afa9a72a63c Mon Sep 17 00:00:00 2001 From: "yi.wu" Date: Fri, 5 May 2017 22:54:50 +0800 Subject: [PATCH 06/30] update for pre-commit --- python/paddle/v2/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 7a9d3a73f4..0942334ca2 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -46,7 +46,8 @@ def init(**kwargs): # NOTE: append arguments if they are in ENV for ek, ev in os.environ.iteritems(): if ek.startswith("PADDLE_"): - args.append('--%s=%s' % (ek.replace("PADDLE_", "").lower(), str(ev))) + args.append('--%s=%s' % (ek.replace("PADDLE_", "").lower(), + str(ev))) # NOTE: overwrite arguments from ENV if it is in kwargs for key in kwargs.keys(): From e4656c27172b8eb243ef79bd72c97f2728c87f86 Mon Sep 17 00:00:00 2001 From: liaogang Date: Sat, 6 May 2017 17:20:14 +0800 Subject: [PATCH 07/30] using one thread to dump sequential output --- paddle/scripts/docker/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/scripts/docker/build.sh b/paddle/scripts/docker/build.sh index bc8eef4ea8..2850e24b3a 100644 --- a/paddle/scripts/docker/build.sh +++ b/paddle/scripts/docker/build.sh @@ -34,7 +34,7 @@ cmake .. \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON make -j `nproc` if [ ${WITH_TESTING:-OFF} == "ON" ] && [ ${RUN_TEST:-OFF} == "ON" ] ; then - ctest -V -j `nproc` + ctest -V fi make install pip install /usr/local/opt/paddle/share/wheels/*.whl From feaf12d4f2ec451fb141577a27d50588ea6f70a6 Mon Sep 17 00:00:00 2001 From: liaogang Date: Sat, 6 May 2017 19:05:19 +0800 Subject: [PATCH 08/30] fix bug when enable gpu unit test on docker --- Dockerfile | 2 +- paddle/scripts/docker/build.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3ad0c9c2f..6d5797da9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN apt-get update && \ apt-get install -y git python-pip python-dev openssh-server bison && \ apt-get install -y wget unzip tar xz-utils bzip2 gzip coreutils && \ apt-get install -y curl sed grep graphviz libjpeg-dev zlib1g-dev && \ - apt-get install -y python-numpy python-matplotlib gcc g++ gfortran && \ + apt-get install -y python-numpy python-matplotlib gcc g++ liblapack-dev liblapacke-dev && \ apt-get install -y automake locales clang-format-3.8 swig doxygen && \ apt-get clean -y diff --git a/paddle/scripts/docker/build.sh b/paddle/scripts/docker/build.sh index 2850e24b3a..f1743813ab 100644 --- a/paddle/scripts/docker/build.sh +++ b/paddle/scripts/docker/build.sh @@ -34,7 +34,8 @@ cmake .. \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON make -j `nproc` if [ ${WITH_TESTING:-OFF} == "ON" ] && [ ${RUN_TEST:-OFF} == "ON" ] ; then - ctest -V + pip uninstall -y py-paddle paddle + ctest -V fi make install pip install /usr/local/opt/paddle/share/wheels/*.whl From 1b85a13c6df3b5648102a31b1d3b5412360c85f5 Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Mon, 8 May 2017 10:09:17 +0800 Subject: [PATCH 09/30] Remove the feenableexcept in initPaddle. --- paddle/capi/Main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/paddle/capi/Main.cpp b/paddle/capi/Main.cpp index 7f24561e9a..78c43949df 100644 --- a/paddle/capi/Main.cpp +++ b/paddle/capi/Main.cpp @@ -25,7 +25,6 @@ limitations under the License. */ static void initPaddle(int argc, char** argv) { paddle::initMain(argc, argv); paddle::initPython(argc, argv); - feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW); } extern "C" { From 886e4becc2fffb7ec5e8313e154a4da9ad6988cd Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 10:49:37 +0800 Subject: [PATCH 10/30] fix gpu_img_conv2 float precision issue --- paddle/gserver/tests/test_NetworkCompare.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/paddle/gserver/tests/test_NetworkCompare.cpp b/paddle/gserver/tests/test_NetworkCompare.cpp index 4db30f37a5..ff1c195cee 100644 --- a/paddle/gserver/tests/test_NetworkCompare.cpp +++ b/paddle/gserver/tests/test_NetworkCompare.cpp @@ -261,9 +261,12 @@ TEST(Compare, img_conv2) { std::string config_file_a = "./gserver/tests/img_conv_a.conf"; std::string config_file_b = "./gserver/tests/img_conv_c.conf"; bool useGpu = FLAGS_use_gpu; + double eps = FLAGS_checkgrad_eps; FLAGS_use_gpu = true; + FLAGS_checkgrad_eps = 1e-3; compareNetwork(config_file_a, config_file_b); FLAGS_use_gpu = useGpu; + FLAGS_checkgrad_eps = eps; } #endif From faf26f0a6d3828ba6edea238a2b8450d51fdb4ae Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 11:09:04 +0800 Subject: [PATCH 11/30] force delete packages before unit test --- paddle/scripts/docker/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/scripts/docker/build.sh b/paddle/scripts/docker/build.sh index f1743813ab..9e72c68d4b 100644 --- a/paddle/scripts/docker/build.sh +++ b/paddle/scripts/docker/build.sh @@ -34,7 +34,7 @@ cmake .. \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON make -j `nproc` if [ ${WITH_TESTING:-OFF} == "ON" ] && [ ${RUN_TEST:-OFF} == "ON" ] ; then - pip uninstall -y py-paddle paddle + pip uninstall -y py-paddle paddle || true ctest -V fi make install From e5b10732b2e30f8015d1c49ce76ac722dba961d9 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 16:28:53 +0800 Subject: [PATCH 12/30] change lapack to lapacke --- paddle/utils/DynamicLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/utils/DynamicLoader.cpp b/paddle/utils/DynamicLoader.cpp index 87c36eae6f..76cf3c3006 100644 --- a/paddle/utils/DynamicLoader.cpp +++ b/paddle/utils/DynamicLoader.cpp @@ -165,8 +165,8 @@ void GetWarpCTCDsoHandle(void** dso_handle) { void GetLapackDsoHandle(void** dso_handle) { #if defined(__APPLE__) || defined(__OSX__) - GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapack.dylib", dso_handle); + GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.dylib", dso_handle); #else - GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapack.so", dso_handle); + GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.so", dso_handle); #endif } From 724130258b8c70c35cb271f6dd483082ae2a705b Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 16:41:38 +0800 Subject: [PATCH 13/30] remove cmake python output --- cmake/util.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/util.cmake b/cmake/util.cmake index 966e0a7bf6..b828eef322 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -149,7 +149,6 @@ endfunction() # Create a python unittest using run_python_tests.sh, # which takes care of making correct running environment function(add_python_test TEST_NAME) - message("PYTHON: ${PYTHON_EXECUTABLE}") add_test(NAME ${TEST_NAME} COMMAND bash ${PROJ_ROOT}/paddle/scripts/run_python_tests.sh ${USE_VIRTUALENV_FOR_TEST} ${PYTHON_EXECUTABLE} ${ARGN} From e9ddff0047283beeeebf15ec9c64c6e0bc35cf95 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 19:17:27 +0800 Subject: [PATCH 14/30] modify img_conv2 unit test --- paddle/gserver/tests/config_file_a.conf | 28 ++++++++++++++++++++ paddle/gserver/tests/config_file_b.conf | 28 ++++++++++++++++++++ paddle/gserver/tests/test_NetworkCompare.cpp | 7 ++--- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 paddle/gserver/tests/config_file_a.conf create mode 100644 paddle/gserver/tests/config_file_b.conf diff --git a/paddle/gserver/tests/config_file_a.conf b/paddle/gserver/tests/config_file_a.conf new file mode 100644 index 0000000000..5e4668f4ff --- /dev/null +++ b/paddle/gserver/tests/config_file_a.conf @@ -0,0 +1,28 @@ +#edit-mode: -*- python -*- +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from paddle.trainer_config_helpers import * + +settings(batch_size=10) +data = data_layer(name ="input", size=8*16*16) +conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, + num_channels=8, + num_filters=16, stride=1, + bias_attr=True, + act=LinearActivation(), + groups=2, + layer_type="cudnn_conv") + +outputs(conv) diff --git a/paddle/gserver/tests/config_file_b.conf b/paddle/gserver/tests/config_file_b.conf new file mode 100644 index 0000000000..2de45466ce --- /dev/null +++ b/paddle/gserver/tests/config_file_b.conf @@ -0,0 +1,28 @@ +#edit-mode: -*- python -*- +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from paddle.trainer_config_helpers import * + +settings(batch_size=10) +data = data_layer(name ="input", size=8*16*16) +conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, + num_channels=8, + num_filters=16, stride=1, + bias_attr=True, + act=LinearActivation(), + groups=2, + layer_type="exconv") + +outputs(conv) diff --git a/paddle/gserver/tests/test_NetworkCompare.cpp b/paddle/gserver/tests/test_NetworkCompare.cpp index ff1c195cee..51b0e48bcc 100644 --- a/paddle/gserver/tests/test_NetworkCompare.cpp +++ b/paddle/gserver/tests/test_NetworkCompare.cpp @@ -258,15 +258,12 @@ TEST(Compare, img_conv) { // Test cudnn_conv and exconv give the same result TEST(Compare, img_conv2) { - std::string config_file_a = "./gserver/tests/img_conv_a.conf"; - std::string config_file_b = "./gserver/tests/img_conv_c.conf"; + std::string config_file_a = "./gserver/tests/config_file_a.conf"; + std::string config_file_b = "./gserver/tests/config_file_b.conf"; bool useGpu = FLAGS_use_gpu; - double eps = FLAGS_checkgrad_eps; FLAGS_use_gpu = true; - FLAGS_checkgrad_eps = 1e-3; compareNetwork(config_file_a, config_file_b); FLAGS_use_gpu = useGpu; - FLAGS_checkgrad_eps = eps; } #endif From e094e095b5ea88cadf3c149ba06e0565146acac1 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 19:19:44 +0800 Subject: [PATCH 15/30] change to lapacke --- paddle/utils/DynamicLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/utils/DynamicLoader.cpp b/paddle/utils/DynamicLoader.cpp index 87c36eae6f..76cf3c3006 100644 --- a/paddle/utils/DynamicLoader.cpp +++ b/paddle/utils/DynamicLoader.cpp @@ -165,8 +165,8 @@ void GetWarpCTCDsoHandle(void** dso_handle) { void GetLapackDsoHandle(void** dso_handle) { #if defined(__APPLE__) || defined(__OSX__) - GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapack.dylib", dso_handle); + GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.dylib", dso_handle); #else - GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapack.so", dso_handle); + GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.so", dso_handle); #endif } From b99891325afdd1cfe3a37ba27f7c0f9a3bd91afa Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 19:52:06 +0800 Subject: [PATCH 16/30] update file name --- paddle/gserver/tests/{config_file_a.conf => img_conv_cudnn.py} | 0 paddle/gserver/tests/{config_file_b.conf => img_conv_exconv.py} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename paddle/gserver/tests/{config_file_a.conf => img_conv_cudnn.py} (100%) rename paddle/gserver/tests/{config_file_b.conf => img_conv_exconv.py} (100%) diff --git a/paddle/gserver/tests/config_file_a.conf b/paddle/gserver/tests/img_conv_cudnn.py similarity index 100% rename from paddle/gserver/tests/config_file_a.conf rename to paddle/gserver/tests/img_conv_cudnn.py diff --git a/paddle/gserver/tests/config_file_b.conf b/paddle/gserver/tests/img_conv_exconv.py similarity index 100% rename from paddle/gserver/tests/config_file_b.conf rename to paddle/gserver/tests/img_conv_exconv.py From 96b33e1e6a33de6fee8276f60b10068080a9b3b3 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 19:53:14 +0800 Subject: [PATCH 17/30] update file name --- paddle/gserver/tests/test_NetworkCompare.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/gserver/tests/test_NetworkCompare.cpp b/paddle/gserver/tests/test_NetworkCompare.cpp index 51b0e48bcc..698a972b62 100644 --- a/paddle/gserver/tests/test_NetworkCompare.cpp +++ b/paddle/gserver/tests/test_NetworkCompare.cpp @@ -258,8 +258,8 @@ TEST(Compare, img_conv) { // Test cudnn_conv and exconv give the same result TEST(Compare, img_conv2) { - std::string config_file_a = "./gserver/tests/config_file_a.conf"; - std::string config_file_b = "./gserver/tests/config_file_b.conf"; + std::string config_file_a = "./gserver/tests/img_conv_cudnn.py"; + std::string config_file_b = "./gserver/tests/img_conv_exconv.py"; bool useGpu = FLAGS_use_gpu; FLAGS_use_gpu = true; compareNetwork(config_file_a, config_file_b); From eef91cd811d78d083949c54d4c6865893263e55b Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 8 May 2017 20:31:05 +0800 Subject: [PATCH 18/30] clang-format --- paddle/gserver/tests/img_conv_cudnn.py | 20 ++++++++++++-------- paddle/gserver/tests/img_conv_exconv.py | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/paddle/gserver/tests/img_conv_cudnn.py b/paddle/gserver/tests/img_conv_cudnn.py index 5e4668f4ff..3934607fa4 100644 --- a/paddle/gserver/tests/img_conv_cudnn.py +++ b/paddle/gserver/tests/img_conv_cudnn.py @@ -16,13 +16,17 @@ from paddle.trainer_config_helpers import * settings(batch_size=10) -data = data_layer(name ="input", size=8*16*16) -conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, - num_channels=8, - num_filters=16, stride=1, - bias_attr=True, - act=LinearActivation(), - groups=2, - layer_type="cudnn_conv") +data = data_layer(name="input", size=8 * 16 * 16) +conv = img_conv_layer( + input=data, + filter_size=1, + filter_size_y=1, + num_channels=8, + num_filters=16, + stride=1, + bias_attr=True, + act=LinearActivation(), + groups=2, + layer_type="cudnn_conv") outputs(conv) diff --git a/paddle/gserver/tests/img_conv_exconv.py b/paddle/gserver/tests/img_conv_exconv.py index 2de45466ce..ad5a8ba2bd 100644 --- a/paddle/gserver/tests/img_conv_exconv.py +++ b/paddle/gserver/tests/img_conv_exconv.py @@ -16,13 +16,17 @@ from paddle.trainer_config_helpers import * settings(batch_size=10) -data = data_layer(name ="input", size=8*16*16) -conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1, - num_channels=8, - num_filters=16, stride=1, - bias_attr=True, - act=LinearActivation(), - groups=2, - layer_type="exconv") +data = data_layer(name="input", size=8 * 16 * 16) +conv = img_conv_layer( + input=data, + filter_size=1, + filter_size_y=1, + num_channels=8, + num_filters=16, + stride=1, + bias_attr=True, + act=LinearActivation(), + groups=2, + layer_type="exconv") outputs(conv) From 2b924ac85dac1312828a16a6e270908b0dd15c21 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Tue, 9 May 2017 11:29:12 +0800 Subject: [PATCH 19/30] Disable the finding of PythonLibs when WITH_PYTHON is set to OFF. --- cmake/external/python.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/external/python.cmake b/cmake/external/python.cmake index fc66d6b215..f4d0daab06 100644 --- a/cmake/external/python.cmake +++ b/cmake/external/python.cmake @@ -16,11 +16,13 @@ INCLUDE(ExternalProject) INCLUDE(python_module) FIND_PACKAGE(PythonInterp 2.7) -FIND_PACKAGE(PythonLibs 2.7) +IF(WITH_PYTHON) + FIND_PACKAGE(PythonLibs 2.7) +ENDIF(WITH_PYTHON) SET(py_env "") SET(USE_VIRTUALENV_FOR_TEST 1) -IF(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) +IF(PYTHONINTERP_FOUND) find_python_module(pip REQUIRED) find_python_module(numpy REQUIRED) find_python_module(wheel REQUIRED) @@ -30,7 +32,7 @@ IF(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) MESSAGE(FATAL_ERROR "Found Python Protobuf ${PY_GOOGLE.PROTOBUF_VERSION} < 3.0.0, " "please use pip to upgrade protobuf. pip install -U protobuf") ENDIF() -ELSE(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) +ELSE(PYTHONINTERP_FOUND) MESSAGE(FATAL_ERROR "Please install python 2.7 before building PaddlePaddle.") ##################################### PYTHON ######################################## SET(PYTHON_SOURCES_DIR ${THIRD_PARTY_PATH}/python) @@ -217,7 +219,7 @@ ELSE(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) LIST(APPEND external_project_dependencies python setuptools six cython wheel python-protobuf numpy) -ENDIF(PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) +ENDIF(PYTHONINTERP_FOUND) IF(WITH_PYTHON) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) From 43493b2a59f17cd768875f15c09c3432c3955300 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 9 May 2017 14:05:35 +0800 Subject: [PATCH 20/30] Expose Inference in Python V2 API. --- python/paddle/v2/inference.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/python/paddle/v2/inference.py b/python/paddle/v2/inference.py index 1fea7917e1..b4bb384969 100644 --- a/python/paddle/v2/inference.py +++ b/python/paddle/v2/inference.py @@ -5,15 +5,22 @@ import topology import minibatch from data_feeder import DataFeeder -__all__ = ['infer'] +__all__ = ['infer', 'Inference'] class Inference(object): """ Inference combines neural network output and parameters together to do inference. + + .. code-block:: python + + inferer = Inference(output_layer=prediction, parameters=parameters) + for data_batch in batches: + print inferer.infer(data_batch) + - :param outptut_layer: The neural network that should be inferenced. + :param output_layer: The neural network that should be inferenced. :type output_layer: paddle.v2.config_base.Layer or the sequence of paddle.v2.config_base.Layer :param parameters: The parameters dictionary. @@ -56,8 +63,14 @@ class Inference(object): item = [each_result[each_field] for each_field in field] yield item - def infer(self, field='value', **kwargs): + def infer(self, input, field='value', **kwargs): + """ + Infer a data by model. + :param input: input data batch. Should be python iterable object. + :param field: output field. + """ retv = None + kwargs['input'] = input for result in self.iter_infer_field(field=field, **kwargs): if retv is None: retv = [[] for i in xrange(len(result))] @@ -79,7 +92,7 @@ def infer(output_layer, parameters, input, feeding=None, field='value'): .. code-block:: python - result = paddle.infer(outptut_layer=prediction, + result = paddle.infer(output_layer=prediction, parameters=parameters, input=SomeData) print result From f3eb6e91469e98c3c0af9c2e86ae071bdbd6b657 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 14:18:50 +0800 Subject: [PATCH 21/30] refine cblas.cmake --- cmake/cblas.cmake | 58 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index 91663a16ba..bb084192f8 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -33,20 +33,18 @@ find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS ${MKL_ROOT}/lib ${MKL_ROOT}/lib/intel64) -if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) +if(MKL_LAPACK_INC_DIR AND MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) + set(CBLAS_FOUND ON) set(CBLAS_PROVIDER MKL) - set(CBLAS_INC_DIR ${MKL_INC_DIR}) - set(CBLAS_LIBRARIES ${MKL_INTEL_LP64} - ${MKL_SEQUENTIAL_LIB} - ${MKL_CORE_LIB}) + set(CBLAS_INC_DIR ${MKL_INC_DIR} ${MKL_LAPACK_INC_DIR}) + set(CBLAS_LIBRARIES ${MKL_INTEL_LP64} ${MKL_SEQUENTIAL_LIB} ${MKL_CORE_LIB}) + add_definitions(-DPADDLE_USE_MKL) add_definitions(-DLAPACK_FOUND) - message(STATUS "Found MKL (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") - set(CBLAS_FOUND ON) - if(${MKL_LAPACK_INC_DIR}) - message(STATUS "Found lapack in MKL (include: ${MKL_LAPACK_INC_DIR})") - endif() - return() # return file. + + message(STATUS "Found MKL (include: ${MKL_INC_DIR}, library: ${CBLAS_LIBRARIES})") + message(STATUS "Found lapack in MKL (include: ${MKL_LAPACK_INC_DIR})") + return() endif() ## Then find atlas. @@ -68,21 +66,20 @@ find_path(ATLAS_CLAPACK_INC_DIR NAMES clapack.h PATHS ${ATLAS_INCLUDE_SEARCH_PATHS}) find_library(ATLAS_CBLAS_LIB NAMES cblas libcblas.so.3 PATHS ${ATLAS_LIB_SEARCH_PATHS}) -find_library(ATLAS_LIB NAMES lapack_atlas liblapack_atlas.so.3 +find_library(ATLAS_CLAPACK_LIB NAMES lapack_atlas liblapack_atlas.so.3 PATHS ${ATLAS_LIB_SEARCH_PATHS}) -if(ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_LIB AND NOT CBLAS_FOUND) +if(ATLAS_CLAPACK_INC_DIR AND ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_CLAPACK_LIB) + set(CBLAS_FOUND ON) set(CBLAS_PROVIDER ATLAS) - set(CBLAS_INC_DIR ${ATLAS_INC_DIR}) - set(CBLAS_LIBRARIES ${ATLAS_LIB} ${ATLAS_CBLAS_LIB}) + set(CBLAS_INC_DIR ${ATLAS_INC_DIR} ${ATLAS_CLAPACK_INC_DIR}) + set(CBLAS_LIBRARIES ${ATLAS_CLAPACK_LIB} ${ATLAS_CBLAS_LIB}) + add_definitions(-DPADDLE_USE_ATLAS) add_definitions(-DLAPACK_FOUND) - message(STATUS "Found ATLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") - set(CBLAS_FOUND ON) - if(ATLAS_CLAPACK_INC_DIR) - set(CBLAS_INC_DIR ${CBLAS_INC_DIR} ${ATLAS_CLAPACK_INC_DIR}) - message(STATUS "Found lapack in ATLAS (include: ${ATLAS_CLAPACK_INC_DIR})") - endif() + + message(STATUS "Found ATLAS (include: ${ATLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") + message(STATUS "Found lapack in ATLAS (include: ${ATLAS_CLAPACK_INC_DIR})") return() endif() @@ -107,16 +104,16 @@ find_path(OPENBLAS_LAPACKE_INC_DIR NAMES lapacke.h find_library(OPENBLAS_LIB NAMES openblas PATHS ${OPENBLAS_LIB_SEARCH_PATHS}) -if(OPENBLAS_INC_DIR AND OPENBLAS_LIB) +if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB) + set(CBLAS_FOUND ON) set(CBLAS_PROVIDER OPENBLAS) - set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR}) + set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR}) set(CBLAS_LIBRARIES ${OPENBLAS_LIB}) + add_definitions(-DLAPACK_FOUND) - message(STATUS "Found OpenBLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") - set(CBLAS_FOUND ON) - if(OPENBLAS_LAPACKE_INC_DIR) - message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})") - endif() + + message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") + message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})") return() endif() @@ -145,9 +142,10 @@ find_library(REFERENCE_CBLAS_LIBRARY NAMES cblas PATHS ${REFERENCE_CBLAS_LIB_SEARCH_PATHS}) if (REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY) + set(CBLAS_FOUND ON) set(CBLAS_PROVIDER REFERENCE) set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR}) set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY}) - message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBS})") - set(CBLAS_FOUND ON) + + message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") endif() From 6dc58cdd2585873e95ccde3ace0696e54c6a6c53 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 14:21:58 +0800 Subject: [PATCH 22/30] modify float precision in img_conv2 --- paddle/gserver/tests/test_NetworkCompare.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/paddle/gserver/tests/test_NetworkCompare.cpp b/paddle/gserver/tests/test_NetworkCompare.cpp index 698a972b62..40e662b22b 100644 --- a/paddle/gserver/tests/test_NetworkCompare.cpp +++ b/paddle/gserver/tests/test_NetworkCompare.cpp @@ -261,9 +261,12 @@ TEST(Compare, img_conv2) { std::string config_file_a = "./gserver/tests/img_conv_cudnn.py"; std::string config_file_b = "./gserver/tests/img_conv_exconv.py"; bool useGpu = FLAGS_use_gpu; + double eps = FLAGS_checkgrad_eps; FLAGS_use_gpu = true; + FLAGS_checkgrad_eps = 1e-2; compareNetwork(config_file_a, config_file_b); FLAGS_use_gpu = useGpu; + FLAGS_checkgrad_eps = eps; } #endif From 1d5d9da9db2dfed356de33dd07ae96769ca52f10 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 15:15:02 +0800 Subject: [PATCH 23/30] refine cblas.cmake --- cmake/cblas.cmake | 3 ++- cmake/external/openblas.cmake | 2 +- paddle/math/MathFunctions.h | 29 ++++++++++++++++++++---- paddle/math/tests/test_matrixCompare.cpp | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index bb084192f8..913f711aff 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -110,6 +110,7 @@ if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB) set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR}) set(CBLAS_LIBRARIES ${OPENBLAS_LIB}) + add_definitions(-DPADDLE_USE_OPENBLAS) add_definitions(-DLAPACK_FOUND) message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") @@ -146,6 +147,6 @@ if (REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY) set(CBLAS_PROVIDER REFERENCE) set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR}) set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY}) - + add_definitions(-DPADDLE_USE_REFERENCE_CBLAS) message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") endif() diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 5b042fec01..18ac74aa6f 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -36,7 +36,7 @@ IF(NOT ${CBLAS_FOUND}) INSTALL_DIR ${CBLAS_INSTALL_DIR} BUILD_IN_SOURCE 1 BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} FC=${CMAKE_Fortran_COMPILER} CC=${CMAKE_C_COMPILER} HOSTCC=${CMAKE_C_COMPILER} NO_LAPACK=1 DYNAMIC_ARCH=1 NO_SHARED=1 libs netlib - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install NO_SHARED=1 PREFIX= + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install NO_SHARED=1 NO_LAPACK=1 PREFIX= UPDATE_COMMAND "" CONFIGURE_COMMAND "" ) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index c8559eefd8..c1d233b6cb 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -18,17 +18,36 @@ limitations under the License. */ #ifdef PADDLE_USE_MKL #include #include -#else -extern "C" { -#include -} +#endif + #ifdef PADDLE_USE_ATLAS extern "C" { +#include #include } -#else +#endif + +#ifdef PADDLE_USE_OPENBLAS +#include #include #endif + +#ifdef PADDLE_USE_REFERENCE_CBLAS +extern "C" { +#include +} +#endif + +#ifndef LAPACK_FOUND +extern "C" { +int LAPACKE_sgetrf(int matrix_layout, int m, int n, +int LAPACKE_dgetrf(int matrix_layout, int m, int n, + double* a, int lda, int* ipiv); +int LAPACKE_sgetri(int matrix_layout, int n, float* a, + int lda, const int* ipiv); +int LAPACKE_dgetri(int matrix_layout, int n, double* a, + int lda, const int* ipiv); +} #endif #include diff --git a/paddle/math/tests/test_matrixCompare.cpp b/paddle/math/tests/test_matrixCompare.cpp index 2bdcab4d86..5a0dffe086 100644 --- a/paddle/math/tests/test_matrixCompare.cpp +++ b/paddle/math/tests/test_matrixCompare.cpp @@ -247,7 +247,7 @@ TEST(Matrix, unary) { << "1. Simply issue `sudo apt-get install liblapacke-dev` to " "avoid re-build source code. \n" << "2. Install MKL/Openblas/ATLAS and re-build PaddlePaddle " - "source code." + "source code."; #endif } } From e2644fffc5b62293b1f12ff56bcd5d470b2e2e3d Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 15:29:48 +0800 Subject: [PATCH 24/30] add semicolon --- paddle/math/MathFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index c1d233b6cb..315e16bff7 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -47,7 +47,7 @@ int LAPACKE_sgetri(int matrix_layout, int n, float* a, int lda, const int* ipiv); int LAPACKE_dgetri(int matrix_layout, int n, double* a, int lda, const int* ipiv); -} +}; #endif #include From e22aa12b5246a1ec5d58e8daab5eb04308a475af Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 15:50:07 +0800 Subject: [PATCH 25/30] fix a bug --- paddle/math/MathFunctions.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index 315e16bff7..8c5f9dd479 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -32,14 +32,9 @@ extern "C" { #include #endif -#ifdef PADDLE_USE_REFERENCE_CBLAS -extern "C" { -#include -} -#endif - #ifndef LAPACK_FOUND extern "C" { +#include int LAPACKE_sgetrf(int matrix_layout, int m, int n, int LAPACKE_dgetrf(int matrix_layout, int m, int n, double* a, int lda, int* ipiv); @@ -47,7 +42,7 @@ int LAPACKE_sgetri(int matrix_layout, int n, float* a, int lda, const int* ipiv); int LAPACKE_dgetri(int matrix_layout, int n, double* a, int lda, const int* ipiv); -}; +} #endif #include From f23e800f6727bacadb603e56a013ec1f815f24f3 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 17:26:15 +0800 Subject: [PATCH 26/30] fix a bug --- paddle/math/MathFunctions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index 8c5f9dd479..a941c548d4 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -36,6 +36,7 @@ extern "C" { extern "C" { #include int LAPACKE_sgetrf(int matrix_layout, int m, int n, + float* a, int lda, int* ipiv); int LAPACKE_dgetrf(int matrix_layout, int m, int n, double* a, int lda, int* ipiv); int LAPACKE_sgetri(int matrix_layout, int n, float* a, From 950aa8a178aacad6751627d8402063e329966748 Mon Sep 17 00:00:00 2001 From: wuyi05 Date: Tue, 9 May 2017 17:26:57 +0800 Subject: [PATCH 27/30] overwrite env with kwargs --- python/paddle/v2/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 0942334ca2..70c8ec0baa 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -43,14 +43,15 @@ __all__ = [ def init(**kwargs): args = [] + args_dict = {} # NOTE: append arguments if they are in ENV for ek, ev in os.environ.iteritems(): - if ek.startswith("PADDLE_"): - args.append('--%s=%s' % (ek.replace("PADDLE_", "").lower(), - str(ev))) + if ek.startswith("PADDLE_INIT_"): + args_dict[ek.replace("PADDLE_INIT_", "").lower()] = str(ev) + args_dict.update(kwargs) # NOTE: overwrite arguments from ENV if it is in kwargs - for key in kwargs.keys(): + for key in args_dict.keys(): args.append('--%s=%s' % (key, str(kwargs[key]))) api.initPaddle(*args) From dee0d9215bb27e5d4eab338fee06d6508c7a7b1c Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 17:44:00 +0800 Subject: [PATCH 28/30] clang-format code --- paddle/math/MathFunctions.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index a941c548d4..8ada0d34c6 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -34,15 +34,15 @@ extern "C" { #ifndef LAPACK_FOUND extern "C" { -#include -int LAPACKE_sgetrf(int matrix_layout, int m, int n, - float* a, int lda, int* ipiv); -int LAPACKE_dgetrf(int matrix_layout, int m, int n, - double* a, int lda, int* ipiv); -int LAPACKE_sgetri(int matrix_layout, int n, float* a, - int lda, const int* ipiv); -int LAPACKE_dgetri(int matrix_layout, int n, double* a, - int lda, const int* ipiv); +#include +int LAPACKE_sgetrf( + int matrix_layout, int m, int n, float* a, int lda, int* ipiv); +int LAPACKE_dgetrf( + int matrix_layout, int m, int n, double* a, int lda, int* ipiv); +int LAPACKE_sgetri( + int matrix_layout, int n, float* a, int lda, const int* ipiv); +int LAPACKE_dgetri( + int matrix_layout, int n, double* a, int lda, const int* ipiv); } #endif From 1976f137b2dc28fa6080f6df27755a5503956240 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Tue, 9 May 2017 22:27:09 +0800 Subject: [PATCH 29/30] add attr() interface to layer --- python/paddle/v2/config_base.py | 5 +++++ python/paddle/v2/topology.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/python/paddle/v2/config_base.py b/python/paddle/v2/config_base.py index b0e8da563e..acda778e0a 100644 --- a/python/paddle/v2/config_base.py +++ b/python/paddle/v2/config_base.py @@ -16,6 +16,7 @@ import collections import re from paddle.trainer_config_helpers.default_decorators import wrap_name_default import paddle.trainer_config_helpers as conf_helps +from topology import Topology class LayerType(type): @@ -161,6 +162,10 @@ class Layer(object): """ return self.__context__[self.context_name()].size + def attr(self): + topo = Topology(self) + return topo.get_layer_proto(self.name) + def __convert_to_v2__(method_name, parent_names, diff --git a/python/paddle/v2/topology.py b/python/paddle/v2/topology.py index ff28c85c53..1e46e4973f 100644 --- a/python/paddle/v2/topology.py +++ b/python/paddle/v2/topology.py @@ -130,6 +130,12 @@ class Topology(object): return [(nm, data_layers[nm].type) for nm in self.proto().input_layer_names] + def get_layer_proto(self, name): + for layer in self.__model_config__.layers: + if layer.name == name: + return layer + return None + def __check_layer_type__(layer): if not isinstance(layer, v2_layer.LayerV2): From ad0608847e8eef659f57d580c3816af653275339 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Wed, 10 May 2017 19:30:04 +0800 Subject: [PATCH 30/30] Fix paddle.init bug --- python/paddle/v2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 70c8ec0baa..d13850597e 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -52,7 +52,7 @@ def init(**kwargs): args_dict.update(kwargs) # NOTE: overwrite arguments from ENV if it is in kwargs for key in args_dict.keys(): - args.append('--%s=%s' % (key, str(kwargs[key]))) + args.append('--%s=%s' % (key, str(args_dict[key]))) api.initPaddle(*args)