Skip to content

Commit 6c1cf60

Browse files
committed
Merge remote-tracking branch 'ups/develop' into fix
2 parents c453573 + 0329ee7 commit 6c1cf60

36 files changed

+1343
-366
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
| jczaja | Jacek Czaja |
2323
| JiayiFeng | Jia-Yi Feng |
2424
| kbinias | Krzysztof Binias |
25+
| kexinzhao | Ke-Xin Zhao |
2526
| kuke | Yi-Bing Liu |
2627
| lcy-seso | Ying Cao |
2728
| lipeng-unisound | Peng Li |

cmake/inference_lib.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function(copy TARGET)
3939
message(FATAL_ERROR "${TARGET} source numbers are not equal to destination numbers")
4040
endif()
4141
math(EXPR len "${copy_lib_SRCS_len} - 1")
42-
42+
4343
add_custom_target(${TARGET} DEPENDS ${copy_lib_DEPS})
4444
foreach(index RANGE ${len})
4545
list(GET copy_lib_SRCS ${index} src)
@@ -155,6 +155,15 @@ copy(inference_lib DEPS paddle_fluid_shared paddle_fluid
155155
DSTS ${dst_dir}/${module} ${dst_dir}/${module}
156156
)
157157

158+
if(WITH_CONTRIB)
159+
set(contrib_dst_dir "${FLUID_INSTALL_DIR}/contrib/inference")
160+
copy(contrib_inference_lib DEPS paddle_inference_api
161+
SRCS ${PADDLE_SOURCE_DIR}/paddle/contrib/inference/paddle_inference_api.h
162+
${PADDLE_BINARY_DIR}/paddle/contrib/inference/libpaddle_inference_api.*
163+
DSTS ${contrib_dst_dir} ${contrib_dst_dir}
164+
)
165+
endif()
166+
158167
set(module "platform")
159168
copy(platform_lib DEPS profiler_py_proto
160169
SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/dynload/*.h ${src_dir}/${module}/details/*.h

doc/fluid/api/layers.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ conv2d
342342
.. autofunction:: paddle.fluid.layers.conv2d
343343
:noindex:
344344

345+
conv3d
346+
------
347+
348+
.. autofunction:: paddle.fluid.layers.conv3d
349+
:noindex:
350+
345351
sequence_pool
346352
-------------
347353

@@ -366,6 +372,12 @@ pool2d
366372
.. autofunction:: paddle.fluid.layers.pool2d
367373
:noindex:
368374

375+
pool3d
376+
------
377+
378+
.. autofunction:: paddle.fluid.layers.pool3d
379+
:noindex:
380+
369381
batch_norm
370382
----------
371383

@@ -384,6 +396,13 @@ conv2d_transpose
384396
.. autofunction:: paddle.fluid.layers.conv2d_transpose
385397
:noindex:
386398

399+
conv3d_transpose
400+
----------------
401+
402+
.. autofunction:: paddle.fluid.layers.conv2d_transpose
403+
:noindex:
404+
405+
387406
sequence_expand
388407
---------------
389408

doc/v2/dev/contribute_to_paddle_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
104104
➜ docker run -it -v $(pwd):/paddle paddle:latest-dev bash -c "cd /paddle/build && ctest"
105105
```
106106

107-
关于构建和测试的更多信息,请参见[这篇文档](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/getstarted/build_and_install/docker_install_cn.rst)
107+
关于构建和测试的更多信息,请参见[使用Docker安装运行](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/v2/build_and_install/docker_install_cn.rst)
108108

109109
## 提交(commit)
110110

paddle/contrib/inference/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cc_test(test_paddle_inference_api
5050
inference_api_test(test_paddle_inference_api_impl
5151
ARGS test_word2vec test_image_classification)
5252

53-
if (WITH_ANAKIN)
53+
if (WITH_ANAKIN AND WITH_TESTING) # only needed in CI
5454
# Due to Anakin do not have official library releases and the versions of protobuf and cuda do not match Paddle's,
5555
# so anakin library will not be merged to our official inference library. To use anakin prediction API, one need to
5656
# compile the libinference_anakin_api.a and compile with anakin.so.

paddle/contrib/tape/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(APPLE)
1717
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pessimizing-move")
1818
endif(APPLE)
1919

20-
cc_library(tape_variable SRCS variable.cc DEPS ${FLUID_CORE_MODULES})
20+
cc_library(tape_variable SRCS variable.cc DEPS ${FLUID_CORE_MODULES} device_context framework_proto proto_desc operator)
2121
cc_library(tape SRCS tape.cc DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB} tape_variable)
2222

2323
cc_test(test_tape

paddle/fluid/framework/init.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License. */
1818

1919
#include "paddle/fluid/framework/init.h"
2020
#include "paddle/fluid/framework/operator.h"
21+
#include "paddle/fluid/operators/math/blas.h"
2122
#include "paddle/fluid/platform/device_context.h"
2223
#include "paddle/fluid/platform/place.h"
2324
#include "paddle/fluid/string/piece.h"
@@ -113,6 +114,9 @@ void InitDevices(bool init_p2p, const std::vector<int> devices) {
113114
}
114115
places.emplace_back(platform::CPUPlace());
115116
platform::DeviceContextPool::Init(places);
117+
#ifndef PADDLE_WITH_MKLDNN
118+
operators::math::SetNumThreads(1);
119+
#endif
116120
}
117121

118122
void InitGLOG(const std::string &prog_name) {

paddle/fluid/inference/tensorrt/convert/op_converter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class OpConverter {
6464
(*it)(op, scope, test_mode);
6565
}
6666

67-
// convert fluid block to tensorrt network
67+
// Convert a fluid block to tensorrt network, NOTE it just convert operators,
68+
// the INetwork's inputs and outputs should specified in some other modules.
6869
void ConvertBlock(const framework::proto::BlockDesc& block,
6970
const std::unordered_set<std::string>& parameters,
7071
const framework::Scope& scope, TensorRTEngine* engine) {

paddle/fluid/inference/tensorrt/engine.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ class TensorRTEngine : public EngineBase {
5151
nvinfer1::Weights w_;
5252
};
5353

54-
TensorRTEngine(int max_batch, int max_workspace, cudaStream_t* stream,
54+
TensorRTEngine(int max_batch, int max_workspace,
55+
cudaStream_t* stream = nullptr,
5556
nvinfer1::ILogger& logger = NaiveLogger::Global())
5657
: max_batch_(max_batch),
5758
max_workspace_(max_workspace),
58-
stream_(stream),
59+
stream_(stream ? stream : &default_stream_),
5960
logger_(logger) {}
6061

6162
virtual ~TensorRTEngine();
@@ -121,6 +122,8 @@ class TensorRTEngine : public EngineBase {
121122
// the max memory size the engine uses
122123
int max_workspace_;
123124
cudaStream_t* stream_;
125+
// If stream_ is not set from outside, hold its own stream.
126+
cudaStream_t default_stream_;
124127
nvinfer1::ILogger& logger_;
125128

126129
std::vector<Buffer> buffers_;
@@ -165,20 +168,31 @@ class TensorRTEngine : public EngineBase {
165168
*/
166169
class TRT_EngineManager {
167170
public:
168-
TensorRTEngine* Create(int max_batch, int max_workspace,
169-
cudaStream_t* stream) {
170-
engines_.emplace_back(new TensorRTEngine(max_batch, max_workspace, stream));
171-
return engines_.back().get();
171+
bool HasEngine(const std::string& name) const {
172+
return engines_.count(name) != 0;
173+
}
174+
175+
// Get an engine called `name`.
176+
TensorRTEngine* Get(const std::string& name) const {
177+
return engines_.at(name).get();
178+
}
179+
180+
// Create or get an engine called `name`
181+
TensorRTEngine* Create(int max_batch, int max_workspace, cudaStream_t* stream,
182+
const std::string& name) {
183+
auto* p = new TensorRTEngine(max_batch, max_workspace, stream);
184+
engines_[name].reset(p);
185+
return p;
172186
}
173187

174188
void DeleteALl() {
175-
for (auto& ptr : engines_) {
176-
ptr.reset(nullptr);
189+
for (auto& item : engines_) {
190+
item.second.reset(nullptr);
177191
}
178192
}
179193

180194
private:
181-
std::vector<std::unique_ptr<TensorRTEngine>> engines_;
195+
std::unordered_map<std::string, std::unique_ptr<TensorRTEngine>> engines_;
182196
};
183197

184198
} // namespace tensorrt

paddle/fluid/operators/activation_op.cc

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,14 @@ class SoftShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
252252
AddOutput("Out", "Output of Softshrink operator");
253253
AddAttr<float>("lambda", "non-negative offset").SetDefault(0.5f);
254254
AddComment(R"DOC(
255-
Softshrink Activation Operator.
255+
:strong:`Softshrink Activation Operator`
256256
257-
$$
258-
out = \begin{cases}
259-
x - \lambda, \text{if } x > \lambda \\
260-
x + \lambda, \text{if } x < -\lambda \\
261-
0, \text{otherwise}
262-
\end{cases}
263-
$$
257+
.. math::
258+
out = \begin{cases}
259+
x - \lambda, \text{if } x > \lambda \\
260+
x + \lambda, \text{if } x < -\lambda \\
261+
0, \text{otherwise}
262+
\end{cases}
264263
265264
)DOC");
266265
}
@@ -271,18 +270,18 @@ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
271270
void Make() override {
272271
AddInput("X", "Input of HardShrink operator");
273272
AddOutput("Out", "Output of HardShrink operator");
274-
AddAttr<float>("threshold", "The value of threshold for HardShrink")
273+
AddAttr<float>("threshold",
274+
"The value of threshold for HardShrink. [default: 0.5]")
275275
.SetDefault(0.5f);
276276
AddComment(R"DOC(
277-
HardShrink Activation Operator.
277+
:strong:`HardShrink activation operator`
278278
279-
$$
280-
out = \begin{cases}
281-
x, \text{if } x > \lambda \\
282-
x, \text{if } x < -\lambda \\
283-
0, \text{otherwise}
284-
\end{cases}
285-
$$
279+
.. math::
280+
out = \begin{cases}
281+
x, \text{if } x > \lambda \\
282+
x, \text{if } x < -\lambda \\
283+
0, \text{otherwise}
284+
\end{cases}
286285
287286
)DOC");
288287
}
@@ -394,18 +393,18 @@ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker {
394393
void Make() override {
395394
AddInput("X", "Input of ThresholdedRelu operator");
396395
AddOutput("Out", "Output of ThresholdedRelu operator");
397-
AddAttr<float>("threshold", "The threshold location of activation")
396+
AddAttr<float>("threshold",
397+
"The threshold location of activation. [default 1.0].")
398398
.SetDefault(1.0f);
399399
AddComment(R"DOC(
400-
ThresholdedRelu Activation Operator.
400+
:strong:`ThresholdedRelu activation operator`
401401
402-
$$
403-
out = \begin{cases}
404-
x, \text{if } x > threshold \\
405-
0, \text{otherwise}
406-
\end{cases}
407-
$$
402+
.. math::
408403
404+
out = \begin{cases}
405+
x, \text{if } x > threshold \\
406+
0, \text{otherwise}
407+
\end{cases}
409408
)DOC");
410409
}
411410
};

0 commit comments

Comments
 (0)