Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e6459329
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
338
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看板
提交
e6459329
编写于
5月 19, 2018
作者:
E
eclipsess
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code style
上级
9bfe2c66
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
198 addition
and
203 deletion
+198
-203
test/operators/test_elementwise_add_op.cpp
test/operators/test_elementwise_add_op.cpp
+101
-104
test/operators/test_mul_op.cpp
test/operators/test_mul_op.cpp
+97
-99
未找到文件。
test/operators/test_elementwise_add_op.cpp
浏览文件 @
e6459329
...
...
@@ -17,114 +17,112 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#pragma once
#include "operators/elementwise_add_op.h"
#include "../test_include.h"
#include "operators/elementwise_add_op.h"
namespace
paddle_mobile
{
namespace
framework
{
template
<
typename
Dtype
>
class
TestElementwiseAddOp
{
public:
TestElementwiseAddOp
(
const
Program
<
Dtype
>
p
)
:
program_
(
p
)
{
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
}
else
{
to_predict_program_
=
program_
.
originProgram
;
}
const
std
::
vector
<
std
::
shared_ptr
<
BlockDesc
>>
blocks
=
to_predict_program_
->
Blocks
();
// DLOG << " **block size " << blocks.size();
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
OpDesc
>>
ops
=
block_desc
->
Ops
();
// DLOG << " ops " << ops.size();
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op
=
ops
[
j
];
// if (op->Type() ==
// "elementwise_add") {
// if
// (op->GetAttrMap().at("axis").Get<int>()
// != -1) {
// DLOG << "attr: axis =
// "
// <<
// op->GetAttrMap().at("axis").Get<int>();
// }
// }
// DLOG << "op:" << op->Type();
if
(
op
->
Type
()
==
"elementwise_add"
&&
op
->
Input
(
"X"
)[
0
]
==
"batch_norm_2.tmp_2"
)
{
DLOG
<<
" elementwise_add attr size: "
<<
op
->
GetAttrMap
().
size
();
DLOG
<<
" inputs size: "
<<
op
->
GetInputs
().
size
();
DLOG
<<
" outputs size: "
<<
op
->
GetOutputs
().
size
();
DLOG
<<
" Input X is : "
<<
op
->
Input
(
"X"
)[
0
];
DLOG
<<
" Input Y is : "
<<
op
->
Input
(
"Y"
)[
0
];
DLOG
<<
" Output Out is : "
<<
op
->
Output
(
"Out"
)[
0
];
Attribute
axis_attr
=
op
->
GetAttrMap
().
at
(
"axis"
);
int
axis
=
axis_attr
.
Get
<
int
>
();
DLOG
<<
" Attr axis is : "
<<
axis
;
std
::
shared_ptr
<
operators
::
ElementwiseAddOp
<
Dtype
,
float
>>
add
=
std
::
make_shared
<
operators
::
ElementwiseAddOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
op
->
GetAttrMap
(),
program_
.
scope
);
ops_of_block_
[
*
block_desc
.
get
()].
push_back
(
add
);
}
}
namespace
framework
{
template
<
typename
Dtype
>
class
TestElementwiseAddOp
{
public:
TestElementwiseAddOp
(
const
Program
<
Dtype
>
p
)
:
program_
(
p
)
{
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
}
else
{
to_predict_program_
=
program_
.
originProgram
;
}
const
std
::
vector
<
std
::
shared_ptr
<
BlockDesc
>>
blocks
=
to_predict_program_
->
Blocks
();
// DLOG << " **block size " << blocks.size();
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
OpDesc
>>
ops
=
block_desc
->
Ops
();
// DLOG << " ops " << ops.size();
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op
=
ops
[
j
];
// if (op->Type() ==
// "elementwise_add") {
// if
// (op->GetAttrMap().at("axis").Get<int>()
// != -1) {
// DLOG << "attr: axis =
// "
// <<
// op->GetAttrMap().at("axis").Get<int>();
// }
// }
// DLOG << "op:" << op->Type();
if
(
op
->
Type
()
==
"elementwise_add"
&&
op
->
Input
(
"X"
)[
0
]
==
"batch_norm_2.tmp_2"
)
{
DLOG
<<
" elementwise_add attr size: "
<<
op
->
GetAttrMap
().
size
();
DLOG
<<
" inputs size: "
<<
op
->
GetInputs
().
size
();
DLOG
<<
" outputs size: "
<<
op
->
GetOutputs
().
size
();
DLOG
<<
" Input X is : "
<<
op
->
Input
(
"X"
)[
0
];
DLOG
<<
" Input Y is : "
<<
op
->
Input
(
"Y"
)[
0
];
DLOG
<<
" Output Out is : "
<<
op
->
Output
(
"Out"
)[
0
];
Attribute
axis_attr
=
op
->
GetAttrMap
().
at
(
"axis"
);
int
axis
=
axis_attr
.
Get
<
int
>
();
DLOG
<<
" Attr axis is : "
<<
axis
;
std
::
shared_ptr
<
operators
::
ElementwiseAddOp
<
Dtype
,
float
>>
add
=
std
::
make_shared
<
operators
::
ElementwiseAddOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
op
->
GetAttrMap
(),
program_
.
scope
);
ops_of_block_
[
*
block_desc
.
get
()].
push_back
(
add
);
}
}
std
::
shared_ptr
<
Tensor
>
predict_add
(
Tensor
&
t1
,
Tensor
&
t2
)
{
// feed
auto
scope
=
program_
.
scope
;
Variable
*
x_feed_value
=
scope
->
Var
(
"batch_norm_2.tmp_2"
);
auto
tensor_x
=
x_feed_value
->
GetMutable
<
Tensor
>
();
tensor_x
->
ShareDataWith
(
t1
);
Variable
*
y_feed_value
=
scope
->
Var
(
"batch_norm_0.tmp_3"
);
auto
tensor_y
=
y_feed_value
->
GetMutable
<
Tensor
>
();
tensor_y
->
ShareDataWith
(
t2
);
Variable
*
con_output
=
scope
->
Var
(
"elementwise_add_0.tmp_0"
);
Tensor
*
output_tensor
=
con_output
->
GetMutable
<
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
({
1
,
3
,
224
,
224
});
// DLOG << typeid(output_tensor).name();
// DLOG << "output_tensor dims: " << output_tensor->dims();
std
::
shared_ptr
<
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
predict_add
(
t1
,
t2
,
0
);
return
out_tensor
;
}
private:
const
framework
::
Program
<
Dtype
>
program_
;
std
::
shared_ptr
<
ProgramDesc
>
to_predict_program_
;
std
::
map
<
framework
::
BlockDesc
,
std
::
vector
<
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>>>
ops_of_block_
;
bool
use_optimize_
=
false
;
void
predict_add
(
const
Tensor
&
t1
,
const
Tensor
&
t2
,
int
block_id
)
{
std
::
shared_ptr
<
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
block_id
);
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
auto
op
=
ops_of_block_
[
*
to_predict_block
.
get
()][
j
];
DLOG
<<
"op -> run()"
;
op
->
Run
();
}
}
};
template
class
TestElementwiseAddOp
<
CPU
>;
}
// namespace framework
}
}
std
::
shared_ptr
<
Tensor
>
predict_add
(
Tensor
&
t1
,
Tensor
&
t2
)
{
// feed
auto
scope
=
program_
.
scope
;
Variable
*
x_feed_value
=
scope
->
Var
(
"batch_norm_2.tmp_2"
);
auto
tensor_x
=
x_feed_value
->
GetMutable
<
Tensor
>
();
tensor_x
->
ShareDataWith
(
t1
);
Variable
*
y_feed_value
=
scope
->
Var
(
"batch_norm_0.tmp_3"
);
auto
tensor_y
=
y_feed_value
->
GetMutable
<
Tensor
>
();
tensor_y
->
ShareDataWith
(
t2
);
Variable
*
con_output
=
scope
->
Var
(
"elementwise_add_0.tmp_0"
);
Tensor
*
output_tensor
=
con_output
->
GetMutable
<
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
({
1
,
3
,
224
,
224
});
// DLOG << typeid(output_tensor).name();
// DLOG << "output_tensor dims: " << output_tensor->dims();
std
::
shared_ptr
<
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
predict_add
(
t1
,
t2
,
0
);
return
out_tensor
;
}
private:
const
framework
::
Program
<
Dtype
>
program_
;
std
::
shared_ptr
<
ProgramDesc
>
to_predict_program_
;
std
::
map
<
framework
::
BlockDesc
,
std
::
vector
<
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>>>
ops_of_block_
;
bool
use_optimize_
=
false
;
void
predict_add
(
const
Tensor
&
t1
,
const
Tensor
&
t2
,
int
block_id
)
{
std
::
shared_ptr
<
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
block_id
);
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
auto
op
=
ops_of_block_
[
*
to_predict_block
.
get
()][
j
];
DLOG
<<
"op -> run()"
;
op
->
Run
();
}
}
};
template
class
TestElementwiseAddOp
<
CPU
>;
}
// namespace framework
}
// namespace paddle_mobile
int
main
()
{
DLOG
<<
"----------**********----------"
;
...
...
@@ -162,4 +160,3 @@ int main() {
<<
output_add_ptr
[
226
];
return
0
;
}
test/operators/test_mul_op.cpp
浏览文件 @
e6459329
...
...
@@ -17,119 +17,117 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#pragma once
#include "operators/mul_op.h"
#include "../test_include.h"
#include "operators/mul_op.h"
namespace
paddle_mobile
{
namespace
framework
{
template
<
typename
Dtype
>
class
TestMulOp
{
public:
TestMulOp
(
const
Program
<
Dtype
>
p
)
:
program_
(
p
)
{
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
}
else
{
to_predict_program_
=
program_
.
originProgram
;
}
namespace
framework
{
template
<
typename
Dtype
>
class
TestMulOp
{
public:
TestMulOp
(
const
Program
<
Dtype
>
p
)
:
program_
(
p
)
{
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
}
else
{
to_predict_program_
=
program_
.
originProgram
;
}
const
std
::
vector
<
std
::
shared_ptr
<
BlockDesc
>>
blocks
=
to_predict_program_
->
Blocks
();
// DLOG << " **block size " << blocks.size();
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
OpDesc
>>
ops
=
block_desc
->
Ops
();
// DLOG << " ops " << ops.size();
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op
=
ops
[
j
];
// if (op->Type() == "mul") {
// DLOG << "x_num_col_dims :
// "
// << op->GetAttrMap()
// .at("x_num_col_dims")
// .Get<int>();
// DLOG << "y_num_col_dims :
// "
// << op->GetAttrMap()
// .at("y_num_col_dims")
// .Get<int>();
// DLOG << " Input X is : "
// << op->Input("X")[0];
// }
// DLOG << "op:" << op->Type();
if
(
op
->
Type
()
==
"mul"
&&
op
->
Input
(
"X"
)[
0
]
==
"pool2d_0.tmp_0"
)
{
DLOG
<<
" mul attr size: "
<<
op
->
GetAttrMap
().
size
();
DLOG
<<
" inputs size: "
<<
op
->
GetInputs
().
size
();
DLOG
<<
" outputs size: "
<<
op
->
GetOutputs
().
size
();
DLOG
<<
" Input X is : "
<<
op
->
Input
(
"X"
)[
0
];
DLOG
<<
" Input Y is : "
<<
op
->
Input
(
"Y"
)[
0
];
DLOG
<<
" Output Out is : "
<<
op
->
Output
(
"Out"
)[
0
];
DLOG
<<
"x_num_col_dims : "
<<
op
->
GetAttrMap
().
at
(
"x_num_col_dims"
).
Get
<
int
>
();
DLOG
<<
"y_num_col_dims : "
<<
op
->
GetAttrMap
().
at
(
"y_num_col_dims"
).
Get
<
int
>
();
std
::
shared_ptr
<
operators
::
MulOp
<
Dtype
,
float
>>
add
=
std
::
make_shared
<
operators
::
MulOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
op
->
GetAttrMap
(),
program_
.
scope
);
ops_of_block_
[
*
block_desc
.
get
()].
push_back
(
add
);
}
}
const
std
::
vector
<
std
::
shared_ptr
<
BlockDesc
>>
blocks
=
to_predict_program_
->
Blocks
();
// DLOG << " **block size " << blocks.size();
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
OpDesc
>>
ops
=
block_desc
->
Ops
();
// DLOG << " ops " << ops.size();
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op
=
ops
[
j
];
// if (op->Type() == "mul") {
// DLOG << "x_num_col_dims :
// "
// << op->GetAttrMap()
// .at("x_num_col_dims")
// .Get<int>();
// DLOG << "y_num_col_dims :
// "
// << op->GetAttrMap()
// .at("y_num_col_dims")
// .Get<int>();
// DLOG << " Input X is : "
// << op->Input("X")[0];
// }
// DLOG << "op:" << op->Type();
if
(
op
->
Type
()
==
"mul"
&&
op
->
Input
(
"X"
)[
0
]
==
"pool2d_0.tmp_0"
)
{
DLOG
<<
" mul attr size: "
<<
op
->
GetAttrMap
().
size
();
DLOG
<<
" inputs size: "
<<
op
->
GetInputs
().
size
();
DLOG
<<
" outputs size: "
<<
op
->
GetOutputs
().
size
();
DLOG
<<
" Input X is : "
<<
op
->
Input
(
"X"
)[
0
];
DLOG
<<
" Input Y is : "
<<
op
->
Input
(
"Y"
)[
0
];
DLOG
<<
" Output Out is : "
<<
op
->
Output
(
"Out"
)[
0
];
DLOG
<<
"x_num_col_dims : "
<<
op
->
GetAttrMap
().
at
(
"x_num_col_dims"
).
Get
<
int
>
();
DLOG
<<
"y_num_col_dims : "
<<
op
->
GetAttrMap
().
at
(
"y_num_col_dims"
).
Get
<
int
>
();
std
::
shared_ptr
<
operators
::
MulOp
<
Dtype
,
float
>>
add
=
std
::
make_shared
<
operators
::
MulOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
op
->
GetAttrMap
(),
program_
.
scope
);
ops_of_block_
[
*
block_desc
.
get
()].
push_back
(
add
);
}
}
}
}
std
::
shared_ptr
<
Tensor
>
predict_add
(
Tensor
&
t1
,
Tensor
&
t2
)
{
// feed
auto
scope
=
program_
.
scope
;
Variable
*
x_feed_value
=
scope
->
Var
(
"pool2d_0.tmp_0"
);
auto
tensor_x
=
x_feed_value
->
GetMutable
<
Tensor
>
();
tensor_x
->
ShareDataWith
(
t1
);
std
::
shared_ptr
<
Tensor
>
predict_add
(
Tensor
&
t1
,
Tensor
&
t2
)
{
// feed
auto
scope
=
program_
.
scope
;
Variable
*
x_feed_value
=
scope
->
Var
(
"pool2d_0.tmp_0"
);
auto
tensor_x
=
x_feed_value
->
GetMutable
<
Tensor
>
();
tensor_x
->
ShareDataWith
(
t1
);
Variable
*
y_feed_value
=
scope
->
Var
(
"fc_0.w_0"
);
auto
tensor_y
=
y_feed_value
->
GetMutable
<
Tensor
>
();
tensor_y
->
ShareDataWith
(
t2
);
Variable
*
y_feed_value
=
scope
->
Var
(
"fc_0.w_0"
);
auto
tensor_y
=
y_feed_value
->
GetMutable
<
Tensor
>
();
tensor_y
->
ShareDataWith
(
t2
);
Variable
*
con_output
=
scope
->
Var
(
"fc_0.tmp_0"
);
Tensor
*
output_tensor
=
con_output
->
GetMutable
<
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
({
3
,
3
});
// DLOG << typeid(output_tensor).name();
// DLOG << "output_tensor dims: " << output_tensor->dims();
Variable
*
con_output
=
scope
->
Var
(
"fc_0.tmp_0"
);
Tensor
*
output_tensor
=
con_output
->
GetMutable
<
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
({
3
,
3
});
// DLOG << typeid(output_tensor).name();
// DLOG << "output_tensor dims: " << output_tensor->dims();
std
::
shared_ptr
<
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
std
::
shared_ptr
<
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
predict_add
(
t1
,
t2
,
0
);
return
out_tensor
;
}
predict_add
(
t1
,
t2
,
0
);
return
out_tensor
;
}
private:
const
framework
::
Program
<
Dtype
>
program_
;
std
::
shared_ptr
<
ProgramDesc
>
to_predict_program_
;
std
::
map
<
framework
::
BlockDesc
,
std
::
vector
<
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>>>
ops_of_block_
;
bool
use_optimize_
=
false
;
void
predict_add
(
const
Tensor
&
t1
,
const
Tensor
&
t2
,
int
block_id
)
{
std
::
shared_ptr
<
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
block_id
);
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
auto
op
=
ops_of_block_
[
*
to_predict_block
.
get
()][
j
];
DLOG
<<
"op -> run()"
;
op
->
Run
();
}
}
};
private:
const
framework
::
Program
<
Dtype
>
program_
;
std
::
shared_ptr
<
ProgramDesc
>
to_predict_program_
;
std
::
map
<
framework
::
BlockDesc
,
std
::
vector
<
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>>>
ops_of_block_
;
bool
use_optimize_
=
false
;
void
predict_add
(
const
Tensor
&
t1
,
const
Tensor
&
t2
,
int
block_id
)
{
std
::
shared_ptr
<
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
block_id
);
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
auto
op
=
ops_of_block_
[
*
to_predict_block
.
get
()][
j
];
DLOG
<<
"op -> run()"
;
op
->
Run
();
}
}
};
template
class
TestMulOp
<
CPU
>;
}
// namespace framework
}
// namespaece paddle_mobile
template
class
TestMulOp
<
CPU
>;
}
// namespace framework
}
// namespace paddle_mobile
int
main
()
{
int
main
()
{
DLOG
<<
"----------**********----------"
;
DLOG
<<
"begin to run MulOp Test"
;
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录