Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
d4b4605f
Mace
项目概览
慢慢CG
/
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看板
提交
d4b4605f
编写于
9月 06, 2017
作者:
李
李寅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AddN op; Refactor op default template impl.
上级
e4c468ea
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
67 addition
and
84 deletion
+67
-84
mace/examples/helloworld.cc
mace/examples/helloworld.cc
+3
-2
mace/kernels/addn.h
mace/kernels/addn.h
+2
-2
mace/kernels/relu.h
mace/kernels/relu.h
+2
-2
mace/ops/BUILD
mace/ops/BUILD
+1
-16
mace/ops/addn.cc
mace/ops/addn.cc
+25
-0
mace/ops/addn.h
mace/ops/addn.h
+27
-0
mace/ops/relu.cc
mace/ops/relu.cc
+0
-9
mace/ops/relu.h
mace/ops/relu.h
+7
-1
mace/ops/relu_test.cc
mace/ops/relu_test.cc
+0
-52
未找到文件。
mace/examples/helloworld.cc
浏览文件 @
d4b4605f
...
...
@@ -27,10 +27,11 @@ int main() {
arg_1
->
set_f
(
1.5
);
OperatorDef
op_def_2
;
op_def_2
.
add_input
(
"Output0"
);
op_def_2
.
add_input
(
"Output1"
);
op_def_2
.
add_output
(
"Output2"
);
op_def_2
.
set_name
(
"
ReluTest2
"
);
op_def_2
.
set_type
(
"
Relu
"
);
op_def_2
.
set_name
(
"
AddNTest
"
);
op_def_2
.
set_type
(
"
AddN
"
);
auto
arg_2
=
op_def_2
.
add_arg
();
arg_2
->
set_name
(
"arg0"
);
arg_2
->
set_f
(
2.5
);
...
...
mace/kernels/addn.h
浏览文件 @
d4b4605f
...
...
@@ -18,10 +18,10 @@ void AddNFuntion(const vector<const Tensor*>& input_tensor, Tensor *output_tenso
int64
size
=
input_tensor
[
0
]
->
size
();
vector
<
const
T
*>
inputs
(
n
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
inputs
[
i
]
=
input_tensor
[
i
]
->
data
<
float
>
();
inputs
[
i
]
=
input_tensor
[
i
]
->
data
<
T
>
();
}
output_tensor
->
ResizeLike
(
input_tensor
[
0
]);
float
*
output
=
output_tensor
->
mutable_data
<
T
>
();
T
*
output
=
output_tensor
->
mutable_data
<
T
>
();
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
for
(
int64
j
=
0
;
j
<
size
;
++
j
)
{
...
...
mace/kernels/relu.h
浏览文件 @
d4b4605f
...
...
@@ -14,8 +14,8 @@ template<typename T>
void
ReluFuntion
(
const
Tensor
*
input_tensor
,
Tensor
*
output_tensor
)
{
int64
size
=
input_tensor
->
size
();
output_tensor
->
ResizeLike
(
input_tensor
);
const
float
*
input
=
input_tensor
->
data
<
float
>
();
float
*
output
=
output_tensor
->
mutable_data
<
float
>
();
const
T
*
input
=
input_tensor
->
data
<
T
>
();
T
*
output
=
output_tensor
->
mutable_data
<
T
>
();
for
(
int64
i
=
0
;
i
<
size
;
++
i
)
{
output
[
i
]
=
std
::
max
(
input
[
i
],
static_cast
<
T
>
(
0
));
...
...
mace/ops/BUILD
浏览文件 @
d4b4605f
...
...
@@ -12,7 +12,7 @@ load("//mace:mace.bzl", "if_android")
cc_library
(
name
=
"ops"
,
srcs
=
[
"relu.cc"
]
,
srcs
=
glob
([
"*.cc"
])
,
hdrs
=
glob
([
"*.h"
]),
deps
=
[
"//mace/proto:cc_proto"
,
...
...
@@ -23,19 +23,4 @@ cc_library(
alwayslink
=
1
,
)
cc_test
(
name
=
"relu_test"
,
srcs
=
[
"relu_test.cc"
,],
deps
=
[
"@gtest//:gtest_main"
,
":ops"
,
],
copts
=
[
'-std=c++11'
],
linkopts
=
if_android
([
"-pie"
,
"-llog"
,
"-latomic"
,
]),
linkstatic
=
1
,
)
mace/ops/addn.cc
0 → 100644
浏览文件 @
d4b4605f
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include "mace/ops/addn.h"
#include "mace/proto/mace.pb.h"
#if __ARM_NEON
#include "mace/kernels/neon/addn_neon.h"
#endif // __ARM_NEON
namespace
mace
{
REGISTER_CPU_OPERATOR
(
AddN
,
AddNOp
<
DeviceType
::
CPU
,
float
>
);
#if __ARM_NEON
template
<
>
bool
AddNOp
<
DeviceType
::
NEON
,
float
>::
Run
()
{
Tensor
*
output_tensor
=
Output
(
0
);
kernels
::
NeonAddNFuntion_float
(
Inputs
(),
output_tensor
);
return
true
;
}
REGISTER_NEON_OPERATOR
(
AddN
,
AddNOp
<
DeviceType
::
NEON
,
float
>
);
#endif // __ARM_NEON
}
// namespace mace
mace/ops/addn.h
0 → 100644
浏览文件 @
d4b4605f
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_OPS_ADDN_H_
#define MACE_OPS_ADDN_H_
#include "mace/core/operator.h"
#include "mace/kernels/addn.h"
namespace
mace
{
template
<
DeviceType
D
,
class
T
>
class
AddNOp
:
public
Operator
<
D
,
T
>
{
public:
AddNOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
)
{}
bool
Run
()
override
{
Tensor
*
output_tensor
=
this
->
Output
(
0
);
kernels
::
AddNFuntion
<
T
>
(
this
->
Inputs
(),
output_tensor
);
return
true
;
}
};
}
// namespace mace
#endif // MACE_OPS_ADDN_H_
mace/ops/relu.cc
浏览文件 @
d4b4605f
...
...
@@ -4,23 +4,14 @@
#include "mace/ops/relu.h"
#include "mace/proto/mace.pb.h"
#include "mace/kernels/relu.h"
#if __ARM_NEON
#include "mace/kernels/neon/relu_neon.h"
#endif // __ARM_NEON
namespace
mace
{
template
<
>
bool
ReluOp
<
DeviceType
::
CPU
,
float
>::
Run
()
{
const
Tensor
*
input_tensor
=
Input
(
0
);
Tensor
*
output_tensor
=
Output
(
0
);
kernels
::
ReluFuntion
<
float
>
(
input_tensor
,
output_tensor
);
return
true
;
}
REGISTER_CPU_OPERATOR
(
Relu
,
ReluOp
<
DeviceType
::
CPU
,
float
>
);
#if __ARM_NEON
template
<
>
bool
ReluOp
<
DeviceType
::
NEON
,
float
>::
Run
()
{
...
...
mace/ops/relu.h
浏览文件 @
d4b4605f
...
...
@@ -6,6 +6,7 @@
#define MACE_OPS_RELU_H_
#include "mace/core/operator.h"
#include "mace/kernels/relu.h"
namespace
mace
{
...
...
@@ -14,7 +15,12 @@ class ReluOp : public Operator<D, T> {
public:
ReluOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
)
{}
bool
Run
()
override
;
bool
Run
()
override
{
const
Tensor
*
input_tensor
=
this
->
Input
(
0
);
Tensor
*
output_tensor
=
this
->
Output
(
0
);
kernels
::
ReluFuntion
<
T
>
(
input_tensor
,
output_tensor
);
return
true
;
}
};
}
// namespace mace
...
...
mace/ops/relu_test.cc
已删除
100644 → 0
浏览文件 @
e4c468ea
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include "gtest/gtest.h"
#include "mace/core/operator.h"
#include "mace/core/net.h"
using
namespace
mace
;
TEST
(
ReluTest
,
Relu
)
{
OperatorRegistry
*
registry
=
gDeviceTypeRegistry
()
->
at
(
DeviceType
::
CPU
);
vector
<
string
>
registry_keys
=
registry
->
Keys
();
for
(
auto
&
key
:
registry_keys
)
{
VLOG
(
0
)
<<
"registry_op: "
<<
key
;
}
// Construct graph
OperatorDef
op_def
;
op_def
.
add_input
(
"Input0"
);
op_def
.
add_output
(
"Output0"
);
op_def
.
set_name
(
"ReluTest"
);
op_def
.
set_type
(
"Relu"
);
auto
arg
=
op_def
.
add_arg
();
arg
->
set_name
(
"arg0"
);
arg
->
set_f
(
1.5
);
NetDef
net_def
;
net_def
.
set_name
(
"NetTest"
);
net_def
.
add_op
()
->
CopyFrom
(
op_def
);
VLOG
(
0
)
<<
net_def
.
DebugString
();
// Create workspace and input tensor
Workspace
ws
;
Tensor
*
input
=
ws
.
CreateTensor
(
"Input0"
,
cpu_allocator
(),
DataType
::
DT_FLOAT
);
input
->
Resize
({
2
,
3
});
float
*
input_data
=
input
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
input_data
[
i
]
=
i
-
3
;
}
// Create Net & run
auto
net
=
CreateNet
(
net_def
,
&
ws
,
DeviceType
::
CPU
);
net
->
Run
();
// Create Op & run
auto
op
=
CreateOperator
(
op_def
,
&
ws
,
DeviceType
::
CPU
);
ASSERT_FLOAT_EQ
(
1.5
f
,
op
->
GetSingleArgument
<
float
>
(
"arg0"
,
1.0
f
));
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录