Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
07fd121d
Mace
项目概览
Xiaomi
/
Mace
通知
107
Star
40
Fork
27
代码
文件
提交
分支
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看板
提交
07fd121d
编写于
5月 29, 2019
作者:
L
liutuo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove transpose half and add transpose before shape() for gpu runtime.
上级
2b820d8b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
81 deletion
+70
-81
mace/core/net_def_adapter.cc
mace/core/net_def_adapter.cc
+64
-76
mace/ops/transpose.cc
mace/ops/transpose.cc
+6
-5
未找到文件。
mace/core/net_def_adapter.cc
浏览文件 @
07fd121d
...
@@ -50,15 +50,6 @@ std::string TransformedName(const std::string &input_name,
...
@@ -50,15 +50,6 @@ std::string TransformedName(const std::string &input_name,
return
ss
.
str
();
return
ss
.
str
();
}
}
#ifdef MACE_ENABLE_OPENCL
bool
TransformRequiredOp
(
const
std
::
string
&
op_type
)
{
static
const
std
::
unordered_set
<
std
::
string
>
kNoTransformOp
=
{
"Shape"
,
"InferConv2dShape"
};
return
kNoTransformOp
.
count
(
op_type
)
==
0
;
}
#endif // MACE_ENABLE_OPENCL
void
BuildTransposeOpDef
(
void
BuildTransposeOpDef
(
const
std
::
string
&
input_name
,
const
std
::
string
&
input_name
,
const
std
::
string
&
output_name
,
const
std
::
string
&
output_name
,
...
@@ -514,76 +505,73 @@ MaceStatus NetDefAdapter::AdaptMemoryType(
...
@@ -514,76 +505,73 @@ MaceStatus NetDefAdapter::AdaptMemoryType(
// (only support one kind of memory type for multiple outputs)
// (only support one kind of memory type for multiple outputs)
op_registry_
->
GetInOutMemoryTypes
(
op_def
->
type
(),
context
);
op_registry_
->
GetInOutMemoryTypes
(
op_def
->
type
(),
context
);
#ifdef MACE_ENABLE_OPENCL
#ifdef MACE_ENABLE_OPENCL
// if op is memory-unused op, no transformation
int
input_size
=
op_def
->
input_size
();
if
(
TransformRequiredOp
(
op_def
->
type
()))
{
for
(
int
i
=
0
;
i
<
input_size
;
++
i
)
{
int
input_size
=
op_def
->
input_size
();
if
(
output_map
->
count
(
op_def
->
input
(
i
))
==
0
)
{
for
(
int
i
=
0
;
i
<
input_size
;
++
i
)
{
MACE_CHECK
(
ws_
->
GetTensor
(
op_def
->
input
(
i
))
!=
nullptr
if
(
output_map
->
count
(
op_def
->
input
(
i
))
==
0
)
{
&&
ws_
->
GetTensor
(
op_def
->
input
(
i
))
->
is_weight
(),
MACE_CHECK
(
ws_
->
GetTensor
(
op_def
->
input
(
i
))
!=
nullptr
"Tensor "
,
op_def
->
input
(
i
),
" of "
,
&&
ws_
->
GetTensor
(
op_def
->
input
(
i
))
->
is_weight
(),
op_def
->
name
(),
" not allocated"
);
"Tensor "
,
op_def
->
input
(
i
),
" of "
,
continue
;
op_def
->
name
(),
" not allocated"
);
}
continue
;
auto
&
input_info
=
output_map
->
at
(
op_def
->
input
(
i
));
}
// check whether to do transform
auto
&
input_info
=
output_map
->
at
(
op_def
->
input
(
i
));
MemoryType
src_mem_type
=
input_info
.
mem_type
;
// check whether to do transform
MemoryType
dst_mem_type
=
context
->
GetInputMemType
(
i
);
MemoryType
src_mem_type
=
input_info
.
mem_type
;
auto
wanted_input_dtype
=
context
->
GetInputDataType
(
i
);
MemoryType
dst_mem_type
=
context
->
GetInputMemType
(
i
);
if
(
src_mem_type
!=
dst_mem_type
||
auto
wanted_input_dtype
=
context
->
GetInputDataType
(
i
);
(
input_info
.
dtype
!=
wanted_input_dtype
&&
if
(
src_mem_type
!=
dst_mem_type
||
(
src_mem_type
!=
MemoryType
::
CPU_BUFFER
(
input_info
.
dtype
!=
wanted_input_dtype
&&
||
dst_mem_type
!=
MemoryType
::
CPU_BUFFER
)))
{
(
src_mem_type
!=
MemoryType
::
CPU_BUFFER
auto
transformed_name
=
TransformedName
(
op_def
->
input
(
i
),
||
dst_mem_type
!=
MemoryType
::
CPU_BUFFER
)))
{
"mem_type"
,
auto
transformed_name
=
TransformedName
(
op_def
->
input
(
i
),
dst_mem_type
);
"mem_type"
,
// check whether the tensor has been transformed
dst_mem_type
);
if
(
transformed_set
->
count
(
transformed_name
)
==
0
)
{
// check whether the tensor has been transformed
VLOG
(
1
)
<<
"Add Transform operation "
<<
op_def
->
name
()
if
(
transformed_set
->
count
(
transformed_name
)
==
0
)
{
<<
" to transform tensor "
VLOG
(
1
)
<<
"Add Transform operation "
<<
op_def
->
name
()
<<
op_def
->
input
(
i
)
<<
"', from memory type "
<<
" to transform tensor "
<<
input_info
.
mem_type
<<
" to "
<<
op_def
->
input
(
i
)
<<
"', from memory type "
<<
dst_mem_type
;
<<
input_info
.
mem_type
<<
" to "
OperatorDef
*
transformed_op_def
=
target_net_def
->
add_op
();
<<
dst_mem_type
;
OpenCLUtil
::
BuildTransformOpDef
(
OperatorDef
*
transformed_op_def
=
target_net_def
->
add_op
();
op_def
->
input
(
i
),
OpenCLUtil
::
BuildTransformOpDef
(
input_info
.
shape
,
op_def
->
input
(
i
),
transformed_name
,
input_info
.
shape
,
wanted_input_dtype
,
transformed_name
,
context
->
GetInputOpenCLBufferType
(
i
),
wanted_input_dtype
,
dst_mem_type
,
context
->
GetInputOpenCLBufferType
(
i
),
input_info
.
data_format
,
dst_mem_type
,
transformed_op_def
);
input_info
.
data_format
,
// set data format arg
transformed_op_def
);
SetProtoArg
<
int
>
(
transformed_op_def
,
// set data format arg
"data_format"
,
SetProtoArg
<
int
>
(
transformed_op_def
,
static_cast
<
int
>
(
input_info
.
data_format
));
"data_format"
,
// set output memory type argument
static_cast
<
int
>
(
input_info
.
data_format
));
SetProtoArg
<
int
>
(
transformed_op_def
,
// set output memory type argument
OutputMemoryTypeTagName
(),
SetProtoArg
<
int
>
(
transformed_op_def
,
dst_mem_type
);
OutputMemoryTypeTagName
(),
dst_mem_type
);
// update tensor consumer information
// update tensor consumer information
output_map
->
at
(
op_def
->
input
(
i
)).
consumer_op_indices
.
push_back
(
output_map
->
at
(
op_def
->
input
(
i
)).
consumer_op_indices
.
push_back
(
target_net_def
->
op_size
()
-
1
);
target_net_def
->
op_size
()
-
1
);
// update output information map
// update output information map
output_map
->
emplace
(
output_map
->
emplace
(
transformed_name
,
transformed_name
,
InternalOutputInfo
(
InternalOutputInfo
(
dst_mem_type
,
dst_mem_type
,
context
->
GetInputDataType
(
i
),
context
->
GetInputDataType
(
i
),
input_info
.
data_format
,
input_info
.
data_format
,
input_info
.
shape
,
input_info
.
shape
,
target_net_def
->
op_size
()
-
1
));
target_net_def
->
op_size
()
-
1
));
// update tensor shape map
// update tensor shape map
tensor_shape_map
->
emplace
(
transformed_name
,
input_info
.
shape
);
tensor_shape_map
->
emplace
(
transformed_name
,
input_info
.
shape
);
// record transformed tensors
// record transformed tensors
transformed_set
->
insert
(
transformed_name
);
transformed_set
->
insert
(
transformed_name
);
}
// update original op_def's input
op_def
->
set_input
(
i
,
transformed_name
);
}
}
// update original op_def's input
op_def
->
set_input
(
i
,
transformed_name
);
}
}
}
}
#else
#else
...
...
mace/ops/transpose.cc
浏览文件 @
07fd121d
...
@@ -27,7 +27,10 @@ namespace mace {
...
@@ -27,7 +27,10 @@ namespace mace {
namespace
ops
{
namespace
ops
{
template
<
DeviceType
D
,
typename
T
>
template
<
DeviceType
D
,
typename
T
>
class
TransposeOp
:
public
Operation
{
class
TransposeOp
;
template
<
DeviceType
D
>
class
TransposeOp
<
D
,
float
>
:
public
Operation
{
public:
public:
explicit
TransposeOp
(
OpConstructContext
*
context
)
explicit
TransposeOp
(
OpConstructContext
*
context
)
:
Operation
(
context
),
:
Operation
(
context
),
...
@@ -49,8 +52,8 @@ class TransposeOp : public Operation {
...
@@ -49,8 +52,8 @@ class TransposeOp : public Operation {
Tensor
::
MappingGuard
input_guard
(
input
);
Tensor
::
MappingGuard
input_guard
(
input
);
Tensor
::
MappingGuard
output_guard
(
output
);
Tensor
::
MappingGuard
output_guard
(
output
);
const
T
*
input_data
=
input
->
data
<
T
>
();
const
float
*
input_data
=
input
->
data
<
float
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
();
float
*
output_data
=
output
->
mutable_data
<
float
>
();
return
Transpose
(
&
context
->
device
()
->
cpu_runtime
()
->
thread_pool
(),
return
Transpose
(
&
context
->
device
()
->
cpu_runtime
()
->
thread_pool
(),
input_data
,
input
->
shape
(),
dims_
,
output_data
);
input_data
,
input
->
shape
(),
dims_
,
output_data
);
...
@@ -63,8 +66,6 @@ class TransposeOp : public Operation {
...
@@ -63,8 +66,6 @@ class TransposeOp : public Operation {
void
RegisterTranspose
(
OpRegistryBase
*
op_registry
)
{
void
RegisterTranspose
(
OpRegistryBase
*
op_registry
)
{
MACE_REGISTER_OP
(
op_registry
,
"Transpose"
,
TransposeOp
,
MACE_REGISTER_OP
(
op_registry
,
"Transpose"
,
TransposeOp
,
DeviceType
::
CPU
,
float
);
DeviceType
::
CPU
,
float
);
MACE_REGISTER_OP
(
op_registry
,
"Transpose"
,
TransposeOp
,
DeviceType
::
CPU
,
half
);
}
}
}
// namespace ops
}
// namespace ops
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录