Skip to content

Commit 27d7b2c

Browse files
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into add_bn_eq
2 parents ac46018 + bf712b5 commit 27d7b2c

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

cmake/external/openblas.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ IF(NOT ${CBLAS_FOUND})
2929
"${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}"
3030
CACHE FILEPATH "openblas library." FORCE)
3131

32-
SET(OPENBLAS_CC "${CMAKE_C_COMPILER}")
32+
SET(OPENBLAS_CC "${CMAKE_C_COMPILER} -Wno-unused-but-set-variable -Wno-unused-variable")
3333

3434
IF(CMAKE_CROSSCOMPILING)
3535
SET(OPTIONAL_ARGS HOSTCC=${HOST_C_COMPILER})

paddle/math/Storage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ limitations under the License. */
1717
#include "paddle/utils/StringUtil.h"
1818
#include "paddle/utils/Util.h"
1919

20+
#ifndef PADDLE_MOBILE_INFERENCE
2021
DEFINE_int32(pool_limit_size,
2122
536870912,
2223
"maximum memory size managed by a memory pool, default is 512M");
24+
#else
25+
DEFINE_int32(pool_limit_size, 0, "default is 0");
26+
#endif
2327

2428
namespace paddle {
2529

paddle/operators/is_empty_op.cc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
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+
15+
#include "paddle/framework/op_registry.h"
16+
#include "paddle/framework/operator.h"
17+
18+
namespace paddle {
19+
namespace operators {
20+
21+
constexpr char kInput[] = "X";
22+
constexpr char kOutput[] = "Out";
23+
24+
class IsEmptyOp : public framework::OperatorBase {
25+
public:
26+
IsEmptyOp(const std::string &type, const framework::VariableNameMap &inputs,
27+
const framework::VariableNameMap &outputs,
28+
const framework::AttributeMap &attrs)
29+
: OperatorBase(type, inputs, outputs, attrs) {}
30+
31+
void Run(const framework::Scope &scope,
32+
const platform::DeviceContext &dev_ctx) const override {
33+
// get input
34+
auto *var = scope.FindVar(Input(kInput));
35+
PADDLE_ENFORCE_NOT_NULL(var);
36+
auto &tensor = var->Get<framework::LoDTensor>();
37+
// get output
38+
auto *out = scope.FindVar(Output(kOutput));
39+
PADDLE_ENFORCE_NOT_NULL(out);
40+
auto *out_tensor = out->GetMutable<framework::LoDTensor>();
41+
42+
out_tensor->Resize({1});
43+
out_tensor->mutable_data<bool>(platform::CPUPlace())[0] =
44+
framework::product(tensor.dims()) == 0;
45+
}
46+
};
47+
48+
class IsEmptyOpProtoMaker : public framework::OpProtoAndCheckerMaker {
49+
public:
50+
IsEmptyOpProtoMaker(framework::OpProto *proto,
51+
framework::OpAttrChecker *op_checker)
52+
: OpProtoAndCheckerMaker(proto, op_checker) {
53+
AddInput(kInput, "(Tensor) Tensor which is to be checked.");
54+
AddOutput(kOutput, "(Tensor) a boolean Tensor that indicate empty or not.");
55+
AddComment(R"DOC(
56+
IsEmpty Operator which checks whether a tensor is empty.
57+
58+
It will just return product(tensor.ddims()) > 0;
59+
)DOC");
60+
}
61+
};
62+
63+
} // namespace operators
64+
} // namespace paddle
65+
66+
REGISTER_OP_WITHOUT_GRADIENT(is_empty, paddle::operators::IsEmptyOp,
67+
paddle::operators::IsEmptyOpProtoMaker);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
import numpy as np
3+
from paddle.v2.framework.op import Operator
4+
import paddle.v2.framework.core as core
5+
6+
7+
def create_tensor(scope, name, np_data):
8+
tensor = scope.var(name).get_tensor()
9+
tensor.set_dims(np_data.shape)
10+
tensor.set(np_data, core.CPUPlace())
11+
return tensor
12+
13+
14+
class TestIsEmptyOp(unittest.TestCase):
15+
def setUp(self):
16+
self.scope = core.Scope()
17+
# create input variables
18+
np_data0 = np.array([0, 1, 2])
19+
create_tensor(self.scope, "X0", np_data0)
20+
21+
np_data1 = np.array([1])
22+
t = create_tensor(self.scope, "X1", np_data1)
23+
t.set_dims([0])
24+
25+
# create output variables
26+
self.scope.var("out")
27+
28+
def test_no_empty(self):
29+
self.one_case("X0", False)
30+
31+
def test_empty(self):
32+
self.one_case("X1", True)
33+
34+
def one_case(self, input, target):
35+
op = Operator(type="is_empty", X=input, Out="out")
36+
ctx = core.DeviceContext.create(core.CPUPlace())
37+
op.run(self.scope, ctx)
38+
out = self.scope.var("out").get_tensor()
39+
self.assertEqual(np.array(out)[0], target)
40+
41+
42+
if __name__ == "__main__":
43+
unittest.main()

0 commit comments

Comments
 (0)