Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
孤小逸
Mace
提交
871e3392
Mace
项目概览
孤小逸
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
1
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,发现更多精彩内容 >>
提交
871e3392
编写于
5月 28, 2018
作者:
李
李寅
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'refactor_arg_helper' into 'master'
refactor arg_helper See merge request !531
上级
e8d613ef
5b35740b
变更
46
隐藏空白更改
内联
并排
Showing
46 changed file
with
183 addition
and
242 deletion
+183
-242
mace/core/arg_helper.cc
mace/core/arg_helper.cc
+52
-84
mace/core/arg_helper.h
mace/core/arg_helper.h
+15
-35
mace/core/buffer.h
mace/core/buffer.h
+2
-2
mace/core/mace.cc
mace/core/mace.cc
+2
-2
mace/core/net.cc
mace/core/net.cc
+6
-6
mace/core/net.h
mace/core/net.h
+2
-2
mace/core/operator.cc
mace/core/operator.cc
+2
-2
mace/core/operator.h
mace/core/operator.h
+7
-17
mace/core/registry.h
mace/core/registry.h
+1
-1
mace/core/runtime/hexagon/hexagon_control_wrapper.h
mace/core/runtime/hexagon/hexagon_control_wrapper.h
+1
-1
mace/core/runtime/hexagon/quantize.h
mace/core/runtime/hexagon/quantize.h
+1
-1
mace/core/tensor.h
mace/core/tensor.h
+2
-2
mace/core/workspace.cc
mace/core/workspace.cc
+3
-3
mace/core/workspace.h
mace/core/workspace.h
+1
-1
mace/ops/activation.h
mace/ops/activation.h
+3
-3
mace/ops/batch_norm.h
mace/ops/batch_norm.h
+2
-2
mace/ops/batch_to_space.h
mace/ops/batch_to_space.h
+2
-2
mace/ops/buffer_to_image.h
mace/ops/buffer_to_image.h
+1
-1
mace/ops/channel_shuffle.h
mace/ops/channel_shuffle.h
+1
-1
mace/ops/concat.h
mace/ops/concat.h
+2
-2
mace/ops/conv_2d.h
mace/ops/conv_2d.h
+4
-4
mace/ops/conv_pool_2d_base.h
mace/ops/conv_pool_2d_base.h
+4
-4
mace/ops/deconv_2d.h
mace/ops/deconv_2d.h
+1
-1
mace/ops/depth_to_space.h
mace/ops/depth_to_space.h
+1
-1
mace/ops/depthwise_conv2d.h
mace/ops/depthwise_conv2d.h
+3
-3
mace/ops/eltwise.h
mace/ops/eltwise.h
+3
-3
mace/ops/folded_batch_norm.h
mace/ops/folded_batch_norm.h
+3
-3
mace/ops/fully_connected.h
mace/ops/fully_connected.h
+3
-3
mace/ops/image_to_buffer.h
mace/ops/image_to_buffer.h
+1
-1
mace/ops/local_response_norm.h
mace/ops/local_response_norm.h
+4
-4
mace/ops/pad.h
mace/ops/pad.h
+2
-2
mace/ops/pooling.h
mace/ops/pooling.h
+2
-2
mace/ops/proposal.h
mace/ops/proposal.h
+8
-8
mace/ops/psroi_align.h
mace/ops/psroi_align.h
+3
-3
mace/ops/reshape.h
mace/ops/reshape.h
+1
-1
mace/ops/resize_bilinear.h
mace/ops/resize_bilinear.h
+2
-2
mace/ops/slice.h
mace/ops/slice.h
+2
-2
mace/ops/space_to_batch.h
mace/ops/space_to_batch.h
+2
-2
mace/ops/space_to_depth.h
mace/ops/space_to_depth.h
+2
-2
mace/ops/transpose.h
mace/ops/transpose.h
+1
-1
mace/ops/winograd_inverse_transform.h
mace/ops/winograd_inverse_transform.h
+6
-6
mace/ops/winograd_transform.h
mace/ops/winograd_transform.h
+2
-2
mace/proto/mace.proto
mace/proto/mace.proto
+7
-4
mace/utils/logging.h
mace/utils/logging.h
+1
-1
mace/utils/timer.h
mace/utils/timer.h
+1
-1
mace/utils/utils.h
mace/utils/utils.h
+6
-6
未找到文件。
mace/core/arg_helper.cc
浏览文件 @
871e3392
...
...
@@ -20,112 +20,80 @@
namespace
mace
{
ArgumentHelper
::
Argument
Helper
(
const
OperatorDef
&
def
)
{
ProtoArgHelper
::
ProtoArg
Helper
(
const
OperatorDef
&
def
)
{
for
(
auto
&
arg
:
def
.
arg
())
{
if
(
arg_map_
.
find
(
arg
.
name
())
!=
arg_map_
.
end
(
))
{
LOG
(
WARNING
)
<<
"Duplicated argument
name found in operator def: "
<<
def
.
name
()
<<
" "
<<
arg
.
name
();
if
(
arg_map_
.
count
(
arg
.
name
()
))
{
LOG
(
WARNING
)
<<
"Duplicated argument
"
<<
arg
.
name
()
<<
" found in operator "
<<
def
.
name
();
}
arg_map_
[
arg
.
name
()]
=
arg
;
}
}
ArgumentHelper
::
Argument
Helper
(
const
NetDef
&
netdef
)
{
ProtoArgHelper
::
ProtoArg
Helper
(
const
NetDef
&
netdef
)
{
for
(
auto
&
arg
:
netdef
.
arg
())
{
MACE_CHECK
(
arg_map_
.
count
(
arg
.
name
())
==
0
,
"Duplicated argument
name
found in net def."
);
"Duplicated argument found in net def."
);
arg_map_
[
arg
.
name
()]
=
arg
;
}
}
bool
ArgumentHelper
::
HasArgument
(
const
std
::
string
&
name
)
const
{
return
arg_map_
.
count
(
name
);
}
namespace
{
// Helper function to verify that conversion between types won't loose any
// significant bit.
template
<
typename
InputType
,
typename
TargetType
>
bool
SupportsLosslessConversion
(
const
InputType
&
value
)
{
inline
bool
IsCastLossless
(
const
InputType
&
value
)
{
return
static_cast
<
InputType
>
(
static_cast
<
TargetType
>
(
value
))
==
value
;
}
}
#define INSTANTIATE_GET_SINGLE_ARGUMENT(T, fieldname, \
enforce_lossless_conversion) \
template <> \
T ArgumentHelper::GetSingleArgument<T>(const std::string &name, \
const T &default_value) const { \
if (arg_map_.count(name) == 0) { \
VLOG(3) << "Using default parameter value " << default_value \
<< " for parameter " << name; \
return default_value; \
} \
MACE_CHECK(arg_map_.at(name).has_##fieldname(), "Argument ", name, \
" does not have the right field: expected field " #fieldname); \
auto value = arg_map_.at(name).fieldname(); \
if (enforce_lossless_conversion) { \
auto supportsConversion = \
SupportsLosslessConversion<decltype(value), T>(value); \
MACE_CHECK(supportsConversion, "Value", value, " of argument ", name, \
"cannot be represented correctly in a target type"); \
} \
return value; \
} \
template <> \
bool ArgumentHelper::HasSingleArgumentOfType<T>( \
const std::string &name) const { \
if (arg_map_.count(name) == 0) { \
return false; \
} \
return arg_map_.at(name).has_##fieldname(); \
#define MACE_GET_OPTIONAL_ARGUMENT_FUNC(T, fieldname, lossless_conversion) \
template <> \
T ProtoArgHelper::GetOptionalArg<T>(const std::string &arg_name, \
const T &default_value) const { \
if (arg_map_.count(arg_name) == 0) { \
VLOG(3) << "Using default parameter " << default_value << " for " \
<< arg_name; \
return default_value; \
} \
MACE_CHECK(arg_map_.at(arg_name).has_##fieldname(), "Argument ", arg_name, \
" not found!"); \
auto value = arg_map_.at(arg_name).fieldname(); \
if (lossless_conversion) { \
const bool castLossless = IsCastLossless<decltype(value), T>(value); \
MACE_CHECK(castLossless, "Value", value, " of argument ", arg_name, \
"cannot be casted losslessly to a target type"); \
} \
return value; \
}
INSTANTIATE_GET_SINGLE_ARGUMENT
(
float
,
f
,
false
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
double
,
f
,
false
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
bool
,
i
,
false
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
int8_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
int16_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
int
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
int64_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
uint8_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
uint16_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
size_t
,
i
,
true
)
INSTANTIATE_GET_SINGLE_ARGUMENT
(
std
::
string
,
s
,
false
)
#undef INSTANTIATE_GET_SINGLE_ARGUMENT
MACE_GET_OPTIONAL_ARGUMENT_FUNC
(
float
,
f
,
false
)
MACE_GET_OPTIONAL_ARGUMENT_FUNC
(
bool
,
i
,
false
)
MACE_GET_OPTIONAL_ARGUMENT_FUNC
(
int
,
i
,
true
)
MACE_GET_OPTIONAL_ARGUMENT_FUNC
(
std
::
string
,
s
,
false
)
#undef MACE_GET_OPTIONAL_ARGUMENT_FUNC
#define INSTANTIATE_GET_REPEATED_ARGUMENT(T, fieldname, \
enforce_lossless_conversion) \
template <> \
std::vector<T> ArgumentHelper::GetRepeatedArgument<T>( \
const std::string &name, const std::vector<T> &default_value) const { \
if (arg_map_.count(name) == 0) { \
return default_value; \
} \
std::vector<T> values; \
for (const auto &v : arg_map_.at(name).fieldname()) { \
if (enforce_lossless_conversion) { \
auto supportsConversion = \
SupportsLosslessConversion<decltype(v), T>(v); \
MACE_CHECK(supportsConversion, "Value", v, " of argument ", name, \
"cannot be represented correctly in a target type"); \
} \
values.push_back(v); \
} \
return values; \
#define MACE_GET_REPEATED_ARGUMENT_FUNC(T, fieldname, lossless_conversion) \
template <> \
std::vector<T> ProtoArgHelper::GetRepeatedArgs<T>( \
const std::string &arg_name, const std::vector<T> &default_value) \
const { \
if (arg_map_.count(arg_name) == 0) { \
return default_value; \
} \
std::vector<T> values; \
for (const auto &v : arg_map_.at(arg_name).fieldname()) { \
if (lossless_conversion) { \
const bool castLossless = IsCastLossless<decltype(v), T>(v); \
MACE_CHECK(castLossless, "Value", v, " of argument ", arg_name, \
"cannot be casted losslessly to a target type"); \
} \
values.push_back(v); \
} \
return values; \
}
INSTANTIATE_GET_REPEATED_ARGUMENT
(
float
,
floats
,
false
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
double
,
floats
,
false
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
bool
,
ints
,
false
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
int8_t
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
int16_t
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
int
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
int64_t
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
uint8_t
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
uint16_t
,
ints
,
true
)
INSTANTIATE_GET_REPEATED_ARGUMENT
(
size_t
,
ints
,
true
)
#undef INSTANTIATE_GET_REPEATED_ARGUMENT
MACE_GET_REPEATED_ARGUMENT_FUNC
(
float
,
floats
,
false
)
MACE_GET_REPEATED_ARGUMENT_FUNC
(
int
,
ints
,
true
)
MACE_GET_REPEATED_ARGUMENT_FUNC
(
int64_t
,
ints
,
true
)
#undef MACE_GET_REPEATED_ARGUMENT_FUNC
}
// namespace mace
mace/core/arg_helper.h
浏览文件 @
871e3392
...
...
@@ -15,61 +15,41 @@
#ifndef MACE_CORE_ARG_HELPER_H_
#define MACE_CORE_ARG_HELPER_H_
#include <map>
#include <string>
#include <vector>
#include <map>
#include "mace/proto/mace.pb.h"
#include "mace/public/mace.h"
namespace
mace
{
/**
* @brief A helper class to index into arguments.
*
* This helper helps us to more easily index into a set of arguments
* that are present in the operator. To save memory, the argument helper
* does not copy the operator def, so one would need to make sure that the
* lifetime of the OperatorDef object outlives that of the ArgumentHelper.
*/
class
ArgumentHelper
{
// Refer to caffe2
class
ProtoArgHelper
{
public:
template
<
typename
Def
>
static
bool
HasArgument
(
const
Def
&
def
,
const
std
::
string
&
name
)
{
return
ArgumentHelper
(
def
).
HasArgument
(
name
);
}
template
<
typename
Def
,
typename
T
>
static
T
Get
SingleArgument
(
const
Def
&
def
,
const
std
::
string
&
name
,
const
T
&
default_value
)
{
return
ArgumentHelper
(
def
).
GetSingleArgument
<
T
>
(
name
,
default_value
);
static
T
Get
OptionalArg
(
const
Def
&
def
,
const
std
::
string
&
arg_
name
,
const
T
&
default_value
)
{
return
ProtoArgHelper
(
def
).
GetOptionalArg
<
T
>
(
arg_
name
,
default_value
);
}
template
<
typename
Def
,
typename
T
>
static
bool
HasSingleArgumentOfType
(
const
Def
&
def
,
const
std
::
string
&
name
)
{
return
ArgumentHelper
(
def
).
HasSingleArgumentOfType
<
T
>
(
name
);
}
template
<
typename
Def
,
typename
T
>
static
std
::
vector
<
T
>
GetRepeatedArgument
(
static
std
::
vector
<
T
>
GetRepeatedArgs
(
const
Def
&
def
,
const
std
::
string
&
name
,
const
std
::
string
&
arg_
name
,
const
std
::
vector
<
T
>
&
default_value
=
std
::
vector
<
T
>
())
{
return
ArgumentHelper
(
def
).
GetRepeatedArgument
<
T
>
(
name
,
default_value
);
return
ProtoArgHelper
(
def
).
GetRepeatedArgs
<
T
>
(
arg_
name
,
default_value
);
}
explicit
ArgumentHelper
(
const
OperatorDef
&
def
);
explicit
ArgumentHelper
(
const
NetDef
&
netdef
);
bool
HasArgument
(
const
std
::
string
&
name
)
const
;
explicit
ProtoArgHelper
(
const
OperatorDef
&
def
);
explicit
ProtoArgHelper
(
const
NetDef
&
netdef
);
template
<
typename
T
>
T
GetSingleArgument
(
const
std
::
string
&
name
,
const
T
&
default_value
)
const
;
template
<
typename
T
>
bool
HasSingleArgumentOfType
(
const
std
::
string
&
name
)
const
;
T
GetOptionalArg
(
const
std
::
string
&
arg_name
,
const
T
&
default_value
)
const
;
template
<
typename
T
>
std
::
vector
<
T
>
GetRepeatedArg
ument
(
const
std
::
string
&
name
,
std
::
vector
<
T
>
GetRepeatedArg
s
(
const
std
::
string
&
arg_
name
,
const
std
::
vector
<
T
>
&
default_value
=
std
::
vector
<
T
>
())
const
;
private:
...
...
mace/core/buffer.h
浏览文件 @
871e3392
...
...
@@ -213,7 +213,7 @@ class Buffer : public BufferBase {
void
*
mapped_buf_
;
bool
is_data_owner_
;
DISABLE_COPY_AND_ASSIGN
(
Buffer
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Buffer
);
};
class
Image
:
public
BufferBase
{
...
...
@@ -330,7 +330,7 @@ class Image : public BufferBase {
void
*
buf_
;
void
*
mapped_buf_
;
DISABLE_COPY_AND_ASSIGN
(
Image
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Image
);
};
class
BufferSlice
:
public
BufferBase
{
...
...
mace/core/mace.cc
浏览文件 @
871e3392
...
...
@@ -110,7 +110,7 @@ class MaceEngine::Impl {
std
::
unique_ptr
<
HexagonControlWrapper
>
hexagon_controller_
;
#endif
DISABLE_COPY_AND_ASSIGN
(
Impl
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Impl
);
};
MaceEngine
::
Impl
::
Impl
(
DeviceType
device_type
)
...
...
@@ -146,7 +146,7 @@ MaceStatus MaceEngine::Impl::Init(
hexagon_controller_
->
SetDebugLevel
(
static_cast
<
int
>
(
mace
::
logging
::
LogMessage
::
MinVLogLevel
()));
int
dsp_mode
=
ArgumentHelper
::
GetSingleArgument
<
NetDef
,
int
>
(
*
net_def
,
"dsp_mode"
,
0
);
ProtoArgHelper
::
GetOptionalArg
<
NetDef
,
int
>
(
*
net_def
,
"dsp_mode"
,
0
);
hexagon_controller_
->
SetGraphMode
(
dsp_mode
);
MACE_CHECK
(
hexagon_controller_
->
SetupGraph
(
*
net_def
,
model_data
),
"hexagon setup graph error"
);
...
...
mace/core/net.cc
浏览文件 @
871e3392
...
...
@@ -42,7 +42,7 @@ SerialNet::SerialNet(const std::shared_ptr<const OperatorRegistry> op_registry,
const
auto
&
operator_def
=
net_def
->
op
(
idx
);
// TODO(liuqi): refactor based on PB
const
int
op_device
=
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
operator_def
,
"device"
,
static_cast
<
int
>
(
device_type_
));
if
(
op_device
==
type
)
{
VLOG
(
3
)
<<
"Creating operator "
<<
operator_def
.
name
()
<<
"("
...
...
@@ -97,12 +97,12 @@ MaceStatus SerialNet::Run(RunMetadata *run_metadata) {
type
.
compare
(
"FusedConv2D"
)
==
0
||
type
.
compare
(
"DepthwiseConv2d"
)
==
0
||
type
.
compare
(
"Pooling"
)
==
0
)
{
strides
=
op
->
GetRepeatedArg
ument
<
int
>
(
"strides"
);
padding_type
=
op
->
Get
SingleArgument
<
int
>
(
"padding"
,
-
1
);
paddings
=
op
->
GetRepeatedArg
ument
<
int
>
(
"padding_values"
);
dilations
=
op
->
GetRepeatedArg
ument
<
int
>
(
"dilations"
);
strides
=
op
->
GetRepeatedArg
s
<
int
>
(
"strides"
);
padding_type
=
op
->
Get
OptionalArg
<
int
>
(
"padding"
,
-
1
);
paddings
=
op
->
GetRepeatedArg
s
<
int
>
(
"padding_values"
);
dilations
=
op
->
GetRepeatedArg
s
<
int
>
(
"dilations"
);
if
(
type
.
compare
(
"Pooling"
)
==
0
)
{
kernels
=
op
->
GetRepeatedArg
ument
<
index_t
>
(
"kernels"
);
kernels
=
op
->
GetRepeatedArg
s
<
index_t
>
(
"kernels"
);
}
else
{
kernels
=
op
->
Input
(
1
)
->
shape
();
}
...
...
mace/core/net.h
浏览文件 @
871e3392
...
...
@@ -44,7 +44,7 @@ class NetBase {
std
::
string
name_
;
const
std
::
shared_ptr
<
const
OperatorRegistry
>
op_registry_
;
DISABLE_COPY_AND_ASSIGN
(
NetBase
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
NetBase
);
};
class
SerialNet
:
public
NetBase
{
...
...
@@ -61,7 +61,7 @@ class SerialNet : public NetBase {
std
::
vector
<
std
::
unique_ptr
<
OperatorBase
>
>
operators_
;
DeviceType
device_type_
;
DISABLE_COPY_AND_ASSIGN
(
SerialNet
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
SerialNet
);
};
std
::
unique_ptr
<
NetBase
>
CreateNet
(
...
...
mace/core/operator.cc
浏览文件 @
871e3392
...
...
@@ -55,9 +55,9 @@ std::unique_ptr<OperatorBase> OperatorRegistry::CreateOperator(
Workspace
*
ws
,
DeviceType
type
,
const
NetMode
mode
)
const
{
const
int
dtype
=
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
const
int
dtype
=
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
operator_def
,
"T"
,
static_cast
<
int
>
(
DT_FLOAT
));
const
int
op_mode_i
=
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
const
int
op_mode_i
=
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
operator_def
,
"mode"
,
static_cast
<
int
>
(
NetMode
::
NORMAL
));
const
NetMode
op_mode
=
static_cast
<
NetMode
>
(
op_mode_i
);
if
(
op_mode
==
mode
)
{
...
...
mace/core/operator.h
浏览文件 @
871e3392
...
...
@@ -35,28 +35,18 @@ class OperatorBase {
explicit
OperatorBase
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
);
virtual
~
OperatorBase
()
noexcept
{}
inline
bool
HasArgument
(
const
std
::
string
&
name
)
const
{
MACE_CHECK
(
operator_def_
,
"operator_def was null!"
);
return
ArgumentHelper
::
HasArgument
(
*
operator_def_
,
name
);
}
template
<
typename
T
>
inline
T
Get
SingleArgument
(
const
std
::
string
&
name
,
const
T
&
default_value
)
const
{
inline
T
Get
OptionalArg
(
const
std
::
string
&
name
,
const
T
&
default_value
)
const
{
MACE_CHECK
(
operator_def_
,
"operator_def was null!"
);
return
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
T
>
(
return
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
T
>
(
*
operator_def_
,
name
,
default_value
);
}
template
<
typename
T
>
inline
bool
HasSingleArgumentOfType
(
const
std
::
string
&
name
)
const
{
MACE_CHECK
(
operator_def_
,
"operator_def was null!"
);
return
ArgumentHelper
::
HasSingleArgumentOfType
<
OperatorDef
,
T
>
(
*
operator_def_
,
name
);
}
template
<
typename
T
>
inline
std
::
vector
<
T
>
GetRepeatedArgument
(
inline
std
::
vector
<
T
>
GetRepeatedArgs
(
const
std
::
string
&
name
,
const
std
::
vector
<
T
>
&
default_value
=
{})
const
{
MACE_CHECK
(
operator_def_
,
"operator_def was null!"
);
return
ArgumentHelper
::
GetRepeatedArgument
<
OperatorDef
,
T
>
(
return
ProtoArgHelper
::
GetRepeatedArgs
<
OperatorDef
,
T
>
(
*
operator_def_
,
name
,
default_value
);
}
...
...
@@ -93,7 +83,7 @@ class OperatorBase {
std
::
vector
<
const
Tensor
*>
inputs_
;
std
::
vector
<
Tensor
*>
outputs_
;
DISABLE_COPY_AND_ASSIGN
(
OperatorBase
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
OperatorBase
);
};
template
<
DeviceType
D
,
class
T
>
...
...
@@ -188,7 +178,7 @@ class OperatorRegistry {
private:
RegistryType
registry_
;
DISABLE_COPY_AND_ASSIGN
(
OperatorRegistry
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
OperatorRegistry
);
};
MACE_DECLARE_REGISTRY
(
OpRegistry
,
...
...
mace/core/registry.h
浏览文件 @
871e3392
...
...
@@ -51,7 +51,7 @@ class Registry {
std
::
map
<
SrcType
,
Creator
>
registry_
;
std
::
mutex
register_mutex_
;
DISABLE_COPY_AND_ASSIGN
(
Registry
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Registry
);
};
template
<
class
SrcType
,
class
ObjectType
,
class
...
Args
>
...
...
mace/core/runtime/hexagon/hexagon_control_wrapper.h
浏览文件 @
871e3392
...
...
@@ -61,7 +61,7 @@ class HexagonControlWrapper {
uint32_t
num_inputs_
;
uint32_t
num_outputs_
;
DISABLE_COPY_AND_ASSIGN
(
HexagonControlWrapper
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
HexagonControlWrapper
);
};
}
// namespace mace
...
...
mace/core/runtime/hexagon/quantize.h
浏览文件 @
871e3392
...
...
@@ -47,7 +47,7 @@ class Quantizer {
float
*
stepsize
,
float
*
recip_stepsize
);
DISABLE_COPY_AND_ASSIGN
(
Quantizer
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Quantizer
);
};
}
// namespace mace
...
...
mace/core/tensor.h
浏览文件 @
871e3392
...
...
@@ -348,7 +348,7 @@ class Tensor {
const
Tensor
*
tensor_
;
std
::
vector
<
size_t
>
mapped_image_pitch_
;
DISABLE_COPY_AND_ASSIGN
(
MappingGuard
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
MappingGuard
);
};
private:
...
...
@@ -361,7 +361,7 @@ class Tensor {
bool
is_buffer_owner_
;
std
::
string
name_
;
DISABLE_COPY_AND_ASSIGN
(
Tensor
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Tensor
);
};
}
// namespace mace
...
...
mace/core/workspace.cc
浏览文件 @
871e3392
...
...
@@ -136,11 +136,11 @@ MaceStatus Workspace::CreateOutputTensorBuffer(const NetDef &net_def,
for
(
auto
&
op
:
net_def
.
op
())
{
// TODO(liuqi): refactor based on PB
const
int
op_device
=
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
op
,
"device"
,
static_cast
<
int
>
(
device_type
));
if
(
op_device
==
device_type
&&
!
op
.
mem_id
().
empty
())
{
const
DataType
op_dtype
=
static_cast
<
DataType
>
(
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
op
,
"T"
,
static_cast
<
int
>
(
DT_FLOAT
)));
if
(
op_dtype
!=
DataType
::
DT_INVALID
)
{
dtype
=
op_dtype
;
...
...
@@ -182,7 +182,7 @@ MaceStatus Workspace::CreateOutputTensorBuffer(const NetDef &net_def,
for
(
auto
&
op
:
net_def
.
op
())
{
// TODO(liuqi): refactor based on PB
const
int
op_device
=
ArgumentHelper
::
GetSingleArgument
<
OperatorDef
,
int
>
(
ProtoArgHelper
::
GetOptionalArg
<
OperatorDef
,
int
>
(
op
,
"device"
,
static_cast
<
int
>
(
device_type
));
if
(
op_device
==
device_type
&&
!
op
.
mem_id
().
empty
())
{
auto
mem_ids
=
op
.
mem_id
();
...
...
mace/core/workspace.h
浏览文件 @
871e3392
...
...
@@ -65,7 +65,7 @@ class Workspace {
std
::
unique_ptr
<
ScratchBuffer
>
host_scratch_buffer_
;
DISABLE_COPY_AND_ASSIGN
(
Workspace
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
Workspace
);
};
}
// namespace mace
...
...
mace/ops/activation.h
浏览文件 @
871e3392
...
...
@@ -29,9 +29,9 @@ class ActivationOp : public Operator<D, T> {
ActivationOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
static_cast
<
T
>
(
OperatorBase
::
Get
SingleArgument
<
float
>
(
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
static_cast
<
T
>
(
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
)))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/batch_norm.h
浏览文件 @
871e3392
...
...
@@ -28,8 +28,8 @@ class BatchNormOp : public Operator<D, T> {
BatchNormOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
false
,
kernels
::
ActivationType
::
NOOP
,
0.0
f
)
{
epsilon_
=
OperatorBase
::
Get
SingleArgument
<
float
>
(
"epsilon"
,
static_cast
<
float
>
(
1e-4
));
epsilon_
=
OperatorBase
::
Get
OptionalArg
<
float
>
(
"epsilon"
,
static_cast
<
float
>
(
1e-4
));
}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/batch_to_space.h
浏览文件 @
871e3392
...
...
@@ -29,8 +29,8 @@ class BatchToSpaceNDOp : public Operator<D, T> {
public:
BatchToSpaceNDOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"crops"
,
{
0
,
0
,
0
,
0
}),
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"block_shape"
,
{
1
,
1
}),
functor_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"crops"
,
{
0
,
0
,
0
,
0
}),
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"block_shape"
,
{
1
,
1
}),
true
)
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/buffer_to_image.h
浏览文件 @
871e3392
...
...
@@ -31,7 +31,7 @@ class BufferToImageOp : public Operator<D, T> {
const
Tensor
*
input_tensor
=
this
->
Input
(
INPUT
);
kernels
::
BufferType
type
=
static_cast
<
kernels
::
BufferType
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
static_cast
<
kernels
::
BufferType
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"buffer_type"
,
static_cast
<
int
>
(
kernels
::
CONV2D_FILTER
)));
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
...
...
mace/ops/channel_shuffle.h
浏览文件 @
871e3392
...
...
@@ -28,7 +28,7 @@ class ChannelShuffleOp : public Operator<D, T> {
public:
ChannelShuffleOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
group_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"group"
,
1
)),
group_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"group"
,
1
)),
functor_
(
this
->
group_
)
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/concat.h
浏览文件 @
871e3392
...
...
@@ -28,13 +28,13 @@ class ConcatOp : public Operator<D, T> {
public:
ConcatOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"axis"
,
3
))
{}
functor_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"axis"
,
3
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
MACE_CHECK
(
this
->
InputSize
()
>=
2
)
<<
"There must be at least two inputs to concat"
;
const
std
::
vector
<
const
Tensor
*>
input_list
=
this
->
Inputs
();
const
int32_t
concat_axis
=
OperatorBase
::
Get
SingleArgument
<
int
>
(
"axis"
,
3
);
const
int32_t
concat_axis
=
OperatorBase
::
Get
OptionalArg
<
int
>
(
"axis"
,
3
);
const
int32_t
input_dims
=
input_list
[
0
]
->
dim_size
();
const
int32_t
axis
=
concat_axis
<
0
?
concat_axis
+
input_dims
:
concat_axis
;
...
...
mace/ops/conv_2d.h
浏览文件 @
871e3392
...
...
@@ -35,10 +35,10 @@ class Conv2dOp : public ConvPool2dOpBase<D, T> {
this
->
paddings_
,
this
->
dilations_
.
data
(),
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"max_limit"
,
0.0
f
),
static_cast
<
bool
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
),
static_cast
<
bool
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"is_filter_transformed"
,
false
)),
ws
->
GetScratchBuffer
(
D
))
{}
...
...
mace/ops/conv_pool_2d_base.h
浏览文件 @
871e3392
...
...
@@ -28,12 +28,12 @@ class ConvPool2dOpBase : public Operator<D, T> {
public:
ConvPool2dOpBase
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
strides_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"strides"
)),
padding_type_
(
static_cast
<
Padding
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
strides_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"strides"
)),
padding_type_
(
static_cast
<
Padding
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"padding"
,
static_cast
<
int
>
(
SAME
)))),
paddings_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"padding_values"
)),
paddings_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"padding_values"
)),
dilations_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"dilations"
,
{
1
,
1
}))
{}
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"dilations"
,
{
1
,
1
}))
{}
protected:
std
::
vector
<
int
>
strides_
;
...
...
mace/ops/deconv_2d.h
浏览文件 @
871e3392
...
...
@@ -32,7 +32,7 @@ class Deconv2dOp : public ConvPool2dOpBase<D, T> {
functor_
(
this
->
strides_
.
data
(),
this
->
padding_type_
,
this
->
paddings_
,
OperatorBase
::
GetRepeatedArg
ument
<
index_t
>
(
"output_shape"
),
OperatorBase
::
GetRepeatedArg
s
<
index_t
>
(
"output_shape"
),
kernels
::
ActivationType
::
NOOP
,
0.0
f
)
{}
...
...
mace/ops/depth_to_space.h
浏览文件 @
871e3392
...
...
@@ -29,7 +29,7 @@ class DepthToSpaceOp : public Operator<D, T> {
public:
DepthToSpaceOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
block_size_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"block_size"
,
1
)),
block_size_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"block_size"
,
1
)),
functor_
(
this
->
block_size_
,
true
)
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/depthwise_conv2d.h
浏览文件 @
871e3392
...
...
@@ -36,9 +36,9 @@ class DepthwiseConv2dOp : public ConvPool2dOpBase<D, T> {
this
->
paddings_
,
this
->
dilations_
.
data
(),
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"max_limit"
,
0.0
f
))
{}
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/eltwise.h
浏览文件 @
871e3392
...
...
@@ -27,10 +27,10 @@ class EltwiseOp : public Operator<D, T> {
EltwiseOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
static_cast
<
kernels
::
EltwiseType
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"type"
,
static_cast
<
int
>
(
kernels
::
EltwiseType
::
NONE
))),
OperatorBase
::
GetRepeatedArg
ument
<
float
>
(
"coeff"
),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"x"
,
1.0
))
{}
OperatorBase
::
GetRepeatedArg
s
<
float
>
(
"coeff"
),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"x"
,
1.0
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input0
=
this
->
Input
(
0
);
...
...
mace/ops/folded_batch_norm.h
浏览文件 @
871e3392
...
...
@@ -30,9 +30,9 @@ class FoldedBatchNormOp : public Operator<D, T> {
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
true
,
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"max_limit"
,
0.0
f
))
{}
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/fully_connected.h
浏览文件 @
871e3392
...
...
@@ -29,9 +29,9 @@ class FullyConnectedOp : public Operator<D, T> {
FullyConnectedOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"max_limit"
,
0.0
f
))
{}
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/image_to_buffer.h
浏览文件 @
871e3392
...
...
@@ -32,7 +32,7 @@ class ImageToBufferOp : public Operator<D, T> {
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
kernels
::
BufferType
type
=
static_cast
<
kernels
::
BufferType
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
static_cast
<
kernels
::
BufferType
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"buffer_type"
,
static_cast
<
int
>
(
kernels
::
CONV2D_FILTER
)));
return
functor_
(
input
,
type
,
output
,
future
);
}
...
...
mace/ops/local_response_norm.h
浏览文件 @
871e3392
...
...
@@ -27,10 +27,10 @@ class LocalResponseNormOp : public Operator<D, T> {
LocalResponseNormOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
()
{
depth_radius_
=
OperatorBase
::
Get
SingleArgument
<
int
>
(
"depth_radius"
,
5
);
bias_
=
OperatorBase
::
Get
SingleArgument
<
float
>
(
"bias"
,
1.0
f
);
alpha_
=
OperatorBase
::
Get
SingleArgument
<
float
>
(
"alpha"
,
1.0
f
);
beta_
=
OperatorBase
::
Get
SingleArgument
<
float
>
(
"beta"
,
0.5
f
);
depth_radius_
=
OperatorBase
::
Get
OptionalArg
<
int
>
(
"depth_radius"
,
5
);
bias_
=
OperatorBase
::
Get
OptionalArg
<
float
>
(
"bias"
,
1.0
f
);
alpha_
=
OperatorBase
::
Get
OptionalArg
<
float
>
(
"alpha"
,
1.0
f
);
beta_
=
OperatorBase
::
Get
OptionalArg
<
float
>
(
"beta"
,
0.5
f
);
}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/pad.h
浏览文件 @
871e3392
...
...
@@ -28,8 +28,8 @@ class PadOp : public Operator<D, T> {
public:
PadOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"paddings"
),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"constant_value"
,
0.0
))
functor_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"paddings"
),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"constant_value"
,
0.0
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/pooling.h
浏览文件 @
871e3392
...
...
@@ -29,9 +29,9 @@ class PoolingOp : public ConvPool2dOpBase<D, T> {
public:
PoolingOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
ConvPool2dOpBase
<
D
,
T
>
(
op_def
,
ws
),
kernels_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"kernels"
)),
kernels_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"kernels"
)),
pooling_type_
(
static_cast
<
PoolingType
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
static_cast
<
PoolingType
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"pooling_type"
,
static_cast
<
int
>
(
AVG
)))),
functor_
(
pooling_type_
,
kernels_
.
data
(),
...
...
mace/ops/proposal.h
浏览文件 @
871e3392
...
...
@@ -26,14 +26,14 @@ class ProposalOp : public Operator<D, T> {
public:
ProposalOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"min_size"
,
16
),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"nms_thresh"
,
0.7
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"pre_nms_top_n"
,
6000
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"post_nms_top_n"
,
300
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"feat_stride"
,
0
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"base_size"
,
12
),
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"scales"
),
OperatorBase
::
GetRepeatedArg
ument
<
float
>
(
"ratios"
))
{}
functor_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"min_size"
,
16
),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"nms_thresh"
,
0.7
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"pre_nms_top_n"
,
6000
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"post_nms_top_n"
,
300
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"feat_stride"
,
0
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"base_size"
,
12
),
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"scales"
),
OperatorBase
::
GetRepeatedArg
s
<
float
>
(
"ratios"
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
rpn_cls_prob
=
this
->
Input
(
RPN_CLS_PROB
);
...
...
mace/ops/psroi_align.h
浏览文件 @
871e3392
...
...
@@ -26,9 +26,9 @@ class PSROIAlignOp : public Operator<D, T> {
public:
PSROIAlignOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
T
>
(
"spatial_scale"
,
0
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"output_dim"
,
0
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"group_size"
,
0
))
{}
functor_
(
OperatorBase
::
Get
OptionalArg
<
T
>
(
"spatial_scale"
,
0
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"output_dim"
,
0
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"group_size"
,
0
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/reshape.h
浏览文件 @
871e3392
...
...
@@ -28,7 +28,7 @@ class ReshapeOp : public Operator<D, T> {
public:
ReshapeOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
shape_
(
OperatorBase
::
GetRepeatedArg
ument
<
int64_t
>
(
"shape"
))
{}
shape_
(
OperatorBase
::
GetRepeatedArg
s
<
int64_t
>
(
"shape"
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
mace/ops/resize_bilinear.h
浏览文件 @
871e3392
...
...
@@ -27,8 +27,8 @@ class ResizeBilinearOp : public Operator<D, T> {
ResizeBilinearOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
GetRepeatedArg
ument
<
index_t
>
(
"size"
,
{
-
1
,
-
1
}),
OperatorBase
::
Get
SingleArgument
<
bool
>
(
"align_corners"
,
false
))
{}
OperatorBase
::
GetRepeatedArg
s
<
index_t
>
(
"size"
,
{
-
1
,
-
1
}),
OperatorBase
::
Get
OptionalArg
<
bool
>
(
"align_corners"
,
false
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
=
this
->
Input
(
0
);
...
...
mace/ops/slice.h
浏览文件 @
871e3392
...
...
@@ -28,14 +28,14 @@ class SliceOp : public Operator<D, T> {
public:
SliceOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"axis"
,
3
))
{}
functor_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"axis"
,
3
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
MACE_CHECK
(
this
->
OutputSize
()
>=
2
)
<<
"There must be at least two outputs for slicing"
;
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
const
std
::
vector
<
Tensor
*>
output_list
=
this
->
Outputs
();
const
int32_t
slice_axis
=
OperatorBase
::
Get
SingleArgument
<
int
>
(
"axis"
,
3
);
const
int32_t
slice_axis
=
OperatorBase
::
Get
OptionalArg
<
int
>
(
"axis"
,
3
);
MACE_CHECK
((
input
->
dim
(
slice_axis
)
%
this
->
OutputSize
())
==
0
)
<<
"Outputs do not split input equally."
;
...
...
mace/ops/space_to_batch.h
浏览文件 @
871e3392
...
...
@@ -30,8 +30,8 @@ class SpaceToBatchNDOp : public Operator<D, T> {
SpaceToBatchNDOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"paddings"
,
{
0
,
0
,
0
,
0
}),
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"block_shape"
,
{
1
,
1
}),
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"paddings"
,
{
0
,
0
,
0
,
0
}),
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"block_shape"
,
{
1
,
1
}),
false
)
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/space_to_depth.h
浏览文件 @
871e3392
...
...
@@ -29,7 +29,7 @@ class SpaceToDepthOp : public Operator<D, T> {
public:
SpaceToDepthOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"block_size"
,
1
),
false
)
{
functor_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"block_size"
,
1
),
false
)
{
}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
@@ -37,7 +37,7 @@ class SpaceToDepthOp : public Operator<D, T> {
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
MACE_CHECK
(
input
->
dim_size
()
==
4
,
"input dim should be 4"
);
const
int
block_size
=
OperatorBase
::
Get
SingleArgument
<
int
>
(
"block_size"
,
1
);
OperatorBase
::
Get
OptionalArg
<
int
>
(
"block_size"
,
1
);
index_t
input_height
;
index_t
input_width
;
index_t
input_depth
;
...
...
mace/ops/transpose.h
浏览文件 @
871e3392
...
...
@@ -28,7 +28,7 @@ class TransposeOp : public Operator<D, T> {
public:
TransposeOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
dims_
(
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"dims"
)),
dims_
(
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"dims"
)),
functor_
(
dims_
)
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
...
...
mace/ops/winograd_inverse_transform.h
浏览文件 @
871e3392
...
...
@@ -30,13 +30,13 @@ class WinogradInverseTransformOp : public Operator<D, T> {
public:
WinogradInverseTransformOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
"batch"
,
1
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"height"
,
0
),
OperatorBase
::
Get
SingleArgument
<
int
>
(
"width"
,
0
),
functor_
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"batch"
,
1
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"height"
,
0
),
OperatorBase
::
Get
OptionalArg
<
int
>
(
"width"
,
0
),
kernels
::
StringToActivationType
(
OperatorBase
::
Get
SingleArgument
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
SingleArgument
<
float
>
(
"max_limit"
,
0.0
f
))
{}
OperatorBase
::
Get
OptionalArg
<
std
::
string
>
(
"activation"
,
"NOOP"
)),
OperatorBase
::
Get
OptionalArg
<
float
>
(
"max_limit"
,
0.0
f
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input_tensor
=
this
->
Input
(
INPUT
);
...
...
mace/ops/winograd_transform.h
浏览文件 @
871e3392
...
...
@@ -28,9 +28,9 @@ class WinogradTransformOp : public Operator<D, T> {
public:
WinogradTransformOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
static_cast
<
Padding
>
(
OperatorBase
::
Get
SingleArgument
<
int
>
(
functor_
(
static_cast
<
Padding
>
(
OperatorBase
::
Get
OptionalArg
<
int
>
(
"padding"
,
static_cast
<
int
>
(
VALID
))),
OperatorBase
::
GetRepeatedArg
ument
<
int
>
(
"padding_values"
))
{}
OperatorBase
::
GetRepeatedArg
s
<
int
>
(
"padding_values"
))
{}
MaceStatus
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input_tensor
=
this
->
Input
(
INPUT
);
...
...
mace/proto/mace.proto
浏览文件 @
871e3392
...
...
@@ -4,8 +4,11 @@ package mace;
option
optimize_for
=
LITE_RUNTIME
;
// For better compatibility,
// the mace.proto is refered from tensorflow and caffe2.
enum
NetMode
{
INIT
=
0
;
INIT
=
0
;
NORMAL
=
1
;
}
...
...
@@ -64,7 +67,7 @@ message OperatorDef {
optional
uint32
op_id
=
101
;
optional
uint32
padding
=
102
;
repeated
NodeInput
node_input
=
103
;
repeated
int32
out_max_byte_size
=
104
;
// only support 32-bit len
repeated
int32
out_max_byte_size
=
104
;
// only support 32-bit len
}
// for memory optimization
...
...
@@ -82,14 +85,14 @@ message InputInfo {
optional
string
name
=
1
;
optional
int32
node_id
=
2
;
repeated
int32
dims
=
3
;
optional
int32
max_byte_size
=
4
;
// only support 32-bit len
optional
int32
max_byte_size
=
4
;
// only support 32-bit len
optional
DataType
data_type
=
5
[
default
=
DT_FLOAT
];
}
message
OutputInfo
{
optional
string
name
=
1
;
optional
int32
node_id
=
2
;
repeated
int32
dims
=
3
;
optional
int32
max_byte_size
=
4
;
// only support 32-bit len
optional
int32
max_byte_size
=
4
;
// only support 32-bit len
optional
DataType
data_type
=
5
[
default
=
DT_FLOAT
];
}
...
...
mace/utils/logging.h
浏览文件 @
871e3392
...
...
@@ -117,7 +117,7 @@ class LatencyLogger {
const
std
::
string
message_
;
int64_t
start_micros_
;
DISABLE_COPY_AND_ASSIGN
(
LatencyLogger
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
LatencyLogger
);
};
#define MACE_LATENCY_LOGGER(vlog_level, ...) \
...
...
mace/utils/timer.h
浏览文件 @
871e3392
...
...
@@ -58,7 +58,7 @@ class WallClockTimer : public Timer {
double
stop_micros_
;
double
accumulated_micros_
;
DISABLE_COPY_AND_ASSIGN
(
WallClockTimer
);
MACE_
DISABLE_COPY_AND_ASSIGN
(
WallClockTimer
);
};
}
// namespace mace
...
...
mace/utils/utils.h
浏览文件 @
871e3392
...
...
@@ -24,11 +24,11 @@
namespace
mace
{
// Disable the copy and assignment operator for a class.
#ifndef DISABLE_COPY_AND_ASSIGN
#define
DISABLE_COPY_AND_ASSIGN(classname
) \
private: \
classname(const classname &) = delete;
\
classname &operator=(const classname
&) = delete
#ifndef
MACE_
DISABLE_COPY_AND_ASSIGN
#define
MACE_DISABLE_COPY_AND_ASSIGN(CLASSNAME
) \
private:
\
CLASSNAME(const CLASSNAME &) = delete;
\
CLASSNAME &operator=(const CLASSNAME
&) = delete
#endif
template
<
typename
Integer
>
...
...
@@ -132,7 +132,7 @@ inline std::vector<std::string> Split(const std::string &str, char delims) {
}
inline
bool
ReadBinaryFile
(
std
::
vector
<
unsigned
char
>
*
data
,
const
std
::
string
&
filename
)
{
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
!
ifs
.
is_open
())
{
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录