Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c52e6647
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看板
未验证
提交
c52e6647
编写于
8月 27, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
8月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix yolov3 test=develop (#1875)
上级
ebcefbba
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
107 addition
and
87 deletion
+107
-87
mobile/src/operators/kernel/cl/gen_code.py
mobile/src/operators/kernel/cl/gen_code.py
+96
-72
mobile/src/operators/slice_op.cpp
mobile/src/operators/slice_op.cpp
+7
-9
mobile/tools/build.sh
mobile/tools/build.sh
+4
-6
未找到文件。
mobile/src/operators/kernel/cl/gen_code.py
浏览文件 @
c52e6647
...
@@ -16,60 +16,37 @@ import re
...
@@ -16,60 +16,37 @@ import re
import
os
import
os
import
sys
import
sys
source
=
"""
def
gen_opencl_kernels
():
#pragma
source
=
"""
#ifdef PADDLE_MOBILE_CL
#pragma
#include <map>
#ifdef PADDLE_MOBILE_CL
#include <string>
#include <map>
#include <vector>
#include <string>
namespace paddle_mobile {
#include <vector>
extern const std::map<std::string, std::vector<unsigned char>> opencl_kernels = {
namespace paddle_mobile {
%s
extern const std::map<std::string, std::vector<unsigned char>> opencl_kernels = {
};
%s
extern const std::vector<std::string> need_conv_header_kernels = {
};
%s
extern const std::vector<std::string> need_conv_header_kernels = {
};
%s
}
};
#endif
}
"""
#endif
"""
def
string_to_hex
(
str
):
def
string_to_hex
(
str
):
hex_list
=
[]
hex_list
=
[]
for
i
in
range
(
len
(
code_str
)):
for
i
in
range
(
len
(
code_str
)):
hex_
=
hex
(
ord
(
code_str
[
i
]))
hex_
=
hex
(
ord
(
code_str
[
i
]))
hex_list
.
append
(
hex_
)
hex_list
.
append
(
hex_
)
return
hex_list
return
hex_list
infile
=
open
(
"cl_kernel/cl_common.h"
,
"r"
)
infile
=
open
(
"cl_kernel/cl_common.h"
,
"r"
)
common_content
=
infile
.
read
()
common_content
=
infile
.
read
()
infile
.
close
()
common_content
=
re
.
sub
(
r
"/\*[^*]*\*/"
,
""
,
common_content
,
flags
=
re
.
DOTALL
)
lines
=
common_content
.
split
(
"
\n
"
)
new_lines
=
[]
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
line
=
line
.
strip
()
if
line
==
""
:
continue
if
line
.
startswith
(
"//"
):
continue
line
=
re
.
sub
(
r
"//.*$"
,
""
,
line
)
new_lines
.
append
(
line
)
common_content
=
"
\n
"
.
join
(
new_lines
)
need_conv_header_kernels
=
[]
cores
=
""
filenames
=
os
.
listdir
(
"cl_kernel"
)
file_count
=
len
(
filenames
)
for
i
in
range
(
file_count
):
filename
=
filenames
[
i
]
infile
=
open
(
"cl_kernel/"
+
filename
,
"r"
)
new_lines
=
[]
content
=
infile
.
read
()
content
=
re
.
sub
(
r
"/\*[^*]*\*/"
,
""
,
content
,
flags
=
re
.
DOTALL
)
infile
.
close
()
infile
.
close
()
lines
=
content
.
split
(
"
\n
"
)
common_content
=
re
.
sub
(
r
"/\*[^*]*\*/"
,
""
,
common_content
,
flags
=
re
.
DOTALL
)
lines
=
common_content
.
split
(
"
\n
"
)
new_lines
=
[]
for
i
in
range
(
len
(
lines
)):
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
line
=
lines
[
i
]
line
=
line
.
strip
()
line
=
line
.
strip
()
...
@@ -78,26 +55,73 @@ for i in range(file_count):
...
@@ -78,26 +55,73 @@ for i in range(file_count):
if
line
.
startswith
(
"//"
):
if
line
.
startswith
(
"//"
):
continue
continue
line
=
re
.
sub
(
r
"//.*$"
,
""
,
line
)
line
=
re
.
sub
(
r
"//.*$"
,
""
,
line
)
if
"cl_common.h"
in
line
:
line
=
common_content
elif
"conv_kernel.inc.cl"
in
line
:
need_conv_header_kernels
.
append
(
"
\"
%s
\"
"
%
filename
)
continue
new_lines
.
append
(
line
)
new_lines
.
append
(
line
)
content
=
"
\n
"
.
join
(
new_lines
)
common_content
=
"
\n
"
.
join
(
new_lines
)
if
content
==
""
:
content
=
" "
need_conv_header_kernels
=
[]
hexes
=
[]
for
char
in
content
:
cores
=
""
hexes
.
append
(
hex
(
ord
(
char
)))
filenames
=
os
.
listdir
(
"cl_kernel"
)
core
=
" {
\"
%s
\"
, {"
%
filename
file_count
=
len
(
filenames
)
for
item
in
hexes
:
for
i
in
range
(
file_count
):
core
+=
str
(
item
)
+
", "
filename
=
filenames
[
i
]
core
=
core
[:
-
2
]
infile
=
open
(
"cl_kernel/"
+
filename
,
"r"
)
core
+=
"}}"
new_lines
=
[]
if
i
!=
file_count
-
1
:
content
=
infile
.
read
()
core
+=
",
\n
"
content
=
re
.
sub
(
r
"/\*[^*]*\*/"
,
""
,
content
,
flags
=
re
.
DOTALL
)
cores
+=
core
infile
.
close
()
lines
=
content
.
split
(
"
\n
"
)
for
i
in
range
(
len
(
lines
)):
line
=
lines
[
i
]
line
=
line
.
strip
()
if
line
==
""
:
continue
if
line
.
startswith
(
"//"
):
continue
line
=
re
.
sub
(
r
"//.*$"
,
""
,
line
)
if
"cl_common.h"
in
line
:
line
=
common_content
elif
"conv_kernel.inc.cl"
in
line
:
need_conv_header_kernels
.
append
(
"
\"
%s
\"
"
%
filename
)
continue
new_lines
.
append
(
line
)
content
=
"
\n
"
.
join
(
new_lines
)
if
content
==
""
:
content
=
" "
hexes
=
[]
for
char
in
content
:
hexes
.
append
(
hex
(
ord
(
char
)))
core
=
" {
\"
%s
\"
, {"
%
filename
for
item
in
hexes
:
core
+=
str
(
item
)
+
", "
core
=
core
[:
-
2
]
core
+=
"}}"
if
i
!=
file_count
-
1
:
core
+=
",
\n
"
cores
+=
core
source
=
source
%
(
cores
,
","
.
join
(
need_conv_header_kernels
))
print
(
source
)
def
gen_empty_opencl_kernels
():
source
=
"""
#pragma
#ifdef PADDLE_MOBILE_CL
#include <map>
#include <string>
#include <vector>
namespace paddle_mobile {
extern const std::map<std::string, std::vector<unsigned char>> opencl_kernels = {
};
extern const std::vector<std::string> need_conv_header_kernels = {
};
}
#endif
"""
print
(
source
)
source
=
source
%
(
cores
,
","
.
join
(
need_conv_header_kernels
))
if
__name__
==
"__main__"
:
print
(
source
)
if
sys
.
argv
[
1
]
==
"0"
:
gen_empty_opencl_kernels
()
elif
sys
.
argv
[
1
]
==
"1"
:
gen_opencl_kernels
()
mobile/src/operators/slice_op.cpp
浏览文件 @
c52e6647
...
@@ -15,7 +15,9 @@ limitations under the License. */
...
@@ -15,7 +15,9 @@ limitations under the License. */
#ifdef SLICE_OP
#ifdef SLICE_OP
#include "operators/slice_op.h"
#include "operators/slice_op.h"
#include <algorithm>
#include <vector>
#include <vector>
namespace
paddle_mobile
{
namespace
paddle_mobile
{
namespace
operators
{
namespace
operators
{
...
@@ -49,18 +51,12 @@ void SliceOp<Dtype, T>::InferShape() const {
...
@@ -49,18 +51,12 @@ void SliceOp<Dtype, T>::InferShape() const {
PADDLE_MOBILE_ENFORCE
(
axes
.
size
()
==
1
,
"axes size should equals 1"
);
PADDLE_MOBILE_ENFORCE
(
axes
.
size
()
==
1
,
"axes size should equals 1"
);
PADDLE_MOBILE_ENFORCE
(
input
->
dims
().
size
()
==
output
->
dims
().
size
(),
PADDLE_MOBILE_ENFORCE
(
input
->
dims
().
size
()
==
output
->
dims
().
size
(),
"input dim size should equals output dim size"
);
"input dim size should equals output dim size"
);
#ifdef PADDLE_MOBILE_CL
PADDLE_MOBILE_ENFORCE
(
PADDLE_MOBILE_ENFORCE
(
in
put
->
dims
().
size
()
-
out
put
->
dims
().
size
()
-
(
axes
[
0
]
-
(
this
->
param_
.
original_output_dims_size_
-
(
axes
[
0
]
-
(
this
->
param_
.
original_output_dims_size_
-
this
->
param_
.
output_
->
dims
().
size
()))
==
this
->
param_
.
output_
->
dims
().
size
()))
==
3
,
3
,
"op only support slice channel now"
);
"op only support slice channel now"
);
#endif
if
(
input
->
dims
().
size
()
>=
4
)
{
PADDLE_MOBILE_ENFORCE
(
input
->
dims
().
size
()
-
axes
[
0
]
==
3
,
"op only support slice channel now"
);
}
auto
starts
=
this
->
param_
.
starts_
;
auto
starts
=
this
->
param_
.
starts_
;
auto
ends
=
this
->
param_
.
ends_
;
auto
ends
=
this
->
param_
.
ends_
;
framework
::
DDim
out_dims
(
input
->
dims
());
framework
::
DDim
out_dims
(
input
->
dims
());
...
@@ -70,7 +66,9 @@ void SliceOp<Dtype, T>::InferShape() const {
...
@@ -70,7 +66,9 @@ void SliceOp<Dtype, T>::InferShape() const {
"axes.size should equal starts.size"
);
"axes.size should equal starts.size"
);
int
dim_value
,
start
,
end
;
int
dim_value
,
start
,
end
;
for
(
size_t
i
=
0
;
i
<
axes
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
axes
.
size
();
++
i
)
{
dim_value
=
out_dims
[
axes
[
i
]];
int
axis
=
axes
[
i
]
-
(
this
->
param_
.
original_output_dims_size_
-
this
->
param_
.
output_
->
dims
().
size
());
dim_value
=
out_dims
[
axis
];
if
(
dim_value
>
0
)
{
if
(
dim_value
>
0
)
{
start
=
starts
[
i
]
<
0
?
(
starts
[
i
]
+
dim_value
)
:
starts
[
i
];
start
=
starts
[
i
]
<
0
?
(
starts
[
i
]
+
dim_value
)
:
starts
[
i
];
end
=
ends
[
i
]
<
0
?
(
ends
[
i
]
+
dim_value
)
:
ends
[
i
];
end
=
ends
[
i
]
<
0
?
(
ends
[
i
]
+
dim_value
)
:
ends
[
i
];
...
@@ -80,7 +78,7 @@ void SliceOp<Dtype, T>::InferShape() const {
...
@@ -80,7 +78,7 @@ void SliceOp<Dtype, T>::InferShape() const {
end
=
std
::
min
(
end
,
dim_value
);
end
=
std
::
min
(
end
,
dim_value
);
// start = std::min(start, end);
// start = std::min(start, end);
PADDLE_MOBILE_ENFORCE
(
end
>
start
,
"end should greater than start"
);
PADDLE_MOBILE_ENFORCE
(
end
>
start
,
"end should greater than start"
);
out_dims
[
ax
es
[
i
]
]
=
end
-
start
;
out_dims
[
ax
is
]
=
end
-
start
;
}
}
}
}
output
->
Resize
(
out_dims
);
output
->
Resize
(
out_dims
);
...
...
mobile/tools/build.sh
浏览文件 @
c52e6647
...
@@ -3,13 +3,11 @@ NETS=""
...
@@ -3,13 +3,11 @@ NETS=""
declare
-a
supportedNets
=(
"googlenet"
"mobilenet"
"yolo"
"squeezenet"
"resnet"
"mobilenetssd"
"nlp"
"mobilenetfssd"
"genet"
"super"
"op"
)
declare
-a
supportedNets
=(
"googlenet"
"mobilenet"
"yolo"
"squeezenet"
"resnet"
"mobilenetssd"
"nlp"
"mobilenetfssd"
"genet"
"super"
"op"
)
# merge cl to so
# merge cl to so
merge_cl_to_so
=
1
merge_cl_to_so
=
0
rm
../src/operators/kernel/cl/opencl_kernels.cpp
rm
../src/operators/kernel/cl/opencl_kernels.cpp
if
[
$merge_cl_to_so
==
1
]
;
then
cd
../src/operators/kernel/cl
cd
../src/operators/kernel/cl
python gen_code.py
$merge_cl_to_so
>
opencl_kernels.cpp
python gen_code.py
>
opencl_kernels.cpp
cd
-
cd
-
fi
build_for_mac
()
{
build_for_mac
()
{
if
[
!
`
which brew
`
]
;
then
if
[
!
`
which brew
`
]
;
then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录