From 18b85e558a35009c3d7108e59c5ce511cf494946 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Thu, 1 Dec 2016 05:49:51 +0000 Subject: [PATCH] Add a script to auto compile the warp-ctc submodule. --- paddle/cuda/CMakeLists.txt | 3 +-- paddle/gserver/tests/CMakeLists.txt | 6 ++++- paddle/gserver/tests/test_WarpCTCLayer.cpp | 27 +++++++++++----------- paddle/scripts/travis/build_and_test.sh | 1 + paddle/scripts/travis/submodules.sh | 18 +++++++++++++++ 5 files changed, 39 insertions(+), 16 deletions(-) create mode 100755 paddle/scripts/travis/submodules.sh diff --git a/paddle/cuda/CMakeLists.txt b/paddle/cuda/CMakeLists.txt index 7e45d3d5789..10fa34b9272 100755 --- a/paddle/cuda/CMakeLists.txt +++ b/paddle/cuda/CMakeLists.txt @@ -18,8 +18,7 @@ set(CUDA_CXX_WITH_GPU_SOURCES src/hl_cudart_wrap.cc src/hl_cuda_cublas.cc src/hl_cuda_cudnn.cc - src/hl_cuda_device.cc - ) + src/hl_cuda_device.cc) if(WITH_GPU) set(CUDA_CXX_SOURCES diff --git a/paddle/gserver/tests/CMakeLists.txt b/paddle/gserver/tests/CMakeLists.txt index 8fc6656bf4d..310c8ad0882 100644 --- a/paddle/gserver/tests/CMakeLists.txt +++ b/paddle/gserver/tests/CMakeLists.txt @@ -71,9 +71,13 @@ add_unittest(test_RecurrentLayer ############### test_WarpCTCLayer ####################### if(NOT WITH_DOUBLE) - add_unittest(test_WarpCTCLayer + add_unittest_without_exec(test_WarpCTCLayer test_WarpCTCLayer.cpp TestUtil.cpp) + + add_test(NAME test_WarpCTCLayer + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_WarpCTCLayer --warpctc_dir=${PROJ_ROOT}/warp-ctc/build + WORKING_DIRECTORY ${PROJ_ROOT}/paddle) endif() ############### test_RecurrentGradientMachine ############### diff --git a/paddle/gserver/tests/test_WarpCTCLayer.cpp b/paddle/gserver/tests/test_WarpCTCLayer.cpp index aba48935a6f..2dd83db3451 100644 --- a/paddle/gserver/tests/test_WarpCTCLayer.cpp +++ b/paddle/gserver/tests/test_WarpCTCLayer.cpp @@ -38,7 +38,7 @@ const real* getData(const Matrix& matrix) { } } -void checkError(const Matrix& matrix1, const Matrix& matrix2) { +int checkError(const Matrix& matrix1, const Matrix& matrix2) { CHECK_EQ(matrix1.getHeight(), matrix2.getHeight()); CHECK_EQ(matrix1.getWidth(), matrix2.getWidth()); CHECK_EQ(matrix1.isTransposed(), matrix2.isTransposed()); @@ -62,6 +62,7 @@ void checkError(const Matrix& matrix1, const Matrix& matrix2) { } } EXPECT_EQ(count, 0) << "There are " << count << " different element."; + return count; } void initArgument(size_t batchSize, @@ -72,7 +73,6 @@ void initArgument(size_t batchSize, data.grad = Matrix::create(batchSize, layerSize, false, useGpu); data.value->randomizeUniform(); data.value->add(-0.5); - /// data.value->sigmoid(*data.value); data.grad->zeroMem(); generateSequenceStartPositions(batchSize, data.sequenceStartPositions); @@ -90,9 +90,6 @@ LayerPtr createDataLayer( dataLayer->setData(data); dataLayer->forward(PASS_GC); - /// std::cout << "dataLayer: " << std::endl; - /// (dataLayer->getOutput().value)->print(std::cout); - return layer; } @@ -198,14 +195,14 @@ LayerPtr createWarpCTCLayer(string name, } TEST(Layer, WarpCTCLayer) { - for (auto layerSize : {10, 64, 128}) { - for (auto batchSize : {1, 10, 20, 64}) { + for (auto layerSize : {10, 64}) { + for (auto batchSize : {1, 10, 32}) { for (auto normByTimes : {false, true}) { for (auto useGpu : {false, true}) { #ifdef PADDLE_ONLY_CPU if (useGpu) continue; #endif - LOG(INFO) << " layerSize=" << layerSize << " batchSize=" << batchSize + LOG(INFO) << "layerSize=" << layerSize << " batchSize=" << batchSize << " normByTimes = " << normByTimes << " useGpu=" << useGpu; FLAGS_use_gpu = useGpu; @@ -229,13 +226,17 @@ TEST(Layer, WarpCTCLayer) { LayerPtr ctcLayer = createCTCLayer( "cost", layerSize, useGpu, normByTimes, dataLayer1, labelLayer); - /// Check loss - checkError(*(warpctcLayer->getOutput().value), - *(ctcLayer->getOutput().value)); + /// Check cost + LOG(INFO) << "Check cost: " + << checkError(*(warpctcLayer->getOutput().value), + *(ctcLayer->getOutput().value)) + << " different elements."; /// Check gradients - checkError(*(dataLayer0->getOutput().grad), - *(dataLayer1->getOutput().grad)); + LOG(INFO) << "Check gradients: " + << checkError(*(dataLayer0->getOutput().grad), + *(dataLayer1->getOutput().grad)) + << " different elements"; } } } diff --git a/paddle/scripts/travis/build_and_test.sh b/paddle/scripts/travis/build_and_test.sh index 242fd982aa0..c46c119daeb 100755 --- a/paddle/scripts/travis/build_and_test.sh +++ b/paddle/scripts/travis/build_and_test.sh @@ -1,4 +1,5 @@ #!/bin/bash +./submodules.sh source ./common.sh CMAKE_EXTRA="" if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then diff --git a/paddle/scripts/travis/submodules.sh b/paddle/scripts/travis/submodules.sh new file mode 100755 index 00000000000..47bd8d87ac6 --- /dev/null +++ b/paddle/scripts/travis/submodules.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +PROJ_ROOT=$(git rev-parse --show-cdup) +SUBMODULES=$(grep path ${PROJ_ROOT}.gitmodules | sed 's/^.*path = //') + +for module in $SUBMODULES +do + case $module in + "warp-ctc") + if [ -d ${PROJ_ROOT}warp-ctc/build ]; then + rm -rf ${PROJ_ROOT}warp-ctc/build + fi + mkdir ${PROJ_ROOT}warp-ctc/build + cd ${PROJ_ROOT}warp-ctc/build + cmake ..; make + ;; + esac +done -- GitLab