Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a2bd1692
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看板
提交
a2bd1692
编写于
10月 25, 2018
作者:
Y
yangfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
depthwise_conv op kernel for gpu
上级
1b01d23c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
109 addition
and
12 deletion
+109
-12
src/framework/cl/cl_image.h
src/framework/cl/cl_image.h
+8
-0
src/framework/cl/cl_image_converter.cpp
src/framework/cl/cl_image_converter.cpp
+92
-0
src/framework/cl/cl_image_converter.h
src/framework/cl/cl_image_converter.h
+6
-0
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
+3
-12
未找到文件。
src/framework/cl/cl_image.h
浏览文件 @
a2bd1692
...
...
@@ -106,6 +106,14 @@ class CLImage {
InitCLImage
(
context
,
command_queue
,
folder_converter
);
PADDLE_MOBILE_ENFORCE
(
tensor_dims_
.
size
()
==
4
,
" tensor dim is not 4"
);
}
void
InitDWImage
(
cl_context
context
,
cl_command_queue
command_queue
)
{
if
(
tensor_data_
==
nullptr
)
{
PADDLE_MOBILE_THROW_EXCEPTION
(
" need call SetTensorData first"
);
}
CLImageConverterDWBlock
*
dw_converter
=
new
CLImageConverterDWBlock
();
InitCLImage
(
context
,
command_queue
,
dw_converter
);
PADDLE_MOBILE_ENFORCE
(
tensor_dims_
.
size
()
==
4
,
" tensor dim is not 4"
);
}
void
InitEmptyImage
(
cl_context
context
,
cl_command_queue
command_queue
,
const
DDim
&
dim
)
{
...
...
src/framework/cl/cl_image_converter.cpp
浏览文件 @
a2bd1692
...
...
@@ -297,5 +297,97 @@ void CLImageConverterNWBlock::ImageToNCHW(half_t *image, float *tensor,
DLOG
<<
" init done"
;
}
const
DDim
&
CLImageConverterDWBlock
::
InitImageDimInfoWith
(
const
DDim
&
tensor_dim
)
{
PADDLE_MOBILE_ENFORCE
(
tensor_dim
.
size
()
==
4
,
" tensor dim is not 4"
);
size_t
N
,
C
,
H
,
W
;
N
=
tensor_dim
[
0
];
C
=
tensor_dim
[
1
];
H
=
tensor_dim
[
2
];
W
=
tensor_dim
[
3
];
size_t
width
=
W
*
((
N
+
3
)
/
4
);
size_t
height
=
C
*
H
;
return
make_ddim
({
width
,
height
});
}
void
CLImageConverterDWBlock
::
NCHWToImage
(
float
*
tensor
,
half_t
*
image
,
const
DDim
&
tensor_dim
)
{
size_t
new_dims
[]
=
{
1
,
1
,
1
,
1
};
for
(
int
j
=
0
;
j
<
tensor_dim
.
size
();
++
j
)
{
new_dims
[
4
-
tensor_dim
.
size
()
+
j
]
=
tensor_dim
[
j
];
}
size_t
N
,
C
,
H
,
W
;
N
=
new_dims
[
1
];
C
=
new_dims
[
0
];
H
=
new_dims
[
2
];
W
=
new_dims
[
3
];
DDim
in_image_dim
=
InitImageDimInfoWith
(
tensor_dim
);
DLOG
<<
" tensor dim "
<<
tensor_dim
;
DLOG
<<
" image dim "
<<
in_image_dim
;
size_t
width
=
in_image_dim
[
0
];
size_t
height
=
in_image_dim
[
1
];
int
w_block
=
width
/
W
;
float
*
p
=
tensor
;
size_t
i0
=
0
;
for
(
int
n
=
0
;
n
<
N
;
n
++
)
{
for
(
int
c
=
0
;
c
<
w_block
*
4
;
c
++
)
{
size_t
i1
=
i0
+
(
c
/
4
)
*
W
;
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
if
(
c
<
C
)
{
// int x = (n * width * H + h * width + (c / 4) * W + w) * 4 +
// (c % 4);
image
[
i2
]
=
Float2Half
(
*
p
);
i2
+=
4
;
p
++
;
}
else
{
image
[
i2
]
=
0.0
;
i2
+=
4
;
}
}
i1
+=
width
;
}
}
i0
+=
width
*
H
;
}
}
void
CLImageConverterDWBlock
::
ImageToNCHW
(
half_t
*
image
,
float
*
tensor
,
const
DDim
&
image_dim
,
const
DDim
&
tensor_dim
)
{
PADDLE_MOBILE_ENFORCE
(
tensor_dim
.
size
()
==
4
,
" tensor dim is not 4"
);
float
*
p
=
tensor
;
int
N
=
tensor_dim
[
1
];
int
C
=
tensor_dim
[
0
];
int
H
=
tensor_dim
[
2
];
int
W
=
tensor_dim
[
3
];
int
width
=
image_dim
[
0
];
int
height
=
image_dim
[
0
];
size_t
i0
=
0
;
for
(
int
n
=
0
;
n
<
N
;
n
++
)
{
for
(
int
c
=
0
;
c
<
C
;
c
++
)
{
size_t
i1
=
i0
+
(
c
/
4
)
*
W
;
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
*
p
=
Half2Float
(
image
[
i2
]);
i2
+=
4
;
p
++
;
}
i1
+=
width
;
}
}
i0
+=
width
*
H
;
}
}
}
// namespace framework
}
// namespace paddle_mobile
src/framework/cl/cl_image_converter.h
浏览文件 @
a2bd1692
...
...
@@ -69,6 +69,12 @@ class CLImageConverterNWBlock : public CLImageConverterBase {
void
ImageToNCHW
(
half_t
*
image
,
float
*
tensor
,
const
DDim
&
image_dim
,
const
DDim
&
tensor_dim
);
};
class
CLImageConverterDWBlock
:
public
CLImageConverterBase
{
const
DDim
&
InitImageDimInfoWith
(
const
DDim
&
tensor_dim
);
void
NCHWToImage
(
float
*
tensor
,
half_t
*
image
,
const
DDim
&
tensor_dim
);
void
ImageToNCHW
(
half_t
*
image
,
float
*
tensor
,
const
DDim
&
image_dim
,
const
DDim
&
tensor_dim
);
};
}
// namespace framework
}
// namespace paddle_mobile
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
浏览文件 @
a2bd1692
...
...
@@ -29,15 +29,6 @@ bool ConvAddBNReluKernel<GPU_CL, float>::Init(
param
->
Paddings
()[
0
]
==
param
->
Paddings
()[
1
],
"need equal"
);
auto
filter_ddim
=
param
->
Filter
()
->
dims
();
std
::
vector
<
int64_t
>
filter_shape
(
{
filter_ddim
[
1
],
filter_ddim
[
0
],
filter_ddim
[
2
],
filter_ddim
[
3
]});
framework
::
DDim
ddim
=
framework
::
make_ddim
(
filter_shape
);
if
(
filter_ddim
[
1
]
==
1
)
{
param
->
Filter
()
->
Resize
(
ddim
);
}
param
->
Bias
()
->
InitCLImage
(
cl_helper_
.
CLContext
(),
cl_helper_
.
CLCommandQueue
());
...
...
@@ -140,10 +131,10 @@ bool ConvAddBNReluKernel<GPU_CL, float>::Init(
this
->
cl_helper_
.
AddKernel
(
"conv_1x1"
,
"conv_add_bn_relu_kernel.cl"
);
DLOG
<<
" conv add bn relu conv 1x1"
;
}
else
if
(
param
->
Filter
()
->
dims
()[
0
]
==
1
&&
}
else
if
(
param
->
Filter
()
->
dims
()[
1
]
==
1
&&
param
->
Input
()
->
dims
()[
1
]
==
param
->
Output
()
->
dims
()[
1
]
&&
param
->
Filter
()
->
dims
()[
2
]
==
3
)
{
param
->
Filter
()
->
Init
CL
Image
(
cl_helper_
.
CLContext
(),
param
->
Filter
()
->
Init
DW
Image
(
cl_helper_
.
CLContext
(),
cl_helper_
.
CLCommandQueue
());
this
->
cl_helper_
.
AddKernel
(
"depth_conv_3x3"
,
"conv_add_bn_relu_kernel.cl"
);
DLOG
<<
" conv add bn relu depth_conv_3x3"
;
...
...
@@ -151,7 +142,7 @@ bool ConvAddBNReluKernel<GPU_CL, float>::Init(
}
else
if
(
param
->
Filter
()
->
dims
()[
2
]
==
3
&&
param
->
Filter
()
->
dims
()[
3
]
==
3
)
{
param
->
Filter
()
->
InitCLImage
(
cl_helper_
.
CLContext
(),
cl_helper_
.
CLCommandQueue
());
cl_helper_
.
CLCommandQueue
());
this
->
cl_helper_
.
AddKernel
(
"conv_3x3"
,
"conv_add_bn_relu_kernel.cl"
);
DLOG
<<
" conv add bn relu conv_3x3"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录