Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0d554f1d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
0d554f1d
编写于
7年前
作者:
D
dongzhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"add template fill function"
上级
c110f565
7 合并请求
!11636
[IMPORTANT] MKLDNN layout: Support for sum operator
,
!8482
Release/0.11.0
,
!8190
Release/0.11.0
,
!8189
Release/0.11.0
,
!6633
给线性回归的get-started代码加上了预测的示例~~
,
!4615
Feature/tensor array add python binding
,
!3060
Random op
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
60 addition
and
7 deletion
+60
-7
paddle/operators/random_op.cc
paddle/operators/random_op.cc
+13
-1
paddle/operators/random_op.cu
paddle/operators/random_op.cu
+13
-0
paddle/operators/random_op.h
paddle/operators/random_op.h
+34
-6
未找到文件。
paddle/operators/random_op.cc
浏览文件 @
0d554f1d
...
...
@@ -3,6 +3,18 @@
namespace
paddle
{
namespace
operators
{
using
paddle
::
platform
::
GPUPlace
;
template
<
GPUPlace
,
typename
T
,
typename
Generator
>
bool
Gaussian
(
Generator
g
,
T
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
)
{
std
::
normal_distribution
<
double
>
distribution
(
mean
,
std
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
output
[
i
]
=
distribution
(
g
());
}
return
true
;
}
class
RandomOp
:
public
framework
::
OperatorWithKernel
{
protected:
void
InferShape
(
...
...
@@ -12,7 +24,7 @@ protected:
PADDLE_ENFORCE
(
outputs
.
size
()
==
1
,
"Output size of RandomOp must be one."
);
PADDLE_ENFORCE
(
inputs
[
0
]
!=
nullptr
&&
outputs
[
0
]
!=
nullptr
,
"Inputs/Outputs of RandomOp must all be set."
);
outputs
[
0
]
->
set_dims
(
inputs
[
0
]
->
dims
(
));
outputs
[
0
]
->
set_dims
(
context
.
op_
.
attrs_
.
at
(
"shape"
));
}
};
...
...
This diff is collapsed.
Click to expand it.
paddle/operators/random_op.cu
浏览文件 @
0d554f1d
#include "paddle/operators/random_op.h"
#include "paddle/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
using
paddle
::
platform
::
GPUPlace
;
template
<
GPUPlace
,
typename
T
,
typename
Generator
>
bool
Gaussian
(
Generator
g
,
T
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
)
{
return
curandGenerateNormal
(
g
,
output
,
size
,
mean
,
std
);
}
}
// operators
}
// paddle
typedef
paddle
::
operators
::
RandomOpKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
RandomOpKernel_GPU_float
;
REGISTER_OP_GPU_KERNEL
(
random_op
,
RandomOpKernel_GPU_float
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
paddle/operators/random_op.h
浏览文件 @
0d554f1d
...
...
@@ -6,24 +6,52 @@
namespace
paddle
{
namespace
operators
{
template
<
typename
Place
,
typename
T
,
typename
Generator
>
bool
Gaussian
(
Generator
g
,
T
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
);
template
<
typename
Place
,
typename
T
>
class
RandomOpKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
KernelContext
&
context
)
const
override
{
auto
*
output
=
context
.
Output
(
0
)
->
GetMutable
<
framework
::
Tensor
>
();
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
shape
=
context
.
op_
.
attrs_
.
at
(
"Shape"
);
auto
mean
=
context
.
op_
.
attrs_
.
at
(
"mean"
);
auto
std
=
context
.
op_
.
attrs_
.
at
(
"std"
);
auto
seed
=
context
.
op_
.
attrs_
.
at
(
"seed"
);
auto
*
output
=
context
.
Output
(
0
)
->
GetMutable
<
framework
::
Tensor
>
();
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
Gaussian
<
Place
,
T
,
>
(,
output
,
output
->
size
(),
mean
,
std
)
:
// std::default_random_engine generator(seed);
// std::normal_distribution<double> distribution(mean, std);
framework
::
EigenMatrix
<
T
>::
From
(
*
output
).
device
(
*
(
context
.
GetEigenDevice
<
Place
>
()))
=
framework
::
EigenMatrix
<
T
>::
Random
();
// framework::EigenMatrix<T>::From(*output).device(*(
// context.GetEigenDevice<Place>())) =
// framework::EigenMatrix<T>::Random();
}
};
// using paddle::platform::CPUPlace;
// template<CPUPlace, typename T>
// class RandomOpKernel : public framework::OpKernel {
// public:
// void Compute(const framework::KernelContext& context) const override {
// std::unique_ptr<default_random_engine> generator(seed);
// for(size_t i=0; i < output->size(); ++i) {
// output[i] = distribution(generator());
// }
// }
// };
// using paddle::platform::GPUPlace;
// template<GPUPlace, typename T>
// class RandomOpKernel : public framework::OpKernel {
// public:
// void Compute(const framework::KernelContext& context) const override {
// }
// }
}
// namespace operators
}
// namespace paddle
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部