Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
毕竟曾有刹那
Mace
提交
f33d4d5a
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,发现更多精彩内容 >>
提交
f33d4d5a
编写于
1月 09, 2019
作者:
李
李寅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support various model input/output
上级
a74002cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
14 deletion
+42
-14
mace/libmace/mace.cc
mace/libmace/mace.cc
+36
-13
mace/public/mace.h
mace/public/mace.h
+6
-1
未找到文件。
mace/libmace/mace.cc
浏览文件 @
f33d4d5a
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#include <sys/mman.h>
#include <sys/mman.h>
#include <unistd.h>
#include <unistd.h>
#include <algorithm>
#include <numeric>
#include <memory>
#include <memory>
#include "mace/core/device_context.h"
#include "mace/core/device_context.h"
...
@@ -313,6 +315,7 @@ class MaceTensor::Impl {
...
@@ -313,6 +315,7 @@ class MaceTensor::Impl {
std
::
vector
<
int64_t
>
shape
;
std
::
vector
<
int64_t
>
shape
;
std
::
shared_ptr
<
float
>
data
;
std
::
shared_ptr
<
float
>
data
;
DataFormat
format
;
DataFormat
format
;
int64_t
buffer_size
;
};
};
MaceTensor
::
MaceTensor
(
const
std
::
vector
<
int64_t
>
&
shape
,
MaceTensor
::
MaceTensor
(
const
std
::
vector
<
int64_t
>
&
shape
,
...
@@ -323,6 +326,8 @@ MaceTensor::MaceTensor(const std::vector<int64_t> &shape,
...
@@ -323,6 +326,8 @@ MaceTensor::MaceTensor(const std::vector<int64_t> &shape,
impl_
->
shape
=
shape
;
impl_
->
shape
=
shape
;
impl_
->
data
=
data
;
impl_
->
data
=
data
;
impl_
->
format
=
format
;
impl_
->
format
=
format
;
impl_
->
buffer_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
float
>
());
}
}
MaceTensor
::
MaceTensor
()
{
MaceTensor
::
MaceTensor
()
{
...
@@ -334,6 +339,7 @@ MaceTensor::MaceTensor(const MaceTensor &other) {
...
@@ -334,6 +339,7 @@ MaceTensor::MaceTensor(const MaceTensor &other) {
impl_
->
shape
=
other
.
shape
();
impl_
->
shape
=
other
.
shape
();
impl_
->
data
=
other
.
data
();
impl_
->
data
=
other
.
data
();
impl_
->
format
=
other
.
data_format
();
impl_
->
format
=
other
.
data_format
();
impl_
->
buffer_size
=
other
.
impl_
->
buffer_size
;
}
}
MaceTensor
::
MaceTensor
(
const
MaceTensor
&&
other
)
{
MaceTensor
::
MaceTensor
(
const
MaceTensor
&&
other
)
{
...
@@ -341,12 +347,14 @@ MaceTensor::MaceTensor(const MaceTensor &&other) {
...
@@ -341,12 +347,14 @@ MaceTensor::MaceTensor(const MaceTensor &&other) {
impl_
->
shape
=
other
.
shape
();
impl_
->
shape
=
other
.
shape
();
impl_
->
data
=
other
.
data
();
impl_
->
data
=
other
.
data
();
impl_
->
format
=
other
.
data_format
();
impl_
->
format
=
other
.
data_format
();
impl_
->
buffer_size
=
other
.
impl_
->
buffer_size
;
}
}
MaceTensor
&
MaceTensor
::
operator
=
(
const
MaceTensor
&
other
)
{
MaceTensor
&
MaceTensor
::
operator
=
(
const
MaceTensor
&
other
)
{
impl_
->
shape
=
other
.
shape
();
impl_
->
shape
=
other
.
shape
();
impl_
->
data
=
other
.
data
();
impl_
->
data
=
other
.
data
();
impl_
->
format
=
other
.
data_format
();
impl_
->
format
=
other
.
data_format
();
impl_
->
buffer_size
=
other
.
impl_
->
buffer_size
;
return
*
this
;
return
*
this
;
}
}
...
@@ -354,6 +362,7 @@ MaceTensor &MaceTensor::operator=(const MaceTensor &&other) {
...
@@ -354,6 +362,7 @@ MaceTensor &MaceTensor::operator=(const MaceTensor &&other) {
impl_
->
shape
=
other
.
shape
();
impl_
->
shape
=
other
.
shape
();
impl_
->
data
=
other
.
data
();
impl_
->
data
=
other
.
data
();
impl_
->
format
=
other
.
data_format
();
impl_
->
format
=
other
.
data_format
();
impl_
->
buffer_size
=
other
.
impl_
->
buffer_size
;
return
*
this
;
return
*
this
;
}
}
...
@@ -484,7 +493,14 @@ MaceStatus MaceEngine::Impl::Init(
...
@@ -484,7 +493,14 @@ MaceStatus MaceEngine::Impl::Init(
<<
"' does not belong to model's inputs: "
<<
"' does not belong to model's inputs: "
<<
MakeString
(
MapKeys
(
input_info_map_
));
<<
MakeString
(
MapKeys
(
input_info_map_
));
}
}
ws_
->
CreateTensor
(
input_name
,
device_
->
allocator
(),
DT_FLOAT
);
Tensor
*
input_tensor
=
ws_
->
CreateTensor
(
input_name
,
device_
->
allocator
(),
DT_FLOAT
);
// Resize to possible largest shape to avoid resize during running.
std
::
vector
<
index_t
>
shape
(
input_info_map_
[
input_name
].
dims_size
());
for
(
int
i
=
0
;
i
<
input_info_map_
[
input_name
].
dims_size
();
++
i
)
{
shape
[
i
]
=
input_info_map_
[
input_name
].
dims
(
i
);
}
input_tensor
->
Resize
(
shape
);
}
}
for
(
auto
output_name
:
output_nodes
)
{
for
(
auto
output_name
:
output_nodes
)
{
if
(
output_info_map_
.
find
(
output_name
)
==
output_info_map_
.
end
())
{
if
(
output_info_map_
.
find
(
output_name
)
==
output_info_map_
.
end
())
{
...
@@ -637,10 +653,13 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
...
@@ -637,10 +653,13 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
std
::
vector
<
index_t
>
shape
=
std
::
vector
<
index_t
>
shape
=
TransposeShape
<
index_t
,
index_t
>
(
output_tensor
->
shape
(),
TransposeShape
<
index_t
,
index_t
>
(
output_tensor
->
shape
(),
dst_dims
);
dst_dims
);
MACE_CHECK
(
shape
==
output
->
second
.
shape
())
int64_t
output_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
<<
"Output shape mismatch: "
std
::
multiplies
<
int64_t
>
());
<<
MakeString
<
int64_t
>
(
shape
)
<<
" != "
MACE_CHECK
(
output_size
<=
output
->
second
.
impl_
->
buffer_size
)
<<
MakeString
<
int64_t
>
(
output
->
second
.
shape
());
<<
"Output size exceeds buffer size: shape"
<<
MakeString
<
int64_t
>
(
shape
)
<<
" vs buffer size "
<<
output
->
second
.
impl_
->
buffer_size
;
output
->
second
.
impl_
->
shape
=
shape
;
Tensor
::
MappingGuard
output_guard
(
output_tensor
);
Tensor
::
MappingGuard
output_guard
(
output_tensor
);
const
float
*
output_data
=
output_tensor
->
data
<
float
>
();
const
float
*
output_data
=
output_tensor
->
data
<
float
>
();
return
ops
::
Transpose
(
output_data
,
return
ops
::
Transpose
(
output_data
,
...
@@ -660,10 +679,13 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
...
@@ -660,10 +679,13 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
std
::
vector
<
index_t
>
shape
=
std
::
vector
<
index_t
>
shape
=
TransposeShape
<
index_t
,
index_t
>
(
output_tensor
->
shape
(),
TransposeShape
<
index_t
,
index_t
>
(
output_tensor
->
shape
(),
dst_dims
);
dst_dims
);
MACE_CHECK
(
shape
==
output
->
second
.
shape
())
int64_t
output_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
<<
"Output shape mismatch: "
std
::
multiplies
<
int64_t
>
());
<<
MakeString
<
int64_t
>
(
shape
)
<<
" != "
MACE_CHECK
(
output_size
<=
output
->
second
.
impl_
->
buffer_size
)
<<
MakeString
<
int64_t
>
(
output
->
second
.
shape
());
<<
"Output size exceeds buffer size: shape"
<<
MakeString
<
int64_t
>
(
shape
)
<<
" vs buffer size "
<<
output
->
second
.
impl_
->
buffer_size
;
output
->
second
.
impl_
->
shape
=
shape
;
Tensor
::
MappingGuard
output_guard
(
output_tensor
);
Tensor
::
MappingGuard
output_guard
(
output_tensor
);
const
float
*
output_data
=
output_tensor
->
data
<
float
>
();
const
float
*
output_data
=
output_tensor
->
data
<
float
>
();
return
ops
::
Transpose
(
output_data
,
return
ops
::
Transpose
(
output_data
,
...
@@ -675,10 +697,11 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
...
@@ -675,10 +697,11 @@ MaceStatus MaceEngine::Impl::TransposeOutput(
auto
shape
=
output_tensor
->
shape
();
auto
shape
=
output_tensor
->
shape
();
int64_t
output_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
int64_t
output_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
int64_t
>
());
std
::
multiplies
<
int64_t
>
());
MACE_CHECK
(
shape
==
output
->
second
.
shape
())
MACE_CHECK
(
output_size
<=
output
->
second
.
impl_
->
buffer_size
)
<<
"Output shape mismatch: "
<<
"Output size exceeds buffer size: shape"
<<
MakeString
<
int64_t
>
(
shape
)
<<
" != "
<<
MakeString
<
int64_t
>
(
shape
)
<<
" vs buffer size "
<<
MakeString
<
int64_t
>
(
output
->
second
.
shape
());
<<
output
->
second
.
impl_
->
buffer_size
;
output
->
second
.
impl_
->
shape
=
shape
;
std
::
memcpy
(
output
->
second
.
data
().
get
(),
output_tensor
->
data
<
float
>
(),
std
::
memcpy
(
output
->
second
.
data
().
get
(),
output_tensor
->
data
<
float
>
(),
output_size
*
sizeof
(
float
));
output_size
*
sizeof
(
float
));
return
MaceStatus
::
MACE_SUCCESS
;
return
MaceStatus
::
MACE_SUCCESS
;
...
...
mace/public/mace.h
浏览文件 @
f33d4d5a
...
@@ -282,8 +282,12 @@ class MACE_API MaceEngineConfig {
...
@@ -282,8 +282,12 @@ class MACE_API MaceEngineConfig {
// MACE input/output tensor
// MACE input/output tensor
class
MACE_API
MaceTensor
{
class
MACE_API
MaceTensor
{
friend
class
MaceEngine
;
public:
public:
// shape - the shape of the tensor, with size n
// shape - the shape of the tensor, with size n, if shape is unknown
// in advance, it should be specified large enough to hold tensor of all
// possible size.
// data - the buffer of the tensor, must not be null with size equals
// data - the buffer of the tensor, must not be null with size equals
// shape[0] * shape[1] * ... * shape[n-1].
// shape[0] * shape[1] * ... * shape[n-1].
// If you want to pass a buffer which is unsuitable to use the default
// If you want to pass a buffer which is unsuitable to use the default
...
@@ -301,6 +305,7 @@ class MACE_API MaceTensor {
...
@@ -301,6 +305,7 @@ class MACE_API MaceTensor {
MaceTensor
&
operator
=
(
const
MaceTensor
&&
other
);
MaceTensor
&
operator
=
(
const
MaceTensor
&&
other
);
~
MaceTensor
();
~
MaceTensor
();
// shape will be updated to the actual output shape after running.
const
std
::
vector
<
int64_t
>
&
shape
()
const
;
const
std
::
vector
<
int64_t
>
&
shape
()
const
;
const
std
::
shared_ptr
<
float
>
data
()
const
;
const
std
::
shared_ptr
<
float
>
data
()
const
;
std
::
shared_ptr
<
float
>
data
();
std
::
shared_ptr
<
float
>
data
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录