Skip to content

Commit 93c034e

Browse files
committed
Merge remote-tracking branch 'ups/develop' into optimize/op/fusion_lstm
2 parents 83f4bc4 + ef628ab commit 93c034e

File tree

16 files changed

+564
-471
lines changed

16 files changed

+564
-471
lines changed

paddle/fluid/inference/api/api_impl.cc

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
#include <sys/time.h>
1615
#include <algorithm>
1716
#include <map>
1817
#include <set>
@@ -23,32 +22,14 @@ limitations under the License. */
2322

2423
#include "paddle/fluid/framework/feed_fetch_method.h"
2524
#include "paddle/fluid/inference/api/api_impl.h"
25+
#include "paddle/fluid/inference/api/timer.h"
2626
#include "paddle/fluid/platform/profiler.h"
2727

2828
DEFINE_bool(profile, false, "Turn on profiler for fluid");
2929

3030
namespace paddle {
3131
namespace {
32-
33-
// Timer for timer
34-
class Timer {
35-
public:
36-
double start;
37-
double startu;
38-
void tic() {
39-
struct timeval tp;
40-
gettimeofday(&tp, NULL);
41-
start = tp.tv_sec;
42-
startu = tp.tv_usec;
43-
}
44-
double toc() {
45-
struct timeval tp;
46-
gettimeofday(&tp, NULL);
47-
double used_time_ms =
48-
(tp.tv_sec - start) * 1000.0 + (tp.tv_usec - startu) / 1000.0;
49-
return used_time_ms;
50-
}
51-
};
32+
using paddle::inference::Timer;
5233

5334
template <class T>
5435
std::string num2str(T a) {
@@ -80,7 +61,7 @@ void NativePaddlePredictor::PrepareFeedFetch() {
8061
bool NativePaddlePredictor::Init(
8162
std::shared_ptr<framework::Scope> parent_scope) {
8263
VLOG(3) << "Predictor::init()";
83-
64+
#if !defined(_WIN32)
8465
if (FLAGS_profile) {
8566
LOG(WARNING) << "Profiler is actived, might affect the performance";
8667
LOG(INFO) << "You can turn off by set gflags '-profile false'";
@@ -89,6 +70,7 @@ bool NativePaddlePredictor::Init(
8970
: platform::ProfilerState::kCPU;
9071
platform::EnableProfiler(tracking_device);
9172
}
73+
#endif
9274

9375
if (config_.use_gpu) {
9476
place_ = paddle::platform::CUDAPlace(config_.device);
@@ -133,10 +115,12 @@ bool NativePaddlePredictor::Init(
133115
}
134116

135117
NativePaddlePredictor::~NativePaddlePredictor() {
118+
#if !defined(_WIN32)
136119
if (FLAGS_profile) {
137120
platform::DisableProfiler(platform::EventSortingKey::kTotal,
138121
"./profile.log");
139122
}
123+
#endif
140124
if (sub_scope_) {
141125
scope_->DeleteScope(sub_scope_);
142126
}

paddle/fluid/inference/api/demo_ci/CMakeLists.txt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ cmake_minimum_required(VERSION 3.0)
33
project(cpp_inference_demo CXX C)
44

55
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6+
if (WIN32)
7+
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
8+
else()
9+
set(CMAKE_STATIC_LIBRARY_PREFIX "")
10+
endif()
611

712
if(NOT DEFINED PADDLE_LIB)
813
message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
@@ -32,44 +37,56 @@ endif(NOT WIN32)
3237
include_directories("${PADDLE_LIB}/third_party/boost")
3338
include_directories("${PADDLE_LIB}/third_party/eigen3")
3439

40+
if (NOT WIN32)
3541
link_directories("${PADDLE_LIB}/third_party/install/snappy/lib")
3642
link_directories("${PADDLE_LIB}/third_party/install/snappystream/lib")
43+
link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")
44+
endif(NOT WIN32)
45+
3746
link_directories("${PADDLE_LIB}/third_party/install/protobuf/lib")
3847
link_directories("${PADDLE_LIB}/third_party/install/glog/lib")
3948
link_directories("${PADDLE_LIB}/third_party/install/gflags/lib")
40-
link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")
49+
link_directories("${PADDLE_LIB}/paddle/fluid/inference")
4150

4251
add_executable(${DEMO_NAME} ${DEMO_NAME}.cc)
4352

4453
if(WITH_MKL)
4554
include_directories("${PADDLE_LIB}/third_party/install/mklml/include")
46-
set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel.so
47-
${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5.so)
55+
set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
56+
${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
4857
set(MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn")
4958
if(EXISTS ${MKLDNN_PATH})
5059
include_directories("${MKLDNN_PATH}/include")
5160
set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
5261
endif()
5362
else()
54-
set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas.a)
63+
set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
5564
endif()
5665

5766
# Note: libpaddle_inference_api.so/a must put before libpaddle_fluid.so/a
5867
if(WITH_STATIC_LIB)
5968
set(DEPS
60-
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.a)
69+
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid${CMAKE_STATIC_LIBRARY_SUFFIX})
6170
else()
6271
set(DEPS
63-
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.so)
72+
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid${CMAKE_SHARED_LIBRARY_SUFFIX})
6473
endif()
65-
set(EXTERNAL_LIB "-lrt -ldl -lpthread")
6674

75+
if (NOT WIN32)
76+
set(EXTERNAL_LIB "-lrt -ldl -lpthread")
6777
set(DEPS ${DEPS}
6878
${MATH_LIB} ${MKLDNN_LIB}
6979
glog gflags protobuf snappystream snappy z
7080
${EXTERNAL_LIB})
81+
else()
82+
set(DEPS ${DEPS}
83+
${MATH_LIB} ${MKLDNN_LIB}
84+
${CMAKE_STATIC_LIBRARY_PREFIX}glog ${CMAKE_STATIC_LIBRARY_PREFIX}gflags ${CMAKE_STATIC_LIBRARY_PREFIX}protobuf
85+
${EXTERNAL_LIB})
86+
endif(NOT WIN32)
87+
7188
if(WITH_GPU)
72-
set(DEPS ${DEPS} ${CUDA_LIB}/libcudart.so)
89+
set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
7390
endif()
7491

7592
target_link_libraries(${DEMO_NAME} ${DEPS})

paddle/fluid/inference/api/helper.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,15 @@
1616

1717
#include <sys/time.h>
1818
#include <algorithm>
19-
#include <numeric>
2019
#include <sstream>
2120
#include <string>
2221
#include <vector>
2322
#include "paddle/fluid/inference/api/paddle_inference_api.h"
23+
#include "paddle/fluid/inference/api/timer.h"
2424

2525
namespace paddle {
2626
namespace inference {
2727

28-
// Timer for timer
29-
class Timer {
30-
public:
31-
double start;
32-
double startu;
33-
void tic() {
34-
struct timeval tp;
35-
gettimeofday(&tp, NULL);
36-
start = tp.tv_sec;
37-
startu = tp.tv_usec;
38-
}
39-
double toc() {
40-
struct timeval tp;
41-
gettimeofday(&tp, NULL);
42-
double used_time_ms =
43-
(tp.tv_sec - start) * 1000.0 + (tp.tv_usec - startu) / 1000.0;
44-
return used_time_ms;
45-
}
46-
};
47-
4828
static void split(const std::string &str, char sep,
4929
std::vector<std::string> *pieces) {
5030
pieces->clear();

paddle/fluid/inference/api/timer.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#pragma once
15+
16+
#include <chrono> // NOLINT
17+
18+
namespace paddle {
19+
namespace inference {
20+
21+
// Timer for timer
22+
class Timer {
23+
public:
24+
std::chrono::high_resolution_clock::time_point start;
25+
std::chrono::high_resolution_clock::time_point startu;
26+
27+
void tic() { start = std::chrono::high_resolution_clock::now(); }
28+
double toc() {
29+
startu = std::chrono::high_resolution_clock::now();
30+
std::chrono::duration<double> time_span =
31+
std::chrono::duration_cast<std::chrono::duration<double>>(startu -
32+
start);
33+
double used_time_ms = static_cast<double>(time_span.count()) * 1000.0;
34+
return used_time_ms;
35+
}
36+
};
37+
38+
} // namespace inference
39+
} // namespace paddle

paddle/fluid/operators/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ function(op_library TARGET)
178178
file(APPEND ${pybind_file} "USE_OP(relu);\n")
179179
elseif(${TARGET} STREQUAL "fake_dequantize")
180180
file(APPEND ${pybind_file} "USE_OP(fake_dequantize_max_abs);\n")
181+
elseif(${TARGET} STREQUAL "fake_quantize")
182+
file(APPEND ${pybind_file} "USE_OP(fake_quantize_abs_max);\n")
181183
elseif(${TARGET} STREQUAL "tensorrt_engine_op")
182184
message(STATUS "Pybind skips [tensorrt_engine_op], for this OP is only used in inference")
183185
elseif(${TARGET} STREQUAL "fc")
@@ -293,6 +295,7 @@ op_library(extract_rows_op DEPS memory)
293295
op_library(flatten_op DEPS reshape_op)
294296
op_library(sequence_pad_op DEPS sequence_padding)
295297
op_library(unstack_op DEPS stack_op)
298+
op_library(fake_quantize_op DEPS memory)
296299

297300
if (WITH_GPU)
298301
op_library(conv_op DEPS vol2col depthwise_conv im2col)

0 commit comments

Comments
 (0)