Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5220e87e
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5220e87e
编写于
5月 29, 2018
作者:
W
wangliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify operator interface for printing tensor array
上级
c84ae255
变更
32
隐藏空白更改
内联
并排
Showing
32 changed file
with
175 addition
and
137 deletion
+175
-137
src/framework/operator.cpp
src/framework/operator.cpp
+35
-1
src/framework/operator.h
src/framework/operator.h
+8
-3
src/framework/tensor.h
src/framework/tensor.h
+54
-48
src/io.cpp
src/io.cpp
+5
-13
src/operators/batchnorm_op.h
src/operators/batchnorm_op.h
+6
-5
src/operators/box_coder_op.h
src/operators/box_coder_op.h
+1
-1
src/operators/concat_op.h
src/operators/concat_op.h
+5
-5
src/operators/conv_op.h
src/operators/conv_op.h
+3
-4
src/operators/elementwise_add_op.h
src/operators/elementwise_add_op.h
+7
-6
src/operators/feed_op.h
src/operators/feed_op.h
+4
-3
src/operators/fetch_op.h
src/operators/fetch_op.h
+4
-7
src/operators/fusion_fc_op.h
src/operators/fusion_fc_op.h
+7
-5
src/operators/lrn_op.h
src/operators/lrn_op.h
+5
-5
src/operators/mul_op.h
src/operators/mul_op.h
+3
-3
src/operators/multiclass_nms_op.h
src/operators/multiclass_nms_op.h
+1
-1
src/operators/pool_op.h
src/operators/pool_op.h
+11
-11
src/operators/prior_box_op.h
src/operators/prior_box_op.h
+1
-1
src/operators/relu_op.h
src/operators/relu_op.h
+1
-1
src/operators/reshape_op.h
src/operators/reshape_op.h
+1
-1
src/operators/sigmoid_op.h
src/operators/sigmoid_op.h
+1
-1
src/operators/softmax_op.h
src/operators/softmax_op.h
+1
-1
src/operators/transpose_op.h
src/operators/transpose_op.h
+1
-1
test/executor_for_test.h
test/executor_for_test.h
+1
-1
test/framework/test_load.cpp
test/framework/test_load.cpp
+1
-1
test/framework/test_optimize.cpp
test/framework/test_optimize.cpp
+1
-1
test/net/test_googlenet.cpp
test/net/test_googlenet.cpp
+1
-1
test/operators/test_pool_op.cpp
test/operators/test_pool_op.cpp
+1
-1
test/operators/test_reshape_op.cpp
test/operators/test_reshape_op.cpp
+1
-1
test/operators/test_sigmoid_op.cpp
test/operators/test_sigmoid_op.cpp
+1
-1
test/operators/test_softmax_op.cpp
test/operators/test_softmax_op.cpp
+1
-1
test/operators/test_transpose_op.cpp
test/operators/test_transpose_op.cpp
+1
-1
test/test_include.h
test/test_include.h
+1
-1
未找到文件。
src/framework/operator.cpp
浏览文件 @
5220e87e
...
...
@@ -13,11 +13,32 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "framework/operator.h"
#include "
framework/op_info
.h"
#include "
operators/op_param
.h"
namespace
paddle_mobile
{
namespace
framework
{
template
<
typename
Dtype
>
vector
<
string
>
OperatorBase
<
Dtype
>::
GetOutKeys
()
const
{
auto
it
=
op_input_output_key
.
find
(
type_
);
if
(
it
==
op_input_output_key
.
end
())
{
DLOG
<<
type_
<<
" has no outputs"
;
}
return
it
->
second
.
second
;
}
template
<
typename
T
>
static
T
*
GetVarValue
(
const
string
&
key
,
const
VariableNameMap
&
var_map
,
const
Scope
&
scope
)
{
auto
var_vec
=
var_map
.
at
(
key
);
if
(
!
var_vec
.
empty
())
{
auto
var
=
scope
.
FindVar
(
var_vec
[
0
]);
return
var
->
GetMutable
<
T
>
();
}
else
{
return
nullptr
;
}
}
template
<
typename
Dtype
>
OperatorBase
<
Dtype
>::
OperatorBase
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
...
...
@@ -31,9 +52,22 @@ OperatorBase<Dtype>::OperatorBase(const std::string &type,
scope_
(
scope
)
{
CheckAllInputOutputSet
();
}
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
CheckAllInputOutputSet
()
const
{}
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
Run
()
const
{
RunImpl
();
#ifdef PADDLE_MOBILE_DEBUG
vector
<
string
>
output_keys
=
GetOutKeys
();
for
(
const
auto
key
:
output_keys
)
{
Tensor
*
out_
=
GetVarValue
<
framework
::
LoDTensor
>
(
key
,
outputs_
,
*
scope_
);
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
out_
;
}
#endif
}
template
class
OperatorBase
<
CPU
>;
template
class
OperatorWithKernel
<
CPU
>;
...
...
src/framework/operator.h
浏览文件 @
5220e87e
...
...
@@ -36,6 +36,8 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
framework
{
using
std
::
string
;
using
std
::
vector
;
static
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
=
{{
"conv2d"
,
{{
"Input"
},
{
"Output"
}}},
...
...
@@ -57,7 +59,9 @@ class OperatorBase : PaddleMobileObject {
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
);
virtual
~
OperatorBase
()
{}
virtual
void
Run
()
const
=
0
;
void
Run
()
const
;
vector
<
string
>
GetOutKeys
()
const
;
virtual
void
RunImpl
()
const
=
0
;
virtual
void
InferShape
()
const
=
0
;
const
VariableNameMap
&
Inputs
()
const
{
return
inputs_
;
}
...
...
@@ -88,7 +92,8 @@ class OperatorWithKernel : public OperatorBase<Dtype> {
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
OperatorBase
<
Dtype
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
virtual
void
Run
()
const
=
0
;
virtual
void
RunImpl
()
const
=
0
;
virtual
void
InferShape
()
const
=
0
;
};
...
...
@@ -113,7 +118,7 @@ class FusionOpMatcher : PaddleMobileObject {
virtual
std
::
string
Type
()
=
0
;
virtual
void
FolderNodes
(
Node
&
node
)
{
virtual
void
FolderNodes
(
const
Node
&
node
)
{
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{});
}
...
...
src/framework/tensor.h
浏览文件 @
5220e87e
...
...
@@ -18,11 +18,12 @@ limitations under the License. */
#include <cstdint>
#include <cstring>
#include <memory>
#include <type_traits>
#include <typeindex>
#include <vector>
#include "data_layout.h"
#include "ddim.h"
#include "
framework/
data_layout.h"
#include "
framework/
ddim.h"
#include "memory/t_malloc.h"
namespace
paddle_mobile
{
...
...
@@ -62,8 +63,8 @@ struct SizeOfTypeFunctor<HEAD, TAIL...> {
static
inline
size_t
SizeOfType
(
std
::
type_index
type
)
{
SizeOfTypeFunctor
<
int
,
float
,
double
,
int16_t
,
int64_t
,
bool
,
size_t
>
functor
;
size_t
size
=
functor
(
type
);
// PADDLE_ENFORCE(size != 0UL, "Cannot get size of type %s",
//
type.name());
PADDLE_MOBILE_ENFORCE
(
size
!=
0UL
,
"Cannot get size of type %s"
,
type
.
name
());
return
size
;
}
...
...
@@ -72,16 +73,27 @@ class LoDTensor;
class
Tensor
{
public:
Tensor
()
:
offset_
(
0
)
{}
template
<
typename
T
>
Tensor
(
std
::
vector
<
T
>
input
,
DDim
ddim
)
:
offset_
(
0
)
{
PADDLE_MOBILE_ENFORCE
(
input
.
size
()
==
framework
::
product
(
ddim
),
"input vector'length should be equal to tensor's length"
);
auto
input_ptr
=
mutable_data
<
T
>
(
ddim
);
for
(
int
i
=
0
;
i
<
input
.
size
();
++
i
)
{
input_ptr
[
i
]
=
input
[
i
];
}
}
/*! Return a pointer to mutable memory block. */
template
<
typename
T
>
inline
T
*
data
()
{
check_memory_size
();
// PADDLE_ENFORCE(std::is_same<T, void>::value ||
// holder_->type().hash_code() ==
// typeid(T).hash_code(),
// "Tensor holds the wrong type, it holds %s",
// this->holder_->type().name());
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()),
"Tensor holds the wrong type, it holds %s"
,
this
->
holder_
->
type
().
name
());
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
...
...
@@ -90,11 +102,11 @@ class Tensor {
template
<
typename
T
>
inline
const
T
*
data
()
const
{
check_memory_size
();
// PADDLE_ENFORCE(std::is_same<T, void>::value ||
// holder_->type().hash_code() ==
// typeid(T).hash_code(
),
//
"Tensor holds the wrong type, it holds %s",
//
this->holder_->type().name());
PADDLE_MOBILE_ENFORCE
(
(
std
::
is_same
<
T
,
void
>::
value
||
holder_
->
type
().
hash_code
()
==
typeid
(
T
).
hash_code
()
),
"Tensor holds the wrong type, it holds %s"
,
this
->
holder_
->
type
().
name
());
return
reinterpret_cast
<
const
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
...
...
@@ -116,17 +128,11 @@ class Tensor {
if
(
holder_
!=
nullptr
)
{
holder_
->
set_type
(
type
);
}
// PADDLE_ENFORCE_GE(numel(), 0,
// "When calling this method, the Tensor's
// numel must be
// " "equal or larger than zero. " "Please
// check
// Tensor::Resize has been called first.");
PADDLE_MOBILE_ENFORCE
(
numel
()
>=
0
,
"the Tensor'snumel must >=0."
)
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
/* some versions of boost::variant don't have operator!= */
if
(
holder_
==
nullptr
||
holder_
->
size
()
<
size
+
offset_
)
{
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
));
offset_
=
0
;
}
return
reinterpret_cast
<
void
*>
(
...
...
@@ -179,16 +185,13 @@ class Tensor {
*/
inline
Tensor
Slice
(
int
begin_idx
,
int
end_idx
)
const
{
check_memory_size
();
// PADDLE_ENFORCE_GE(begin_idx, 0,
// "The start row index must be greater than
// 0.");
// PADDLE_ENFORCE_LE(end_idx, dims_[0], "The end row index is
// out of
// bound."); PADDLE_ENFORCE_LT(
// begin_idx, end_idx,
// "The start row index must be lesser than the end row
// index.");
PADDLE_MOBILE_ENFORCE
(
begin_idx
>=
0
,
"The start row index must be greater than 0."
)
PADDLE_MOBILE_ENFORCE
(
end_idx
<=
dims_
[
0
],
"The end row index is out of bound."
)
PADDLE_MOBILE_ENFORCE
(
begin_idx
<
end_idx
,
"The start row index must be lesser than the end row index"
)
if
(
dims_
[
0
]
==
1
)
{
return
*
this
;
}
else
{
...
...
@@ -205,10 +208,9 @@ class Tensor {
}
std
::
type_index
type
()
const
{
// PADDLE_ENFORCE_NOT_NULL(
// holder_, "Tensor not initialized yet
// when
// Tensor::type() is called.");
PADDLE_MOBILE_ENFORCE
(
holder_
!=
nullptr
,
"Tensor not initialized yet when Tensor::type() is called."
)
return
holder_
->
type
();
}
...
...
@@ -221,12 +223,8 @@ class Tensor {
PADDLE_MOBILE_ENFORCE
(
holder_
!=
nullptr
,
"Tensor holds no memory. Call Tensor::mutable_data first."
);
PADDLE_MOBILE_ENFORCE
(
numel
()
*
SizeOfType
(
type
())
<=
memory_size
(),
"Tensor's dims_ is out of bound. CallTensor::mutable_data "
"first to re-allocate memory.
\n
"
"or maybe the required data-type mismatches the data\
already stored."
);
PADDLE_MOBILE_ENFORCE
(
numel
()
*
SizeOfType
(
type
())
<=
memory_size
(),
"Tensor's dims_ is out of bound. "
);
}
inline
DataLayout
layout
()
const
{
return
layout_
;
}
...
...
@@ -257,13 +255,8 @@ class Tensor {
memory
::
PODDeleter
<
uint8_t
>
()),
size_
(
size
),
type_
(
type
)
{
// PADDLE_ENFORCE_NOT_NULL(ptr_,
// "Insufficient %s
// memory to allocation.",
// (is_cpu_place(place_)
// ?
// "CPU" :
// "GPU"));
PADDLE_MOBILE_ENFORCE
(
ptr_
!=
nullptr
,
"Insufficient memory to allocation"
);
}
virtual
size_t
size
()
const
{
return
size_
;
}
...
...
@@ -321,6 +314,19 @@ class Tensor {
size_t
offset_
;
};
#ifdef PADDLE_MOBILE_DEBUG
inline
Print
&
operator
<<
(
Print
&
printer
,
const
Tensor
&
tensor
)
{
printer
<<
" dims: "
<<
tensor
.
dims
()
<<
"
\n
"
;
int
stride
=
tensor
.
numel
()
/
20
;
stride
=
stride
>
0
?
stride
:
1
;
for
(
int
i
=
0
;
i
<
tensor
.
numel
();
i
+=
stride
)
{
printer
<<
tensor
.
data
<
float
>
()[
i
]
<<
" "
;
}
return
printer
;
}
#endif
inline
Tensor
ReshapeToMatrix
(
const
Tensor
&
src
,
int
num_col_dims
)
{
Tensor
res
;
res
.
ShareDataWith
(
src
);
...
...
src/io.cpp
浏览文件 @
5220e87e
...
...
@@ -12,10 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "io.h"
#include "
/
io.h"
#include <fstream>
#include <vector>
#include "common/enforce.h"
#include "common/log.h"
#include "framework/framework.pb-c.h"
...
...
@@ -53,7 +52,7 @@ static size_t ReadBuffer(const char *file_name, uint8_t **out) {
DLOG
<<
"model size: "
<<
size
;
*
out
=
(
uint8_t
*
)
malloc
(
size
);
*
out
=
reinterpret_cast
<
uint8_t
*>
(
size
);
size_t
cur_len
=
0
;
size_t
nread
;
...
...
@@ -364,7 +363,7 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
is
.
read
(
static_cast
<
char
*>
(
memory
),
memory_size
*
type_size
);
is
.
close
();
}
;
}
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
InitMemory
()
{
...
...
@@ -381,6 +380,7 @@ void Executor<Dtype, P>::InitMemory() {
}
else
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
auto
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
tensor
->
template
mutable_data
<
Ptype
>();
}
}
...
...
@@ -406,15 +406,7 @@ void Executor<Dtype, P>::predict(const framework::Tensor &t, int block_id) {
template
<
typename
Dtype
,
Precision
P
>
std
::
vector
<
typename
Executor
<
Dtype
,
P
>::
Ptype
>
Executor
<
Dtype
,
P
>::
predict
(
const
std
::
vector
<
Ptype
>
&
input
,
const
std
::
vector
<
int64_t
>
&
dims
)
{
DLOG
<<
"start predict: "
;
framework
::
LoDTensor
tensor
;
auto
ddim
=
framework
::
make_ddim
(
dims
);
auto
input_ptr
=
tensor
.
mutable_data
<
Ptype
>
(
ddim
);
for
(
int
i
=
0
;
i
<
input
.
size
();
++
i
)
{
input_ptr
[
i
]
=
input
[
i
];
}
framework
::
Tensor
tensor
(
input
,
framework
::
make_ddim
(
dims
));
predict
(
tensor
,
0
);
...
...
src/operators/batchnorm_op.h
浏览文件 @
5220e87e
...
...
@@ -12,19 +12,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/batchnorm_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
BatchNormOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
BatchNormOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
BatchNormOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
...
...
@@ -32,7 +33,7 @@ class BatchNormOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
BatchNormKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/box_coder_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class BoxCoderOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
BoxCoderKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/concat_op.h
浏览文件 @
5220e87e
...
...
@@ -13,25 +13,25 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/concat_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
ConcatOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ConcatOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
ConcatOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
ConcatKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/conv_op.h
浏览文件 @
5220e87e
...
...
@@ -14,14 +14,13 @@ limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/conv_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
ConvOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
...
...
@@ -35,7 +34,7 @@ class ConvOp : public framework::OperatorWithKernel<DeviceType> {
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
({
"Filter"
,
"Input"
});
...
...
src/operators/elementwise_add_op.h
浏览文件 @
5220e87e
...
...
@@ -12,19 +12,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "kernel/elementwise_add_kernel.h"
#include "op_param.h"
#include "op
erators/op
_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
ElementwiseAddOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ElementwiseAddOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
ElementwiseAddOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
...
...
@@ -32,7 +33,7 @@ class ElementwiseAddOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
ElementwiseAddKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/feed_op.h
浏览文件 @
5220e87e
...
...
@@ -14,22 +14,23 @@ limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
FeedOp
:
public
framework
::
OperatorBase
<
DeviceType
>
{
public:
FeedOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
FeedOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorBase
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
param_
.
Out
()
->
ShareDataWith
(
*
param_
.
InputX
());
}
void
Run
Impl
()
const
{
param_
.
Out
()
->
ShareDataWith
(
*
param_
.
InputX
());
}
void
InferShape
()
const
{
auto
out_dims
=
param_
.
Out
()
->
dims
();
...
...
src/operators/fetch_op.h
浏览文件 @
5220e87e
...
...
@@ -14,27 +14,24 @@ limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
FetchOp
:
public
framework
::
OperatorBase
<
DeviceType
>
{
public:
FetchOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
FetchOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorBase
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
param_
.
Out
()
->
ShareDataWith
(
*
param_
.
InputX
());
for
(
int
i
=
0
;
i
<
param_
.
Out
()
->
numel
();
++
i
)
{
DLOG
<<
param_
.
Out
()
->
template
data
<
float
>()[
i
];
}
}
void
RunImpl
()
const
{
param_
.
Out
()
->
ShareDataWith
(
*
param_
.
InputX
());
}
void
InferShape
()
const
{
auto
x_dims
=
param_
.
InputX
()
->
dims
();
...
...
src/operators/fusion_fc_op.h
浏览文件 @
5220e87e
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#include <string>
#include <vector>
#include "framework/operator.h"
#include "framework/program/program-optimize/fusion_op_register.h"
...
...
@@ -22,7 +23,8 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
operators
{
using
std
::
string
;
using
std
::
vector
;
class
FusionFcMatcher
:
public
framework
::
FusionOpMatcher
{
public:
FusionFcMatcher
()
{
...
...
@@ -30,8 +32,8 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
node_
>
std
::
make_shared
<
framework
::
Node
>
(
"elementwise_add"
);
}
void
FolderNodes
(
framework
::
Node
&
node
)
{
std
::
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
origin_descs
=
void
FolderNodes
(
const
framework
::
Node
&
node
)
{
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
origin_descs
=
node
.
OpDescs
(
node_
.
Depth
());
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{{
"elementwise_add"
,
{
"Y"
,
"Z"
}}});
}
...
...
@@ -42,7 +44,7 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
template
<
typename
DeviceType
,
typename
T
>
class
FushionFcOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
FushionFcOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
FushionFcOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
...
...
@@ -50,7 +52,7 @@ class FushionFcOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
FushionFcKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/lrn_op.h
浏览文件 @
5220e87e
...
...
@@ -11,27 +11,27 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/lrn_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
LrnOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
LrnOp
(
const
st
d
::
st
ring
&
type
,
const
VariableNameMap
&
inputs
,
LrnOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
LrnKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/mul_op.h
浏览文件 @
5220e87e
...
...
@@ -11,7 +11,9 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/mul_kernel.h"
#include "operators/op_param.h"
...
...
@@ -19,8 +21,6 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
MulOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
...
...
@@ -31,7 +31,7 @@ class MulOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
MulKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/multiclass_nms_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class MultiClassNMSOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
MultiClassNMSKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/pool_op.h
浏览文件 @
5220e87e
...
...
@@ -17,25 +17,25 @@ limitations under the License. */
#include <framework/operator.h>
#include <operators/kernel/pool_kernel.h>
#include <operators/op_param.h>
#include <string>
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
using
framework
::
AttributeMap
;
using
framework
::
Scope
;
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
PoolOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
class
PoolOp
:
public
OperatorWithKernel
<
DeviceType
>
{
public:
PoolOp
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
PoolOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
OperatorWithKernel
<
DeviceType
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
using
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
// InferShape();
void
RunImpl
()
const
{
operators
::
PoolKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
({
"X"
});
...
...
src/operators/prior_box_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class PriorBoxOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
PriorBoxKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/relu_op.h
浏览文件 @
5220e87e
...
...
@@ -35,7 +35,7 @@ class ReluOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
ReluKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/reshape_op.h
浏览文件 @
5220e87e
...
...
@@ -35,7 +35,7 @@ class ReshapeOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
ReshapeKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
src/operators/sigmoid_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class SigmoidOp : public framework::OperatorWithKernel<DeviceType> {
void
InferShape
()
const
override
;
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
SigmoidKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
({
"X"
});
...
...
src/operators/softmax_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class SoftmaxOp : public framework::OperatorWithKernel<DeviceType> {
void
InferShape
()
const
override
;
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
SoftmaxKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
({
"X"
});
...
...
src/operators/transpose_op.h
浏览文件 @
5220e87e
...
...
@@ -36,7 +36,7 @@ class TransposeOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
void
Run
()
const
{
void
Run
Impl
()
const
{
operators
::
TransposeKernel
<
DeviceType
,
T
>
kernel
;
kernel
.
Compute
(
param_
);
}
...
...
test/executor_for_test.h
浏览文件 @
5220e87e
...
...
@@ -17,9 +17,9 @@ limitations under the License. */
#include <string>
#include <vector>
#include "./io.h"
#include "common/log.h"
#include "framework/op_registry.h"
#include "io/io.h"
#include "operators/conv_op.h"
#include "operators/elementwise_add_op.h"
#include "operators/pool_op.h"
...
...
test/framework/test_load.cpp
浏览文件 @
5220e87e
...
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "io.h"
#include "io
/io
.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/framework/test_optimize.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "framework/program/program-optimize/node.h"
#include "framework/program/program-optimize/program_optimize.h"
#include "io.h"
#include "io
/io
.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/net/test_googlenet.cpp
浏览文件 @
5220e87e
...
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include "../test_helper.h"
#include "../test_include.h"
#include "io.h"
#include "io
/io
.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/operators/test_pool_op.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "../executor_for_test.h"
#include "../test_helper.h"
#include "io.h"
#include "io
/io
.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/operators/test_reshape_op.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "../executor_for_test.h"
#include "../test_helper.h"
#include "
.
/io.h"
#include "
io
/io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/operators/test_sigmoid_op.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "../../src/operators/kernel/sigmoid_kernel.h"
#include "../test_helper.h"
#include "
.
/io.h"
#include "
io
/io.h"
int
main
()
{
paddle_mobile
::
framework
::
Tensor
input
;
...
...
test/operators/test_softmax_op.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "../executor_for_test.h"
#include "../test_helper.h"
#include "
.
/io.h"
#include "
io
/io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/operators/test_transpose_op.cpp
浏览文件 @
5220e87e
...
...
@@ -14,7 +14,7 @@ limitations under the License. */
#include "../executor_for_test.h"
#include "../test_helper.h"
#include "
.
/io.h"
#include "
io
/io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/test_include.h
浏览文件 @
5220e87e
...
...
@@ -29,4 +29,4 @@ limitations under the License. */
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
#include "io.h"
#include "io
/io
.h"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录