Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
df8ad667
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
提交
df8ad667
编写于
5月 17, 2018
作者:
W
wangliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify code style
上级
5a152298
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
140 addition
and
136 deletion
+140
-136
src/framework/operator.cpp
src/framework/operator.cpp
+15
-15
src/framework/operator.h
src/framework/operator.h
+29
-28
src/framework/variable.h
src/framework/variable.h
+67
-65
src/operators/conv_op.h
src/operators/conv_op.h
+29
-28
未找到文件。
src/framework/operator.cpp
浏览文件 @
df8ad667
...
...
@@ -21,22 +21,22 @@ SOFTWARE.
namespace
paddle_mobile
{
namespace
framework
{
template
<
typename
Dtype
>
OperatorBase
<
Dtype
>::
OperatorBase
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
type_
(
type
),
inputs_
(
inputs
),
outputs_
(
outputs
),
attrs_
(
attrs
),
scope_
(
scope
)
{
CheckAllInputOutputSet
();
}
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
CheckAllInputOutputSet
()
const
{}
template
class
OperatorBase
<
CPU
>;
template
class
OperatorWithKernel
<
CPU
>;
template
<
typename
Dtype
>
OperatorBase
<
Dtype
>::
OperatorBase
(
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
std
::
shared_ptr
<
Scope
>
scope
)
:
type_
(
type
),
inputs_
(
inputs
),
outputs_
(
outputs
),
attrs_
(
attrs
),
scope_
(
scope
)
{
CheckAllInputOutputSet
();
}
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
CheckAllInputOutputSet
()
const
{}
template
class
OperatorBase
<
CPU
>;
template
class
OperatorWithKernel
<
CPU
>;
}
// namespace framework
}
// namespace paddle_mobile
src/framework/operator.h
浏览文件 @
df8ad667
...
...
@@ -22,32 +22,33 @@ SOFTWARE.
#include "operators/kernel/pool_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
ConvOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ConvOp
(
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
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
,
ConvParam
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
();
}
private:
ConvParam
param_
;
};
}
// operators
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
ConvOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ConvOp
(
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
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
,
ConvParam
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
();
}
private:
ConvParam
param_
;
};
}
// operators
}
// paddle_mobile
src/framework/variable.h
浏览文件 @
df8ad667
...
...
@@ -26,69 +26,71 @@ SOFTWARE.
#include <typeinfo>
namespace
paddle_mobile
{
namespace
framework
{
class
Variable
:
public
PaddleMobileObject
{
public:
template
<
typename
T
>
const
T
*
Get
()
const
{
return
static_cast
<
const
T
*>
(
holder_
->
Ptr
());
}
bool
IsInitialized
()
const
{
return
holder_
!=
nullptr
;
}
const
std
::
string
*
Name
()
{
return
name_
;
}
template
<
typename
T
>
T
*
GetMutable
()
{
if
(
!
IsType
<
T
>
())
{
if
(
*
Name
()
==
"pixel"
)
{
// std::cout << " reset " << *Name() << std::endl;
}
holder_
.
reset
(
new
PlaceholderImp
<
T
>
(
new
T
()));
}
return
static_cast
<
T
*>
(
holder_
->
Ptr
());
}
template
<
typename
T
>
bool
IsType
()
const
{
if
(
holder_
)
{
// printf("not null \n");
printf
(
" holder type : %s, this type %s
\n
"
,
holder_
->
Type
().
name
(),
typeid
(
T
).
name
());
}
// std::cout << " " << holder_->Type() << " " << typeid(T) <<
// std::endl;
return
holder_
!=
nullptr
&&
holder_
->
Type
()
==
typeid
(
T
);
}
void
Clear
()
{
holder_
.
reset
();
}
std
::
type_index
Type
()
const
{
return
holder_
->
Type
();
}
void
SetName
(
const
std
::
string
*
name
)
{
name_
=
name
;
}
private:
struct
Placeholder
{
Placeholder
()
=
default
;
virtual
~
Placeholder
()
=
default
;
virtual
const
std
::
type_info
&
Type
()
const
=
0
;
virtual
void
*
Ptr
()
const
=
0
;
};
template
<
typename
T
>
struct
PlaceholderImp
:
public
Placeholder
{
explicit
PlaceholderImp
(
T
*
ptr
)
:
ptr_
(
ptr
),
type_
(
typeid
(
T
))
{}
virtual
const
std
::
type_info
&
Type
()
const
{
return
type_
;
}
virtual
void
*
Ptr
()
const
override
{
return
static_cast
<
void
*>
(
ptr_
.
get
());
}
std
::
unique_ptr
<
T
>
ptr_
;
const
std
::
type_info
&
type_
;
};
std
::
unique_ptr
<
Placeholder
>
holder_
;
friend
class
Scope
;
const
std
::
string
*
name_
;
};
}
// namespace framework
namespace
framework
{
class
Variable
:
public
PaddleMobileObject
{
public:
template
<
typename
T
>
const
T
*
Get
()
const
{
return
static_cast
<
const
T
*>
(
holder_
->
Ptr
());
}
bool
IsInitialized
()
const
{
return
holder_
!=
nullptr
;
}
const
std
::
string
*
Name
()
{
return
name_
;
}
template
<
typename
T
>
T
*
GetMutable
()
{
if
(
!
IsType
<
T
>
())
{
if
(
*
Name
()
==
"pixel"
)
{
// std::cout << " reset " << *Name() <<
// std::endl;
}
holder_
.
reset
(
new
PlaceholderImp
<
T
>
(
new
T
()));
}
return
static_cast
<
T
*>
(
holder_
->
Ptr
());
}
template
<
typename
T
>
bool
IsType
()
const
{
if
(
holder_
)
{
// printf("not null \n");
printf
(
" holder type : %s, this type %s
\n
"
,
holder_
->
Type
().
name
(),
typeid
(
T
).
name
());
}
// std::cout << " " << holder_->Type() << " " <<
// typeid(T) <<
// std::endl;
return
holder_
!=
nullptr
&&
holder_
->
Type
()
==
typeid
(
T
);
}
void
Clear
()
{
holder_
.
reset
();
}
std
::
type_index
Type
()
const
{
return
holder_
->
Type
();
}
void
SetName
(
const
std
::
string
*
name
)
{
name_
=
name
;
}
private:
struct
Placeholder
{
Placeholder
()
=
default
;
virtual
~
Placeholder
()
=
default
;
virtual
const
std
::
type_info
&
Type
()
const
=
0
;
virtual
void
*
Ptr
()
const
=
0
;
};
template
<
typename
T
>
struct
PlaceholderImp
:
public
Placeholder
{
explicit
PlaceholderImp
(
T
*
ptr
)
:
ptr_
(
ptr
),
type_
(
typeid
(
T
))
{}
virtual
const
std
::
type_info
&
Type
()
const
{
return
type_
;
}
virtual
void
*
Ptr
()
const
override
{
return
static_cast
<
void
*>
(
ptr_
.
get
());
}
std
::
unique_ptr
<
T
>
ptr_
;
const
std
::
type_info
&
type_
;
};
std
::
unique_ptr
<
Placeholder
>
holder_
;
friend
class
Scope
;
const
std
::
string
*
name_
;
};
}
// namespace framework
}
// namespace paddle_mobile
src/operators/conv_op.h
浏览文件 @
df8ad667
...
...
@@ -22,32 +22,33 @@ SOFTWARE.
#include "operators/kernel/conv_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
ConvOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ConvOp
(
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
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
,
ConvParam
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
();
}
private:
ConvParam
param_
;
};
}
// operators
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
ConvOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
>
{
public:
ConvOp
(
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
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
void
Run
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
,
ConvParam
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
();
}
private:
ConvParam
param_
;
};
}
// operators
}
// paddle_mobile
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录