Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a2b6978b
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a2b6978b
编写于
8月 28, 2019
作者:
Z
zp7
提交者:
Yanzhan Yang
8月 28, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix infershape when cmakelist option CPU&GPU_CL is ON, test=develop (#1880)
上级
05d3b19b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
137 addition
and
133 deletion
+137
-133
mobile/src/operators/increment_op.cpp
mobile/src/operators/increment_op.cpp
+3
-3
mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp
mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp
+2
-3
mobile/src/operators/lod_reset_op.cpp
mobile/src/operators/lod_reset_op.cpp
+4
-4
mobile/src/operators/one_hot_op.cpp
mobile/src/operators/one_hot_op.cpp
+3
-3
mobile/src/operators/op_param.h
mobile/src/operators/op_param.h
+1
-1
mobile/src/operators/reduce_prod_op.cpp
mobile/src/operators/reduce_prod_op.cpp
+6
-5
mobile/src/operators/reshape2_op.cpp
mobile/src/operators/reshape2_op.cpp
+37
-37
mobile/src/operators/slice_op.cpp
mobile/src/operators/slice_op.cpp
+32
-28
mobile/src/operators/top_k_op.cpp
mobile/src/operators/top_k_op.cpp
+6
-6
mobile/src/operators/transpose2_op.cpp
mobile/src/operators/transpose2_op.cpp
+43
-43
未找到文件。
mobile/src/operators/increment_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -27,9 +27,9 @@ void IncrementOp<Dtype, T>::InferShape() const {
auto
out
=
this
->
param_
.
Out
();
PADDLE_MOBILE_ENFORCE
(
input
->
numel
()
==
1
,
"input's numel should be 1"
);
out
->
Resize
(
input
->
dims
());
#ifdef PADDLE_MOBILE_CPU
out
->
set_lod
(
input
->
lod
());
#endif
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
out
->
set_lod
(
input
->
lod
());
}
}
}
// namespace operators
...
...
mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp
浏览文件 @
a2b6978b
...
...
@@ -23,13 +23,12 @@ template <>
bool
ElementwiseAddKernel
<
GPU_CL
,
float
>::
Init
(
ElementwiseAddParam
<
GPU_CL
>
*
param
)
{
DLOG
<<
"-----init add-----"
;
CLImage
*
bias
=
reinterpret_cast
<
CLImage
*>
(
const_cast
<
CLImage
*>
(
param
->
InputY
()));
CLImage
*
bias
=
reinterpret_cast
<
CLImage
*>
(
const_cast
<
CLImage
*>
(
param
->
InputY
()));
if
(
!
bias
->
isInit
())
{
bias
->
InitNormalCLImage
(
cl_helper_
.
CLContext
(),
this
->
cl_helper_
.
CLCommandQueue
());
}
DLOG
<<
" bias: "
<<
*
bias
;
if
(
bias
->
dims
().
size
()
==
4
)
{
this
->
cl_helper_
.
AddKernel
(
"elementwise_add"
,
"elementwise_add_kernel.cl"
);
...
...
mobile/src/operators/lod_reset_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -23,11 +23,11 @@ template <typename Dtype, typename T>
void
LodResetOp
<
Dtype
,
T
>::
InferShape
()
const
{
const
auto
&
input_dims
=
this
->
param_
.
input_x_
->
dims
();
this
->
param_
.
output_
->
Resize
(
input_dims
);
#ifdef PADDLE_MOBILE_CPU
if
(
this
->
param_
.
append
)
{
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_x_
->
lod
());
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
if
(
this
->
param_
.
append
)
{
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_x_
->
lod
());
}
}
#endif
}
}
// namespace operators
...
...
mobile/src/operators/one_hot_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -26,9 +26,9 @@ void OnehotOp<Dtype, T>::InferShape() const {
framework
::
DDim
out_dims
(
x_dims
);
out_dims
[
out_dims
.
size
()
-
1
]
=
depth
;
this
->
param_
.
output_
->
Resize
(
out_dims
);
#ifdef PADDLE_MOBILE_CPU
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
#endif
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
}
}
}
// namespace operators
...
...
mobile/src/operators/op_param.h
浏览文件 @
a2b6978b
...
...
@@ -14,9 +14,9 @@ limitations under the License. */
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <memory>
#include "common/log.h"
#include "common/type_define.h"
#include "common/types.h"
...
...
mobile/src/operators/reduce_prod_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#include "operators/reduce_prod_op.h"
#include <algorithm>
#include <vector>
namespace
paddle_mobile
{
namespace
operators
{
...
...
@@ -64,12 +65,12 @@ void ReduceProdOp<Dtype, T>::InferShape() const {
}
auto
out_dims
=
framework
::
make_ddim
(
dims_vector
);
this
->
param_
.
Output
()
->
Resize
(
out_dims
);
#ifdef PADDLE_MOBILE_CPU
if
(
dims
[
0
]
!=
0
)
{
// Only pass LoD when not reducing on the first dim.
this
->
param_
.
Output
()
->
set_lod
(
this
->
param_
.
Input
()
->
lod
());
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
if
(
dims
[
0
]
!=
0
)
{
// Only pass LoD when not reducing on the first dim.
this
->
param_
.
Output
()
->
set_lod
(
this
->
param_
.
Input
()
->
lod
());
}
}
#endif
}
}
...
...
mobile/src/operators/reshape2_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -27,60 +27,60 @@ void Reshape2Op<Dtype, T>::InferShape() const {
}
auto
&
shape
=
this
->
param_
.
Shape
();
auto
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
#ifdef PADDLE_MOBILE_CL
auto
input_dim_size
=
input_x_dims
.
size
();
bool
shouldResize
=
true
;
if
(
input_dim_size
>
4
)
{
for
(
int
i
=
0
;
i
<
input_dim_size
-
4
;
++
i
)
{
if
(
input_x_dims
[
i
]
!=
0
&&
input_x_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
auto
input_dim_size
=
input_x_dims
.
size
();
if
(
input_dim_size
>
4
)
{
for
(
int
i
=
0
;
i
<
input_dim_size
-
4
;
++
i
)
{
if
(
input_x_dims
[
i
]
!=
0
&&
input_x_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
}
}
}
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_intput_dims
;
temp_intput_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
input_dim_size
-
4
;
i
<
input_dim_size
;
++
i
)
{
temp_intput_dims
.
push_back
(
input_x_dims
[
i
]);
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_intput_dims
;
temp_intput_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
input_dim_size
-
4
;
i
<
input_dim_size
;
++
i
)
{
temp_intput_dims
.
push_back
(
input_x_dims
[
i
]);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_intput_dims
);
this
->
param_
.
InputX
()
->
Resize
(
temp_ddim
);
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_intput_dims
);
this
->
param_
.
InputX
()
->
Resize
(
temp_ddim
);
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
}
}
#endif
auto
out_dims
=
ValidateShape
(
shape
,
input_x_dims
);
this
->
param_
.
Out
()
->
Resize
(
out_dims
);
#ifdef PADDLE_MOBILE_CL
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
shouldResize
=
true
;
if
(
out_dims
.
size
()
>
4
)
{
for
(
int
i
=
0
;
i
<
out_dims
.
size
()
-
4
;
++
i
)
{
if
(
out_dims
[
i
]
!=
0
&&
out_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
shouldResize
=
true
;
if
(
out_dims
.
size
()
>
4
)
{
for
(
int
i
=
0
;
i
<
out_dims
.
size
()
-
4
;
++
i
)
{
if
(
out_dims
[
i
]
!=
0
&&
out_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
}
}
}
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_output_dims
;
temp_output_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
out_dims
.
size
()
-
4
;
i
<
out_dims
.
size
();
++
i
)
{
temp_output_dims
.
push_back
(
out_dims
[
i
]);
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_output_dims
;
temp_output_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
out_dims
.
size
()
-
4
;
i
<
out_dims
.
size
();
++
i
)
{
temp_output_dims
.
push_back
(
out_dims
[
i
]);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_output_dims
);
this
->
param_
.
Out
()
->
Resize
(
temp_ddim
);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_output_dims
);
this
->
param_
.
Out
()
->
Resize
(
temp_ddim
);
}
}
#endif
std
::
vector
<
int64_t
>
xshape_dims
(
input_x_dims
.
size
()
+
1
,
0
);
for
(
int
i
=
0
;
i
<
input_x_dims
.
size
();
++
i
)
{
xshape_dims
[
i
+
1
]
=
input_x_dims
[
i
];
}
this
->
param_
.
OutputXShape
()
->
Resize
(
framework
::
make_ddim
(
xshape_dims
));
#ifdef PADDLE_MOBILE_CL
this
->
param_
.
OutputXShape
()
->
Resize
(
input_x_dims
);
#endif
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
this
->
param_
.
OutputXShape
()
->
Resize
(
input_x_dims
);
}
}
}
// namespace operators
...
...
mobile/src/operators/slice_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -26,37 +26,39 @@ void SliceOp<Dtype, T>::InferShape() const {
auto
axes
=
this
->
param_
.
axes_
;
auto
input
=
this
->
param_
.
input_
;
auto
output
=
this
->
param_
.
output_
;
#ifdef PADDLE_MOBILE_CL
auto
output_dims
=
output
->
dims
();
auto
output_dims_size
=
output_dims
.
size
();
bool
should_resize
=
true
;
if
(
output_dims_size
>
4
)
{
for
(
int
i
=
0
;
i
<
output_dims_size
-
4
;
++
i
)
{
if
(
output_dims
[
i
]
!=
0
&&
output_dims
[
i
]
!=
1
)
{
should_resize
=
false
;
break
;
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
auto
output_dims
=
output
->
dims
();
auto
output_dims_size
=
output_dims
.
size
();
bool
should_resize
=
true
;
if
(
output_dims_size
>
4
)
{
for
(
int
i
=
0
;
i
<
output_dims_size
-
4
;
++
i
)
{
if
(
output_dims
[
i
]
!=
0
&&
output_dims
[
i
]
!=
1
)
{
should_resize
=
false
;
break
;
}
}
}
if
(
should_resize
)
{
std
::
vector
<
int64_t
>
temp_output_dims
;
temp_output_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
output_dims_size
-
4
;
i
<
output_dims_size
;
++
i
)
{
temp_output_dims
.
push_back
(
output_dims
[
i
]);
if
(
should_resize
)
{
std
::
vector
<
int64_t
>
temp_output_dims
;
temp_output_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
output_dims_size
-
4
;
i
<
output_dims_size
;
++
i
)
{
temp_output_dims
.
push_back
(
output_dims
[
i
]);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_output_dims
);
this
->
param_
.
output_
->
Resize
(
temp_ddim
);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_output_dims
);
this
->
param_
.
output_
->
Resize
(
temp_ddim
);
}
}
#endif
PADDLE_MOBILE_ENFORCE
(
axes
.
size
()
==
1
,
"axes size should equals 1"
);
PADDLE_MOBILE_ENFORCE
(
input
->
dims
().
size
()
==
output
->
dims
().
size
(),
"input dim size should equals output dim size"
);
PADDLE_MOBILE_ENFORCE
(
output
->
dims
().
size
()
-
(
axes
[
0
]
-
(
this
->
param_
.
original_output_dims_size_
-
this
->
param_
.
output_
->
dims
().
size
()))
==
3
,
"op only support slice channel now"
);
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
PADDLE_MOBILE_ENFORCE
(
output
->
dims
().
size
()
-
(
axes
[
0
]
-
(
this
->
param_
.
original_output_dims_size_
-
this
->
param_
.
output_
->
dims
().
size
()))
==
3
,
"op only support slice channel now"
);
}
auto
starts
=
this
->
param_
.
starts_
;
auto
ends
=
this
->
param_
.
ends_
;
framework
::
DDim
out_dims
(
input
->
dims
());
...
...
@@ -82,11 +84,13 @@ void SliceOp<Dtype, T>::InferShape() const {
}
}
output
->
Resize
(
out_dims
);
#if !defined(PADDLE_MOBILE_CL) && defined(PADDLE_MOBILE_CPU)
if
(
axes
[
0
]
!=
0
)
{
output
->
set_lod
(
input
->
lod
());
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
LoDTensor
*
output_lod
=
reinterpret_cast
<
LoDTensor
*>
(
output
);
LoDTensor
*
input_lod
=
reinterpret_cast
<
LoDTensor
*>
(
input
);
if
(
axes
[
0
]
!=
0
)
{
output_lod
->
set_lod
(
input_lod
->
lod
());
}
}
#endif
}
}
// namespace operators
...
...
mobile/src/operators/top_k_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -19,18 +19,18 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
D
eviceT
ype
,
typename
T
>
void
TopKOp
<
D
eviceT
ype
,
T
>::
InferShape
()
const
{
template
<
typename
D
t
ype
,
typename
T
>
void
TopKOp
<
D
t
ype
,
T
>::
InferShape
()
const
{
const
int
k
=
this
->
param_
.
k_
;
auto
dims
=
this
->
param_
.
input_
->
dims
();
// should check k <= dims[-1] && k >= 1
dims
[
dims
.
size
()
-
1
]
=
k
;
this
->
param_
.
output_
->
Resize
(
dims
);
this
->
param_
.
indices_
->
Resize
(
dims
);
#ifdef PADDLE_MOBILE_CPU
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
this
->
param_
.
indices_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
#endif
if
(
std
::
is_same
<
DeviceType
<
kCPU
>
,
Dtype
>::
value
)
{
this
->
param_
.
output_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
this
->
param_
.
indices_
->
set_lod
(
this
->
param_
.
input_
->
lod
());
}
}
}
// namespace operators
...
...
mobile/src/operators/transpose2_op.cpp
浏览文件 @
a2b6978b
...
...
@@ -29,54 +29,54 @@ void Transpose2Op<Dtype, T>::InferShape() const {
size_t
x_dims_size
=
input_x_dims
.
size
();
size_t
axis_size
=
axis
.
size
();
#ifdef PADDLE_MOBILE_CL
bool
shouldResize
=
true
;
int
diff_dim
=
0
;
if
(
axis_size
>
4
)
{
for
(
int
i
=
0
;
i
<
axis_size
-
4
;
++
i
)
{
if
(
axis
[
i
]
!=
i
)
{
shouldResize
=
false
;
break
;
}
else
{
diff_dim
++
;
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
bool
shouldResize
=
true
;
int
diff_dim
=
0
;
if
(
axis_size
>
4
)
{
for
(
int
i
=
0
;
i
<
axis_size
-
4
;
++
i
)
{
if
(
axis
[
i
]
!=
i
)
{
shouldResize
=
false
;
break
;
}
else
{
diff_dim
++
;
}
}
}
if
(
shouldResize
)
{
std
::
vector
<
int
>
temp_axis_dims
;
temp_axis_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
axis_size
-
4
;
i
<
axis_size
;
++
i
)
{
temp_axis_dims
.
push_back
(
axis
[
i
]
-
diff_dim
);
if
(
shouldResize
)
{
std
::
vector
<
int
>
temp_axis_dims
;
temp_axis_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
axis_size
-
4
;
i
<
axis_size
;
++
i
)
{
temp_axis_dims
.
push_back
(
axis
[
i
]
-
diff_dim
);
}
axis
.
resize
(
4
);
axis
.
clear
();
axis
.
insert
(
axis
.
begin
(),
temp_axis_dims
.
begin
(),
temp_axis_dims
.
end
());
}
axis
.
resize
(
4
);
axis
.
clear
();
axis
.
insert
(
axis
.
begin
(),
temp_axis_dims
.
begin
(),
temp_axis_dims
.
end
());
}
}
auto
input_dim_size
=
input_x_dims
.
size
();
shouldResize
=
true
;
if
(
input_dim_size
>
4
)
{
for
(
int
i
=
0
;
i
<
input_dim_size
-
4
;
++
i
)
{
if
(
input_x_dims
[
i
]
!=
0
&&
input_x_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
auto
input_dim_size
=
input_x_dims
.
size
();
shouldResize
=
true
;
if
(
input_dim_size
>
4
)
{
for
(
int
i
=
0
;
i
<
input_dim_size
-
4
;
++
i
)
{
if
(
input_x_dims
[
i
]
!=
0
&&
input_x_dims
[
i
]
!=
1
)
{
shouldResize
=
false
;
break
;
}
}
}
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_intput_dims
;
temp_intput_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
input_dim_size
-
4
;
i
<
input_dim_size
;
++
i
)
{
temp_intput_dims
.
push_back
(
input_x_dims
[
i
]);
if
(
shouldResize
)
{
std
::
vector
<
int64_t
>
temp_intput_dims
;
temp_intput_dims
.
reserve
(
static_cast
<
size_t
>
(
4
));
for
(
int
i
=
input_dim_size
-
4
;
i
<
input_dim_size
;
++
i
)
{
temp_intput_dims
.
push_back
(
input_x_dims
[
i
]);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_intput_dims
);
this
->
param_
.
InputX
()
->
Resize
(
temp_ddim
);
}
framework
::
DDim
temp_ddim
=
framework
::
make_ddim
(
temp_intput_dims
);
this
->
param_
.
InputX
()
->
Resize
(
temp_ddim
);
}
}
axis_size
=
axis
.
size
();
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
x_dims_size
=
input_x_dims
.
size
();
#endif
axis_size
=
axis
.
size
();
input_x_dims
=
this
->
param_
.
InputX
()
->
dims
();
x_dims_size
=
input_x_dims
.
size
();
}
PADDLE_MOBILE_ENFORCE
((
x_dims_size
==
axis_size
),
"input_dims must "
...
...
@@ -100,9 +100,9 @@ void Transpose2Op<Dtype, T>::InferShape() const {
xshape_dims
[
i
+
1
]
=
input_x_dims
[
i
];
}
this
->
param_
.
OutputXShape
()
->
Resize
(
framework
::
make_ddim
(
xshape_dims
));
#ifdef PADDLE_MOBILE_CL
this
->
param_
.
OutputXShape
()
->
Resize
(
input_x_dims
);
#endif
if
(
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Dtype
>::
value
)
{
this
->
param_
.
OutputXShape
()
->
Resize
(
input_x_dims
);
}
}
}
// namespace operators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录