Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项目经理老王
Mace
提交
b3524eb5
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,发现更多精彩内容 >>
提交
b3524eb5
编写于
9月 20, 2018
作者:
李
李寅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Preallocate full size scratch buffer for variable-length models
上级
94b88a0c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
0 deletion
+59
-0
mace/core/buffer.h
mace/core/buffer.h
+1
-0
mace/core/operator.h
mace/core/operator.h
+9
-0
mace/core/tensor.h
mace/core/tensor.h
+30
-0
mace/core/workspace.cc
mace/core/workspace.cc
+11
-0
mace/kernels/matmul.h
mace/kernels/matmul.h
+8
-0
未找到文件。
mace/core/buffer.h
浏览文件 @
b3524eb5
...
...
@@ -469,6 +469,7 @@ class ScratchBuffer: public Buffer {
MaceStatus
GrowSize
(
index_t
size
)
{
if
(
size
>
size_
)
{
VLOG
(
1
)
<<
"Grow scratch size to: "
<<
size
;
MACE_CHECK
(
offset_
==
0
,
"scratch is being used, cannot grow size"
);
return
Resize
(
size
);
}
...
...
mace/core/operator.h
浏览文件 @
b3524eb5
...
...
@@ -117,6 +117,15 @@ class Operator : public OperatorBase {
}
outputs_
.
push_back
(
MACE_CHECK_NOTNULL
(
ws
->
CreateTensor
(
output_str
,
context
->
device
()
->
allocator
(),
output_type
)));
if
(
i
<
operator_def
.
output_shape_size
())
{
std
::
vector
<
index_t
>
shape_configured
(
operator_def
.
output_shape
(
i
).
dims_size
());
for
(
size_t
dim
=
0
;
dim
<
shape_configured
.
size
();
++
dim
)
{
shape_configured
[
dim
]
=
operator_def
.
output_shape
(
i
).
dims
(
dim
);
}
ws
->
GetTensor
(
output_str
)
->
SetShapeConfigured
(
shape_configured
);
}
}
}
}
...
...
mace/core/tensor.h
浏览文件 @
b3524eb5
...
...
@@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include "mace/core/buffer.h"
#include "mace/core/preallocated_pooled_allocator.h"
...
...
@@ -159,6 +160,34 @@ class Tensor {
inline
const
std
::
vector
<
index_t
>
&
shape
()
const
{
return
shape_
;
}
inline
std
::
vector
<
index_t
>
max_shape
()
const
{
if
(
shape_configured_
.
empty
())
{
return
shape
();
}
else
{
auto
&
_shape
=
shape
();
std
::
vector
<
index_t
>
max_shape
(
_shape
.
size
());
MACE_CHECK
(
_shape
.
size
()
==
shape_configured_
.
size
());
for
(
size_t
i
=
0
;
i
<
shape_configured_
.
size
();
++
i
)
{
max_shape
[
i
]
=
std
::
max
(
_shape
[
i
],
shape_configured_
[
i
]);
}
return
max_shape
;
}
}
inline
index_t
max_size
()
const
{
auto
_max_shape
=
max_shape
();
return
std
::
accumulate
(
_max_shape
.
begin
(),
_max_shape
.
end
(),
1
,
std
::
multiplies
<
index_t
>
());
}
inline
index_t
raw_max_size
()
const
{
return
max_size
()
*
SizeOfType
();
}
inline
void
SetShapeConfigured
(
const
std
::
vector
<
index_t
>
&
shape_configured
)
{
shape_configured_
=
shape_configured
;
}
inline
index_t
dim_size
()
const
{
return
shape_
.
size
();
}
inline
index_t
dim
(
unsigned
int
index
)
const
{
...
...
@@ -431,6 +460,7 @@ class Tensor {
Allocator
*
allocator_
;
DataType
dtype_
;
std
::
vector
<
index_t
>
shape_
;
std
::
vector
<
index_t
>
shape_configured_
;
std
::
vector
<
size_t
>
image_shape_
;
BufferBase
*
buffer_
;
BufferSlice
buffer_slice_
;
...
...
mace/core/workspace.cc
浏览文件 @
b3524eb5
...
...
@@ -340,6 +340,17 @@ MaceStatus Workspace::CreateOutputTensorBuffer(const NetDef &net_def,
output_type
);
}
}
for
(
int
output_idx
=
0
;
output_idx
<
op
.
output_shape_size
();
++
output_idx
)
{
std
::
vector
<
index_t
>
shape_configured
(
op
.
output_shape
(
output_idx
).
dims_size
());
for
(
size_t
dim
=
0
;
dim
<
shape_configured
.
size
();
++
dim
)
{
shape_configured
[
dim
]
=
op
.
output_shape
(
output_idx
).
dims
(
dim
);
}
tensor_map_
[
op
.
output
(
output_idx
)]
->
SetShapeConfigured
(
shape_configured
);
}
}
}
return
MaceStatus
::
MACE_SUCCESS
;
...
...
mace/kernels/matmul.h
浏览文件 @
b3524eb5
...
...
@@ -91,6 +91,14 @@ struct MatMulFunctor : OpKernel {
auto
scratch_buffer
=
context_
->
workspace
()
->
GetScratchBuffer
(
D
);
scratch_buffer
->
Rewind
();
index_t
scratch_size
=
C
->
raw_max_size
();
if
(
!
A
->
is_weight
())
{
scratch_size
+=
A
->
raw_max_size
();
}
if
(
!
B
->
is_weight
())
{
scratch_size
+=
B
->
raw_max_size
();
}
scratch_buffer
->
GrowSize
(
scratch_size
);
sgemm_
.
Run
(
a_ptr_base
,
b_ptr_base
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录