Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
f81222da
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看板
提交
f81222da
编写于
12月 31, 2019
作者:
X
xiebaiyuan
提交者:
GitHub
12月 31, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[mobile][opencl] suite model male2fe ,support a type element_mul ,test=mobile (#2705)
上级
7e75d3c5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
128 addition
and
68 deletion
+128
-68
mobile/src/operators/kernel/cl/cl_kernel/elementwise_mul_kernel.cl
...c/operators/kernel/cl/cl_kernel/elementwise_mul_kernel.cl
+18
-0
mobile/src/operators/kernel/cl/elementwise_mul_kernel.cpp
mobile/src/operators/kernel/cl/elementwise_mul_kernel.cpp
+110
-68
未找到文件。
mobile/src/operators/kernel/cl/cl_kernel/elementwise_mul_kernel.cl
浏览文件 @
f81222da
...
...
@@ -110,4 +110,22 @@ __kernel void channel_mul_d2(__global image2d_t input, __global image2d_t bias,
half4
in
=
read_imageh
(
input,
sampler,
coords
)
;
half4
output
=
mad
(
in,
biase,
0
)
;
write_imageh
(
outputImage,
coords,
output
)
;
}
__kernel
void
channel_mul_d4
(
__global
image2d_t
input,
__global
image2d_t
bias,
__write_only
image2d_t
outputImage,
int
w
)
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
| CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
int2
coords
;
coords.x
=
x
;
coords.y
=
y
;
int2
coords_bias
;
coords_bias.x
=
x
/
w
;
coords_bias.y
=
0
;
half4
in
=
read_imageh
(
input,
sampler,
coords
)
;
half4
biase
=
read_imageh
(
bias,
sampler,
coords_bias
)
;
half4
output
=
in
*
biase
;
write_imageh
(
outputImage,
coords,
output
)
;
}
\ No newline at end of file
mobile/src/operators/kernel/cl/elementwise_mul_kernel.cpp
浏览文件 @
f81222da
...
...
@@ -30,16 +30,23 @@ bool ElementwiseMulKernel<GPU_CL, float>::Init(
if
(
bias
->
dims
()
==
param
->
InputX
()
->
dims
())
{
DLOG
<<
"init element wise mul"
;
this
->
cl_helper_
.
AddKernel
(
"elementwise_mul"
,
"elementwise_mul_kernel.cl"
);
}
else
if
(
bias
->
dims
().
size
()
==
1
)
{
DLOG
<<
"init channel_mul"
;
this
->
cl_helper_
.
AddKernel
(
"channel_mul"
,
"elementwise_mul_kernel.cl"
);
}
else
if
(
bias
->
dims
().
size
()
==
2
)
{
// etc. input 1 72 28 28
// filter 1 72
DLOG
<<
"init channel_mul_d2"
;
this
->
cl_helper_
.
AddKernel
(
"channel_mul_d2"
,
"elementwise_mul_kernel.cl"
);
}
else
{
PADDLE_MOBILE_ENFORCE
(
false
,
"element mul not supported yet"
);
const
int
bias_dim_size
=
bias
->
dims
().
size
();
if
(
bias_dim_size
==
1
)
{
DLOG
<<
"init channel_mul"
;
this
->
cl_helper_
.
AddKernel
(
"channel_mul"
,
"elementwise_mul_kernel.cl"
);
}
else
if
(
bias_dim_size
==
2
)
{
// etc. input 1 72 28 28
// filter 1 72
DLOG
<<
"init channel_mul_d2"
;
this
->
cl_helper_
.
AddKernel
(
"channel_mul_d2"
,
"elementwise_mul_kernel.cl"
);
}
else
if
(
bias_dim_size
==
4
)
{
DLOG
<<
"init channel_mul_d4"
;
this
->
cl_helper_
.
AddKernel
(
"channel_mul_d4"
,
"elementwise_mul_kernel.cl"
);
}
else
{
PADDLE_MOBILE_ENFORCE
(
false
,
"element mul not supported this situation yet"
);
}
}
return
true
;
}
...
...
@@ -71,68 +78,103 @@ void ElementwiseMulKernel<GPU_CL, float>::Compute(
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
if
(
bias
->
dims
().
size
()
==
1
)
{
DLOG
<<
"channel mul"
;
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
input
->
dims
().
size
()
-
1
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
input_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
bias_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
output_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
reinterpret_cast
<
void
*>
(
&
tensor_w
));
CL_CHECK_ERRORS
(
status
);
auto
width
=
input
->
ImageWidth
();
auto
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
if
(
bias
->
dims
().
size
()
==
2
)
{
DLOG
<<
"channel mul d2"
;
}
else
{
const
int
bias_dim_size
=
bias
->
dims
().
size
();
if
(
bias_dim_size
==
1
)
{
DLOG
<<
"channel mul"
;
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
input
->
dims
().
size
()
-
1
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
input_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
bias_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
output_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
reinterpret_cast
<
void
*>
(
&
tensor_w
));
CL_CHECK_ERRORS
(
status
);
auto
width
=
input
->
ImageWidth
();
auto
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
if
(
bias_dim_size
==
2
)
{
DLOG
<<
"channel mul d2"
;
// etc. input 1 72 28 28
// filter 1 72 --> 1 1 1 72
DLOG
<<
"input->ImageDims(): "
<<
input
->
ImageDims
();
DLOG
<<
"bias->ImageDims(): "
<<
bias
->
ImageDims
();
DLOG
<<
"out->ImageDims(): "
<<
output
->
ImageDims
();
// etc. input 1 72 28 28
// filter 1 72 --> 1 1 1 72
DLOG
<<
"input->ImageDims(): "
<<
input
->
ImageDims
();
DLOG
<<
"bias->ImageDims(): "
<<
bias
->
ImageDims
();
DLOG
<<
"out->ImageDims(): "
<<
output
->
ImageDims
();
DLOG
<<
"channel mul d2"
;
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
input
->
dims
().
size
()
-
1
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
input_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
bias_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
output_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
reinterpret_cast
<
void
*>
(
&
tensor_w
));
CL_CHECK_ERRORS
(
status
);
auto
width
=
input
->
ImageWidth
();
auto
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
DLOG
<<
"channel mul d2"
;
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
input
->
dims
().
size
()
-
1
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
input_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
bias_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
output_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
reinterpret_cast
<
void
*>
(
&
tensor_w
));
CL_CHECK_ERRORS
(
status
);
auto
width
=
input
->
ImageWidth
();
auto
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
// bias->PrintTensor(*bias);
}
else
{
PADDLE_MOBILE_ENFORCE
(
false
,
"element mul not support this situation yet"
)
// bias->PrintTensor(*bias);
}
else
if
(
bias_dim_size
==
4
)
{
DLOG
<<
"channel_mul_d4"
;
// etc. input 1 72 28 28
// filter 1 72 --> 1 1 1 72
DLOG
<<
"input->ImageDims(): "
<<
input
->
ImageDims
();
DLOG
<<
"bias->ImageDims(): "
<<
bias
->
ImageDims
();
DLOG
<<
"out->ImageDims(): "
<<
output
->
ImageDims
();
DLOG
<<
"channel mul d2"
;
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
input
->
dims
().
size
()
-
1
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
input_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
bias_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
reinterpret_cast
<
void
*>
(
&
output_image
));
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
reinterpret_cast
<
void
*>
(
&
tensor_w
));
CL_CHECK_ERRORS
(
status
);
auto
width
=
input
->
ImageWidth
();
auto
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
{
PADDLE_MOBILE_ENFORCE
(
false
,
"element mul not support this situation yet"
)
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录