Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
11f9f5fb
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
11f9f5fb
编写于
7月 26, 2017
作者:
D
dongzhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"fix const dependency hell"
上级
984225ec
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
36 addition
and
35 deletion
+36
-35
paddle/framework/operator.cc
paddle/framework/operator.cc
+2
-2
paddle/framework/operator.h
paddle/framework/operator.h
+7
-7
paddle/operators/random_op.h
paddle/operators/random_op.h
+25
-24
paddle/platform/device_context.h
paddle/platform/device_context.h
+2
-2
未找到文件。
paddle/framework/operator.cc
浏览文件 @
11f9f5fb
...
...
@@ -22,14 +22,14 @@ namespace framework {
template
<
>
Eigen
::
DefaultDevice
*
KernelContext
::
GetEigenDevice
<
platform
::
CPUPlace
,
Eigen
::
DefaultDevice
>
()
const
{
return
device_context_
.
get_eigen_device
<
Eigen
::
DefaultDevice
>
();
return
device_context_
->
get_eigen_device
<
Eigen
::
DefaultDevice
>
();
}
#ifndef PADDLE_ONLY_CPU
template
<
>
Eigen
::
GpuDevice
*
KernelContext
::
GetEigenDevice
<
platform
::
GPUPlace
,
Eigen
::
GpuDevice
>
()
const
{
return
device_context_
.
get_eigen_device
<
Eigen
::
GpuDevice
>
();
return
device_context_
->
get_eigen_device
<
Eigen
::
GpuDevice
>
();
}
#endif
...
...
paddle/framework/operator.h
浏览文件 @
11f9f5fb
...
...
@@ -88,7 +88,7 @@ class OperatorBase {
/// Net will call this function to Run an op.
virtual
void
Run
(
const
std
::
shared_ptr
<
Scope
>&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
=
0
;
platform
::
DeviceContext
&
dev_ctx
)
const
=
0
;
// Get a input with argument's name described in `op_proto`
const
std
::
string
&
Input
(
const
std
::
string
&
name
)
const
;
...
...
@@ -113,8 +113,8 @@ class OperatorBase {
class
KernelContext
{
public:
KernelContext
(
const
OperatorBase
*
op
,
const
std
::
shared_ptr
<
Scope
>&
scope
,
const
platform
::
DeviceContext
&
device_context
)
:
op_
(
*
op
),
scope_
(
scope
),
device_context_
(
device_context
)
{}
platform
::
DeviceContext
&
device_context
)
:
op_
(
*
op
),
scope_
(
scope
),
device_context_
(
&
device_context
)
{}
const
Variable
*
Input
(
int
index
)
const
{
return
scope_
->
GetVariable
(
op_
.
inputs_
[
index
]);
...
...
@@ -155,11 +155,11 @@ class KernelContext {
typename
EigenDeviceConverter
<
PlaceType
>::
EigenDeviceType
>
DeviceType
*
GetEigenDevice
()
const
;
platform
::
Place
GetPlace
()
const
{
return
device_context_
.
GetPlace
();
}
platform
::
Place
GetPlace
()
const
{
return
device_context_
->
GetPlace
();
}
const
OperatorBase
&
op_
;
const
std
::
shared_ptr
<
Scope
>
&
scope_
;
const
platform
::
DeviceContext
&
device_context_
;
const
std
::
shared_ptr
<
Scope
>
scope_
;
platform
::
DeviceContext
*
device_context_
;
};
class
OpKernel
{
...
...
@@ -213,7 +213,7 @@ class OperatorWithKernel : public OperatorBase {
std
::
unordered_map
<
OpKernelKey
,
std
::
unique_ptr
<
OpKernel
>
,
OpKernelHash
>
;
void
Run
(
const
std
::
shared_ptr
<
Scope
>&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
final
{
platform
::
DeviceContext
&
dev_ctx
)
const
final
{
auto
&
opKernel
=
AllOpKernels
().
at
(
type_
).
at
(
OpKernelKey
(
dev_ctx
));
opKernel
->
Compute
(
KernelContext
(
this
,
scope
,
dev_ctx
));
}
...
...
paddle/operators/random_op.h
浏览文件 @
11f9f5fb
...
...
@@ -7,25 +7,15 @@
namespace
paddle
{
namespace
operators
{
template
<
typename
T
,
typename
DeviceContext
>
bool
Gaussian
(
DeviceContext
&
ctx
,
framework
::
Tensor
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
seed
)
{
return
false
;
}
template
<
typename
T
>
bool
Gaussian
(
platform
::
CPUDeviceContext
&
ctx
,
framework
::
Tensor
*
output
,
bool
Gaussian
(
platform
::
CPUDeviceContext
*
ctx
,
T
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
seed
)
{
auto
g
=
ctx
.
RandGenerator
(
seed
);
std
::
normal_distribution
<
double
>
distribution
(
mean
,
std
);
auto
g
=
ctx
->
RandGenerator
(
seed
);
std
::
normal_distribution
<
T
>
distribution
(
mean
,
std
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
output
[
i
]
=
distribution
(
g
);
}
...
...
@@ -34,13 +24,13 @@ bool Gaussian(platform::CPUDeviceContext& ctx,
#ifndef PADDLE_ONLY_CPU
template
<
typename
T
>
bool
Gaussian
(
platform
::
CUDADeviceContext
&
ctx
,
framework
::
Tensor
*
output
,
bool
Gaussian
(
platform
::
CUDADeviceContext
*
ctx
,
T
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
seed
)
{
auto
g
=
RandGenerator
(
seed
);
auto
g
=
ctx
->
RandGenerator
(
seed
);
return
curandGenerateNormal
(
g
,
output
,
size
,
mean
,
std
);
}
#endif
...
...
@@ -53,13 +43,24 @@ public:
auto
std
=
context
.
op_
.
GetAttr
<
T
>
(
"std"
);
auto
seed
=
context
.
op_
.
GetAttr
<
T
>
(
"seed"
);
auto
*
output
=
context
.
Output
(
0
)
->
GetMutable
<
framework
::
Tensor
>
();
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
Gaussian
(
context
.
device_context_
,
output
,
auto
place
=
context
.
GetPlace
();
if
(
platform
::
is_cpu_place
(
place
))
{
Gaussian
(
dynamic_cast
<
platform
::
CPUDeviceContext
*>
(
context
.
device_context_
),
output
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
framework
::
product
(
output
->
dims
()),
mean
,
std
,
seed
);
}
else
{
Gaussian
(
dynamic_cast
<
platform
::
CUDADeviceContext
*>
(
context
.
device_context_
),
output
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
framework
::
product
(
output
->
dims
()),
mean
,
std
,
seed
);
}
}
};
...
...
paddle/platform/device_context.h
浏览文件 @
11f9f5fb
...
...
@@ -49,7 +49,7 @@ class CPUDeviceContext : public DeviceContext {
return
retv
;
}
const
random_generator_type
&
RandGenerator
(
const
int
seed
)
{
random_generator_type
&
RandGenerator
(
const
int
seed
)
{
if
(
!
rand_generator_
)
{
random_seed_
=
seed
;
rand_generator_
.
reset
(
new
random_generator_type
(
random_seed_
));
...
...
@@ -98,7 +98,7 @@ class CUDADeviceContext : public DeviceContext {
"cudaStreamSynchronize failed"
);
}
c
onst
c
urandGenerator_t
RandGenerator
(
const
int
seed
)
{
curandGenerator_t
RandGenerator
(
const
int
seed
)
{
if
(
!
rand_generator_
)
{
random_seed_
=
seed
;
GPUPlaceGuard
guard
(
gpu_place_
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录