Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ec11393f
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ec11393f
编写于
6月 07, 2018
作者:
R
Ruilong Liu
提交者:
GitHub
6月 07, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #376 from cocodark/develop
shrink so size
上级
d0e76b9c
e7bb332e
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
128 addition
and
327 deletion
+128
-327
CMakeLists.txt
CMakeLists.txt
+4
-3
src/common/variant.h
src/common/variant.h
+2
-6
src/framework/attribute.h
src/framework/attribute.h
+1
-1
src/framework/data_layout.h
src/framework/data_layout.h
+1
-2
src/framework/ddim.cpp
src/framework/ddim.cpp
+33
-35
src/framework/ddim.h
src/framework/ddim.h
+2
-6
src/framework/dim.h
src/framework/dim.h
+7
-90
src/framework/lod_tensor.cpp
src/framework/lod_tensor.cpp
+40
-44
src/framework/program/program-optimize/node.cpp
src/framework/program/program-optimize/node.cpp
+2
-1
src/framework/program/program-optimize/node.h
src/framework/program/program-optimize/node.h
+6
-2
src/framework/scope.h
src/framework/scope.h
+5
-5
src/framework/tensor_util.cpp
src/framework/tensor_util.cpp
+0
-70
src/framework/tensor_util.h
src/framework/tensor_util.h
+0
-38
src/operators/kernel/arm/batchnorm_kernel.cpp
src/operators/kernel/arm/batchnorm_kernel.cpp
+1
-1
tools/build.sh
tools/build.sh
+24
-23
未找到文件。
CMakeLists.txt
浏览文件 @
ec11393f
cmake_minimum_required
(
VERSION 3.0
)
project
(
paddle-mobile
)
add_definitions
(
-DPADDLE_MOBILE_DEBUG
)
add_definitions
(
-DENABLE_EXCEPTION
)
#
add_definitions(-DPADDLE_MOBILE_DEBUG)
#
add_definitions(-DENABLE_EXCEPTION)
if
(
IS_MAC
)
add_definitions
(
-DX86
)
...
...
@@ -15,7 +15,8 @@ else ()
add_definitions
(
-DX86
)
endif
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++14"
)
set
(
CMAKE_BUILD_TYPE Release
)
set
(
CMAKE_VERBOSE_MAKEFILE ON
)
set
(
CMAKE_EXPORT_COMPILE_COMMANDS ON
)
...
...
src/common/variant.h
浏览文件 @
ec11393f
...
...
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "common/enforce.h"
#include "common/log.h"
#pragma once
...
...
@@ -55,15 +56,11 @@ class RawData {
char
data
[
size
];
RawData
()
{}
RawData
(
const
RawData
&
raw_data
)
{
strcpy
(
data
,
raw_data
.
data
);
}
// void operator=(const RawData &raw_data){
// strcpy(data, raw_data.data);
// }
};
template
<
typename
...
Ts
>
struct
Variant
{
Variant
(
const
Variant
&
variant
)
{
// std::cout << " 赋值构造函数 " << std::endl;
type_id
=
variant
.
type_id
;
data
=
variant
.
data
;
}
...
...
@@ -85,8 +82,7 @@ struct Variant {
if
(
type_id
==
typeid
(
T
).
hash_code
())
{
return
*
const_cast
<
T
*>
(
reinterpret_cast
<
const
T
*>
(
&
data
));
}
else
{
// std::cout << " bad cast in variant " << std::endl;
throw
std
::
bad_cast
();
PADDLE_MOBILE_THROW_EXCEPTION
(
" bad cast in variant "
);
}
}
...
...
src/framework/attribute.h
浏览文件 @
ec11393f
...
...
@@ -127,7 +127,7 @@ class Attribute {
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
int64_t
).
hash_code
())
{
return
vistor
(
attr
.
variant_
.
Get
<
int64_t
>
());
}
else
{
throw
std
::
bad_exception
(
);
PADDLE_MOBILE_THROW_EXCEPTION
(
"type not support"
);
}
}
...
...
src/framework/data_layout.h
浏览文件 @
ec11393f
...
...
@@ -15,7 +15,6 @@ limitations under the License. */
#pragma once
#include <cctype>
#include <iostream>
#include <string>
namespace
paddle_mobile
{
...
...
@@ -40,7 +39,7 @@ inline DataLayout StringToDataLayout(const std::string &str) {
}
else
if
(
s
==
"ANYLAYOUT"
)
{
return
DataLayout
::
kAnyLayout
;
}
else
{
// std::cout << "Unknown storage order string: %s", s;
PADDLE_MOBILE_THROW_EXCEPTION
(
"Unknown storage order string: %s"
,
s
)
}
}
...
...
src/framework/ddim.cpp
浏览文件 @
ec11393f
...
...
@@ -63,9 +63,6 @@ void make_ddim(DDim &ddim, const int64_t *dims, int n) {
ddim
=
make_dim
<
9
>
(
dims
);
break
;
default:
// std::cout << "Dynamic dimensions must have between [1,
// 9]
// dimensions.";
break
;
}
}
...
...
@@ -133,9 +130,6 @@ int64_t DDim::operator[](int idx) const {
int
DDim
::
size
()
const
{
return
arity
(
*
this
);
}
bool
DDim
::
operator
==
(
DDim
d
)
const
{
// if (var.which() != d.getVar().which()) {
// return false;
// } else {
std
::
vector
<
int64_t
>
v1
=
vectorize
(
*
this
);
std
::
vector
<
int64_t
>
v2
=
vectorize
(
d
);
...
...
@@ -157,7 +151,7 @@ DDim DDim::operator+(DDim d) const {
std
::
vector
<
int64_t
>
v3
;
assert
(
v1
.
size
()
==
v2
.
size
()
);
PADDLE_MOBILE_ENFORCE
(
v1
.
size
()
==
v2
.
size
(),
"v1.size() != v2.size()"
);
for
(
unsigned
int
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
v3
.
push_back
(
v1
[
i
]
+
v2
[
i
]);
...
...
@@ -172,7 +166,7 @@ DDim DDim::operator*(DDim d) const {
std
::
vector
<
int64_t
>
v3
;
assert
(
v1
.
size
()
==
v2
.
size
()
);
PADDLE_MOBILE_ENFORCE
(
v1
.
size
()
==
v2
.
size
(),
"v1.size() == v2.size()"
);
for
(
unsigned
int
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
v3
.
push_back
(
v1
[
i
]
*
v2
[
i
]);
...
...
@@ -235,13 +229,10 @@ struct SliceVectorizeVisitor : Vistor<void> {
SliceVectorizeVisitor
(
std
::
vector
<
int64_t
>
&
v
,
int
b
,
int
e
)
:
vector
(
v
),
begin
(
b
),
end
(
e
)
{
// PADDLE_ENFORCE(begin < end,
// "Begin index must be less than end index in
// ddim
// slice.");
// PADDLE_ENFORCE(begin >= 0,
// "Begin index can't be less than zero in
// ddim slice.");
PADDLE_MOBILE_ENFORCE
(
begin
<
end
,
"Begin index must be less than end index in ddim slice."
);
PADDLE_MOBILE_ENFORCE
(
begin
>=
0
,
"Begin index can't be less than zero in ddim slice."
);
}
template
<
int
S
>
...
...
@@ -267,9 +258,7 @@ DDim slice_ddim(const DDim &ddim, int begin, int end) {
std
::
vector
<
int64_t
>
vec
;
vec
.
reserve
(
end
-
begin
);
SliceVectorizeVisitor
visitor
(
vec
,
begin
,
end
);
// boost::apply_visitor(visitor, dim);
DDim
::
ApplyVistor
(
visitor
,
ddim
);
// visitor(ddim.var.Get<Dim<4>>());
return
make_ddim
(
vec
);
}
...
...
@@ -287,31 +276,40 @@ struct ArityVisitor : Vistor<int> {
int
arity
(
const
DDim
&
d
)
{
ArityVisitor
arityVisitor
=
ArityVisitor
();
return
DDim
::
ApplyVistor
(
arityVisitor
,
d
);
// return arityVisitor(d.var.Get<Dim<4>>());
// return boost::apply_visitor(ArityVisitor(), d); }
}
/// \cond HIDDEN
/// \endcond
/// \cond HIDDEN
struct
OSVistor
:
Vistor
<
std
::
ostream
&>
{
OSVistor
(
std
::
ostream
&
os
)
:
os_
(
os
)
{}
/// \endcond
template
<
int
D
>
std
::
ostream
&
operator
()(
Dim
<
D
>
dim
)
const
{
return
os_
<<
dim
;
// struct OSVistor : Vistor<std::ostream &> {
// OSVistor(std::ostream &os) : os_(os) {}
//
// template <int D>
// std::ostream &operator()(Dim<D> dim) const {
// return os_ << dim;
// }
//
// private:
// std::ostream &os_;
//};
// std::ostream &operator<<(std::ostream &os, const DDim &ddim) {
// auto vistor = OSVistor(os);
// DDim::ApplyVistor(vistor, ddim);
// return os;
//}
#ifdef PADDLE_MOBILE_DEBUG
inline
Print
&
operator
<<
(
Print
&
printer
,
const
DDim
&
ddim
)
{
for
(
int
j
=
0
;
j
<
ddim
.
size
();
++
j
)
{
printer
<<
ddim
[
j
]
<<
" "
;
}
private:
std
::
ostream
&
os_
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
DDim
&
ddim
)
{
auto
vistor
=
OSVistor
(
os
);
DDim
::
ApplyVistor
(
vistor
,
ddim
);
return
os
;
return
printer
;
}
#endif
DDim
::
DDim
(
std
::
initializer_list
<
int64_t
>
init_list
)
{
*
this
=
make_ddim
(
init_list
);
}
...
...
src/framework/ddim.h
浏览文件 @
ec11393f
...
...
@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once
#include <initializer_list>
#include <stdexcept>
#include <vector>
#include "common/enforce.h"
#include "common/variant.h"
#include "dim.h"
...
...
@@ -57,9 +57,7 @@ struct DDim {
}
else
if
(
d
.
var
.
TypeId
()
==
typeid
(
Dim
<
9
>
).
hash_code
())
{
return
vistor
(
d
.
var
.
Get
<
Dim
<
9
>>
());
}
else
{
printf
(
" dim not support
\n
"
);
throw
std
::
bad_exception
();
// return typename Vistor::type_t();
DLOG
<<
" dim not support"
;
}
}
...
...
@@ -139,8 +137,6 @@ DDim slice_ddim(const DDim &dim, int begin, int end);
int
arity
(
const
DDim
&
ddim
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DDim
&
);
// Reshape a tensor to a matrix. The matrix's first dimension(column
// length)
// will be the product of tensor's first `num_col_dims` dimensions.
...
...
src/framework/dim.h
浏览文件 @
ec11393f
...
...
@@ -14,10 +14,7 @@ limitations under the License. */
#pragma once
#include <sstream>
#include <stdexcept>
#include <type_traits>
#include "common/enforce.h"
namespace
paddle_mobile
{
namespace
framework
{
...
...
@@ -71,13 +68,9 @@ struct Dim<0> {
Dim
()
{}
Dim
(
int
idx
,
const
Dim
<
0
>
&
size
)
{
#ifndef __CUDA_ARCH__
if
(
idx
>
0
)
{
throw
std
::
invalid_argument
(
"Index out of range."
);
PADDLE_MOBILE_THROW_EXCEPTION
(
"Index out of range."
)
}
#else
PADDLE_ASSERT
(
idx
==
0
);
#endif
}
bool
operator
==
(
const
Dim
<
0
>
&
o
)
const
{
return
true
;
}
...
...
@@ -123,13 +116,10 @@ struct DimGetter<0> {
template
<
int
D
>
int64_t
&
indexer
(
Dim
<
D
>
&
dim
,
int
idx
)
{
#ifndef __CUDA_ARCH__
if
(
idx
<
0
)
{
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
PADDLE_MOBILE_THROW_EXCEPTION
(
"Tried to access a negative dimension"
)
}
#else
PADDLE_ASSERT
(
idx
>=
0
);
#endif
if
(
idx
==
0
)
{
return
dim
.
head
;
}
...
...
@@ -138,30 +128,14 @@ int64_t &indexer(Dim<D> &dim, int idx) {
template
<
>
int64_t
&
indexer
<
0
>
(
Dim
<
0
>
&
dim
,
int
idx
)
{
#ifndef __CUDA_ARCH__
throw
std
::
invalid_argument
(
"Invalid index"
);
#else
PADDLE_ASSERT
(
false
);
#if CUDA_VERSION < 8000
// On CUDA versions previous to 8.0, only __shared__ variables
// could be declared as static in the device code.
int64_t
head
=
0
;
#else
static
int64_t
head
=
0
;
#endif
return
head
;
#endif
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid index"
)
}
template
<
int
D
>
int64_t
indexer
(
const
Dim
<
D
>
&
dim
,
int
idx
)
{
#ifndef __CUDA_ARCH__
if
(
idx
<
0
)
{
throw
std
::
invalid_argument
(
"Tried to access a negative dimension"
);
PADDLE_MOBILE_THROW_EXCEPTION
(
"Tried to access a negative dimension"
)
}
#else
PADDLE_ASSERT
(
idx
>=
0
);
#endif
if
(
idx
==
0
)
{
return
dim
.
head
;
}
...
...
@@ -170,19 +144,7 @@ int64_t indexer(const Dim<D> &dim, int idx) {
template
<
>
int64_t
indexer
<
0
>
(
const
Dim
<
0
>
&
dim
,
int
idx
)
{
#ifndef __CUDA_ARCH__
throw
std
::
invalid_argument
(
"Invalid index"
);
#else
PADDLE_ASSERT
(
false
);
#if CUDA_VERSION < 8000
// On CUDA versions previous to 8.0, only __shared__ variables
// could be declared as static in the device code.
int64_t
head
=
0
;
#else
static
int64_t
head
=
0
;
#endif
return
head
;
#endif
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid index"
)
}
}
// namespace
...
...
@@ -363,50 +325,5 @@ Dim<sizeof...(Args)> make_dim(Args... idxes) {
return
Dim
<
sizeof
...(
Args
)
>
(
idxes
...);
}
// Allows us to output a Dim
// XXX For some reason, overloading fails to resolve this correctly
template
<
int
i
>
typename
std
::
enable_if
<
(
i
>
1
),
std
::
ostream
&>::
type
operator
<<
(
std
::
ostream
&
os
,
const
Dim
<
i
>
&
d
)
{
os
<<
d
.
head
<<
", "
<<
d
.
tail
;
return
os
;
}
// Base case that allows us to output a Dim
// XXX I wish this could be an overload instead of a template
template
<
int
i
>
typename
std
::
enable_if
<
(
i
==
1
),
std
::
ostream
&>::
type
operator
<<
(
std
::
ostream
&
os
,
const
Dim
<
i
>
&
d
)
{
os
<<
d
.
head
;
return
os
;
}
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Dim
<
0
>
&
d
)
{
return
os
;
}
template
<
int
i
>
std
::
string
Dim
<
i
>::
to_string
()
const
{
std
::
stringstream
stream
;
stream
<<
*
this
;
return
stream
.
str
();
}
template
<
int
D
>
Dim
<
D
>
linear_to_dimension
(
int
linear_index
,
Dim
<
D
>
extents
)
{
Dim
<
D
>
result
;
for
(
int
i
=
0
;
i
<
D
-
1
;
++
i
)
{
result
[
i
]
=
linear_index
%
extents
[
i
];
linear_index
/=
extents
[
i
];
}
result
[
D
-
1
]
=
linear_index
;
return
result
;
}
}
// namespace framework
}
// namespace paddle_mobile
src/framework/lod_tensor.cpp
浏览文件 @
ec11393f
...
...
@@ -13,53 +13,49 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "lod_tensor.h"
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <iterator>
namespace
paddle_mobile
{
namespace
framework
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
LoD
&
lod
)
{
os
<<
"{"
;
for
(
auto
&
v
:
lod
)
{
os
<<
"{"
;
bool
is_first
=
true
;
for
(
auto
&
i
:
v
)
{
if
(
is_first
)
{
os
<<
i
;
is_first
=
false
;
}
else
{
os
<<
", "
<<
i
;
}
}
os
<<
"}"
;
}
os
<<
"}"
;
return
os
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
LoDTensor
&
t
)
{
PADDLE_MOBILE_ENFORCE
(
t
.
type
().
hash_code
()
==
typeid
(
float
).
hash_code
(),
"t.type() is not float"
);
os
<<
"dim: "
<<
t
.
dims
()
<<
"
\n
"
;
os
<<
"lod: "
<<
t
.
lod
()
<<
"
\n
"
;
// only print first ten elements
int64_t
size
=
t
.
numel
()
<
10
?
t
.
numel
()
:
10
;
for
(
int64_t
i
=
0
;
i
<
size
;
++
i
)
{
os
<<
t
.
data
<
float
>
()[
i
]
<<
" "
;
}
return
os
;
}
std
::
string
LoDToString
(
const
LoD
&
lod
)
{
std
::
ostringstream
stream
;
stream
<<
lod
;
return
stream
.
str
();
}
//
std::ostream &operator<<(std::ostream &os, const LoD &lod) {
//
os << "{";
//
for (auto &v : lod) {
//
os << "{";
//
bool is_first = true;
//
for (auto &i : v) {
//
if (is_first) {
//
os << i;
//
is_first = false;
//
} else {
//
os << ", " << i;
//
}
//
}
//
os << "}";
//
}
//
os << "}";
//
//
return os;
//
}
//
//
std::ostream &operator<<(std::ostream &os, const LoDTensor &t) {
//
PADDLE_MOBILE_ENFORCE(t.type().hash_code() == typeid(float).hash_code(),
//
"t.type() is not float");
//
os << "dim: " << t.dims() << "\n";
//
os << "lod: " << t.lod() << "\n";
//
// only print first ten elements
//
int64_t size = t.numel() < 10 ? t.numel() : 10;
//
for (int64_t i = 0; i < size; ++i) {
//
os << t.data<float>()[i] << " ";
//
}
//
//
return os;
//
}
//
std::string LoDToString(const LoD &lod) {
//
std::ostringstream stream;
//
stream << lod;
//
return stream.str();
//
}
LoD
SliceInLevel
(
const
LoD
&
in
,
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
...
...
@@ -139,7 +135,7 @@ bool CheckLoD(const LoD &in, int tensor_height) {
if
(
a
<
b
)
return
true
;
return
false
;
}))
{
std
::
cout
<<
"ascending error"
;
PADDLE_MOBILE_THROW_EXCEPTION
(
"ascending error"
)
return
false
;
}
}
...
...
src/framework/program/program-optimize/node.cpp
浏览文件 @
ec11393f
...
...
@@ -144,7 +144,7 @@ void Node::Folder(
}
}
}
#ifdef PADDLE_MOBILE_DEBUG
std
::
string
Node
::
ToString
(
std
::
string
blank
,
const
Node
*
node
)
const
{
std
::
stringstream
ss
;
ss
<<
type_
<<
"->
\n
"
;
...
...
@@ -175,6 +175,7 @@ Print &operator<<(Print &printer, const Node &node) {
printer
<<
node
.
ToString
();
return
printer
;
}
#endif
}
// namespace framework
}
// namespace paddle_mobile
src/framework/program/program-optimize/node.h
浏览文件 @
ec11393f
...
...
@@ -17,7 +17,6 @@ limitations under the License. */
#include <map>
#include <string>
#include <vector>
#include "common/log.h"
#include "framework/program/op_desc.h"
...
...
@@ -34,7 +33,11 @@ class Node {
:
op_desc_
(
op_desc
),
type_
(
op_desc
->
Type
())
{}
Node
&
operator
>
(
std
::
shared_ptr
<
Node
>
node
);
bool
operator
==
(
const
Node
&
in
);
#ifdef PADDLE_MOBILE_DEBUG
std
::
string
ToString
()
const
;
void
Description
();
#endif
std
::
shared_ptr
<
Node
>
To
(
int
size
);
uint
Depth
(
uint
begin
=
0
);
Node
&
Folder
(
...
...
@@ -44,7 +47,6 @@ class Node {
std
::
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
OpDescs
(
uint
size
);
std
::
shared_ptr
<
framework
::
OpDesc
>
OpDescOfNode
()
{
return
op_desc_
;
}
std
::
string
Type
()
{
return
type_
;
}
void
Description
();
private:
void
OpDescs
(
uint
size
,
...
...
@@ -56,7 +58,9 @@ class Node {
std
::
map
<
std
::
string
,
std
::
pair
<
std
::
string
,
std
::
string
>>
*
change
,
Node
*
begin_node
,
std
::
vector
<
std
::
shared_ptr
<
Node
>>
*
removed_nodes
);
std
::
shared_ptr
<
framework
::
OpDesc
>
op_desc_
;
#ifdef PADDLE_MOBILE_DEBUG
std
::
string
ToString
(
std
::
string
blank
,
const
Node
*
node
)
const
;
#endif
std
::
vector
<
std
::
shared_ptr
<
Node
>>
outputs_
;
std
::
vector
<
Node
*>
inputs_
;
std
::
string
type_
;
...
...
src/framework/scope.h
浏览文件 @
ec11393f
...
...
@@ -14,17 +14,17 @@ limitations under the License. */
#pragma once
#include <list>
//std::list
#include <mutex>
//std::mutex
#include <unordered_map>
//std::unordered_map
#include <list>
#include <mutex>
#include <unordered_map>
#include "variable.h"
namespace
paddle_mobile
{
namespace
framework
{
class
Scope
{
public:
Scope
()
{}
~
Scope
()
{}
Scope
()
=
default
;
~
Scope
()
=
default
;
Scope
&
NewScope
()
const
;
...
...
src/framework/tensor_util.cpp
浏览文件 @
ec11393f
...
...
@@ -13,89 +13,19 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "tensor_util.h"
#include <algorithm>
#include <limits>
#include <vector>
namespace
paddle_mobile
{
namespace
framework
{
void
TensorCopy
(
const
Tensor
&
src
,
Tensor
*
dst
)
{
// VLOG(3) << "TensorCopy " << src.dims() << " from " <<
// src.place() << " to
// "
// << dst_place;
src
.
check_memory_size
();
dst
->
Resize
(
src
.
dims
());
dst
->
set_layout
(
src
.
layout
());
auto
src_ptr
=
src
.
data
<
void
>
();
auto
dst_ptr
=
dst
->
mutable_data
(
src
.
type
());
auto
size
=
src
.
numel
()
*
SizeOfType
(
src
.
type
());
memory
::
Copy
(
dst_ptr
,
src_ptr
,
size
);
}
void
TensorCopySync
(
const
Tensor
&
src
,
Tensor
*
dst
)
{
src
.
check_memory_size
();
dst
->
Resize
(
src
.
dims
());
dst
->
set_layout
(
src
.
layout
());
auto
src_ptr
=
src
.
data
<
void
>
();
auto
dst_ptr
=
dst
->
mutable_data
(
src
.
type
());
auto
size
=
src
.
numel
()
*
SizeOfType
(
src
.
type
());
memory
::
Copy
(
dst_ptr
,
src_ptr
,
size
);
}
template
<
typename
Predicate
>
struct
AnyDTypeVisitor
{
Predicate
predicate_
;
const
Tensor
&
tensor_
;
Tensor
*
out_
;
AnyDTypeVisitor
(
Predicate
predicate
,
const
Tensor
&
tensor
,
Tensor
*
out
)
:
predicate_
(
predicate
),
tensor_
(
tensor
),
out_
(
out
)
{}
template
<
typename
T
>
void
operator
()()
const
{
// auto t = EigenVector<T>::Flatten(tensor_);
// auto o = EigenScalar<bool>::From(*out_);
// return any of predicate_(t) is true.
// o.device(*ctx_.eigen_device()) = predicate_(t).any();
}
};
struct
ContainsNANPredicate
{
template
<
typename
T
>
auto
operator
()(
const
T
&
eigen_vec
)
const
->
decltype
(
std
::
declval
<
T
>
().
isnan
())
{
// Cast eigen_vector to vector of bool. true if is inf.
return
eigen_vec
.
isnan
();
}
};
struct
ContainsInfPredicate
{
template
<
typename
T
>
auto
operator
()(
const
T
&
eigen_vec
)
const
->
decltype
(
std
::
declval
<
T
>
().
isinf
())
{
// Cast eigen_vector to vector of bool. true if is inf.
return
eigen_vec
.
isinf
();
}
};
struct
DeserializedDataFunctor
{
DeserializedDataFunctor
(
void
**
buf
,
Tensor
*
tensor
)
:
buf_
(
buf
),
tensor_
(
tensor
)
{}
template
<
typename
T
>
void
operator
()()
{
*
buf_
=
tensor_
->
mutable_data
<
T
>
();
}
void
**
buf_
;
Tensor
*
tensor_
;
};
}
// namespace framework
}
// namespace paddle_mobile
src/framework/tensor_util.h
浏览文件 @
ec11393f
...
...
@@ -21,44 +21,6 @@ namespace paddle_mobile {
namespace
framework
{
void
TensorCopy
(
const
Tensor
&
src
,
Tensor
*
dst
);
void
TensorCopySync
(
const
Tensor
&
src
,
Tensor
*
dst
);
template
<
typename
T
>
void
TensorFromVector
(
const
std
::
vector
<
T
>
&
src
,
Tensor
*
dst
);
template
<
typename
T
>
void
TesnorToVector
(
const
Tensor
&
src
,
std
::
vector
<
T
>
*
dst
);
bool
TensorContainsNAN
(
const
framework
::
Tensor
&
tensor
);
bool
TensorContainsInf
(
const
framework
::
Tensor
&
tensor
);
void
TensorToStream
(
std
::
ostream
&
os
,
const
Tensor
&
tensor
);
void
TensorFromStream
(
std
::
istream
&
is
,
Tensor
*
tensor
);
//
// The implementation of template functions.
//
template
<
typename
T
>
void
TensorFromVector
(
const
std
::
vector
<
T
>
&
src
,
Tensor
*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
());
dst
->
Resize
({
static_cast
<
int64_t
>
(
src
.
size
())});
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
mutable_data
<
T
>
());
auto
size
=
src
.
size
()
*
sizeof
(
T
);
memory
::
Copy
(
dst_ptr
,
src_ptr
,
size
);
}
template
<
typename
T
>
void
TensorToVector
(
const
Tensor
&
src
,
std
::
vector
<
T
>
*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
T
>
());
auto
size
=
src
.
numel
()
*
sizeof
(
T
);
dst
->
resize
(
src
.
numel
());
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
data
());
memory
::
Copy
(
dst_ptr
,
src_ptr
,
size
);
}
}
// namespace framework
}
// namespace paddle_mobile
src/operators/kernel/arm/batchnorm_kernel.cpp
浏览文件 @
ec11393f
...
...
@@ -49,7 +49,7 @@ void BatchNormKernel<CPU, float>::Compute(const BatchNormParam ¶m) const {
Tensor
inv_std
;
auto
inv_std_ptr
=
inv_std
.
mutable_data
<
float
>
(
make_ddim
({
C
}));
if
(
C
!=
variance
->
numel
())
{
std
::
cout
<<
"C must equal to variance.numel()"
<<
std
::
endl
;
DLOG
<<
"C must equal to variance.numel()"
;
}
assert
(
C
==
variance
->
numel
());
...
...
tools/build.sh
浏览文件 @
ec11393f
...
...
@@ -46,7 +46,7 @@ build_for_android() {
if
[
"
${
PLATFORM
}
"
=
"arm-v7a"
]
;
then
ABI
=
"armeabi-v7a with NEON"
ARM_PLATFORM
=
"V7"
CXX_FLAGS
=
"-O3 -std=c++11 -s -march=armv7-a -mfpu=neon -mfloat-abi=softfp -pie -fPIE -w -Wno-error=format-security -
llog
"
CXX_FLAGS
=
"-O3 -std=c++11 -s -march=armv7-a -mfpu=neon -mfloat-abi=softfp -pie -fPIE -w -Wno-error=format-security -
fno-exceptions
"
elif
[
"
${
PLATFORM
}
"
=
"arm-v8a"
]
;
then
ABI
=
"arm64-v8a"
ARM_PLATFORM
=
"V8"
...
...
@@ -72,9 +72,10 @@ build_for_android() {
-DCMAKE_CXX_FLAGS
=
"
${
CXX_FLAGS
}
"
\
-DANDROID_STL
=
c++_static
\
-DANDROID
=
true
\
-D
"
${
NET
}
"
=
true
\
-D
"
${
NET
}
=true"
\
-D
"
${
ARM_PLATFORM
}
"
=
true
else
cmake ..
\
-B
"../build/release/
${
PLATFORM
}
"
\
-DANDROID_ABI
=
"
${
ABI
}
"
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录