Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
9d499955
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
9d499955
编写于
2月 14, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
f79ad065
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
293 addition
and
88 deletion
+293
-88
src/framework/executor.cpp
src/framework/executor.cpp
+43
-36
src/framework/executor.h
src/framework/executor.h
+2
-2
src/framework/load_ops.h
src/framework/load_ops.h
+3
-0
src/framework/operator.cpp
src/framework/operator.cpp
+8
-6
src/framework/program/program_desc.cpp
src/framework/program/program_desc.cpp
+1
-2
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+4
-4
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+3
-3
src/operators/beam_search_decode_op.cpp
src/operators/beam_search_decode_op.cpp
+37
-0
src/operators/beam_search_decode_op.h
src/operators/beam_search_decode_op.h
+32
-0
src/operators/feed_op.cpp
src/operators/feed_op.cpp
+2
-1
src/operators/kernel/arm/beam_search_decode_kernel.cpp
src/operators/kernel/arm/beam_search_decode_kernel.cpp
+37
-0
src/operators/kernel/arm/feed_kernel.cpp
src/operators/kernel/arm/feed_kernel.cpp
+3
-2
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
+2
-1
src/operators/kernel/arm/while_kernel.cpp
src/operators/kernel/arm/while_kernel.cpp
+43
-2
src/operators/kernel/beam_search_decode_kernel.h
src/operators/kernel/beam_search_decode_kernel.h
+57
-0
src/operators/kernel/while_kernel.h
src/operators/kernel/while_kernel.h
+3
-5
src/operators/op_param.h
src/operators/op_param.h
+9
-24
tools/op.cmake
tools/op.cmake
+4
-0
未找到文件。
src/framework/executor.cpp
浏览文件 @
9d499955
...
...
@@ -170,20 +170,19 @@ void Executor<Device, T>::InitMemory() {
for
(
const
auto
&
block
:
program_desc_
->
Blocks
())
{
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
auto
var
=
program_
.
scope
->
Var
(
var_desc
->
Name
());
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
if
(
var_desc
->
Persistable
())
{
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
var
->
template
GetMutable
<
framework
::
LoDTensorArray
>();
continue
;
}
char
*
origin_data
=
ReadFileToBuff
(
program_
.
model_path
+
"/"
+
var_desc
->
Name
());
char
*
data
=
origin_data
;
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
LoadMemory
(
reinterpret_cast
<
void
**>
(
&
data
),
var_desc
,
tensor
);
delete
[]
origin_data
;
}
else
{
if
(
var_desc
->
Type
()
==
VARTYPE_TYPE_LOD_TENSOR
)
{
varInputMemory
(
var_desc
,
var
,
tensor
);
}
varInputMemory
(
var_desc
,
var
);
}
}
}
...
...
@@ -205,23 +204,18 @@ void Executor<Device, T>::InitCombineMemory() {
for
(
const
auto
&
block
:
program_desc_
->
Blocks
())
{
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
auto
var
=
program_
.
scope
->
Var
(
var_desc
->
Name
());
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
if
(
var_desc
->
Persistable
())
{
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
var
->
template
GetMutable
<
framework
::
LoDTensorArray
>();
continue
;
}
DLOG
<<
" init combine memory persistable: "
<<
var_desc
->
Name
();
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
LoadMemory
(
reinterpret_cast
<
void
**>
(
&
data
),
var_desc
,
tensor
);
}
else
{
if
(
var_desc
->
Type
()
==
VARTYPE_TYPE_LOD_TENSOR
)
{
DLOG
<<
" init combine memory no persistable in lod: "
<<
var_desc
->
Name
();
varInputMemory
(
var_desc
,
var
,
tensor
);
}
else
{
DLOG
<<
" init combine memory no persistable: "
<<
var_desc
->
Name
();
}
DLOG
<<
" init combine memory no persistable: "
<<
var_desc
->
Name
();
varInputMemory
(
var_desc
,
var
);
}
}
}
...
...
@@ -239,6 +233,7 @@ void Executor<Device, T>::InitNoPersistableMemory(const Tensor &input_tensor) {
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
if
(
var_desc
->
Persistable
())
{
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
var
->
template
GetMutable
<
framework
::
LoDTensorArray
>();
continue
;
}
}
else
{
...
...
@@ -249,6 +244,9 @@ void Executor<Device, T>::InitNoPersistableMemory(const Tensor &input_tensor) {
input_tensor
.
dims
()[
3
]});
tensor
->
Resize
(
new_dim
);
tensor
->
template
mutable_data
<
T
>();
}
else
{
PADDLE_MOBILE_THROW_EXCEPTION
(
"Unsupported var type `%d`"
,
var_desc
->
Type
());
}
}
}
...
...
@@ -261,34 +259,43 @@ void Executor<Device, T>::InitNoPersistableMemory(const Tensor &input_tensor) {
template
<
typename
Device
,
typename
T
>
bool
Executor
<
Device
,
T
>::
varInputMemory
(
const
std
::
shared_ptr
<
VarDesc
>
&
var_desc
,
Variable
*
var
,
LoDTensor
*
tensor
)
const
{
const
std
::
shared_ptr
<
VarDesc
>
&
var_desc
,
Variable
*
var
)
const
{
#ifdef PADDLE_MOBILE_FPGA
tensor
->
init
(
typeid
(
float
));
return
true
;
#endif
auto
type
=
var_desc
->
Tensor_desc
().
DataType
();
switch
(
type
)
{
case
VARTYPE_TYPE_FP32
:
tensor
->
mutable_data
<
float
>
();
break
;
case
VARTYPE_TYPE_INT8
:
tensor
->
mutable_data
<
int8_t
>
();
break
;
case
VARTYPE_TYPE_INT32
:
tensor
->
mutable_data
<
int32_t
>
();
break
;
case
VARTYPE_TYPE_INT64
:
tensor
->
mutable_data
<
int64_t
>
();
break
;
default:
break
;
auto
TypeId
=
[](
const
VarType_Type
&
type
)
->
std
::
type_index
{
switch
(
type
)
{
case
VARTYPE_TYPE_BOOL
:
return
typeid
(
bool
);
case
VARTYPE_TYPE_FP32
:
return
typeid
(
float
);
case
VARTYPE_TYPE_INT8
:
return
typeid
(
int8_t
);
case
VARTYPE_TYPE_INT32
:
return
typeid
(
int
);
case
VARTYPE_TYPE_INT64
:
return
typeid
(
int64_t
);
default:
PADDLE_MOBILE_THROW_EXCEPTION
(
"got unhandled var type `%d`"
,
type
);
}
};
auto
type
=
var_desc
->
Type
();
if
(
type
==
VARTYPE_TYPE_LOD_TENSOR
)
{
auto
data_type
=
var_desc
->
Tensor_desc
().
DataType
();
framework
::
LoDTensor
*
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
tensor
->
mutable_data
(
TypeId
(
data_type
));
}
else
if
(
type
==
VARTYPE_TYPE_STEP_SCOPES
)
{
std
::
vector
<
framework
::
Scope
*>
*
step_scopes
=
var
->
template
GetMutable
<
std
::
vector
<
framework
::
Scope
*
>
>
();
}
else
if
(
type
==
VARTYPE_TYPE_STEP_LOD_TENSOR_ARRAY
)
{
framework
::
LoDTensorArray
*
tensor_array
=
var
->
template
GetMutable
<
framework
::
LoDTensorArray
>();
}
else
{
PADDLE_MOBILE_THROW_EXCEPTION
(
"got unhandled var type `%d`"
,
type
);
}
bool
is_mute_match
=
(
type
==
VARTYPE_TYPE_FP32
)
||
(
type
==
VARTYPE_TYPE_INT8
)
||
(
type
==
VARTYPE_TYPE_INT32
)
||
(
type
==
VARTYPE_TYPE_INT64
);
PADDLE_MOBILE_ENFORCE
(
is_mute_match
,
"got unhandled data type : %d"
,
type
);
return
is_mute_match
;
return
true
;
}
template
<
typename
Device
,
typename
T
>
...
...
src/framework/executor.h
浏览文件 @
9d499955
...
...
@@ -61,8 +61,8 @@ class Executor {
protected:
Executor
()
=
default
;
bool
varInputMemory
(
const
std
::
shared_ptr
<
VarDesc
>
&
var_desc
,
Variable
*
var
,
LoDTensor
*
tenso
r
)
const
;
bool
varInputMemory
(
const
std
::
shared_ptr
<
VarDesc
>
&
var_desc
,
Variable
*
va
r
)
const
;
void
InitMemory
();
void
InitCombineMemory
();
void
InitNoPersistableMemory
(
const
Tensor
&
input_tensor
);
...
...
src/framework/load_ops.h
浏览文件 @
9d499955
...
...
@@ -324,3 +324,6 @@ LOAD_OP1(psroi_pool, CPU);
#ifdef ROI_PERSPECTIVE_OP
LOAD_OP1
(
roi_perspective_transform
,
CPU
);
#endif
#ifdef BEAM_SEARCH_DECODE_OP
LOAD_OP1
(
beam_search_decode
,
CPU
);
#endif
src/framework/operator.cpp
浏览文件 @
9d499955
...
...
@@ -64,9 +64,10 @@ void OperatorBase<Dtype>::Run() {
for
(
const
auto
key
:
input_keys
)
{
auto
var_vec_in
=
inputs_
.
at
(
key
);
for
(
int
i
=
0
;
i
<
var_vec_in
.
size
();
++
i
)
{
auto
vari
=
this
->
scope_
->
FindVar
(
var_vec_in
[
i
]);
if
(
vari
->
IsInitialized
())
{
const
Tensor
*
tensor
=
vari
->
template
Get
<
framework
::
LoDTensor
>();
auto
var
=
this
->
scope_
->
FindVar
(
var_vec_in
[
i
]);
if
(
var
->
IsInitialized
()
&&
var
->
template
IsType
<
framework
::
LoDTensor
>())
{
const
Tensor
*
tensor
=
var
->
template
Get
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" input- "
<<
key
<<
"="
<<
*
tensor
;
}
}
...
...
@@ -74,9 +75,10 @@ void OperatorBase<Dtype>::Run() {
for
(
const
auto
key
:
GetOutKeys
())
{
auto
var_vec_out
=
outputs_
.
at
(
key
);
for
(
int
i
=
0
;
i
<
var_vec_out
.
size
();
++
i
)
{
auto
vari
=
scope_
->
FindVar
(
var_vec_out
[
i
]);
if
(
vari
->
IsInitialized
())
{
const
Tensor
*
tensor
=
vari
->
template
Get
<
framework
::
LoDTensor
>();
auto
var
=
scope_
->
FindVar
(
var_vec_out
[
i
]);
if
(
var
->
IsInitialized
()
&&
var
->
template
IsType
<
framework
::
LoDTensor
>())
{
const
Tensor
*
tensor
=
var
->
template
Get
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
tensor
;
}
}
...
...
src/framework/program/program_desc.cpp
浏览文件 @
9d499955
...
...
@@ -78,9 +78,8 @@ void ProgramDesc::Description(std::string header) {
}
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
LOG
(
kLOG_DEBUG1
)
<<
"var name: "
<<
var_desc
->
Name
();
if
(
var_desc
->
Type
()
==
VARTYPE_TYPE_LOD_TENSOR
)
{
LOG
(
kLOG_DEBUG1
)
<<
"var name: "
<<
var_desc
->
Name
();
const
TensorDesc
&
tensor_desc
=
var_desc
->
Tensor_desc
();
LOG
(
kLOG_DEBUG2
)
<<
"in var tensor desc dims size: "
...
...
src/io/paddle_mobile.cpp
浏览文件 @
9d499955
...
...
@@ -152,14 +152,14 @@ PMStatus PaddleMobile<Device, T>::Predict() {
}
template
<
typename
Device
,
typename
T
>
void
PaddleMobile
<
Device
,
T
>::
Feed
(
const
framework
::
Tensor
&
input
,
const
std
::
string
&
var_name
)
{
void
PaddleMobile
<
Device
,
T
>::
Feed
(
const
std
::
string
&
var_name
,
const
framework
::
Tensor
&
input
)
{
executor_
->
SetInput
(
input
,
var_name
);
}
template
<
typename
Device
,
typename
T
>
void
PaddleMobile
<
Device
,
T
>::
Feed
(
const
framework
::
LoDTensor
&
input
,
const
std
::
string
&
var_name
)
{
void
PaddleMobile
<
Device
,
T
>::
Feed
(
const
std
::
string
&
var_name
,
const
framework
::
LoDTensor
&
input
)
{
executor_
->
SetInput
(
input
,
var_name
);
}
...
...
src/io/paddle_mobile.h
浏览文件 @
9d499955
...
...
@@ -33,7 +33,7 @@ namespace paddle_mobile {
template
<
typename
Device
,
typename
T
=
float
>
class
PaddleMobile
{
public:
PaddleMobile
(
PaddleMobileConfigInternal
config
)
:
config_
(
config
)
{
explicit
PaddleMobile
(
PaddleMobileConfigInternal
config
)
:
config_
(
config
)
{
#ifndef PADDLE_MOBILE_CL
bool
is_gpu
=
std
::
is_same
<
DeviceType
<
kGPU_CL
>
,
Device
>::
value
;
PADDLE_MOBILE_ENFORCE
(
!
is_gpu
,
"Please recompile with GPU_CL is on"
);
...
...
@@ -69,8 +69,8 @@ class PaddleMobile {
const
std
::
vector
<
int64_t
>
&
dims
);
PMStatus
Predict
();
void
Feed
(
const
framework
::
LoDTensor
&
input
,
const
std
::
string
&
var_name
);
void
Feed
(
const
framework
::
Tensor
&
input
,
const
std
::
string
&
var_name
);
void
Feed
(
const
std
::
string
&
var_name
,
const
framework
::
LoDTensor
&
input
);
void
Feed
(
const
std
::
string
&
var_name
,
const
framework
::
Tensor
&
input
);
typedef
std
::
shared_ptr
<
framework
::
LoDTensor
>
LoDTensorPtr
;
LoDTensorPtr
Fetch
(
const
std
::
string
&
var_name
);
...
...
src/operators/beam_search_decode_op.cpp
0 → 100644
浏览文件 @
9d499955
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
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. */
#ifdef BEAM_SEARCH_DECODE_OP
#pragma once
#include "operators/beam_search_decode_op.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
BeamSearchDecodeOp
<
Dtype
,
T
>::
InferShape
()
const
{}
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
beam_search_decode
,
ops
::
BeamSearchDecodeOp
);
#endif
namespace
ops
=
paddle_mobile
::
operators
;
#endif // BEAM_SEARCH_DECODE_OP
src/operators/beam_search_decode_op.h
0 → 100644
浏览文件 @
9d499955
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
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. */
#ifdef BEAM_SEARCH_DECODE_OP
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/beam_search_decode_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
DECLARE_OPERATOR
(
BeamSearchDecode
,
BeamSearchDecodeParam
,
BeamSearchDecodeKernel
);
}
// namespace operators
}
// namespace paddle_mobile
#endif // BEAM_SEARCH_DECODE_OP
src/operators/feed_op.cpp
浏览文件 @
9d499955
...
...
@@ -21,7 +21,8 @@ template <typename DeviceType, typename T>
void
FeedOp
<
DeviceType
,
T
>::
InferShape
()
const
{
auto
out_dims
=
this
->
param_
.
Out
()
->
dims
();
out_dims
[
0
]
=
this
->
param_
.
BatchSize
();
auto
input_dims
=
this
->
param_
.
InputX
()
->
dims
();
int
col
=
this
->
param_
.
Col
();
auto
input_dims
=
this
->
param_
.
InputX
()
->
at
(
col
).
dims
();
if
(
input_dims
.
size
()
==
4
)
{
this
->
param_
.
Out
()
->
Resize
(
input_dims
);
}
else
{
...
...
src/operators/kernel/arm/beam_search_decode_kernel.cpp
0 → 100644
浏览文件 @
9d499955
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
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. */
#ifdef BEAM_SEARCH_DECODE_OP
#include "operators/kernel/beam_search_decode_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
BeamSearchDecodeKernel
<
CPU
,
float
>::
Init
(
BeamSearchDecodeParam
<
CPU
>
*
param
)
{
return
true
;
}
template
<
>
void
BeamSearchDecodeKernel
<
CPU
,
float
>::
Compute
(
const
BeamSearchDecodeParam
<
CPU
>
&
param
)
{
// TODO(hjchen2)
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/arm/feed_kernel.cpp
浏览文件 @
9d499955
...
...
@@ -24,8 +24,9 @@ bool FeedKernel<CPU, float>::Init(FeedParam<CPU> *param) {
template
<
>
void
FeedKernel
<
CPU
,
float
>::
Compute
(
const
FeedParam
<
CPU
>
&
param
)
{
param
.
Out
()
->
ShareDataWith
(
*
(
param
.
InputX
()));
param
.
Out
()
->
set_lod
(
param
.
InputX
()
->
lod
());
int
col
=
param
.
Col
();
param
.
Out
()
->
ShareDataWith
(
param
.
InputX
()
->
at
(
col
));
param
.
Out
()
->
set_lod
(
param
.
InputX
()
->
at
(
col
).
lod
());
}
template
class
FeedKernel
<
CPU
,
float
>;
...
...
src/operators/kernel/arm/tensor_array_read_write_kernel.cpp
浏览文件 @
9d499955
...
...
@@ -28,8 +28,9 @@ void WriteToArrayKernel<CPU, float>::Compute(
const
WriteToArrayParam
<
CPU
>
&
param
)
{
int64_t
offset
=
param
.
index_
->
data
<
int64_t
>
()[
0
];
if
(
offset
>=
param
.
output_
->
size
())
{
param
.
output_
->
resize
(
offset
);
param
.
output_
->
resize
(
offset
+
1
);
}
framework
::
LoDTensor
*
out_tensor
=
&
(
param
.
output_
->
at
(
offset
));
out_tensor
->
set_lod
(
param
.
input_
->
lod
());
if
(
param
.
input_
->
memory_size
()
>
0
)
{
...
...
src/operators/kernel/arm/while_kernel.cpp
浏览文件 @
9d499955
...
...
@@ -12,12 +12,46 @@ 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. */
#ifdef WHILE_OP
#include "operators/kernel/while_kernel.h"
#include "framework/op_registry.h"
#include "framework/operator.h"
namespace
paddle_mobile
{
namespace
operators
{
#ifdef WHILE_OP
class
StepExecutor
{
typedef
std
::
shared_ptr
<
framework
::
OperatorBase
<
CPU
>>
OperatorPtr
;
public:
StepExecutor
(
const
framework
::
BlockDesc
*
block
,
framework
::
Scope
*
scope
)
:
scope_
(
std
::
shared_ptr
<
framework
::
Scope
>
(
scope
))
{
std
::
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
ops
=
block
->
Ops
();
ops_of_block_
.
resize
(
ops
.
size
());
for
(
int
i
=
0
;
i
<
ops
.
size
();
++
i
)
{
std
::
shared_ptr
<
framework
::
OpDesc
>
op_desc
=
ops
[
i
];
auto
op_handler
=
framework
::
OpRegistry
<
CPU
>::
CreateOp
(
op_desc
->
Type
(),
op_desc
->
GetInputs
(),
op_desc
->
GetOutputs
(),
op_desc
->
GetAttrMap
(),
scope_
);
ops_of_block_
[
i
]
=
op_handler
;
}
}
void
Run
()
{
for
(
auto
&
op_handler
:
ops_of_block_
)
{
DLOG
<<
"run op: "
<<
op_handler
->
Type
();
op_handler
->
InferShape
();
op_handler
->
Run
();
DLOG
<<
"run op finish"
;
}
}
private:
std
::
shared_ptr
<
framework
::
Scope
>
scope_
;
std
::
vector
<
OperatorPtr
>
ops_of_block_
;
};
template
<
>
bool
WhileKernel
<
CPU
,
float
>::
Init
(
WhileParam
<
CPU
>
*
param
)
{
return
true
;
...
...
@@ -26,8 +60,15 @@ bool WhileKernel<CPU, float>::Init(WhileParam<CPU> *param) {
template
<
>
void
WhileKernel
<
CPU
,
float
>::
Compute
(
const
WhileParam
<
CPU
>
&
param
)
{
// TODO(hjchen2)
auto
&
current_scope
=
param
.
scope_
->
NewScope
();
StepExecutor
executor
(
param
.
sub_block_
,
&
current_scope
);
while
(
param
.
cond_
->
data
<
bool
>
()[
0
])
{
executor
.
Run
();
}
param
.
scope_
->
DeleteScope
(
&
current_scope
);
}
#endif // WHILE_OP
}
// namespace operators
}
// namespace paddle_mobile
#endif // WHILE_OP
src/operators/kernel/beam_search_decode_kernel.h
0 → 100644
浏览文件 @
9d499955
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
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. */
#ifdef BEAM_SEARCH_DECODE_OP
#pragma once
#include "framework/operator.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
>
class
BeamSearchDecodeParam
:
public
OpParam
{
public:
BeamSearchDecodeParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
ids_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Ids"
,
inputs
,
scope
);
scores_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensorArray
>
(
"Scores"
,
inputs
,
scope
);
sentence_ids_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"SentenceIds"
,
outputs
,
scope
);
sentence_scores_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"SentenceScores"
,
outputs
,
scope
);
beam_size_
=
OpParam
::
GetAttr
<
int
>
(
"beam_size"
,
attrs
);
end_id_
=
OpParam
::
GetAttr
<
int
>
(
"end_id"
,
attrs
);
}
public:
framework
::
LoDTensorArray
*
ids_
;
framework
::
LoDTensorArray
*
scores_
;
framework
::
LoDTensor
*
sentence_ids_
;
framework
::
LoDTensor
*
sentence_scores_
;
int
beam_size_
;
int
end_id_
;
};
DECLARE_KERNEL
(
BeamSearchDecode
,
BeamSearchDecodeParam
);
}
// namespace operators
}
// namespace paddle_mobile
#endif // BEAM_SEARCH_DECODE_OP
src/operators/kernel/while_kernel.h
浏览文件 @
9d499955
...
...
@@ -26,18 +26,16 @@ class WhileParam : public OpParam {
public:
WhileParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
:
inputs_
(
inputs
),
outputs_
(
outputs
),
scope_
(
scope
)
{
:
scope_
(
&
scope
)
{
cond_
=
OpParam
::
GetVarValue
<
framework
::
LoDTensor
>
(
"Condition"
,
inputs
,
scope
);
sub_block_
=
OpParam
::
GetAttr
<
framework
::
BlockDesc
*>
(
"sub_block"
,
attrs
);
}
public:
const
Scope
*
scope_
;
framework
::
LoDTensor
*
cond_
;
const
framework
::
BlockDesc
*
sub_block_
;
const
VariableNameMap
inputs_
;
const
VariableNameMap
outputs_
;
const
Scope
scope_
;
framework
::
BlockDesc
*
sub_block_
;
};
DECLARE_KERNEL
(
While
,
WhileParam
);
...
...
src/operators/op_param.h
浏览文件 @
9d499955
...
...
@@ -1172,18 +1172,21 @@ class FeedParam : public OpParam {
public:
FeedParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
LoDTensor
>
(
inputs
,
scope
);
input_x_
=
InputXFrom
<
framework
::
LoDTensorArray
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
col_
=
GetAttr
<
int
>
(
"col"
,
attrs
);
auto
var
=
scope
.
FindVar
(
"batch_size"
);
batch_size
=
var
->
GetValue
<
int
>
();
}
const
LoDTensor
*
InputX
()
const
{
return
input_x_
;
}
const
framework
::
LoDTensorArray
*
InputX
()
const
{
return
input_x_
;
}
GType
*
Out
()
const
{
return
out_
;
}
const
int
Col
()
const
{
return
col_
;
}
const
int
BatchSize
()
const
{
return
batch_size
;
}
private:
LoDTensor
*
input_x_
;
framework
::
LoDTensorArray
*
input_x_
;
GType
*
out_
;
int
col_
;
int
batch_size
;
};
...
...
@@ -3008,24 +3011,6 @@ class LogicalUnaryParam : public OpParam {
};
#endif // LOGICAL_NOT_OP
// #ifdef WHILE_OP
// template <typename Dtype>
// class WhileParam : public OpParam {
// public:
// WhileParam(const VariableNameMap &inputs,
// const VariableNameMap &outputs, const AttributeMap &attrs,
// const Scope &scope) {
// cond_ = OpParam::GetVarValue<framework::LoDTensor>("Condition", inputs,
// scope); block_desc_ = OpParam::GetAttr<framework::BlockDesc
// *>("sub_block", attrs);
// }
//
// public:
// framework::LoDTensor *cond_;
// const framework::BlockDesc *block_desc_;
// };
// #endif // WHILE_OP
#ifdef WRITE_TO_ARRAY_OP
template
<
typename
Dtype
>
class
WriteToArrayParam
:
public
OpParam
{
...
...
@@ -3099,17 +3084,17 @@ class IncrementParam : public OpParam {
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
output_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
step_
=
OpParam
::
GetAttr
<
in
t
>
(
"step"
,
attrs
);
step_
=
OpParam
::
GetAttr
<
floa
t
>
(
"step"
,
attrs
);
}
const
GType
*
InputX
()
const
{
return
input_x_
;
}
GType
*
Out
()
const
{
return
output_
;
}
in
t
Step
()
const
{
return
step_
;
}
floa
t
Step
()
const
{
return
step_
;
}
public:
GType
*
input_x_
;
GType
*
output_
;
in
t
step_
;
floa
t
step_
;
};
#endif // INCREMENT_OP
...
...
tools/op.cmake
浏览文件 @
9d499955
...
...
@@ -294,6 +294,7 @@ if(NOT FOUND_MATCH)
set
(
PROPOSAL_OP ON
)
set
(
PSROI_POOL_OP ON
)
set
(
ROI_PERSPECTIVE_OP ON
)
set
(
BEAM_SEARCH_DECODE_OP ON
)
endif
()
# option(BATCHNORM_OP "" ON)
...
...
@@ -597,3 +598,6 @@ endif()
if
(
ROI_PERSPECTIVE_OP
)
add_definitions
(
-DROI_PERSPECTIVE_OP
)
endif
()
if
(
BEAM_SEARCH_DECODE_OP
)
add_definitions
(
-DBEAM_SEARCH_DECODE_OP
)
endif
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录