Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项目经理老王
Mace
提交
34c223e7
Mace
项目概览
项目经理老王
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
34c223e7
编写于
10月 17, 2018
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support eltwise broadcast on channel dimension
上级
f7ee57b0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
64 addition
and
9 deletion
+64
-9
mace/kernels/opencl/cl/eltwise.cl
mace/kernels/opencl/cl/eltwise.cl
+4
-1
mace/kernels/opencl/image/eltwise.h
mace/kernels/opencl/image/eltwise.h
+14
-7
mace/ops/eltwise_test.cc
mace/ops/eltwise_test.cc
+46
-1
未找到文件。
mace/kernels/opencl/cl/eltwise.cl
浏览文件 @
34c223e7
...
...
@@ -35,6 +35,9 @@ __kernel void eltwise(OUT_OF_RANGE_PARAMS
DATA_TYPE4 in1 = READ_IMAGET(input1, SAMPLER, (int2)(chan_idx, batch_idx));
#elif INPUT_TYPE == 3
DATA_TYPE4 in1 = READ_IMAGET(input1, SAMPLER, (int2)(chan_idx, 0));
#elif INPUT_TYPE == 4
DATA_TYPE4 tmp = READ_IMAGET(input1, SAMPLER, (int2)(pos, hb));
DATA_TYPE4 in1 = (DATA_TYPE4)(tmp.x, tmp.x, tmp.x, tmp.x);
#else
DATA_TYPE4 in1 = READ_IMAGET(input1, SAMPLER, (int2)(pos, hb));
#endif
...
...
@@ -80,7 +83,7 @@ __kernel void eltwise(OUT_OF_RANGE_PARAMS
#endif
#endif
#if INPUT_TYPE == 1
#if INPUT_TYPE == 1
|| INPUT_TYPE == 4
#if ELTWISE_TYPE == 0 || ELTWISE_TYPE == 1 || ELTWISE_TYPE == 4 || \
ELTWISE_TYPE == 5 || ELTWISE_TYPE == 8 |
|
ELTWISE_TYPE
==
9
const
int
remain_channel
=
channel
-
4
*
chan_idx
;
...
...
mace/kernels/opencl/image/eltwise.h
浏览文件 @
34c223e7
...
...
@@ -77,12 +77,14 @@ MaceStatus EltwiseKernel<T>::Compute(
}
if
(
input1
->
dim_size
()
==
1
)
{
MACE_CHECK
(
input0
->
dim
(
3
)
==
input1
->
dim
(
0
))
<<
"Element-Wise op
only support channel dimension broadcast"
;
<<
"Element-Wise op
support broadcast on only-channel or non-channel dimension"
;
// NOLINT(whitespace/line_length)
}
else
{
MACE_CHECK
((
input0
->
dim
(
0
)
==
input1
->
dim
(
0
)
||
input1
->
dim
(
0
)
==
1
)
&&
input0
->
dim
(
3
)
==
input1
->
dim
(
3
)
&&
input1
->
dim
(
1
)
==
1
&&
input1
->
dim
(
2
)
==
1
)
<<
"Element-Wise op only support channel dimension broadcast"
;
MACE_CHECK
(((
input0
->
dim
(
0
)
==
input1
->
dim
(
0
)
||
input1
->
dim
(
0
)
==
1
)
&&
input0
->
dim
(
3
)
==
input1
->
dim
(
3
)
&&
input1
->
dim
(
1
)
==
1
&&
input1
->
dim
(
2
)
==
1
)
||
(
input0
->
dim
(
0
)
==
input1
->
dim
(
0
)
&&
input0
->
dim
(
1
)
==
input1
->
dim
(
1
)
&&
input0
->
dim
(
2
)
==
input1
->
dim
(
2
)
&&
input1
->
dim
(
3
)
==
1
))
<<
"Element-Wise op support broadcast on only-channel or non-channel dimension"
;
// NOLINT(whitespace/line_length)
}
}
}
...
...
@@ -129,10 +131,15 @@ MaceStatus EltwiseKernel<T>::Compute(
if
(
input1
==
nullptr
)
{
built_options
.
emplace
(
"-DINPUT_TYPE=1"
);
}
else
if
(
input0
->
size
()
!=
input1
->
size
())
{
if
(
input1
->
dim
(
0
)
==
1
||
input1
->
dim_size
()
==
1
)
if
(
input0
->
dim
(
0
)
==
input1
->
dim
(
0
)
&&
input0
->
dim
(
1
)
==
input1
->
dim
(
1
)
&&
input0
->
dim
(
2
)
==
input1
->
dim
(
2
)
&&
input1
->
dim
(
3
)
==
1
)
{
// only broadcast on channel
built_options
.
emplace
(
"-DINPUT_TYPE=4"
);
}
else
if
(
input1
->
dim
(
0
)
==
1
||
input1
->
dim_size
()
==
1
)
{
built_options
.
emplace
(
"-DINPUT_TYPE=3"
);
else
}
else
{
built_options
.
emplace
(
"-DINPUT_TYPE=2"
);
}
if
(
swapped
)
built_options
.
emplace
(
"-DSWAPPED"
);
}
if
(
!
coeff_
.
empty
())
built_options
.
emplace
(
"-DCOEFF_SUM"
);
...
...
mace/ops/eltwise_test.cc
浏览文件 @
34c223e7
...
...
@@ -202,6 +202,27 @@ void TensorGeneralBroadcastEltwise(const kernels::EltwiseType type,
// Run
net
.
RunOp
(
D
);
}
else
if
(
D
==
DeviceType
::
GPU
)
{
BufferToImage
<
D
,
T
>
(
&
net
,
"Input0"
,
"InputImage0"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
BufferToImage
<
D
,
T
>
(
&
net
,
"Input1"
,
"InputImage1"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
auto
op_builder
=
OpDefBuilder
(
"Eltwise"
,
"EltwiseTest"
)
.
AddIntArg
(
"T"
,
DataTypeToEnum
<
T
>::
v
())
.
Input
(
"InputImage0"
)
.
Input
(
"InputImage1"
)
.
AddIntArg
(
"type"
,
static_cast
<
int
>
(
type
))
.
AddFloatsArg
(
"coeff"
,
coeff
)
.
OutputType
({
kernels
::
IsLogicalType
(
type
)
?
DT_INT32
:
DT_FLOAT
})
.
Output
(
"OutputImage"
);
op_builder
.
Finalize
(
net
.
NewOperatorDef
());
// Run
net
.
RunOp
(
D
);
ImageToBuffer
<
D
,
float
>
(
&
net
,
"OutputImage"
,
"Output"
,
kernels
::
BufferType
::
IN_OUT_CHANNEL
);
}
else
{
MACE_NOT_IMPLEMENTED
;
}
...
...
@@ -747,7 +768,7 @@ TEST_F(EltwiseOpTest, RandomTensorTensorHalf) {
{
3
,
31
,
37
,
17
});
}
TEST_F
(
EltwiseOpTest
,
TensorGeneralBroadcast
)
{
TEST_F
(
EltwiseOpTest
,
TensorGeneralBroadcast
CPU
)
{
TensorGeneralBroadcastEltwise
<
DeviceType
::
CPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
SUM
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
2
,
3
,
4
,
6
,
7
,
8
});
...
...
@@ -774,6 +795,30 @@ TEST_F(EltwiseOpTest, TensorGeneralBroadcast) {
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
1
,
0
,
0
,
0
,
0
,
0
});
}
TEST_F
(
EltwiseOpTest
,
TensorGeneralBroadcastGPU
)
{
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
SUM
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
2
,
3
,
4
,
6
,
7
,
8
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
SUB
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
0
,
1
,
2
,
2
,
3
,
4
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
PROD
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
8
,
10
,
12
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
DIV
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
2
,
2.5
,
3
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
MIN
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
1
,
1
,
1
,
2
,
2
,
2
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
MAX
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
});
TensorGeneralBroadcastEltwise
<
DeviceType
::
GPU
,
float
,
float
>
(
kernels
::
EltwiseType
::
SQR_DIFF
,
{
1
,
1
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
},
{
1
,
1
,
2
,
1
},
{
1
,
2
},
{
1
,
1
,
2
,
3
},
{
0
,
1
,
4
,
4
,
9
,
16
});
}
TEST_F
(
EltwiseOpTest
,
QuantizedSum
)
{
QuantizedSum
({
1
,
32
,
32
,
16
});
QuantizedSum
({
1
,
31
,
31
,
17
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录