Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
3c49e7b1
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c49e7b1
编写于
9月 13, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move EigenDeviceConverter to device_context.h
上级
0f42e564
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
24 deletion
+47
-24
paddle/framework/operator.cc
paddle/framework/operator.cc
+2
-2
paddle/framework/operator.h
paddle/framework/operator.h
+2
-17
paddle/operators/math/activation.h
paddle/operators/math/activation.h
+20
-0
paddle/platform/device_context.cc
paddle/platform/device_context.cc
+4
-3
paddle/platform/device_context.h
paddle/platform/device_context.h
+18
-1
paddle/platform/device_context_test.cc
paddle/platform/device_context_test.cc
+1
-1
未找到文件。
paddle/framework/operator.cc
浏览文件 @
3c49e7b1
...
...
@@ -22,14 +22,14 @@ namespace framework {
template
<
>
Eigen
::
DefaultDevice
&
ExecutionContext
::
GetEigenDevice
<
platform
::
CPUPlace
,
Eigen
::
DefaultDevice
>
()
const
{
return
*
device_context_
->
get_eigen_device
<
Eigen
::
DefaultDevi
ce
>
();
return
*
device_context_
->
get_eigen_device
<
platform
::
CPUPla
ce
>
();
}
#ifndef PADDLE_ONLY_CPU
template
<
>
Eigen
::
GpuDevice
&
ExecutionContext
::
GetEigenDevice
<
platform
::
GPUPlace
,
Eigen
::
GpuDevice
>
()
const
{
return
*
device_context_
->
get_eigen_device
<
Eigen
::
GpuDevi
ce
>
();
return
*
device_context_
->
get_eigen_device
<
platform
::
GPUPla
ce
>
();
}
#endif
...
...
paddle/framework/operator.h
浏览文件 @
3c49e7b1
...
...
@@ -331,21 +331,6 @@ class InferShapeContext {
const
Scope
&
scope_
;
};
template
<
typename
T
>
struct
EigenDeviceConverter
;
template
<>
struct
EigenDeviceConverter
<
platform
::
CPUPlace
>
{
using
EigenDeviceType
=
Eigen
::
DefaultDevice
;
};
#ifndef PADDLE_ONLY_CPU
template
<>
struct
EigenDeviceConverter
<
platform
::
GPUPlace
>
{
using
EigenDeviceType
=
Eigen
::
GpuDevice
;
};
#endif
class
ExecutionContext
:
public
InferShapeContext
{
public:
ExecutionContext
(
const
OperatorBase
&
op
,
const
Scope
&
scope
,
...
...
@@ -353,8 +338,8 @@ class ExecutionContext : public InferShapeContext {
:
InferShapeContext
(
op
,
scope
),
device_context_
(
device_context
)
{}
template
<
typename
PlaceType
,
typename
DeviceType
=
typename
EigenDeviceConverter
<
PlaceType
>::
EigenDeviceType
>
typename
DeviceType
=
typename
platform
::
EigenDeviceConverter
<
PlaceType
>::
EigenDeviceType
>
DeviceType
&
GetEigenDevice
()
const
;
platform
::
Place
GetPlace
()
const
{
return
device_context_
->
GetPlace
();
}
...
...
paddle/operators/math/activation.h
0 → 100644
浏览文件 @
3c49e7b1
#include "paddle/framework/eigen.h"
#include "paddle/framework/tensor.h"
namespace
paddle
{
namespace
operators
{
namespace
math
{
template
<
typename
Place
,
typename
T
>
struct
sigmoid
{
void
operator
()(
const
platform
::
DeviceContext
&
deice_context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
*
output
)
{
auto
x
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
output
);
auto
y
=
framework
::
EigenVector
<
T
>::
Flatten
(
input
);
auto
*
place
=
device_context
.
get_eigen_device
<
Place
>
();
y
.
device
(
*
place
)
=
1.
/
(
1.
+
(
-
x
).
exp
());
}
};
}
}
}
paddle/platform/device_context.cc
浏览文件 @
3c49e7b1
...
...
@@ -16,8 +16,8 @@ namespace paddle {
namespace
platform
{
template
<
>
Eigen
::
DefaultDevice
*
DeviceContext
::
get_eigen_device
<
Eigen
::
DefaultDevice
>
()
const
{
Eigen
::
DefaultDevice
*
DeviceContext
::
get_eigen_device
<
CPUPlace
,
Eigen
::
DefaultDevice
>
()
const
{
return
reinterpret_cast
<
const
CPUDeviceContext
*>
(
this
)
->
eigen_device
();
}
...
...
@@ -91,7 +91,8 @@ class EigenCudaStreamDevice : public Eigen::StreamInterface {
};
template
<
>
Eigen
::
GpuDevice
*
DeviceContext
::
get_eigen_device
<
Eigen
::
GpuDevice
>
()
const
{
Eigen
::
GpuDevice
*
DeviceContext
::
get_eigen_device
<
GPUPlace
,
Eigen
::
GpuDevice
>
()
const
{
return
reinterpret_cast
<
const
CUDADeviceContext
*>
(
this
)
->
eigen_device
();
}
...
...
paddle/platform/device_context.h
浏览文件 @
3c49e7b1
...
...
@@ -27,12 +27,29 @@ limitations under the License. */
namespace
paddle
{
namespace
platform
{
template
<
typename
T
>
struct
EigenDeviceConverter
;
template
<
>
struct
EigenDeviceConverter
<
platform
::
CPUPlace
>
{
using
EigenDeviceType
=
Eigen
::
DefaultDevice
;
};
#ifndef PADDLE_ONLY_CPU
template
<
>
struct
EigenDeviceConverter
<
platform
::
GPUPlace
>
{
using
EigenDeviceType
=
Eigen
::
GpuDevice
;
};
#endif
class
DeviceContext
{
public:
virtual
~
DeviceContext
()
{}
virtual
Place
GetPlace
()
const
=
0
;
template
<
typename
DeviceType
>
template
<
typename
PlaceType
,
typename
DeviceType
=
typename
EigenDeviceConverter
<
PlaceType
>
::
EigenDeviceType
>
DeviceType
*
get_eigen_device
()
const
;
};
...
...
paddle/platform/device_context_test.cc
浏览文件 @
3c49e7b1
...
...
@@ -24,7 +24,7 @@ TEST(Device, Init) {
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
DeviceContext
*
device_context
=
new
CUDADeviceContext
(
GPUPlace
(
i
));
Eigen
::
GpuDevice
*
gpu_device
=
device_context
->
template
get_eigen_device
<
Eigen
::
GpuDevi
ce
>();
device_context
->
template
get_eigen_device
<
GPUPla
ce
>();
ASSERT_NE
(
nullptr
,
gpu_device
);
delete
device_context
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录