Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
5d5d06c2
Mace
项目概览
慢慢CG
/
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看板
提交
5d5d06c2
编写于
12月 02, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix buffer to image bug for half type and refactor some cl apis.
上级
3272a989
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
86 addition
and
36 deletion
+86
-36
mace/kernels/opencl/addn.cc
mace/kernels/opencl/addn.cc
+1
-1
mace/kernels/opencl/batch_norm_opencl.cc
mace/kernels/opencl/batch_norm_opencl.cc
+1
-1
mace/kernels/opencl/buffer_to_image.cc
mace/kernels/opencl/buffer_to_image.cc
+7
-2
mace/kernels/opencl/conv_2d_opencl_1x1.cc
mace/kernels/opencl/conv_2d_opencl_1x1.cc
+2
-2
mace/kernels/opencl/conv_2d_opencl_3x3.cc
mace/kernels/opencl/conv_2d_opencl_3x3.cc
+2
-2
mace/kernels/opencl/depthwise_conv_opencl_3x3.cc
mace/kernels/opencl/depthwise_conv_opencl_3x3.cc
+1
-1
mace/kernels/opencl/helper.cc
mace/kernels/opencl/helper.cc
+26
-18
mace/kernels/opencl/helper.h
mace/kernels/opencl/helper.h
+5
-2
mace/kernels/opencl/pooling_opencl.cc
mace/kernels/opencl/pooling_opencl.cc
+2
-2
mace/kernels/opencl/relu_opencl.cc
mace/kernels/opencl/relu_opencl.cc
+1
-1
mace/kernels/opencl/resize_bilinear_opencl.cc
mace/kernels/opencl/resize_bilinear_opencl.cc
+2
-2
mace/kernels/opencl/space_to_batch_opecl.cc
mace/kernels/opencl/space_to_batch_opecl.cc
+1
-1
mace/ops/buffer_to_image_test.cc
mace/ops/buffer_to_image_test.cc
+35
-1
未找到文件。
mace/kernels/opencl/addn.cc
浏览文件 @
5d5d06c2
...
...
@@ -17,7 +17,7 @@ static void Add2(const Tensor *input0, const Tensor *input1, Tensor *output) {
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
output
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
output
->
dtype
()));
auto
addn_kernel
=
runtime
->
BuildKernel
(
"addn"
,
"add2"
,
built_options
);
const
uint32_t
lws
=
runtime
->
GetKernelMaxWorkGroupSize
(
addn_kernel
);
...
...
mace/kernels/opencl/batch_norm_opencl.cc
浏览文件 @
5d5d06c2
...
...
@@ -30,7 +30,7 @@ void BatchNormFunctor<DeviceType::OPENCL, float>::operator()(
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
input
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
input
->
dtype
()));
auto
bm_kernel
=
runtime
->
BuildKernel
(
"batch_norm"
,
"batch_norm"
,
built_options
);
const
uint32_t
kwg_size
=
runtime
->
GetKernelMaxWorkGroupSize
(
bm_kernel
);
...
...
mace/kernels/opencl/buffer_to_image.cc
浏览文件 @
5d5d06c2
...
...
@@ -24,8 +24,13 @@ void BufferToImageFunctor<DeviceType::OPENCL, T>::operator()(Tensor *buffer,
}
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
DataTypeToCLType
(
DataTypeToEnum
<
T
>::
value
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
DataTypeToOPENCLCMDDataType
(
DataTypeToEnum
<
T
>::
value
));
if
(
buffer
->
dtype
()
==
image
->
dtype
())
{
built_options
.
emplace
(
"-DDATA_TYPE="
+
DtToCLDt
(
DataTypeToEnum
<
T
>::
value
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
DtToCLCMDDt
(
DataTypeToEnum
<
T
>::
value
));
}
else
{
built_options
.
emplace
(
"-DDATA_TYPE="
+
DtToUpstreamCLDt
(
DataTypeToEnum
<
T
>::
value
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
DtToUpstreamCLCMDDt
(
DataTypeToEnum
<
T
>::
value
));
}
auto
runtime
=
OpenCLRuntime
::
Get
();
string
kernel_name
;
switch
(
type
)
{
...
...
mace/kernels/opencl/conv_2d_opencl_1x1.cc
浏览文件 @
5d5d06c2
...
...
@@ -34,8 +34,8 @@ void Conv1x1(const Tensor *input,
MACE_CHECK
(
input_batch
==
batch
);
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
ataTypeToOPENCLCMDDataType
(
dt
));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
tToUpstreamCLCMDDt
(
dt
));
built_options
.
emplace
(
"-DSTRIDE="
+
ToString
(
stride
));
if
(
bias
!=
nullptr
)
{
built_options
.
emplace
(
"-DBIAS"
);
...
...
mace/kernels/opencl/conv_2d_opencl_3x3.cc
浏览文件 @
5d5d06c2
...
...
@@ -26,8 +26,8 @@ static void Conv2d3x3S12(const Tensor *input, const Tensor *filter,
const
index_t
width_blocks
=
RoundUpDiv
<
index_t
,
5
>
(
width
);
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
ataTypeToOPENCLCMDDataType
(
dt
));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
tToUpstreamCLCMDDt
(
dt
));
built_options
.
emplace
(
bias
!=
nullptr
?
"-DBIAS"
:
""
);
built_options
.
emplace
(
"-DSTRIDE="
+
ToString
(
stride
));
if
(
fused_relu
)
{
...
...
mace/kernels/opencl/depthwise_conv_opencl_3x3.cc
浏览文件 @
5d5d06c2
...
...
@@ -32,7 +32,7 @@ static void InnerDepthwiseConvOpenclK3x3S12(const Tensor *input,
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
input
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
input
->
dtype
()));
built_options
.
emplace
(
stride
==
1
?
"-DSTRIDE_1"
:
""
);
built_options
.
emplace
(
bias
!=
nullptr
?
"-DBIAS"
:
""
);
auto
conv_kernel
=
runtime
->
BuildKernel
(
"depthwise_conv_3x3"
,
"depthwise_conv_3x3"
,
built_options
);
...
...
mace/kernels/opencl/helper.cc
浏览文件 @
5d5d06c2
...
...
@@ -54,34 +54,42 @@ void CalImage2DShape(const std::vector<index_t> &shape, /* NHWC */
}
std
::
string
DataTypeToCLType
(
const
DataType
dt
)
{
std
::
string
DtToCLDt
(
const
DataType
dt
)
{
switch
(
dt
)
{
case
DT_FLOAT
:
return
"float"
;
case
DT_HALF
:
return
"half"
;
default:
LOG
(
FATAL
)
<<
"Unsupported data type"
;
return
""
;
}
}
std
::
string
DtToCLCMDDt
(
const
DataType
dt
)
{
switch
(
dt
)
{
case
DT_FLOAT
:
return
"f"
;
case
DT_HALF
:
return
"h"
;
default:
LOG
(
FATAL
)
<<
"Not supported data type for opencl cmd data type"
;
return
""
;
}
}
std
::
string
DtToUpstreamCLDt
(
const
DataType
dt
)
{
switch
(
dt
)
{
case
DT_FLOAT
:
case
DT_HALF
:
return
"float"
;
case
DT_UINT8
:
return
"uchar"
;
case
DT_INT8
:
return
"char"
;
case
DT_DOUBLE
:
return
"double"
;
case
DT_INT32
:
return
"int"
;
case
DT_UINT32
:
return
"int"
;
case
DT_UINT16
:
return
"ushort"
;
case
DT_INT16
:
return
"short"
;
case
DT_INT64
:
return
"long"
;
default:
LOG
(
FATAL
)
<<
"Unsupported data type"
;
return
""
;
}
}
std
::
string
D
ataTypeToOPENCLCMDDataType
(
const
DataType
dt
)
{
std
::
string
D
tToUpstreamCLCMDDt
(
const
DataType
dt
)
{
switch
(
dt
)
{
case
DT_FLOAT
:
case
DT_HALF
:
...
...
mace/kernels/opencl/helper.h
浏览文件 @
5d5d06c2
...
...
@@ -19,10 +19,13 @@ void CalImage2DShape(const std::vector<index_t> &shape, /* NHWC */
const
BufferType
type
,
std
::
vector
<
size_t
>
&
image_shape
);
std
::
string
D
ataTypeToOPENCLCMDDataType
(
const
DataType
dt
);
std
::
string
D
tToCLCMDDt
(
const
DataType
dt
);
std
::
string
D
ataTypeToCLType
(
const
DataType
dt
);
std
::
string
D
tToUpstreamCLCMDDt
(
const
DataType
dt
);
std
::
string
DtToCLDt
(
const
DataType
dt
);
std
::
string
DtToUpstreamCLDt
(
const
DataType
dt
);
}
// namespace kernels
}
// namespace mace
...
...
mace/kernels/opencl/pooling_opencl.cc
浏览文件 @
5d5d06c2
...
...
@@ -32,7 +32,7 @@ static void Pooling3(const Tensor *input,
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
input
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
input
->
dtype
()));
built_options
.
emplace
(
stride
[
0
]
==
1
?
"-DSTRIDE_1"
:
""
);
auto
pooling_kernel
=
runtime
->
BuildKernel
(
"pooling"
,
"pooling3"
,
built_options
);
...
...
@@ -80,7 +80,7 @@ static void PoolingN(const Tensor *input,
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
input
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
input
->
dtype
()));
auto
pooling_kernel
=
runtime
->
BuildKernel
(
"pooling"
,
"poolingn"
,
built_options
);
const
uint32_t
lws
[
3
]
=
{
1
,
8
,
128
};
...
...
mace/kernels/opencl/relu_opencl.cc
浏览文件 @
5d5d06c2
...
...
@@ -23,7 +23,7 @@ void ReluFunctor<DeviceType::OPENCL, float>::operator()(const Tensor *input,
auto
program
=
runtime
->
program
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
input
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
input
->
dtype
()));
if
(
max_limit_
<
0
)
{
auto
relu_kernel
=
runtime
->
BuildKernel
(
"relu"
,
"relu"
,
built_options
);
const
uint32_t
lws
=
runtime
->
GetKernelMaxWorkGroupSize
(
relu_kernel
);
...
...
mace/kernels/opencl/resize_bilinear_opencl.cc
浏览文件 @
5d5d06c2
...
...
@@ -41,8 +41,8 @@ void ResizeBilinearFunctor<DeviceType::OPENCL, T>::operator()(
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
auto
dt
=
DataTypeToEnum
<
T
>::
value
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
ataTypeToOPENCLCMDDataType
(
dt
));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
dt
));
built_options
.
emplace
(
"-DCMD_DATA_TYPE="
+
D
tToUpstreamCLCMDDt
(
dt
));
auto
rb_kernel
=
runtime
->
BuildKernel
(
"resize_bilinear"
,
"resize_bilinear_nocache"
,
built_options
);
const
uint32_t
kwg_size
=
runtime
->
GetKernelMaxWorkGroupSize
(
rb_kernel
);
...
...
mace/kernels/opencl/space_to_batch_opecl.cc
浏览文件 @
5d5d06c2
...
...
@@ -20,7 +20,7 @@ void SpaceToBatchFunctor<DeviceType::OPENCL, float>::operator()(Tensor *space_te
Tensor
*
batch_tensor
)
{
auto
runtime
=
OpenCLRuntime
::
Get
();
std
::
set
<
std
::
string
>
built_options
;
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
ataTypeToCLType
(
space_tensor
->
dtype
()));
built_options
.
emplace
(
"-DDATA_TYPE="
+
D
tToUpstreamCLDt
(
space_tensor
->
dtype
()));
auto
s2b_kernel
=
runtime
->
BuildKernel
(
"space_to_batch"
,
"space_to_batch"
,
built_options
);
uint32_t
idx
=
0
;
...
...
mace/ops/buffer_to_image_test.cc
浏览文件 @
5d5d06c2
...
...
@@ -43,7 +43,7 @@ TEST(BufferToImageTest, ArgSmall) {
}
TEST
(
BufferToImageTest
,
ArgHalfSmall
)
{
TestBidirectionTransform
<
DeviceType
::
OPENCL
,
half
>
(
kernels
::
ARGUMENT
,
{
1
});
TestBidirectionTransform
<
DeviceType
::
OPENCL
,
half
>
(
kernels
::
ARGUMENT
,
{
1
1
});
}
TEST
(
BufferToImageTest
,
ArgMedia
)
{
...
...
@@ -97,3 +97,37 @@ TEST(BufferToImageTest, Filter3x3Meida) {
TEST
(
BufferToImageTest
,
Filter3x3Large
)
{
TestBidirectionTransform
<
DeviceType
::
OPENCL
,
float
>
(
kernels
::
FILTER
,
{
3
,
3
,
128
,
256
});
}
template
<
DeviceType
D
,
typename
T
>
void
TestDiffTypeBidirectionTransform
(
const
int
type
,
const
std
::
vector
<
index_t
>
&
input_shape
)
{
OpsTestNet
net
;
OpDefBuilder
(
"BufferToImage"
,
"BufferToImageTest"
)
.
Input
(
"Input"
)
.
Output
(
"B2IOutput"
)
.
AddIntArg
(
"buffer_type"
,
type
)
.
AddIntArg
(
"T"
,
DataTypeToEnum
<
T
>::
value
)
.
Finalize
(
net
.
NewOperatorDef
());
// Add input data
net
.
AddRandomInput
<
D
,
float
>
(
"Input"
,
input_shape
);
// Run
net
.
RunOp
(
D
);
OpDefBuilder
(
"ImageToBuffer"
,
"ImageToBufferTest"
)
.
Input
(
"B2IOutput"
)
.
Output
(
"I2BOutput"
)
.
AddIntArg
(
"buffer_type"
,
type
)
.
AddIntArg
(
"T"
,
DataTypeToEnum
<
T
>::
value
)
.
Finalize
(
net
.
NewOperatorDef
());
// Run
net
.
RunOp
(
D
);
// Check
ExpectTensorNear
<
float
,
T
>
(
*
net
.
GetOutput
(
"Input"
),
*
net
.
GetOutput
(
"I2BOutput"
),
1e-2
);
}
TEST
(
BufferToImageTest
,
ArgFloatToHalfSmall
)
{
TestDiffTypeBidirectionTransform
<
DeviceType
::
OPENCL
,
half
>
(
kernels
::
ARGUMENT
,
{
11
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录