Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f3d1fac2
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f3d1fac2
编写于
4月 02, 2019
作者:
S
superjomn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix kernel registry
上级
027cbe83
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
68 addition
and
45 deletion
+68
-45
paddle/fluid/lite/CMakeLists.txt
paddle/fluid/lite/CMakeLists.txt
+1
-0
paddle/fluid/lite/core/kernel.h
paddle/fluid/lite/core/kernel.h
+6
-5
paddle/fluid/lite/core/op_lite.h
paddle/fluid/lite/core/op_lite.h
+4
-4
paddle/fluid/lite/core/op_registry.cc
paddle/fluid/lite/core/op_registry.cc
+1
-1
paddle/fluid/lite/core/op_registry.h
paddle/fluid/lite/core/op_registry.h
+28
-12
paddle/fluid/lite/core/scope.cc
paddle/fluid/lite/core/scope.cc
+1
-2
paddle/fluid/lite/core/scope.h
paddle/fluid/lite/core/scope.h
+1
-1
paddle/fluid/lite/core/scope_test.cc
paddle/fluid/lite/core/scope_test.cc
+1
-1
paddle/fluid/lite/core/tensor.cc
paddle/fluid/lite/core/tensor.cc
+1
-1
paddle/fluid/lite/core/tensor.h
paddle/fluid/lite/core/tensor.h
+0
-1
paddle/fluid/lite/core/variable.cc
paddle/fluid/lite/core/variable.cc
+1
-1
paddle/fluid/lite/operators/CMakeLists.txt
paddle/fluid/lite/operators/CMakeLists.txt
+4
-1
paddle/fluid/lite/operators/fc_op.cc
paddle/fluid/lite/operators/fc_op.cc
+1
-1
paddle/fluid/lite/operators/fc_op.h
paddle/fluid/lite/operators/fc_op.h
+17
-13
paddle/fluid/lite/utils/all.h
paddle/fluid/lite/utils/all.h
+1
-1
未找到文件。
paddle/fluid/lite/CMakeLists.txt
浏览文件 @
f3d1fac2
...
...
@@ -4,3 +4,4 @@ add_subdirectory(cuda)
add_subdirectory
(
operators
)
add_subdirectory
(
kernels
)
add_subdirectory
(
model_parser
)
add_subdirectory
(
utils
)
paddle/fluid/lite/core/kernel.h
浏览文件 @
f3d1fac2
...
...
@@ -18,10 +18,11 @@
#include <boost/variant.hpp>
#include <map>
#include <string>
#include "paddle/fluid/framework/op_desc.h"
#include "context.h"
#include "target_wrapper.h"
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/lite/operators/op_params.h"
#include "paddle/fluid/lite/utils/all.h"
#include "target_wrapper.h"
namespace
paddle
{
namespace
lite
{
...
...
@@ -39,11 +40,11 @@ class OpKernel {
void
SetContext
(
context_ptr_t
&&
ctx
)
{
context_
=
std
::
move
(
ctx
);
}
void
SetParam
(
any
param
)
{
param_
=
param
;
}
void
SetParam
(
operators
::
param_t
param
)
{
param_
=
param
;
}
template
<
typename
Param
>
Param
&
param
()
const
{
return
*
any_cast
<
Param
>
(
&
param_
);
return
param_
.
get
<
Param
>
(
);
}
virtual
void
Run
()
{
CHECK
(
false
)
<<
"Not Implemented"
;
}
...
...
@@ -52,7 +53,7 @@ class OpKernel {
protected:
context_ptr_t
context_
;
mutable
any
param_
;
mutable
operators
::
param_t
param_
;
};
}
// namespace lite
...
...
paddle/fluid/lite/core/op_lite.h
浏览文件 @
f3d1fac2
...
...
@@ -18,11 +18,12 @@
#include <boost/variant.hpp>
#include <map>
#include <string>
#include "context.h"
#include "kernel.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/lite/core/context.h"
#include "paddle/fluid/lite/core/kernel.h"
#include "paddle/fluid/lite/core/scope.h"
namespace
paddle
{
namespace
lite
{
...
...
@@ -66,8 +67,7 @@ class OpLite : public Registry {
// Run this operator.
virtual
bool
Run
()
=
0
;
// Build the operator, attach it with the runtime environment.
virtual
bool
Build
(
const
framework
::
OpDesc
&
opdesc
,
framework
::
Scope
*
scope
)
=
0
;
virtual
bool
Build
(
const
framework
::
OpDesc
&
opdesc
,
lite
::
Scope
*
scope
)
=
0
;
// Human-readable information.
virtual
std
::
string
DebugString
()
const
=
0
;
...
...
paddle/fluid/lite/core/op_registry.cc
浏览文件 @
f3d1fac2
...
...
@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "op_registry.h"
\ No newline at end of file
#include "paddle/fluid/lite/core/op_registry.h"
\ No newline at end of file
paddle/fluid/lite/core/op_registry.h
浏览文件 @
f3d1fac2
...
...
@@ -15,9 +15,9 @@
#include <memory>
#include <string>
#include <unordered_map>
#include "kernel.h"
#include "op_lite.h"
#include "target_wrapper.h"
#include "
paddle/fluid/lite/core/
kernel.h"
#include "
paddle/fluid/lite/core/
op_lite.h"
#include "
paddle/fluid/lite/core/
target_wrapper.h"
#include "paddle/fluid/lite/utils/all.h"
namespace
paddle
{
...
...
@@ -50,16 +50,32 @@ class OpLiteRegistor : public Registor<OpClass> {
};
template
<
TargetType
Target
,
PrecisionType
Precision
>
class
KernelRegistryForTarget
:
public
Factory
<
OpKernel
<
Target
,
Precision
>>
{}
;
using
KernelRegistryForTarget
=
Factory
<
OpKernel
<
Target
,
Precision
>>
;
class
KernelRegistry
final
{
public:
using
any_kernel_registor_t
=
variant
<
KernelRegistryForTarget
<
TargetType
::
kCUDA
,
PrecisionType
::
kFloat
>
*
,
//
KernelRegistryForTarget
<
TargetType
::
kCUDA
,
PrecisionType
::
kInt8
>
*
,
//
KernelRegistryForTarget
<
TargetType
::
kX86
,
PrecisionType
::
kFloat
>
*
,
//
KernelRegistryForTarget
<
TargetType
::
kX86
,
PrecisionType
::
kInt8
>
*
,
//
KernelRegistryForTarget
<
TargetType
::
kARM
,
PrecisionType
::
kFloat
>
*
,
//
KernelRegistryForTarget
<
TargetType
::
kHost
,
PrecisionType
::
kFloat
>
*
//
>
;
KernelRegistry
()
{
#define INIT_FOR(target__, precision__) \
registries_[KernelRegistry::GetKernelOffset<TARGET(target__), \
PRECISION(precision__)>()] = \
&KernelRegistryForTarget<TARGET(target__), \
PRECISION(precision__)>::Global();
/*
using kernel_target_t =
KernelRegistryForTarget<TARGET(kCUDA), PRECISION(kFloat)>;
registries_[0].set<kernel_target_t *>(
&KernelRegistryForTarget<TARGET(kCUDA), PRECISION(kFloat)>::Global());
*/
#define INIT_FOR(target__, precision__) \
registries_[KernelRegistry::GetKernelOffset<TARGET(target__), \
PRECISION(precision__)>()] \
.set<KernelRegistryForTarget<TARGET(target__), PRECISION(precision__)> \
*>(&KernelRegistryForTarget<TARGET(target__), \
PRECISION(precision__)>::Global());
// Currently, just register 2 kernel targets.
INIT_FOR
(
kARM
,
kFloat
);
INIT_FOR
(
kHost
,
kFloat
);
...
...
@@ -76,8 +92,8 @@ class KernelRegistry final {
typename
KernelRegistryForTarget
<
Target
,
Precision
>::
creator_t
&&
creator
)
{
using
kernel_registor_t
=
KernelRegistryForTarget
<
Target
,
Precision
>
;
any_cast
<
kernel_registor_t
*>
(
registries_
[
GetKernelOffset
<
Target
,
Precision
>
()]
)
registries_
[
GetKernelOffset
<
Target
,
Precision
>
()]
.
template
get
<
kernel_registor_t
*
>(
)
->
Register
(
name
,
std
::
move
(
creator
));
}
...
...
@@ -88,7 +104,7 @@ class KernelRegistry final {
}
private:
std
::
array
<
any
,
kNumTargets
*
kNumPrecisions
>
registries_
;
std
::
array
<
any
_kernel_registor_t
,
kNumTargets
*
kNumPrecisions
>
registries_
;
};
template
<
TargetType
target
,
PrecisionType
precision
,
typename
KernelType
>
...
...
paddle/fluid/lite/core/scope.cc
浏览文件 @
f3d1fac2
...
...
@@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "scope.h"
#include "scope.h"
#include "paddle/fluid/lite/core/scope.h"
namespace
paddle
{
namespace
lite
{
...
...
paddle/fluid/lite/core/scope.h
浏览文件 @
f3d1fac2
...
...
@@ -19,7 +19,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include "variable.h"
#include "
paddle/fluid/lite/core/
variable.h"
namespace
paddle
{
namespace
lite
{
...
...
paddle/fluid/lite/core/scope_test.cc
浏览文件 @
f3d1fac2
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "scope.h"
#include "
paddle/fluid/lite/core/
scope.h"
#include <gtest/gtest.h>
namespace
paddle
{
...
...
paddle/fluid/lite/core/tensor.cc
浏览文件 @
f3d1fac2
...
...
@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tensor.h"
#include "
paddle/fluid/lite/core/
tensor.h"
paddle/fluid/lite/core/tensor.h
浏览文件 @
f3d1fac2
...
...
@@ -57,7 +57,6 @@ using LoD = std::vector<std::vector<size_t>>;
// A light-weight tensor implementation.
class
Tensor
{
public:
void
SyncEventTree
();
Tensor
()
=
default
;
template
<
typename
T
>
...
...
paddle/fluid/lite/core/variable.cc
浏览文件 @
f3d1fac2
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "variable.h"
#include "
paddle/fluid/lite/core/
variable.h"
namespace
paddle
{
namespace
lite
{}
// namespace lite
...
...
paddle/fluid/lite/operators/CMakeLists.txt
浏览文件 @
f3d1fac2
cc_library
(
fc_op_lite SRCS fc_op.cc DEPS op_lite
)
cc_library
(
fc_op_lite SRCS fc_op.cc DEPS op_lite
op_params_lite tensor_lite
)
cc_library
(
relu_op_lite SRCS relu_op.cc DEPS op_lite
)
cc_library
(
op_params_lite SRCS op_params.cc DEPS tensor_lite
)
cc_test
(
test_fc_op_lite SRCS fc_op_test.cc DEPS fc_op_lite
)
paddle/fluid/lite/operators/fc_op.cc
浏览文件 @
f3d1fac2
...
...
@@ -53,7 +53,7 @@ bool FcOpLite::InferShape() const {
const
auto
w_dims
=
param_
.
w
->
dims
();
// Set output dims
std
::
vector
<
int
>
output_dims
(
param_
.
in_num_col_dims
+
1
,
0
);
std
::
vector
<
int
64_t
>
output_dims
(
param_
.
in_num_col_dims
+
1
,
0
);
for
(
int
i
=
0
;
i
<
param_
.
in_num_col_dims
;
++
i
)
{
output_dims
[
i
]
=
input_dims
[
i
];
}
...
...
paddle/fluid/lite/operators/fc_op.h
浏览文件 @
f3d1fac2
...
...
@@ -15,23 +15,15 @@
#include <string>
#include <vector>
#include "paddle/fluid/lite/core/op_lite.h"
#include "paddle/fluid/lite/core/scope.h"
#include "paddle/fluid/lite/core/tensor.h"
#include "paddle/fluid/lite/operators/op_params.h"
#include "paddle/fluid/lite/utils/all.h"
namespace
paddle
{
namespace
lite
{
namespace
operators
{
struct
FcParam
{
Tensor
*
input
{
nullptr
};
Tensor
*
w
{
nullptr
};
Tensor
*
bias
{
nullptr
};
Tensor
*
output
{
nullptr
};
// the input matrix dimentions.
lite
::
DDim
in_mat_dims
;
int
in_num_col_dims
{
0
};
};
class
FcOpLite
:
public
OpLite
{
public:
FcOpLite
()
{}
...
...
@@ -42,9 +34,21 @@ class FcOpLite : public OpLite {
bool
Run
()
override
{
return
false
;
}
bool
Build
(
const
framework
::
OpDesc
&
opdesc
,
framework
::
Scope
*
scope
)
override
{
return
false
;
// TODO(Superjomn) replace framework::OpDesc with a lite one.
bool
Build
(
const
framework
::
OpDesc
&
op_desc
,
lite
::
Scope
*
scope
)
override
{
auto
input
=
op_desc
.
Input
(
"Input"
).
front
();
auto
W
=
op_desc
.
Input
(
"W"
).
front
();
auto
bias
=
op_desc
.
Input
(
"bias"
).
front
();
auto
out
=
op_desc
.
Output
(
"bias"
).
front
();
param_
.
input
=
scope
->
FindVar
(
input
)
->
GetMutable
<
Tensor
>
();
param_
.
w
=
scope
->
FindVar
(
W
)
->
GetMutable
<
Tensor
>
();
param_
.
bias
=
scope
->
FindVar
(
bias
)
->
GetMutable
<
Tensor
>
();
param_
.
output
=
scope
->
FindVar
(
out
)
->
GetMutable
<
Tensor
>
();
param_
.
in_num_col_dims
=
boost
::
any_cast
<
int
>
(
op_desc
.
GetAttr
(
"in_num_col_dims"
));
return
true
;
}
std
::
string
DebugString
()
const
override
{
return
"fc"
;
}
...
...
paddle/fluid/lite/utils/all.h
浏览文件 @
f3d1fac2
...
...
@@ -14,7 +14,7 @@
#pragma once
#include "paddle/fluid/lite/utils/varient.h"
#include "paddle/fluid/lite/utils/check.h"
#include "paddle/fluid/lite/utils/factory.h"
#include "paddle/fluid/lite/utils/macros.h"
#include "paddle/fluid/lite/utils/varient.h"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录