Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
cb871b06
Mace
项目概览
Xiaomi
/
Mace
通知
106
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cb871b06
编写于
9月 01, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Neon device
上级
87134853
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
13 deletion
+52
-13
mace/core/allocator.h
mace/core/allocator.h
+12
-9
mace/core/operator.cc
mace/core/operator.cc
+8
-1
mace/core/operator.h
mace/core/operator.h
+11
-0
mace/ops/relu.cc
mace/ops/relu.cc
+17
-0
mace/proto/mace.proto
mace/proto/mace.proto
+4
-3
未找到文件。
mace/core/allocator.h
浏览文件 @
cb871b06
...
...
@@ -12,8 +12,13 @@
namespace
mace
{
// 16 bytes = 32 * 4 (Neon)
#ifdef __ANDROID__
// 16 bytes = 128 bits = 32 * 4 (Neon)
constexpr
size_t
kMaceAlignment
=
16
;
#else
// 32 bytes = 256 bits (AVX512)
constexpr
size_t
kMaceAlignment
=
32
;
#endif
class
Allocator
{
public:
...
...
@@ -41,25 +46,18 @@ class CPUAllocator: public Allocator {
void
*
data
=
nullptr
;
#ifdef __ANDROID__
data
=
memalign
(
kMaceAlignment
,
nbytes
);
#elif defined(_MSC_VER)
data
=
_aligned_malloc
(
nbytes
,
kMaceAlignment
);
#else
CHECK
(
posix_memalign
(
&
data
,
kMaceAlignment
,
nbytes
)
==
0
);
#endif
CHECK_NOTNULL
(
data
);
// TODO(heliangliang) This should be avoided sometimes
memset
(
data
,
0
,
nbytes
);
return
data
;
}
#ifdef _MSC_VER
void
Delete
(
void
*
data
)
{
_aligned_free
(
data
);
}
#else
void
Delete
(
void
*
data
)
{
free
(
data
);
}
#endif
void
CopyBytes
(
void
*
dst
,
const
void
*
src
,
size_t
size
)
{
memcpy
(
dst
,
src
,
size
);
...
...
@@ -80,6 +78,11 @@ struct DeviceContext<DeviceType::CPU> {
static
Allocator
*
allocator
()
{
return
cpu_allocator
();
}
};
template
<
>
struct
DeviceContext
<
DeviceType
::
NEON
>
{
static
Allocator
*
allocator
()
{
return
cpu_allocator
();
}
};
Allocator
*
GetDeviceAllocator
(
DeviceType
type
);
}
// namespace mace
...
...
mace/core/operator.cc
浏览文件 @
cb871b06
...
...
@@ -18,6 +18,13 @@ MACE_DEFINE_REGISTRY(
Workspace
*
);
MACE_REGISTER_DEVICE_TYPE
(
DeviceType
::
CPU
,
CPUOperatorRegistry
);
MACE_DEFINE_REGISTRY
(
NEONOperatorRegistry
,
OperatorBase
,
const
OperatorDef
&
,
Workspace
*
);
MACE_REGISTER_DEVICE_TYPE
(
DeviceType
::
NEON
,
CPUOperatorRegistry
);
unique_ptr
<
OperatorBase
>
CreateOperator
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
,
...
...
@@ -33,4 +40,4 @@ OperatorBase::OperatorBase(const OperatorDef &operator_def, Workspace *ws)
}
}
// namespace mace
\ No newline at end of file
}
// namespace mace
mace/core/operator.h
浏览文件 @
cb871b06
...
...
@@ -145,6 +145,17 @@ MACE_DECLARE_REGISTRY(
#define REGISTER_CPU_OPERATOR(name, ...) \
MACE_REGISTER_CLASS(CPUOperatorRegistry, name, __VA_ARGS__)
MACE_DECLARE_REGISTRY
(
NEONOperatorRegistry
,
OperatorBase
,
const
OperatorDef
&
,
Workspace
*
);
#define REGISTER_NEON_OPERATOR_CREATOR(key, ...) \
MACE_REGISTER_CREATOR(NEONOperatorRegistry, key, __VA_ARGS__)
#define REGISTER_NEON_OPERATOR(name, ...) \
MACE_REGISTER_CLASS(NEONOperatorRegistry, name, __VA_ARGS__)
unique_ptr
<
OperatorBase
>
CreateOperator
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
,
...
...
mace/ops/relu.cc
浏览文件 @
cb871b06
...
...
@@ -23,6 +23,23 @@ bool ReluOp<DeviceType::CPU, float>::Run() {
return
true
;
}
template
<
>
bool
ReluOp
<
DeviceType
::
NEON
,
float
>::
Run
()
{
const
Tensor
*
X
=
Input
(
0
);
Tensor
*
Y
=
Output
(
0
);
Y
->
ResizeLike
(
X
);
const
float
*
Xdata
=
X
->
data
<
float
>
();
float
*
Ydata
=
Y
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
X
->
size
();
++
i
)
{
Ydata
[
i
]
=
std
::
max
(
Xdata
[
i
],
0.
f
);
VLOG
(
0
)
<<
i
<<
": "
<<
Xdata
[
i
]
<<
" "
<<
Ydata
[
i
];
}
return
true
;
}
REGISTER_CPU_OPERATOR
(
Relu
,
ReluOp
<
DeviceType
::
CPU
,
float
>
);
REGISTER_NEON_OPERATOR
(
Relu
,
ReluOp
<
DeviceType
::
NEON
,
float
>
);
}
// namespace mace
mace/proto/mace.proto
浏览文件 @
cb871b06
...
...
@@ -3,8 +3,9 @@ syntax = "proto2";
package
mace
;
enum
DeviceType
{
CPU
=
0
;
// In default, we will use CPU.
GPU
=
1
;
CPU
=
0
;
// In default, we will use CPU.
NEON
=
1
;
OPENCL
=
2
;
}
enum
DataType
{
...
...
@@ -70,4 +71,4 @@ message NetDef {
optional
string
version
=
3
;
repeated
Argument
arg
=
4
;
repeated
TensorProto
tensors
=
5
;
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录