Skip to content

Commit

Permalink
Add a script to auto compile the warp-ctc submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xreki committed Dec 1, 2016
1 parent 25f1fbc commit 18b85e5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
3 changes: 1 addition & 2 deletions paddle/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion paddle/gserver/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###############
Expand Down
27 changes: 14 additions & 13 deletions paddle/gserver/tests/test_WarpCTCLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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";
}
}
}
Expand Down
1 change: 1 addition & 0 deletions paddle/scripts/travis/build_and_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
./submodules.sh
source ./common.sh
CMAKE_EXTRA=""
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
Expand Down
18 changes: 18 additions & 0 deletions paddle/scripts/travis/submodules.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 18b85e5

Please sign in to comment.