Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
f00f1bf6
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
提交
f00f1bf6
编写于
10月 14, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
suite raspberry std::string copy issue with gcc
上级
9301c53b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
68 addition
and
16 deletion
+68
-16
src/common/variant.h
src/common/variant.h
+31
-4
src/framework/attribute.h
src/framework/attribute.h
+9
-2
src/framework/variable.h
src/framework/variable.h
+7
-0
src/operators/op_param.h
src/operators/op_param.h
+11
-8
test/net/test_nlp.cpp
test/net/test_nlp.cpp
+9
-1
test/operators/test_box_coder_op.cpp
test/operators/test_box_coder_op.cpp
+1
-1
未找到文件。
src/common/variant.h
浏览文件 @
f00f1bf6
...
@@ -57,7 +57,12 @@ class RawData {
...
@@ -57,7 +57,12 @@ class RawData {
public:
public:
char
data
[
size
];
char
data
[
size
];
RawData
()
{}
RawData
()
{}
RawData
(
const
RawData
&
raw_data
)
{
strcpy
(
data
,
raw_data
.
data
);
}
RawData
(
const
RawData
&
raw_data
)
{
memcpy
(
data
,
raw_data
.
data
,
size
);
}
RawData
&
operator
=
(
const
RawData
&
raw_data
)
{
memcpy
(
data
,
raw_data
.
data
,
size
);
return
*
this
;
}
};
};
template
<
typename
...
Ts
>
template
<
typename
...
Ts
>
...
@@ -74,14 +79,36 @@ struct Variant {
...
@@ -74,14 +79,36 @@ struct Variant {
template
<
typename
T
,
typename
...
Args
>
template
<
typename
T
,
typename
...
Args
>
void
Set
(
Args
&&
...
args
)
{
void
Set
(
Args
&&
...
args
)
{
helper
::
Destroy
(
type_id
,
&
data
);
helper
::
Destroy
(
type_id
,
&
data
.
data
);
new
(
&
data
)
T
(
std
::
forward
<
Args
>
(
args
)...);
new
(
&
data
.
data
)
T
(
std
::
forward
<
Args
>
(
args
)...);
type_id
=
typeid
(
T
).
hash_code
();
type_id
=
typeid
(
T
).
hash_code
();
}
}
void
SetString
(
std
::
string
&
string
)
{
// helper::Destroy(type_id, &data);
type_id
=
typeid
(
std
::
string
).
hash_code
();
strcpy
(
data
.
data
,
string
.
c_str
());
}
std
::
string
GetString
()
const
{
if
(
type_id
==
typeid
(
std
::
string
).
hash_code
())
{
return
std
::
string
(
data
.
data
);
}
else
{
PADDLE_MOBILE_THROW_EXCEPTION
(
" bad cast in variant data type not a string "
);
exit
(
0
);
}
}
template
<
typename
T
>
template
<
typename
T
>
T
&
Get
()
const
{
T
&
Get
()
const
{
if
(
type_id
==
typeid
(
T
).
hash_code
())
{
if
(
type_id
==
typeid
(
std
::
string
).
hash_code
())
{
PADDLE_MOBILE_THROW_EXCEPTION
(
"Please use getString to get an string (to avoid of an issue with "
"gcc "
"stl lib with string copy)"
);
exit
(
0
);
}
else
if
(
type_id
==
typeid
(
T
).
hash_code
())
{
return
*
const_cast
<
T
*>
(
reinterpret_cast
<
const
T
*>
(
&
data
));
return
*
const_cast
<
T
*>
(
reinterpret_cast
<
const
T
*>
(
&
data
));
}
else
{
}
else
{
PADDLE_MOBILE_THROW_EXCEPTION
(
" bad cast in variant"
);
PADDLE_MOBILE_THROW_EXCEPTION
(
" bad cast in variant"
);
...
...
src/framework/attribute.h
浏览文件 @
f00f1bf6
...
@@ -51,7 +51,7 @@ class Attribute {
...
@@ -51,7 +51,7 @@ class Attribute {
break
;
break
;
}
}
case
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING
:
{
case
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING
:
{
attr
.
Set
<
std
::
string
>
(
std
::
string
(
attr_desc
->
s
));
attr
.
Set
String
(
std
::
string
(
attr_desc
->
s
));
break
;
break
;
}
}
case
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS
:
{
case
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS
:
{
...
@@ -108,6 +108,13 @@ class Attribute {
...
@@ -108,6 +108,13 @@ class Attribute {
return
variant_
.
Get
<
T
>
();
return
variant_
.
Get
<
T
>
();
}
}
Attribute
&
SetString
(
std
::
string
string
)
{
variant_
.
SetString
(
string
);
return
*
this
;
}
std
::
string
GetString
()
const
{
return
variant_
.
GetString
();
}
template
<
typename
Vistor
>
template
<
typename
Vistor
>
static
typename
Vistor
::
type_t
ApplyVistor
(
Vistor
vistor
,
Attribute
attr
)
{
static
typename
Vistor
::
type_t
ApplyVistor
(
Vistor
vistor
,
Attribute
attr
)
{
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
int
).
hash_code
())
{
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
int
).
hash_code
())
{
...
@@ -115,7 +122,7 @@ class Attribute {
...
@@ -115,7 +122,7 @@ class Attribute {
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
float
).
hash_code
())
{
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
float
).
hash_code
())
{
return
vistor
(
attr
.
variant_
.
Get
<
float
>
());
return
vistor
(
attr
.
variant_
.
Get
<
float
>
());
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
string
).
hash_code
())
{
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
string
).
hash_code
())
{
return
vistor
(
attr
.
variant_
.
Get
<
string
>
());
return
vistor
(
attr
.
variant_
.
Get
String
());
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
vector
<
int
>
).
hash_code
())
{
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
vector
<
int
>
).
hash_code
())
{
return
vistor
(
attr
.
variant_
.
Get
<
vector
<
int
>>
());
return
vistor
(
attr
.
variant_
.
Get
<
vector
<
int
>>
());
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
vector
<
float
>
).
hash_code
())
{
}
else
if
(
attr
.
variant_
.
TypeId
()
==
typeid
(
vector
<
float
>
).
hash_code
())
{
...
...
src/framework/variable.h
浏览文件 @
f00f1bf6
...
@@ -33,6 +33,13 @@ class Variable {
...
@@ -33,6 +33,13 @@ class Variable {
template
<
typename
T
>
template
<
typename
T
>
const
T
GetValue
()
const
{
const
T
GetValue
()
const
{
if
(
typeid
(
T
)
==
typeid
(
std
::
string
))
{
PADDLE_MOBILE_THROW_EXCEPTION
(
"Please use getString to get an string (to avoid of an issue with "
"gcc "
"stl lib with string copy)"
);
exit
(
0
);
}
return
variant
.
Get
<
T
>
();
return
variant
.
Get
<
T
>
();
}
}
...
...
src/operators/op_param.h
浏览文件 @
f00f1bf6
...
@@ -263,6 +263,9 @@ class OpParam {
...
@@ -263,6 +263,9 @@ class OpParam {
static
const
T
GetAttr
(
const
string
&
key
,
const
AttributeMap
&
map
)
{
static
const
T
GetAttr
(
const
string
&
key
,
const
AttributeMap
&
map
)
{
return
((
Attribute
)
map
.
at
(
key
)).
Get
<
T
>
();
return
((
Attribute
)
map
.
at
(
key
)).
Get
<
T
>
();
}
}
static
const
std
::
string
GetStringAttr
(
const
string
&
key
,
const
AttributeMap
&
map
)
{
return
((
Attribute
)
map
.
at
(
key
)).
GetString
();
}
static
const
bool
HasAttr
(
const
string
&
key
,
const
AttributeMap
&
map
)
{
static
const
bool
HasAttr
(
const
string
&
key
,
const
AttributeMap
&
map
)
{
return
map
.
count
(
key
)
>
0
;
return
map
.
count
(
key
)
>
0
;
...
@@ -493,7 +496,7 @@ class LrnParam : public OpParam {
...
@@ -493,7 +496,7 @@ class LrnParam : public OpParam {
alpha_
=
GetAttr
<
float
>
(
"alpha"
,
attrs
);
alpha_
=
GetAttr
<
float
>
(
"alpha"
,
attrs
);
beta_
=
GetAttr
<
float
>
(
"beta"
,
attrs
);
beta_
=
GetAttr
<
float
>
(
"beta"
,
attrs
);
k_
=
GetAttr
<
float
>
(
"k"
,
attrs
);
k_
=
GetAttr
<
float
>
(
"k"
,
attrs
);
data_format_
=
Get
Attr
<
string
>
(
"data_format"
,
attrs
);
data_format_
=
Get
StringAttr
(
"data_format"
,
attrs
);
}
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
...
@@ -590,7 +593,7 @@ class PoolParam : public OpParam {
...
@@ -590,7 +593,7 @@ class PoolParam : public OpParam {
input_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
input_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
output_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
output_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
pooling_type_
=
Get
Attr
<
string
>
(
"pooling_type"
,
attrs
);
pooling_type_
=
Get
StringAttr
(
"pooling_type"
,
attrs
);
ksize_
=
GetAttr
<
vector
<
int
>>
(
"ksize"
,
attrs
);
ksize_
=
GetAttr
<
vector
<
int
>>
(
"ksize"
,
attrs
);
strides_
=
GetAttr
<
vector
<
int
>>
(
"strides"
,
attrs
);
strides_
=
GetAttr
<
vector
<
int
>>
(
"strides"
,
attrs
);
paddings_
=
GetAttr
<
vector
<
int
>>
(
"paddings"
,
attrs
);
paddings_
=
GetAttr
<
vector
<
int
>>
(
"paddings"
,
attrs
);
...
@@ -724,7 +727,7 @@ class BoxCoderParam : public OpParam {
...
@@ -724,7 +727,7 @@ class BoxCoderParam : public OpParam {
input_priorboxvar_
=
InputPriorBoxVarFrom
<
GType
>
(
inputs
,
scope
);
input_priorboxvar_
=
InputPriorBoxVarFrom
<
GType
>
(
inputs
,
scope
);
input_targetbox_
=
InputTargetBoxFrom
<
GType
>
(
inputs
,
scope
);
input_targetbox_
=
InputTargetBoxFrom
<
GType
>
(
inputs
,
scope
);
output_box_
=
OutputBoxFrom
<
GType
>
(
outputs
,
scope
);
output_box_
=
OutputBoxFrom
<
GType
>
(
outputs
,
scope
);
code_type_
=
Get
Attr
<
std
::
string
>
(
"code_type"
,
attrs
);
code_type_
=
Get
StringAttr
(
"code_type"
,
attrs
);
}
}
const
RType
*
InputPriorBox
()
const
{
return
input_priorbox_
;
}
const
RType
*
InputPriorBox
()
const
{
return
input_priorbox_
;
}
...
@@ -1199,7 +1202,7 @@ class PReluParam : public OpParam {
...
@@ -1199,7 +1202,7 @@ class PReluParam : public OpParam {
alpha_
=
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
alpha_
=
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
framework
::
DDim
dims
=
alpha_
->
dims
();
framework
::
DDim
dims
=
alpha_
->
dims
();
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
mode_
=
Get
Attr
<
std
::
string
>
(
"mode"
,
attrs
);
mode_
=
Get
StringAttr
(
"mode"
,
attrs
);
DLOG
<<
"PReluParam mode after"
<<
mode_
;
DLOG
<<
"PReluParam mode after"
<<
mode_
;
}
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
...
@@ -1330,7 +1333,7 @@ class FusionConvAddPReluParam : public ConvParam<Dtype> {
...
@@ -1330,7 +1333,7 @@ class FusionConvAddPReluParam : public ConvParam<Dtype> {
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
alpha_
=
OpParam
::
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
alpha_
=
OpParam
::
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
mode_
=
OpParam
::
Get
Attr
<
std
::
string
>
(
"mode"
,
attrs
);
mode_
=
OpParam
::
Get
StringAttr
(
"mode"
,
attrs
);
framework
::
DDim
dims
=
alpha_
->
dims
();
framework
::
DDim
dims
=
alpha_
->
dims
();
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
scope
);
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
scope
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
axis_
=
OpParam
::
GetAttr
<
int
>
(
"axis"
,
attrs
);
...
@@ -1373,7 +1376,7 @@ class FusionConvAddAddPReluParam : public ConvParam<Dtype> {
...
@@ -1373,7 +1376,7 @@ class FusionConvAddAddPReluParam : public ConvParam<Dtype> {
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
:
ConvParam
<
Dtype
>
(
inputs
,
outputs
,
attrs
,
scope
)
{
bias1_
=
OpParam
::
InputYFrom1
<
GType
>
(
inputs
,
scope
);
bias1_
=
OpParam
::
InputYFrom1
<
GType
>
(
inputs
,
scope
);
alpha_
=
OpParam
::
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
alpha_
=
OpParam
::
InputAlphaFrom
<
GType
>
(
inputs
,
scope
);
mode_
=
OpParam
::
Get
Attr
<
std
::
string
>
(
"mode"
,
attrs
);
mode_
=
OpParam
::
Get
StringAttr
(
"mode"
,
attrs
);
framework
::
DDim
dims
=
alpha_
->
dims
();
framework
::
DDim
dims
=
alpha_
->
dims
();
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
scope
);
bias_
=
OpParam
::
InputYFrom
<
GType
>
(
inputs
,
scope
);
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
output_
=
OpParam
::
OutFrom
<
GType
>
(
outputs
,
scope
);
...
@@ -1980,8 +1983,8 @@ class GruParam : public OpParam {
...
@@ -1980,8 +1983,8 @@ class GruParam : public OpParam {
OutputBatchResetHiddenPrevFrom
<
GType
>
(
outputs
,
scope
);
OutputBatchResetHiddenPrevFrom
<
GType
>
(
outputs
,
scope
);
output_batch_hidden_
=
OutputBatchHiddenFrom
<
GType
>
(
outputs
,
scope
);
output_batch_hidden_
=
OutputBatchHiddenFrom
<
GType
>
(
outputs
,
scope
);
output_hidden_
=
OutputHiddenFrom
<
GType
>
(
outputs
,
scope
);
output_hidden_
=
OutputHiddenFrom
<
GType
>
(
outputs
,
scope
);
activation_
=
Get
Attr
<
std
::
string
>
(
"activation"
,
attrs
);
activation_
=
Get
StringAttr
(
"activation"
,
attrs
);
gate_activation_
=
Get
Attr
<
std
::
string
>
(
"gate_activation"
,
attrs
);
gate_activation_
=
Get
StringAttr
(
"gate_activation"
,
attrs
);
is_reverse_
=
GetAttr
<
bool
>
(
"is_reverse"
,
attrs
);
is_reverse_
=
GetAttr
<
bool
>
(
"is_reverse"
,
attrs
);
}
}
const
GType
*
InputInput
()
const
{
return
input_input_
;
}
const
GType
*
InputInput
()
const
{
return
input_input_
;
}
...
...
test/net/test_nlp.cpp
浏览文件 @
f00f1bf6
...
@@ -60,7 +60,15 @@ int main() {
...
@@ -60,7 +60,15 @@ int main() {
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
// 1064 1603 644 699 2878 1219 867 1352 8 1 13 312 479
// 1064 1603 644 699 2878 1219 867 1352 8 1 13 312 479
std
::
vector
<
int64_t
>
ids
{
1791
,
656
,
1549
,
281
,
96
};
std
::
vector
<
int64_t
>
ids
{
2084
,
635
,
1035
,
197
,
990
,
150
,
1132
,
2403
,
546
,
770
,
4060
,
3352
,
1798
,
1589
,
1352
,
98
,
136
,
3461
,
3186
,
1159
,
515
,
764
,
278
,
1178
,
5044
,
4060
,
943
,
932
,
463
,
1198
,
3352
,
374
,
1198
,
3352
,
374
,
2047
,
1069
,
1589
,
3672
,
1178
,
1178
,
2165
,
1178
,
2084
,
635
,
3087
,
2236
,
546
,
2047
,
1549
,
546
,
2047
,
302
,
2202
,
398
,
804
,
397
,
657
,
804
,
866
,
932
,
2084
,
515
,
2165
,
397
,
302
,
2202
,
526
,
992
,
906
,
1215
,
1589
,
4493
,
2403
,
723
,
932
,
2084
,
635
,
1352
,
932
,
444
,
2047
,
1159
,
1893
,
1579
,
59
,
330
,
98
,
1296
,
1159
,
3430
,
738
,
3186
,
1071
,
2174
,
3933
};
paddle_mobile
::
framework
::
LoDTensor
words
;
paddle_mobile
::
framework
::
LoDTensor
words
;
auto
size
=
static_cast
<
int
>
(
ids
.
size
());
auto
size
=
static_cast
<
int
>
(
ids
.
size
());
...
...
test/operators/test_box_coder_op.cpp
浏览文件 @
f00f1bf6
...
@@ -46,7 +46,7 @@ class TestBoxCoderOp {
...
@@ -46,7 +46,7 @@ class TestBoxCoderOp {
DLOG
<<
" Input TargetBox is : "
<<
op
->
Input
(
"TargetBox"
)[
0
];
DLOG
<<
" Input TargetBox is : "
<<
op
->
Input
(
"TargetBox"
)[
0
];
DLOG
<<
" OutputBox is : "
<<
op
->
Output
(
"OutputBox"
)[
0
];
DLOG
<<
" OutputBox is : "
<<
op
->
Output
(
"OutputBox"
)[
0
];
DLOG
<<
" code_type : "
DLOG
<<
" code_type : "
<<
op
->
GetAttrMap
().
at
(
"code_type"
).
Get
<
std
::
string
>
();
<<
op
->
GetAttrMap
().
at
(
"code_type"
).
Get
String
();
std
::
shared_ptr
<
operators
::
BoxCoderOp
<
Dtype
,
float
>>
boxcoder
=
std
::
shared_ptr
<
operators
::
BoxCoderOp
<
Dtype
,
float
>>
boxcoder
=
std
::
make_shared
<
operators
::
BoxCoderOp
<
Dtype
,
float
>>
(
std
::
make_shared
<
operators
::
BoxCoderOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录