From a6336543f11482f6ae749f402705bba71dbc5606 Mon Sep 17 00:00:00 2001 From: Wilber Date: Fri, 24 Apr 2020 14:25:52 +0800 Subject: [PATCH] [Demo][Cuda] Modify cxx&python demo of Cuda backend for release/v2.6 (#3473) * fix cuda demo. test=develop * update type error. test=develop --- docs/demo_guides/cuda.md | 6 +++--- lite/api/paddle_api.h | 2 +- lite/demo/cxx/cuda_demo/CMakeLists.txt | 20 ++++++++++++-------- lite/tools/build.sh | 1 + 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/demo_guides/cuda.md b/docs/demo_guides/cuda.md index 8b3e76acef..f863fd8686 100644 --- a/docs/demo_guides/cuda.md +++ b/docs/demo_guides/cuda.md @@ -48,7 +48,7 @@ cuda的编译结果位于 `build_cuda/inference_lite_lib` 4、 `demo` 文件夹:c++ demo. -如果编译打开了python选项,则会在 `build_cuda/inference_lite_lib/python/lib/` 目录下生成 `lite_core.so`。 +如果编译打开了python选项,则会在 `build_cuda/inference_lite_lib/python/lib/` 目录下生成 `lite.so`。 ## 运行 @@ -66,7 +66,7 @@ wget https://paddle-inference-dist.cdn.bcebos.com/PaddleLite/kite.jpg 二: 运行 -**NOTE:**此处示例使用的是python接口。 +**NOTE:** 此处示例使用的是python接口。 ``` python #-*- coding: utf-8 -*- @@ -75,7 +75,7 @@ import sys import numpy as np import cv2 sys.path.append('build_cuda/inference_lite_lib/python/lib') -from lite_core import * +from lite import * def read_img(im_path, resize_h, resize_w): im = cv2.imread(im_path).astype('float32') diff --git a/lite/api/paddle_api.h b/lite/api/paddle_api.h index dfb0a7fa68..b08f2f5c74 100644 --- a/lite/api/paddle_api.h +++ b/lite/api/paddle_api.h @@ -181,7 +181,7 @@ class LITE_API CxxConfig : public ConfigBase { #endif #ifdef LITE_WITH_CUDA void set_multi_stream(bool multi_stream) { multi_stream_ = multi_stream; } - int multi_stream() const { return multi_stream_; } + bool multi_stream() const { return multi_stream_; } #endif #ifdef LITE_WITH_MLU diff --git a/lite/demo/cxx/cuda_demo/CMakeLists.txt b/lite/demo/cxx/cuda_demo/CMakeLists.txt index e27548b4e5..f057a1f189 100644 --- a/lite/demo/cxx/cuda_demo/CMakeLists.txt +++ b/lite/demo/cxx/cuda_demo/CMakeLists.txt @@ -1,20 +1,24 @@ -project(demo CXX C) cmake_minimum_required(VERSION 2.8) +project(demo CXX C) + +add_definitions(-DLITE_WITH_CUDA) set(TARGET demo) set(CMAKE_CXX_FLAGS "-std=c++11 -O3") -set(LITE_LIB "${PROJECT_SOURCE_DIR}/../../cxx") -set(PROTOBUF_LIB "${PROJECT_SOURCE_DIR}/../../third_party/protobuf") +set(LITE_ROOT "${PROJECT_SOURCE_DIR}/../../cxx") +set(PROTOBUF_ROOT "${PROJECT_SOURCE_DIR}/../../third_party/protobuf") -include_directories("${LITE_LIB}/include") -link_directories("${LITE_LIB}/lib") -link_directories("${PROTOBUF_LIB}/lib") +include_directories("${LITE_ROOT}/include") +link_directories("${LITE_ROOT}/lib") +link_directories("${PROTOBUF_ROOT}/lib") +# cuda lib +link_directories("/usr/local/cuda/lib64/") add_executable(${TARGET} ${TARGET}.cc) -set(DEPS ${LITE_LIB}/lib/libpaddle_full_api_shared.so) +set(DEPS ${LITE_ROOT}/lib/libpaddle_full_api_shared.so) set(DEPS ${DEPS} protobuf-lite) -set(DEPS ${DEPS} "-lrt -lpthread -ldl") +set(DEPS ${DEPS} "-lrt -lpthread -ldl -lcudart") target_link_libraries(${TARGET} ${DEPS}) diff --git a/lite/tools/build.sh b/lite/tools/build.sh index 632da81cb1..1158344607 100755 --- a/lite/tools/build.sh +++ b/lite/tools/build.sh @@ -350,6 +350,7 @@ function make_cuda { -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF \ -DWITH_TESTING=OFF \ -DLITE_WITH_ARM=OFF \ + -DLITE_WITH_STATIC_CUDA=OFF \ -DLITE_WITH_PYTHON=${BUILD_PYTHON} \ -DLITE_BUILD_EXTRA=ON \ -DLITE_WITH_XPU=$BUILD_XPU \ -- GitLab