Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
9f9dc890
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看板
提交
9f9dc890
编写于
2月 28, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove proto from variable name
上级
198344e7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
52 addition
and
40 deletion
+52
-40
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
+8
-8
mace/core/serializer.cc
mace/core/serializer.cc
+28
-20
mace/core/serializer.h
mace/core/serializer.h
+4
-2
mace/core/tensor.h
mace/core/tensor.h
+4
-2
mace/core/workspace.cc
mace/core/workspace.cc
+8
-8
未找到文件。
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
浏览文件 @
9f9dc890
...
@@ -64,29 +64,29 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def) {
...
@@ -64,29 +64,29 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def) {
std
::
thread
const_thread
([
&
]()
{
std
::
thread
const_thread
([
&
]()
{
std
::
cout
<<
"thread function
\n
"
;
std
::
cout
<<
"thread function
\n
"
;
std
::
vector
<
hexagon_nn_const_node
>
const_node_list
;
std
::
vector
<
hexagon_nn_const_node
>
const_node_list
;
for
(
const
ConstTensor
&
tensor_proto
:
net_def
.
tensors
())
{
for
(
const
ConstTensor
&
const_tensor
:
net_def
.
tensors
())
{
std
::
vector
<
int
>
tensor_shape
(
tensor_proto
.
dims
().
begin
(),
std
::
vector
<
int
>
tensor_shape
(
const_tensor
.
dims
().
begin
(),
tensor_proto
.
dims
().
end
());
const_tensor
.
dims
().
end
());
while
(
tensor_shape
.
size
()
<
4
)
{
while
(
tensor_shape
.
size
()
<
4
)
{
tensor_shape
.
insert
(
tensor_shape
.
begin
(),
1
);
tensor_shape
.
insert
(
tensor_shape
.
begin
(),
1
);
}
}
hexagon_nn_const_node
const_node
;
hexagon_nn_const_node
const_node
;
const_node
.
node_id
=
node_id
(
tensor_proto
.
node_id
());
const_node
.
node_id
=
node_id
(
const_tensor
.
node_id
());
const_node
.
tensor
.
batches
=
tensor_shape
[
0
];
const_node
.
tensor
.
batches
=
tensor_shape
[
0
];
const_node
.
tensor
.
height
=
tensor_shape
[
1
];
const_node
.
tensor
.
height
=
tensor_shape
[
1
];
const_node
.
tensor
.
width
=
tensor_shape
[
2
];
const_node
.
tensor
.
width
=
tensor_shape
[
2
];
const_node
.
tensor
.
depth
=
tensor_shape
[
3
];
const_node
.
tensor
.
depth
=
tensor_shape
[
3
];
if
(
tensor_proto
.
data_type
()
==
DataType
::
DT_INT32
if
(
const_tensor
.
data_type
()
==
DataType
::
DT_INT32
&&
tensor_proto
.
data_size
()
==
0
)
{
&&
const_tensor
.
data_size
()
==
0
)
{
const_node
.
tensor
.
data
=
NULL
;
const_node
.
tensor
.
data
=
NULL
;
const_node
.
tensor
.
dataLen
=
0
;
const_node
.
tensor
.
dataLen
=
0
;
}
else
{
}
else
{
const_node
.
tensor
.
data
=
const_node
.
tensor
.
data
=
const_cast
<
unsigned
char
*>
(
tensor_proto
.
data
());
const_cast
<
unsigned
char
*>
(
const_tensor
.
data
());
const_node
.
tensor
.
dataLen
=
const_node
.
tensor
.
dataLen
=
tensor_proto
.
data_size
()
*
GetEnumTypeSize
(
tensor_proto
.
data_type
());
const_tensor
.
data_size
()
*
GetEnumTypeSize
(
const_tensor
.
data_type
());
}
}
const_node_list
.
push_back
(
const_node
);
const_node_list
.
push_back
(
const_node
);
// 255 is magic number: why fastrpc limits sequence length to that?
// 255 is magic number: why fastrpc limits sequence length to that?
...
...
mace/core/serializer.cc
浏览文件 @
9f9dc890
...
@@ -12,56 +12,64 @@ std::unique_ptr<ConstTensor> Serializer::Serialize(const Tensor &tensor,
...
@@ -12,56 +12,64 @@ std::unique_ptr<ConstTensor> Serializer::Serialize(const Tensor &tensor,
return
nullptr
;
return
nullptr
;
}
}
std
::
unique_ptr
<
Tensor
>
Serializer
::
Deserialize
(
const
ConstTensor
&
proto
,
std
::
unique_ptr
<
Tensor
>
Serializer
::
Deserialize
(
const
ConstTensor
&
const_tensor
,
DeviceType
type
)
{
DeviceType
type
)
{
std
::
unique_ptr
<
Tensor
>
tensor
(
std
::
unique_ptr
<
Tensor
>
tensor
(
new
Tensor
(
GetDeviceAllocator
(
type
),
proto
.
data_type
()));
new
Tensor
(
GetDeviceAllocator
(
type
),
const_tensor
.
data_type
()));
std
::
vector
<
index_t
>
dims
;
std
::
vector
<
index_t
>
dims
;
for
(
const
index_t
d
:
proto
.
dims
())
{
for
(
const
index_t
d
:
const_tensor
.
dims
())
{
dims
.
push_back
(
d
);
dims
.
push_back
(
d
);
}
}
tensor
->
Resize
(
dims
);
tensor
->
Resize
(
dims
);
switch
(
proto
.
data_type
())
{
switch
(
const_tensor
.
data_type
())
{
case
DT_HALF
:
case
DT_HALF
:
tensor
->
Copy
<
half
>
(
reinterpret_cast
<
const
half
*>
(
proto
.
data
()),
tensor
->
Copy
<
half
>
(
reinterpret_cast
<
const
half
*>
(
const_tensor
.
data
()),
proto
.
data_size
());
const_tensor
.
data_size
());
break
;
break
;
case
DT_FLOAT
:
case
DT_FLOAT
:
tensor
->
Copy
<
float
>
(
reinterpret_cast
<
const
float
*>
(
proto
.
data
()),
tensor
->
Copy
<
float
>
(
reinterpret_cast
<
const
float
*>
(
const_tensor
.
data
()),
proto
.
data_size
());
const_tensor
.
data_size
());
break
;
break
;
case
DT_DOUBLE
:
case
DT_DOUBLE
:
tensor
->
Copy
<
double
>
(
reinterpret_cast
<
const
double
*>
(
proto
.
data
()),
tensor
->
Copy
<
double
>
(
proto
.
data_size
());
reinterpret_cast
<
const
double
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_INT32
:
case
DT_INT32
:
tensor
->
Copy
<
int32_t
>
(
reinterpret_cast
<
const
int32_t
*>
(
proto
.
data
()),
tensor
->
Copy
<
int32_t
>
(
proto
.
data_size
());
reinterpret_cast
<
const
int32_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_INT64
:
case
DT_INT64
:
tensor
->
Copy
<
int64_t
>
(
reinterpret_cast
<
const
int64_t
*>
(
proto
.
data
()),
tensor
->
Copy
<
int64_t
>
(
proto
.
data_size
());
reinterpret_cast
<
const
int64_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_UINT8
:
case
DT_UINT8
:
tensor
->
Copy
<
uint8_t
>
(
reinterpret_cast
<
const
uint8_t
*>
(
proto
.
data
()),
tensor
->
Copy
<
uint8_t
>
(
proto
.
data_size
());
reinterpret_cast
<
const
uint8_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_INT16
:
case
DT_INT16
:
tensor
->
CopyWithCast
<
int32_t
,
uint16_t
>
(
tensor
->
CopyWithCast
<
int32_t
,
uint16_t
>
(
reinterpret_cast
<
const
int32_t
*>
(
proto
.
data
()),
proto
.
data_size
());
reinterpret_cast
<
const
int32_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_INT8
:
case
DT_INT8
:
tensor
->
CopyWithCast
<
int32_t
,
int8_t
>
(
tensor
->
CopyWithCast
<
int32_t
,
int8_t
>
(
reinterpret_cast
<
const
int32_t
*>
(
proto
.
data
()),
proto
.
data_size
());
reinterpret_cast
<
const
int32_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_UINT16
:
case
DT_UINT16
:
tensor
->
CopyWithCast
<
int32_t
,
int16_t
>
(
tensor
->
CopyWithCast
<
int32_t
,
int16_t
>
(
reinterpret_cast
<
const
int32_t
*>
(
proto
.
data
()),
proto
.
data_size
());
reinterpret_cast
<
const
int32_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
case
DT_BOOL
:
case
DT_BOOL
:
tensor
->
CopyWithCast
<
int32_t
,
bool
>
(
tensor
->
CopyWithCast
<
int32_t
,
bool
>
(
reinterpret_cast
<
const
int32_t
*>
(
proto
.
data
()),
proto
.
data_size
());
reinterpret_cast
<
const
int32_t
*>
(
const_tensor
.
data
()),
const_tensor
.
data_size
());
break
;
break
;
default:
default:
MACE_NOT_IMPLEMENTED
;
MACE_NOT_IMPLEMENTED
;
...
...
mace/core/serializer.h
浏览文件 @
9f9dc890
...
@@ -15,9 +15,11 @@ class Serializer {
...
@@ -15,9 +15,11 @@ class Serializer {
Serializer
()
{}
Serializer
()
{}
~
Serializer
()
{}
~
Serializer
()
{}
std
::
unique_ptr
<
ConstTensor
>
Serialize
(
const
Tensor
&
tensor
,
const
std
::
string
&
name
);
std
::
unique_ptr
<
ConstTensor
>
Serialize
(
const
Tensor
&
tensor
,
const
std
::
string
&
name
);
std
::
unique_ptr
<
Tensor
>
Deserialize
(
const
ConstTensor
&
proto
,
DeviceType
type
);
std
::
unique_ptr
<
Tensor
>
Deserialize
(
const
ConstTensor
&
const_tensor
,
DeviceType
type
);
DISABLE_COPY_AND_ASSIGN
(
Serializer
);
DISABLE_COPY_AND_ASSIGN
(
Serializer
);
};
};
...
...
mace/core/tensor.h
浏览文件 @
9f9dc890
...
@@ -324,12 +324,12 @@ class Tensor {
...
@@ -324,12 +324,12 @@ class Tensor {
}
}
}
}
}
}
MappingGuard
(
MappingGuard
&&
other
)
{
MappingGuard
(
MappingGuard
&&
other
)
{
tensor_
=
other
.
tensor_
;
tensor_
=
other
.
tensor_
;
other
.
tensor_
=
nullptr
;
other
.
tensor_
=
nullptr
;
}
}
MappingGuard
(
const
MappingGuard
&
other
)
=
delete
;
MappingGuard
&
operator
=
(
const
MappingGuard
&
other
)
=
delete
;
~
MappingGuard
()
{
~
MappingGuard
()
{
if
(
tensor_
!=
nullptr
)
tensor_
->
Unmap
();
if
(
tensor_
!=
nullptr
)
tensor_
->
Unmap
();
}
}
...
@@ -339,6 +339,8 @@ class Tensor {
...
@@ -339,6 +339,8 @@ class Tensor {
private:
private:
const
Tensor
*
tensor_
;
const
Tensor
*
tensor_
;
std
::
vector
<
size_t
>
mapped_image_pitch_
;
std
::
vector
<
size_t
>
mapped_image_pitch_
;
DISABLE_COPY_AND_ASSIGN
(
MappingGuard
);
};
};
private:
private:
...
...
mace/core/workspace.cc
浏览文件 @
9f9dc890
...
@@ -72,15 +72,15 @@ Tensor *Workspace::GetTensor(const std::string &name) {
...
@@ -72,15 +72,15 @@ Tensor *Workspace::GetTensor(const std::string &name) {
void
Workspace
::
LoadModelTensor
(
const
NetDef
&
net_def
,
DeviceType
type
)
{
void
Workspace
::
LoadModelTensor
(
const
NetDef
&
net_def
,
DeviceType
type
)
{
MACE_LATENCY_LOGGER
(
1
,
"Load model tensors"
);
MACE_LATENCY_LOGGER
(
1
,
"Load model tensors"
);
Serializer
serializer
;
Serializer
serializer
;
for
(
auto
&
tensor_proto
:
net_def
.
tensors
())
{
for
(
auto
&
const_tensor
:
net_def
.
tensors
())
{
MACE_LATENCY_LOGGER
(
2
,
"Load tensor "
,
tensor_proto
.
name
());
MACE_LATENCY_LOGGER
(
2
,
"Load tensor "
,
const_tensor
.
name
());
VLOG
(
3
)
<<
"Tensor name: "
<<
tensor_proto
.
name
()
VLOG
(
3
)
<<
"Tensor name: "
<<
const_tensor
.
name
()
<<
", data type: "
<<
tensor_proto
.
data_type
()
<<
", data type: "
<<
const_tensor
.
data_type
()
<<
", shape: "
<<
", shape: "
<<
MakeString
(
std
::
vector
<
index_t
>
(
tensor_proto
.
dims
().
begin
(),
<<
MakeString
(
std
::
vector
<
index_t
>
(
const_tensor
.
dims
().
begin
(),
tensor_proto
.
dims
().
end
()));
const_tensor
.
dims
().
end
()));
tensor_map_
[
tensor_proto
.
name
()]
=
tensor_map_
[
const_tensor
.
name
()]
=
serializer
.
Deserialize
(
tensor_proto
,
type
);
serializer
.
Deserialize
(
const_tensor
,
type
);
}
}
if
(
type
==
DeviceType
::
OPENCL
)
{
if
(
type
==
DeviceType
::
OPENCL
)
{
CreateImageOutputTensor
(
net_def
);
CreateImageOutputTensor
(
net_def
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录