Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
74cf7adb
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看板
提交
74cf7adb
编写于
12月 29, 2018
作者:
李
李寅
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'rm-dynamic-cast' into 'master'
BUG: Remove RTTI related code (dynamic_cast, typeid). See merge request !934
上级
f4a28ad1
986aec9b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
14 deletion
+45
-14
mace/core/buffer.h
mace/core/buffer.h
+36
-2
mace/core/runtime/opencl/scratch_image.cc
mace/core/runtime/opencl/scratch_image.cc
+1
-1
mace/core/tensor.h
mace/core/tensor.h
+6
-7
mace/core/workspace.cc
mace/core/workspace.cc
+2
-4
未找到文件。
mace/core/buffer.h
浏览文件 @
74cf7adb
...
...
@@ -25,6 +25,12 @@
#include "mace/core/types.h"
namespace
mace
{
namespace
core
{
enum
BufferType
{
BT_BUFFER
,
BT_IMAGE
,
};
}
// namespace core
class
BufferBase
{
public:
...
...
@@ -32,6 +38,8 @@ class BufferBase {
explicit
BufferBase
(
index_t
size
)
:
size_
(
size
)
{}
virtual
~
BufferBase
()
{}
virtual
core
::
BufferType
buffer_type
()
const
=
0
;
virtual
void
*
buffer
()
=
0
;
virtual
const
void
*
raw_data
()
const
=
0
;
...
...
@@ -63,6 +71,8 @@ class BufferBase {
virtual
void
Clear
(
index_t
size
)
=
0
;
virtual
const
std
::
vector
<
size_t
>
shape
()
const
=
0
;
virtual
index_t
offset
()
const
{
return
0
;
}
template
<
typename
T
>
...
...
@@ -106,6 +116,10 @@ class Buffer : public BufferBase {
}
}
core
::
BufferType
buffer_type
()
const
{
return
core
::
BufferType
::
BT_BUFFER
;
}
void
*
buffer
()
{
MACE_CHECK_NOTNULL
(
buf_
);
return
buf_
;
...
...
@@ -207,6 +221,11 @@ class Buffer : public BufferBase {
memset
(
reinterpret_cast
<
char
*>
(
raw_mutable_data
()),
0
,
size
);
}
const
std
::
vector
<
size_t
>
shape
()
const
{
MACE_NOT_IMPLEMENTED
;
return
{};
}
protected:
Allocator
*
allocator_
;
void
*
buf_
;
...
...
@@ -238,6 +257,10 @@ class Image : public BufferBase {
return
data_type_
;
}
core
::
BufferType
buffer_type
()
const
{
return
core
::
BufferType
::
BT_IMAGE
;
}
void
*
buffer
()
{
MACE_CHECK_NOTNULL
(
buf_
);
return
buf_
;
...
...
@@ -253,8 +276,6 @@ class Image : public BufferBase {
return
mapped_buf_
;
}
std
::
vector
<
size_t
>
image_shape
()
const
{
return
shape_
;
}
MaceStatus
Allocate
(
index_t
nbytes
)
{
MACE_UNUSED
(
nbytes
);
LOG
(
FATAL
)
<<
"Image should not call this allocate function"
;
...
...
@@ -328,6 +349,10 @@ class Image : public BufferBase {
MACE_NOT_IMPLEMENTED
;
}
const
std
::
vector
<
size_t
>
shape
()
const
{
return
shape_
;
}
private:
Allocator
*
allocator_
;
std
::
vector
<
size_t
>
shape_
;
...
...
@@ -365,6 +390,10 @@ class BufferSlice : public BufferBase {
}
}
core
::
BufferType
buffer_type
()
const
{
return
core
::
BufferType
::
BT_BUFFER
;
}
void
*
buffer
()
{
MACE_CHECK_NOTNULL
(
buffer_
);
return
buffer_
->
buffer
();
...
...
@@ -454,6 +483,11 @@ class BufferSlice : public BufferBase {
memset
(
raw_mutable_data
(),
0
,
size
);
}
const
std
::
vector
<
size_t
>
shape
()
const
{
MACE_NOT_IMPLEMENTED
;
return
{};
}
private:
BufferBase
*
buffer_
;
void
*
mapped_buf_
;
...
...
mace/core/runtime/opencl/scratch_image.cc
浏览文件 @
74cf7adb
...
...
@@ -33,7 +33,7 @@ Image *ScratchImageManager::Spawn(
for
(
int
i
=
0
;
i
<
image_count
;
++
i
)
{
int
count
=
reference_count_
[
i
];
if
(
count
==
0
&&
images_
.
at
(
count
)
->
dtype
()
==
dt
)
{
auto
image_shape
=
images_
.
at
(
count
)
->
image_
shape
();
auto
image_shape
=
images_
.
at
(
count
)
->
shape
();
if
(
image_shape
[
0
]
>=
shape
[
0
]
&&
image_shape
[
1
]
>=
shape
[
1
])
{
found_image_idx
=
i
;
break
;
...
...
mace/core/tensor.h
浏览文件 @
74cf7adb
...
...
@@ -215,7 +215,7 @@ class Tensor {
inline
bool
has_opencl_image
()
const
{
return
buffer_
!=
nullptr
&&
!
buffer_
->
OnHost
()
&&
typeid
(
*
buffer_
)
==
typeid
(
Image
)
;
buffer_
->
buffer_type
()
==
core
::
BufferType
::
BT_IMAGE
;
}
inline
bool
has_opencl_buffer
()
const
{
...
...
@@ -226,7 +226,7 @@ class Tensor {
MACE_CHECK
(
buffer_
!=
nullptr
,
"Tensor "
,
name_
,
" is empty"
);
if
(
buffer_
->
OnHost
())
{
return
MemoryType
::
CPU_BUFFER
;
}
else
if
(
typeid
(
*
buffer_
)
==
typeid
(
Image
)
)
{
}
else
if
(
buffer_
->
buffer_type
()
==
core
::
BufferType
::
BT_IMAGE
)
{
return
MemoryType
::
GPU_IMAGE
;
}
else
{
return
MemoryType
::
GPU_BUFFER
;
...
...
@@ -343,12 +343,11 @@ class Tensor {
}
else
{
MACE_CHECK
(
has_opencl_image
(),
name_
,
": Cannot ResizeImage buffer, use Resize."
);
Image
*
image
=
dynamic_cast
<
Image
*>
(
buffer_
);
MACE_CHECK
(
image_shape
[
0
]
<=
image
->
image_shape
()[
0
]
&&
image_shape
[
1
]
<=
image
->
image_shape
()[
1
],
MACE_CHECK
(
image_shape
[
0
]
<=
buffer_
->
shape
()[
0
]
&&
image_shape
[
1
]
<=
buffer_
->
shape
()[
1
],
"tensor (source op "
,
name_
,
"): current physical image shape: "
,
image
->
image_
shape
()[
0
],
", "
,
image
->
image_
shape
()[
1
],
" < logical image shape: "
,
"): current physical image shape: "
,
buffer_
->
shape
()[
0
],
", "
,
buffer_
->
shape
()[
1
],
" < logical image shape: "
,
image_shape
[
0
],
", "
,
image_shape
[
1
]);
return
MaceStatus
::
MACE_SUCCESS
;
}
...
...
mace/core/workspace.cc
浏览文件 @
74cf7adb
...
...
@@ -272,11 +272,9 @@ MaceStatus Workspace::PreallocateOutputTensor(
<<
" Mem: "
<<
tensor_mem
.
second
.
first
<<
" Data type: "
<<
tensor
->
dtype
()
<<
" Image shape: "
<<
dynamic_cast
<
Image
*>
(
tensor
->
UnderlyingBuffer
())
->
image_shape
()[
0
]
<<
tensor
->
UnderlyingBuffer
()
->
shape
()[
0
]
<<
", "
<<
dynamic_cast
<
Image
*>
(
tensor
->
UnderlyingBuffer
())
->
image_shape
()[
1
];
<<
tensor
->
UnderlyingBuffer
()
->
shape
()[
1
];
tensor
->
set_data_format
(
DataFormat
::
NHWC
);
}
else
{
VLOG
(
1
)
<<
"Tensor: "
<<
tensor_mem
.
first
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录