Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
28d07522
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
28d07522
编写于
10月 23, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve opencl assign operation
上级
6cc1d13d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
18 deletion
+43
-18
mace/kernels/opencl/cl/assign_f32.cl
mace/kernels/opencl/cl/assign_f32.cl
+34
-9
mace/kernels/opencl/conv_2d_opencl_1x1.cc
mace/kernels/opencl/conv_2d_opencl_1x1.cc
+9
-9
未找到文件。
mace/kernels/opencl/cl/assign_f32.cl
浏览文件 @
28d07522
void
kernel
assign_f32
(
global
float
*vec,
private
const
float
value
)
{
int
idx
=
get_global_id
(
0
)
;
vec[idx]
=
value
;
void
kernel
assign_v16_f32
(
global
float
*output,
private
const
float
value,
private
const
int
pixels
)
{
int
pixel_block
=
get_global_id
(
0
)
;
int
pixel_offset
=
pixel_block
*
16
;
float
*output_ptr
=
output
+
pixel_offset
;
int
remains
=
pixels
-
pixel_offset
;
if
(
remains
>=
16
)
{
for
(
int
i
=
0
; i < 4; ++i) {
vstore4
(
value,
i,
output_ptr
)
;
}
}
else
{
for
(
int
i
=
0
; i < remains; ++i) {
output_ptr[i]
=
value
;
}
}
}
void
kernel
assign_
vec_f32
(
global
float
*vec
,
global
float
*values,
private
int
pixels
)
{
void
kernel
assign_
3d_v16_f32
(
global
float
*output
,
global
const
float
*values,
private
const
int
pixels
)
{
int
batch
=
get_global_id
(
0
)
;
int
channel
=
get_global_id
(
1
)
;
int
channels
=
get_global_size
(
1
)
;
int
pixel_block
=
get_global_id
(
2
)
;
int
pixel_offset
=
pixel_block
*
16
;
float
value
=
values[channel]
;
float
*ptr
=
vec
+
(
batch
*
channels
+
channel
)
*
pixels
;
for
(
int
i
=
0
; i < pixels; ++i) {
ptr[i]
=
value
;
float
*output_ptr
=
output
+
(
batch
*
channels
+
channel
)
*
pixels
+
pixel_offset
;
int
remains
=
pixels
-
pixel_offset
;
if
(
remains
>=
16
)
{
for
(
int
i
=
0
; i < 4; ++i) {
vstore4
(
value,
i,
output_ptr
)
;
}
}
else
{
for
(
int
i
=
0
; i < remains; ++i) {
output_ptr[i]
=
value
;
}
}
}
mace/kernels/opencl/conv_2d_opencl_1x1.cc
浏览文件 @
28d07522
...
...
@@ -13,35 +13,35 @@ namespace kernels {
static
constexpr
index_t
kInputChannelBlockSize
=
2
;
static
constexpr
index_t
kOutputChannelBlockSize
=
4
;
// TODO(heliangliang) fix bad performance
void
AssignBias
(
Tensor
*
output
,
const
Tensor
*
bias
)
{
auto
runtime
=
OpenCLRuntime
::
Get
();
auto
program
=
runtime
->
program
();
if
(
bias
==
nullptr
)
{
auto
assign_bias
=
cl
::
KernelFunctor
<
cl
::
Buffer
,
float
>
(
program
,
"assign_f32"
);
int
global_size
=
output
->
NumElements
();
cl
::
KernelFunctor
<
cl
::
Buffer
,
float
,
int
>
(
program
,
"assign_v16_f32"
);
index_t
pixels
=
output
->
NumElements
();
index_t
blocks
=
(
pixels
+
15
)
/
16
;
cl_int
error
;
assign_bias
(
cl
::
EnqueueArgs
(
runtime
->
command_queue
(),
cl
::
NDRange
(
global_size
),
cl
::
NDRange
(
blocks
),
cl
::
NullRange
),
*
(
static_cast
<
cl
::
Buffer
*>
(
output
->
buffer
())),
0.0
f
,
error
);
0.0
f
,
static_cast
<
int
>
(
pixels
),
error
);
MACE_CHECK
(
error
==
CL_SUCCESS
);
}
else
{
auto
output_shape
=
output
->
shape
();
index_t
batch
=
output_shape
[
0
];
index_t
channels
=
output_shape
[
1
];
index_t
pixels
=
output_shape
[
2
]
*
output_shape
[
3
];
index_t
blocks
=
(
pixels
+
15
)
/
16
;
MACE_CHECK
(
channels
==
bias
->
shape
()[
0
],
"Channels mismatch"
);
auto
assign_bias
=
cl
::
KernelFunctor
<
cl
::
Buffer
,
cl
::
Buffer
,
int
>
(
program
,
"assign_
vec
_f32"
);
cl
::
KernelFunctor
<
cl
::
Buffer
,
cl
::
Buffer
,
int
>
(
program
,
"assign_
3d_v16
_f32"
);
cl_int
error
;
assign_bias
(
cl
::
EnqueueArgs
(
runtime
->
command_queue
(),
cl
::
NDRange
(
batch
,
channels
),
cl
::
N
ullRange
),
cl
::
NDRange
(
batch
,
channels
,
blocks
),
cl
::
N
DRange
(
1
,
8
,
128
)
),
*
(
static_cast
<
cl
::
Buffer
*>
(
output
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
bias
->
buffer
())),
static_cast
<
int
>
(
pixels
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录