Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
984225ec
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看板
提交
984225ec
编写于
7月 25, 2017
作者:
D
dongzhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"fix operator"
上级
2b3e3621
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
75 deletion
+39
-75
paddle/framework/operator.cc
paddle/framework/operator.cc
+12
-2
paddle/operators/random_op.cc
paddle/operators/random_op.cc
+3
-20
paddle/operators/random_op.cu
paddle/operators/random_op.cu
+0
-13
paddle/operators/random_op.h
paddle/operators/random_op.h
+18
-36
python/paddle/v2/framework/tests/CMakeLists.txt
python/paddle/v2/framework/tests/CMakeLists.txt
+2
-1
python/paddle/v2/framework/tests/test_random_op.py
python/paddle/v2/framework/tests/test_random_op.py
+4
-3
未找到文件。
paddle/framework/operator.cc
浏览文件 @
984225ec
...
@@ -12,9 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,9 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <algorithm>
#include "paddle/framework/operator.h"
#include "paddle/framework/operator.h"
#include <algorithm>
#include <iterator>
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
...
@@ -95,6 +95,16 @@ std::string OperatorBase::DebugString() const {
...
@@ -95,6 +95,16 @@ std::string OperatorBase::DebugString() const {
ss
<<
", "
;
ss
<<
", "
;
}
}
}
}
ss
<<
"), "
;
ss
<<
"Attrs:("
;
size_t
i
=
0
;
for
(
auto
&
attr
:
attrs_
)
{
ss
<<
attr
.
first
;
if
(
i
!=
attrs_
.
size
()
-
1
)
{
ss
<<
", "
;
}
i
++
;
}
ss
<<
")."
;
ss
<<
")."
;
return
ss
.
str
();
return
ss
.
str
();
}
}
...
...
paddle/operators/random_op.cc
浏览文件 @
984225ec
...
@@ -13,28 +13,12 @@
...
@@ -13,28 +13,12 @@
limitations under the License. */
limitations under the License. */
#include "paddle/operators/random_op.h"
#include "paddle/operators/random_op.h"
#include "glog/logging.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/op_registry.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
// using paddle::platform::CPUPlace;
// template <paddle::platform::CPUPlace, typename T, typename DeviceContext>
template
<
typename
T
>
bool
Gaussian
(
platform
::
CPUDeviceContext
&
ctx
,
framework
::
Tensor
*
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
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
output
[
i
]
=
distribution
(
g
());
}
return
true
;
}
class
RandomOp
:
public
framework
::
OperatorWithKernel
{
class
RandomOp
:
public
framework
::
OperatorWithKernel
{
protected:
protected:
void
InferShape
(
void
InferShape
(
...
@@ -42,11 +26,10 @@ protected:
...
@@ -42,11 +26,10 @@ protected:
const
std
::
vector
<
framework
::
Tensor
*>&
outputs
)
const
override
{
const
std
::
vector
<
framework
::
Tensor
*>&
outputs
)
const
override
{
PADDLE_ENFORCE
(
inputs
.
size
()
==
0
,
"Input size of RandomOp must be zero."
);
PADDLE_ENFORCE
(
inputs
.
size
()
==
0
,
"Input size of RandomOp must be zero."
);
PADDLE_ENFORCE
(
outputs
.
size
()
==
1
,
"Output size of RandomOp must be one."
);
PADDLE_ENFORCE
(
outputs
.
size
()
==
1
,
"Output size of RandomOp must be one."
);
PADDLE_ENFORCE
(
inputs
[
0
]
!=
nullptr
&&
outputs
[
0
]
!=
nullptr
,
PADDLE_ENFORCE
(
outputs
[
0
]
!=
nullptr
,
"
Inputs/
Outputs of RandomOp must all be set."
);
"Outputs of RandomOp must all be set."
);
outputs
[
0
]
->
Resize
(
outputs
[
0
]
->
Resize
(
framework
::
make_ddim
(
this
->
GetAttr
<
std
::
vector
<
int
>>
(
"shape"
)));
framework
::
make_ddim
(
this
->
GetAttr
<
std
::
vector
<
int
>>
(
"shape"
)));
// outputs[0]->set_dims(context.op_.attrs_.at("shape"));
}
}
};
};
...
...
paddle/operators/random_op.cu
浏览文件 @
984225ec
#include "paddle/operators/random_op.h"
#include "paddle/operators/random_op.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
bool
Gaussian
(
platform
::
CUDADeviceContext
&
ctx
,
framework
::
Tensor
*
output
,
const
int
size
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
seed
)
{
auto
g
=
RandGenerator
(
seed
);
return
curandGenerateNormal
(
g
,
output
,
size
,
mean
,
std
);
}
}
// operators
}
// paddle
typedef
paddle
::
operators
::
RandomOpKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
typedef
paddle
::
operators
::
RandomOpKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
RandomOpKernel_GPU_float
;
RandomOpKernel_GPU_float
;
...
...
paddle/operators/random_op.h
浏览文件 @
984225ec
...
@@ -13,7 +13,9 @@ bool Gaussian(DeviceContext& ctx,
...
@@ -13,7 +13,9 @@ bool Gaussian(DeviceContext& ctx,
const
int
size
,
const
int
size
,
const
T
&
mean
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
std
,
const
T
&
seed
);
const
T
&
seed
)
{
return
false
;
}
template
<
typename
T
>
template
<
typename
T
>
bool
Gaussian
(
platform
::
CPUDeviceContext
&
ctx
,
bool
Gaussian
(
platform
::
CPUDeviceContext
&
ctx
,
...
@@ -21,14 +23,27 @@ bool Gaussian(platform::CPUDeviceContext& ctx,
...
@@ -21,14 +23,27 @@ bool Gaussian(platform::CPUDeviceContext& ctx,
const
int
size
,
const
int
size
,
const
T
&
mean
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
std
,
const
T
&
seed
);
const
T
&
seed
)
{
auto
g
=
ctx
.
RandGenerator
(
seed
);
std
::
normal_distribution
<
double
>
distribution
(
mean
,
std
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
output
[
i
]
=
distribution
(
g
);
}
return
true
;
}
#ifndef PADDLE_ONLY_CPU
template
<
typename
T
>
template
<
typename
T
>
bool
Gaussian
(
platform
::
CUDADeviceContext
&
ctx
,
bool
Gaussian
(
platform
::
CUDADeviceContext
&
ctx
,
framework
::
Tensor
*
output
,
framework
::
Tensor
*
output
,
const
int
size
,
const
int
size
,
const
T
&
mean
,
const
T
&
mean
,
const
T
&
std
,
const
T
&
std
,
const
T
&
seed
);
const
T
&
seed
)
{
auto
g
=
RandGenerator
(
seed
);
return
curandGenerateNormal
(
g
,
output
,
size
,
mean
,
std
);
}
#endif
template
<
typename
Place
,
typename
T
>
template
<
typename
Place
,
typename
T
>
class
RandomOpKernel
:
public
framework
::
OpKernel
{
class
RandomOpKernel
:
public
framework
::
OpKernel
{
...
@@ -45,41 +60,8 @@ public:
...
@@ -45,41 +60,8 @@ public:
mean
,
mean
,
std
,
std
,
seed
);
seed
);
// Gaussian<T, const platform::DeviceContext>(context.device_context_,
// output,
// framework::product(output->dims()),
// mean, std, seed);
// 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();
}
}
};
};
// 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 operators
}
// namespace paddle
}
// namespace paddle
python/paddle/v2/framework/tests/CMakeLists.txt
浏览文件 @
984225ec
...
@@ -12,4 +12,5 @@ add_python_test(test_framework
...
@@ -12,4 +12,5 @@ add_python_test(test_framework
test_mul_op.py
test_mul_op.py
test_sigmoid_op.py
test_sigmoid_op.py
test_softmax_op.py
test_softmax_op.py
test_rowwise_add_op.py
)
test_rowwise_add_op.py
test_random_op.py
)
python/paddle/v2/framework/tests/test_random_op.py
浏览文件 @
984225ec
...
@@ -15,13 +15,14 @@ class TestRandomOp(unittest.TestCase):
...
@@ -15,13 +15,14 @@ class TestRandomOp(unittest.TestCase):
if
scope
.
get_var
(
out
)
is
None
:
if
scope
.
get_var
(
out
)
is
None
:
scope
.
create_var
(
out
).
get_tensor
()
scope
.
create_var
(
out
).
get_tensor
()
tensor
=
scope
.
get_var
(
"
Y
"
).
get_tensor
()
tensor
=
scope
.
get_var
(
"
Out
"
).
get_tensor
()
op
.
infer_shape
(
scope
)
op
.
infer_shape
(
scope
)
self
.
assertEqual
([
1000
,
1000
],
tensor
.
shape
())
self
.
assertEqual
([
1000
,
1000
],
tensor
.
shape
())
ctx
=
core
.
DeviceContext
.
cpu_context
()
ctx
=
core
.
DeviceContext
.
cpu_context
()
op
.
run
(
scope
,
ctx
)
op
.
run
(
scope
,
ctx
)
self
.
assertAlmostEqual
(
numpy
.
std
(
tensor
),
1.0
)
tensor_array
=
numpy
.
array
(
tensor
)
self
.
assertAlmostEqual
(
numpy
.
mean
(
tensor
),
5.0
)
self
.
assertAlmostEqual
(
numpy
.
std
(
tensor_array
),
1.0
)
self
.
assertAlmostEqual
(
numpy
.
mean
(
tensor_array
),
5.0
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录