提交 f8a74ccc 编写于 作者: L Luo Tao

add shared library test

上级 2d9bd762
...@@ -11,9 +11,9 @@ if(NOT DEFINED DEMO_NAME) ...@@ -11,9 +11,9 @@ if(NOT DEFINED DEMO_NAME)
message(FATAL_ERROR "please set DEMO_NAME with -DDEMO_NAME=demo_name") message(FATAL_ERROR "please set DEMO_NAME with -DDEMO_NAME=demo_name")
endif() endif()
option(WITH_MKLDNN "Compile PaddlePaddle with MKLDNN" OFF) option(WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." ON)
option(WITH_MKL "Compile PaddlePaddle with MKL support, default use openblas." ON) option(WITH_GPU "Compile demo with GPU/CPU, default use CPU." OFF)
option(WITH_GPU "Compile PaddlePaddle with GPU, default use CPU." OFF) option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static." ON)
if(WITH_GPU) if(WITH_GPU)
set(CUDA_LIB "/usr/local/cuda/lib64/" CACHE STRING "CUDA Library") set(CUDA_LIB "/usr/local/cuda/lib64/" CACHE STRING "CUDA Library")
...@@ -52,17 +52,21 @@ else() ...@@ -52,17 +52,21 @@ else()
set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas.a) set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas.a)
endif() endif()
set(ARCHIVE_START "-Wl,--whole-archive") if(WITH_STATIC_LIB)
set(ARCHIVE_END "-Wl,--no-whole-archive") set(DEPS
"-Wl,--whole-archive"
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.a
"-Wl,--no-whole-archive"
${PADDLE_LIB}/contrib/inference/libpaddle_inference_api.a)
else()
set(DEPS
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.so
${PADDLE_LIB}/contrib/inference/libpaddle_inference_api.so)
endif()
set(EXTERNAL_LIB "-lrt -ldl -lpthread") set(EXTERNAL_LIB "-lrt -ldl -lpthread")
set(DEPS set(DEPS ${DEPS}
${ARCHIVE_START} ${MATH_LIB} ${MKLDNN_LIB}
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.a
${ARCHIVE_END}
${PADDLE_LIB}/contrib/inference/libpaddle_inference_api.a
${MATH_LIB}
${MKLDNN_LIB}
glog gflags protobuf snappystream snappy z glog gflags protobuf snappystream snappy z
${EXTERNAL_LIB}) ${EXTERNAL_LIB})
if(WITH_GPU) if(WITH_GPU)
......
...@@ -2,25 +2,28 @@ set -x ...@@ -2,25 +2,28 @@ set -x
PADDLE_ROOT=$1 PADDLE_ROOT=$1
WITH_MKL=$2 WITH_MKL=$2
WITH_GPU=$3 WITH_GPU=$3
mkdir -p build
cd build
rm -rf *
cmake .. -DPADDLE_LIB=${PADDLE_ROOT}/build/fluid_install_dir/ \
-DWITH_MKL=$WITH_MKL \
-DDEMO_NAME=simple_on_word2vec \
-DWITH_GPU=$WITH_GPU
make
if [ $3 == "ON" ]; then if [ $3 == "ON" ]; then
use_gpu_list='true false' use_gpu_list='true false'
else else
use_gpu_list='false' use_gpu_list='false'
fi fi
for use_gpu in $use_gpu_list; do
./simple_on_word2vec \ mkdir -p build
--dirname=${PADDLE_ROOT}/build/python/paddle/fluid/tests/book/word2vec.inference.model \ cd build
--use_gpu=$use_gpu
for WITH_STATIC_LIB in true false; do
rm -rf *
cmake .. -DPADDLE_LIB=${PADDLE_ROOT}/build/fluid_install_dir/ \
-DWITH_MKL=$WITH_MKL \
-DDEMO_NAME=simple_on_word2vec \
-DWITH_GPU=$WITH_GPU \
-DWITH_STATIC_LIB=$WITH_STATIC_LIB
make
for use_gpu in $use_gpu_list; do
./simple_on_word2vec \
--dirname=${PADDLE_ROOT}/build/python/paddle/fluid/tests/book/word2vec.inference.model \
--use_gpu=$use_gpu
done
done done
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
exit 0 exit 0
......
...@@ -61,11 +61,15 @@ void Main(bool use_gpu) { ...@@ -61,11 +61,15 @@ void Main(bool use_gpu) {
//# 4. Get output. //# 4. Get output.
PADDLE_ENFORCE(outputs.size(), 1UL); PADDLE_ENFORCE(outputs.size(), 1UL);
LOG(INFO) << "output buffer size: " << outputs.front().data.length(); // Check the output buffer size and result of each tid.
PADDLE_ENFORCE(outputs.front().data.length(), 33168UL);
float result[5] = {
0.00129761, 0.00151112, 0.000423564, 0.00108815, 0.000932706};
const size_t num_elements = outputs.front().data.length() / sizeof(float); const size_t num_elements = outputs.front().data.length() / sizeof(float);
// The outputs' buffers are in CPU memory. // The outputs' buffers are in CPU memory.
for (size_t i = 0; i < std::min(5UL, num_elements); i++) { for (size_t i = 0; i < std::min(5UL, num_elements); i++) {
LOG(INFO) << static_cast<float*>(outputs.front().data.data())[i]; PADDLE_ENFORCE(static_cast<float*>(outputs.front().data.data())[i],
result[i]);
} }
} }
} }
...@@ -101,13 +105,16 @@ void MainThreads(int num_threads, bool use_gpu) { ...@@ -101,13 +105,16 @@ void MainThreads(int num_threads, bool use_gpu) {
// 4. Get output. // 4. Get output.
PADDLE_ENFORCE(outputs.size(), 1UL); PADDLE_ENFORCE(outputs.size(), 1UL);
LOG(INFO) << "TID: " << tid << ", " // Check the output buffer size and result of each tid.
<< "output buffer size: " << outputs.front().data.length(); PADDLE_ENFORCE(outputs.front().data.length(), 33168UL);
float result[5] = {
0.00129761, 0.00151112, 0.000423564, 0.00108815, 0.000932706};
const size_t num_elements = const size_t num_elements =
outputs.front().data.length() / sizeof(float); outputs.front().data.length() / sizeof(float);
// The outputs' buffers are in CPU memory. // The outputs' buffers are in CPU memory.
for (size_t i = 0; i < std::min(5UL, num_elements); i++) { for (size_t i = 0; i < std::min(5UL, num_elements); i++) {
LOG(INFO) << static_cast<float*>(outputs.front().data.data())[i]; PADDLE_ENFORCE(static_cast<float*>(outputs.front().data.data())[i],
result[i]);
} }
} }
}); });
...@@ -126,7 +133,6 @@ int main(int argc, char** argv) { ...@@ -126,7 +133,6 @@ int main(int argc, char** argv) {
paddle::demo::MainThreads(1, false /* use_gpu*/); paddle::demo::MainThreads(1, false /* use_gpu*/);
paddle::demo::MainThreads(4, false /* use_gpu*/); paddle::demo::MainThreads(4, false /* use_gpu*/);
if (FLAGS_use_gpu) { if (FLAGS_use_gpu) {
LOG(INFO) << "use_gpu=true";
paddle::demo::Main(true /*use_gpu*/); paddle::demo::Main(true /*use_gpu*/);
paddle::demo::MainThreads(1, true /*use_gpu*/); paddle::demo::MainThreads(1, true /*use_gpu*/);
paddle::demo::MainThreads(4, true /*use_gpu*/); paddle::demo::MainThreads(4, true /*use_gpu*/);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册