Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
c05a4e58
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c05a4e58
编写于
4月 21, 2019
作者:
S
Superjomn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor Context and link with kernel
Only kernel has context, not the OpLite.
上级
8532bb4a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
69 deletion
+37
-69
paddle/fluid/lite/core/context.h
paddle/fluid/lite/core/context.h
+30
-58
paddle/fluid/lite/core/kernel.h
paddle/fluid/lite/core/kernel.h
+5
-4
paddle/fluid/lite/core/op_lite.h
paddle/fluid/lite/core/op_lite.h
+2
-3
paddle/fluid/lite/core/types.h
paddle/fluid/lite/core/types.h
+0
-4
未找到文件。
paddle/fluid/lite/core/context.h
浏览文件 @
c05a4e58
...
@@ -25,61 +25,6 @@
...
@@ -25,61 +25,6 @@
namespace
paddle
{
namespace
paddle
{
namespace
lite
{
namespace
lite
{
template
<
TargetType
Target
>
class
Context
{
public:
using
target_wrapper_t
=
TargetWrapper
<
Target
>
;
using
stream_t
=
typename
TargetWrapper
<
Target
>::
stream_t
;
using
event_t
=
typename
TargetWrapper
<
Target
>::
event_t
;
Context
()
=
default
;
Context
(
int
device_id
,
stream_t
compute_stream
,
stream_t
data_stream
)
:
device_id_
(
device_id
),
compute_stream_
(
compute_stream
),
data_stream_
(
data_stream
)
{}
void
SetDeviceId
(
int
device_id
)
{
device_id_
=
device_id
;
}
void
SetComputeStream
(
stream_t
x
)
{
compute_stream_
=
x
;
}
void
SetDataStream
(
stream_t
x
)
{
data_stream_
=
x
;
}
void
SetDependEvents
(
const
std
::
vector
<
event_t
>&
events
)
{
depend_events_
=
events
;
}
int
device_id
()
const
{
return
device_id_
;
}
stream_t
compute_stream
()
const
{
return
compute_stream_
;
}
stream_t
data_stream
()
const
{
return
data_stream_
;
}
const
std
::
vector
<
event_t
>&
depend_events
()
const
{
return
depend_events_
;
}
private:
int
device_id_
{
0
};
stream_t
compute_stream_
;
stream_t
data_stream_
;
std
::
vector
<
event_t
>
depend_events_
;
};
class
OpContext
final
{
public:
template
<
TargetType
Target
>
using
target_ptr_t
=
std
::
unique_ptr
<
Context
<
Target
>>
;
// @param target valid target.
explicit
OpContext
(
TargetType
target
)
:
targets_
(
std
::
vector
<
TargetType
>
({
target
}))
{}
// @param target valid target.
explicit
OpContext
(
const
std
::
vector
<
TargetType
>&
target
)
:
targets_
(
target
)
{}
const
std
::
vector
<
TargetType
>&
target
()
const
{
return
targets_
;
}
template
<
TargetType
Target
>
target_ptr_t
<
Target
>
CreateContext
()
{
return
target_ptr_t
<
Target
>
(
new
Context
<
Target
>
);
}
private:
std
::
vector
<
TargetType
>
targets_
;
};
#ifdef LITE_WITH_CUDA
#ifdef LITE_WITH_CUDA
// Only works with CUDA kernels.
// Only works with CUDA kernels.
struct
CUDAContext
{
struct
CUDAContext
{
...
@@ -88,7 +33,7 @@ struct CUDAContext {
...
@@ -88,7 +33,7 @@ struct CUDAContext {
cudaStream_t
io_stream
;
cudaStream_t
io_stream
;
// not thread-safe, should allocate for each thread.
// not thread-safe, should allocate for each thread.
std
::
shared_ptr
<
cuda
::
Blas
<
float
>>
b
i
as_fp32
;
std
::
shared_ptr
<
cuda
::
Blas
<
float
>>
b
l
as_fp32
;
// kernel information
// kernel information
std
::
vector
<
cudaEvent_t
>
input_events
;
std
::
vector
<
cudaEvent_t
>
input_events
;
...
@@ -108,12 +53,39 @@ struct X86Context {
...
@@ -108,12 +53,39 @@ struct X86Context {
class
KernelContext
{
class
KernelContext
{
public:
public:
#ifdef LITE_WITH_CUDA
#ifdef LITE_WITH_CUDA
CUDAContext
cuda_ctx
;
CUDAContext
&
AsCudaContext
()
{
if
(
target_
!=
TARGET
(
kUnk
))
{
CHECK
(
target_
==
TARGET
(
kCUDA
));
}
else
{
target_
=
TARGET
(
kCUDA
);
cuda_ctx_
.
reset
(
new
CUDAContext
);
}
return
*
cuda_ctx_
;
}
#endif // LITE_WITH_CUDA
#ifdef LITE_WITH_X86
X86Context
&
AsX86Context
()
{
if
(
target_
!=
TARGET
(
kUnk
))
{
CHECK
(
target_
==
TARGET
(
kX86
));
}
else
{
target_
=
TARGET
(
kX86
);
x86_ctx_
.
reset
(
new
X86Context
);
}
return
*
x86_ctx_
;
}
#endif // lite_with_x86
private:
#ifdef LITE_WITH_CUDA
std
::
unique_ptr
<
CUDAContext
>
cuda_ctx_
;
#endif
#endif
#ifdef LITE_WITH_X86
#ifdef LITE_WITH_X86
X86Context
x86_ctx
;
std
::
unique_ptr
<
X86Context
>
x86_ctx_
;
#endif
#endif
TargetType
target_
{
TARGET
(
kUnk
)};
};
};
}
// namespace lite
}
// namespace lite
...
...
paddle/fluid/lite/core/kernel.h
浏览文件 @
c05a4e58
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#pragma once
#pragma once
#include <map>
#include <map>
#include <memory>
#include <set>
#include <set>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -35,9 +36,8 @@ class KernelBase {
...
@@ -35,9 +36,8 @@ class KernelBase {
public:
public:
virtual
void
Run
()
=
0
;
virtual
void
Run
()
=
0
;
template
<
TargetType
Target
>
void
SetContext
(
std
::
unique_ptr
<
KernelContext
>&&
ctx
)
{
void
SetContext
(
std
::
unique_ptr
<
Context
<
Target
>>&&
ctx
)
{
context_
=
std
::
move
(
ctx
);
context_
.
set
<
std
::
unique_ptr
<
Context
<
Target
>>>
(
std
::
move
(
ctx
));
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -59,13 +59,14 @@ class KernelBase {
...
@@ -59,13 +59,14 @@ class KernelBase {
virtual
TargetType
target
()
const
=
0
;
virtual
TargetType
target
()
const
=
0
;
virtual
PrecisionType
precision
()
const
=
0
;
virtual
PrecisionType
precision
()
const
=
0
;
virtual
DataLayoutType
layout
()
const
=
0
;
virtual
DataLayoutType
layout
()
const
=
0
;
const
KernelContext
*
context
()
const
{
return
context_
.
get
();
}
virtual
std
::
string
name
()
const
=
0
;
virtual
std
::
string
name
()
const
=
0
;
virtual
~
KernelBase
()
=
default
;
virtual
~
KernelBase
()
=
default
;
protected:
protected:
core
::
any_context_t
context_
;
std
::
unique_ptr
<
KernelContext
>
context_
;
mutable
operators
::
param_t
param_
;
mutable
operators
::
param_t
param_
;
// The corresponding op type.
// The corresponding op type.
std
::
string
op_type_
;
std
::
string
op_type_
;
...
...
paddle/fluid/lite/core/op_lite.h
浏览文件 @
c05a4e58
...
@@ -67,8 +67,8 @@ class OpLite : public Registry {
...
@@ -67,8 +67,8 @@ class OpLite : public Registry {
OpLite
()
=
default
;
OpLite
()
=
default
;
OpLite
(
const
std
::
string
&
type
)
:
op_type_
(
type
)
{}
OpLite
(
const
std
::
string
&
type
)
:
op_type_
(
type
)
{}
OpLite
(
std
::
unique_ptr
<
OpContext
>
&&
x
,
const
std
::
vector
<
Place
>
&
valid_places
)
OpLite
(
const
std
::
vector
<
Place
>
&
valid_places
)
:
op_context_
(
std
::
move
(
x
)),
valid_places_
(
valid_places
)
{}
:
valid_places_
(
valid_places
)
{}
void
SetValidPlaces
(
const
std
::
vector
<
Place
>
&
places
)
{
void
SetValidPlaces
(
const
std
::
vector
<
Place
>
&
places
)
{
valid_places_
=
places
;
valid_places_
=
places
;
...
@@ -126,7 +126,6 @@ class OpLite : public Registry {
...
@@ -126,7 +126,6 @@ class OpLite : public Registry {
friend
class
mir
::
SSAGraph
;
friend
class
mir
::
SSAGraph
;
protected:
protected:
std
::
unique_ptr
<
OpContext
>
op_context_
;
std
::
unique_ptr
<
KernelBase
>
kernel_
;
std
::
unique_ptr
<
KernelBase
>
kernel_
;
std
::
string
op_type_
;
std
::
string
op_type_
;
std
::
vector
<
Place
>
valid_places_
;
std
::
vector
<
Place
>
valid_places_
;
...
...
paddle/fluid/lite/core/types.h
浏览文件 @
c05a4e58
...
@@ -21,10 +21,6 @@ namespace paddle {
...
@@ -21,10 +21,6 @@ namespace paddle {
namespace
lite
{
namespace
lite
{
namespace
core
{
namespace
core
{
using
any_context_t
=
variant
<
Context
<
TARGET
(
kX86
)
>
,
//
Context
<
TARGET
(
kCUDA
)
>
//
>
;
// Factors that impact the kernel picking strategy. Multiple factors can be
// Factors that impact the kernel picking strategy. Multiple factors can be
// considered together by using statement like 'factor1 | factor2'
// considered together by using statement like 'factor1 | factor2'
class
KernelPickFactor
{
class
KernelPickFactor
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录