Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
409ac4a3
P
Paddle
项目概览
机器未来
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
409ac4a3
编写于
9月 03, 2017
作者:
Q
Qiao Longfei
提交者:
GitHub
9月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3819 from jacquesqiao/add-getop-to-ctx
add op() to InferShapeContext
上级
c1feb27f
d323831a
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
32 addition
and
26 deletion
+32
-26
paddle/framework/operator.h
paddle/framework/operator.h
+10
-0
paddle/framework/operator_test.cc
paddle/framework/operator_test.cc
+6
-6
paddle/operators/gaussian_random_op.cc
paddle/operators/gaussian_random_op.cc
+3
-4
paddle/operators/gaussian_random_op.cu
paddle/operators/gaussian_random_op.cu
+3
-4
paddle/operators/mul_op.cc
paddle/operators/mul_op.cc
+2
-2
paddle/operators/scale_op.h
paddle/operators/scale_op.h
+1
-1
paddle/operators/sgd_op.h
paddle/operators/sgd_op.h
+1
-1
paddle/operators/uniform_random_op.cc
paddle/operators/uniform_random_op.cc
+3
-4
paddle/operators/uniform_random_op.cu
paddle/operators/uniform_random_op.cu
+3
-4
未找到文件。
paddle/framework/operator.h
浏览文件 @
409ac4a3
...
@@ -233,6 +233,15 @@ class InferShapeContext {
...
@@ -233,6 +233,15 @@ class InferShapeContext {
InferShapeContext
(
const
OperatorBase
&
op
,
const
Scope
&
scope
)
InferShapeContext
(
const
OperatorBase
&
op
,
const
Scope
&
scope
)
:
op_
(
op
),
scope_
(
scope
)
{}
:
op_
(
op
),
scope_
(
scope
)
{}
const
OperatorBase
&
op
()
const
{
return
op_
;
}
const
Scope
&
scope
()
const
{
return
scope_
;
}
template
<
typename
T
>
inline
const
T
&
GetAttr
(
const
std
::
string
&
name
)
const
{
return
op_
.
GetAttr
<
T
>
(
name
);
}
size_t
InputSize
(
const
std
::
string
&
name
)
const
{
size_t
InputSize
(
const
std
::
string
&
name
)
const
{
return
op_
.
Inputs
(
name
).
size
();
return
op_
.
Inputs
(
name
).
size
();
}
}
...
@@ -314,6 +323,7 @@ class InferShapeContext {
...
@@ -314,6 +323,7 @@ class InferShapeContext {
return
res
;
return
res
;
}
}
private:
const
OperatorBase
&
op_
;
const
OperatorBase
&
op_
;
const
Scope
&
scope_
;
const
Scope
&
scope_
;
};
};
...
...
paddle/framework/operator_test.cc
浏览文件 @
409ac4a3
...
@@ -122,10 +122,10 @@ class CPUKernelTest : public OpKernel {
...
@@ -122,10 +122,10 @@ class CPUKernelTest : public OpKernel {
public:
public:
void
Compute
(
const
ExecutionContext
&
ctx
)
const
{
void
Compute
(
const
ExecutionContext
&
ctx
)
const
{
std
::
cout
<<
"this is cpu kernel"
<<
std
::
endl
;
std
::
cout
<<
"this is cpu kernel"
<<
std
::
endl
;
std
::
cout
<<
ctx
.
op
_
.
DebugString
()
<<
std
::
endl
;
std
::
cout
<<
ctx
.
op
()
.
DebugString
()
<<
std
::
endl
;
cpu_kernel_run_num
++
;
cpu_kernel_run_num
++
;
ASSERT_EQ
(
ctx
.
op
_
.
Input
(
"x"
),
"IN1"
);
ASSERT_EQ
(
ctx
.
op
()
.
Input
(
"x"
),
"IN1"
);
ASSERT_EQ
(
ctx
.
op
_
.
Output
(
"y"
),
"OUT1"
);
ASSERT_EQ
(
ctx
.
op
()
.
Output
(
"y"
),
"OUT1"
);
}
}
};
};
...
@@ -148,7 +148,7 @@ class OpKernelTestMultiInputsProtoAndCheckerMaker
...
@@ -148,7 +148,7 @@ class OpKernelTestMultiInputsProtoAndCheckerMaker
class
CPUKernalMultiInputsTest
:
public
OpKernel
{
class
CPUKernalMultiInputsTest
:
public
OpKernel
{
public:
public:
void
Compute
(
const
ExecutionContext
&
ctx
)
const
{
void
Compute
(
const
ExecutionContext
&
ctx
)
const
{
auto
xs
=
ctx
.
op
_
.
Inputs
(
"xs"
);
auto
xs
=
ctx
.
op
()
.
Inputs
(
"xs"
);
ASSERT_EQ
(
xs
.
size
(),
3UL
);
ASSERT_EQ
(
xs
.
size
(),
3UL
);
ASSERT_EQ
(
xs
[
0
],
"x0"
);
ASSERT_EQ
(
xs
[
0
],
"x0"
);
ASSERT_EQ
(
xs
[
1
],
"x1"
);
ASSERT_EQ
(
xs
[
1
],
"x1"
);
...
@@ -172,10 +172,10 @@ class CPUKernalMultiInputsTest : public OpKernel {
...
@@ -172,10 +172,10 @@ class CPUKernalMultiInputsTest : public OpKernel {
auto
outTensor0
=
ctx
.
MultiOutput
<
Tensor
>
(
"ys"
);
auto
outTensor0
=
ctx
.
MultiOutput
<
Tensor
>
(
"ys"
);
ASSERT_EQ
(
outTensor0
.
size
(),
2U
);
ASSERT_EQ
(
outTensor0
.
size
(),
2U
);
auto
k
=
ctx
.
op
_
.
Input
(
"k"
);
auto
k
=
ctx
.
op
()
.
Input
(
"k"
);
ASSERT_EQ
(
k
,
"k0"
);
ASSERT_EQ
(
k
,
"k0"
);
auto
ys
=
ctx
.
op
_
.
Outputs
(
"ys"
);
auto
ys
=
ctx
.
op
()
.
Outputs
(
"ys"
);
ASSERT_EQ
(
ys
.
size
(),
2UL
);
ASSERT_EQ
(
ys
.
size
(),
2UL
);
ASSERT_EQ
(
ys
[
0
],
"y0"
);
ASSERT_EQ
(
ys
[
0
],
"y0"
);
ASSERT_EQ
(
ys
[
1
],
"y1"
);
ASSERT_EQ
(
ys
[
1
],
"y1"
);
...
...
paddle/operators/gaussian_random_op.cc
浏览文件 @
409ac4a3
...
@@ -19,13 +19,12 @@ template <typename T>
...
@@ -19,13 +19,12 @@ template <typename T>
class
CPUGaussianRandomKernel
:
public
framework
::
OpKernel
{
class
CPUGaussianRandomKernel
:
public
framework
::
OpKernel
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
float
mean
=
context
.
op_
.
GetAttr
<
float
>
(
"mean"
);
float
mean
=
context
.
GetAttr
<
float
>
(
"mean"
);
float
std
=
context
.
op_
.
GetAttr
<
float
>
(
"std"
);
float
std
=
context
.
GetAttr
<
float
>
(
"std"
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
unsigned
int
seed
=
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
GetAttr
<
int
>
(
"seed"
));
static_cast
<
unsigned
int
>
(
context
.
op_
.
GetAttr
<
int
>
(
"seed"
));
std
::
minstd_rand
engine
;
std
::
minstd_rand
engine
;
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
seed
=
std
::
random_device
()();
seed
=
std
::
random_device
()();
...
...
paddle/operators/gaussian_random_op.cu
浏览文件 @
409ac4a3
...
@@ -42,14 +42,13 @@ class GPUGaussianRandomKernel : public framework::OpKernel {
...
@@ -42,14 +42,13 @@ class GPUGaussianRandomKernel : public framework::OpKernel {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
unsigned
int
seed
=
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
GetAttr
<
int
>
(
"seed"
));
static_cast
<
unsigned
int
>
(
context
.
op_
.
GetAttr
<
int
>
(
"seed"
));
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
std
::
random_device
rd
;
std
::
random_device
rd
;
seed
=
rd
();
seed
=
rd
();
}
}
T
mean
=
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"mean"
));
T
mean
=
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"mean"
));
T
std
=
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"std"
));
T
std
=
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"std"
));
thrust
::
counting_iterator
<
unsigned
int
>
index_sequence_begin
(
0
);
thrust
::
counting_iterator
<
unsigned
int
>
index_sequence_begin
(
0
);
ssize_t
N
=
framework
::
product
(
tensor
->
dims
());
ssize_t
N
=
framework
::
product
(
tensor
->
dims
());
thrust
::
transform
(
index_sequence_begin
,
index_sequence_begin
+
N
,
thrust
::
transform
(
index_sequence_begin
,
index_sequence_begin
+
N
,
...
...
paddle/operators/mul_op.cc
浏览文件 @
409ac4a3
...
@@ -29,10 +29,10 @@ class MulOp : public framework::OperatorWithKernel {
...
@@ -29,10 +29,10 @@ class MulOp : public framework::OperatorWithKernel {
auto
dim1
=
ctx
.
Input
<
Tensor
>
(
"Y"
)
->
dims
();
auto
dim1
=
ctx
.
Input
<
Tensor
>
(
"Y"
)
->
dims
();
PADDLE_ENFORCE_EQ
(
dim0
.
size
(),
2
,
PADDLE_ENFORCE_EQ
(
dim0
.
size
(),
2
,
"input X(%s) should be a tensor with 2 dims, a matrix"
,
"input X(%s) should be a tensor with 2 dims, a matrix"
,
ctx
.
op
_
.
Input
(
"X"
));
ctx
.
op
()
.
Input
(
"X"
));
PADDLE_ENFORCE_EQ
(
dim1
.
size
(),
2
,
PADDLE_ENFORCE_EQ
(
dim1
.
size
(),
2
,
"input Y(%s) should be a tensor with 2 dims, a matrix"
,
"input Y(%s) should be a tensor with 2 dims, a matrix"
,
ctx
.
op
_
.
Input
(
"Y"
));
ctx
.
op
()
.
Input
(
"Y"
));
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
dim0
[
1
],
dim1
[
0
],
dim0
[
1
],
dim1
[
0
],
"First matrix's width must be equal with second matrix's height."
);
"First matrix's width must be equal with second matrix's height."
);
...
...
paddle/operators/scale_op.h
浏览文件 @
409ac4a3
...
@@ -27,7 +27,7 @@ class ScaleKernel : public framework::OpKernel {
...
@@ -27,7 +27,7 @@ class ScaleKernel : public framework::OpKernel {
auto
*
in
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
in
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
tensor
->
mutable_data
<
T
>
(
in
->
place
());
tensor
->
mutable_data
<
T
>
(
in
->
place
());
auto
scale
=
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
AttrType
>
(
"scale"
));
auto
scale
=
static_cast
<
T
>
(
context
.
GetAttr
<
AttrType
>
(
"scale"
));
auto
eigen_out
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
tensor
);
auto
eigen_out
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
tensor
);
auto
eigen_in
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
in
);
auto
eigen_in
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
in
);
...
...
paddle/operators/sgd_op.h
浏览文件 @
409ac4a3
...
@@ -31,7 +31,7 @@ class SGDOpKernel : public framework::OpKernel {
...
@@ -31,7 +31,7 @@ class SGDOpKernel : public framework::OpKernel {
auto
param
=
ctx
.
Input
<
Tensor
>
(
"param"
);
auto
param
=
ctx
.
Input
<
Tensor
>
(
"param"
);
auto
grad
=
ctx
.
Input
<
Tensor
>
(
"grad"
);
auto
grad
=
ctx
.
Input
<
Tensor
>
(
"grad"
);
auto
param_out
=
ctx
.
Output
<
Tensor
>
(
"param_out"
);
auto
param_out
=
ctx
.
Output
<
Tensor
>
(
"param_out"
);
float
lr
=
ctx
.
op_
.
GetAttr
<
float
>
(
"learning_rate"
);
float
lr
=
ctx
.
GetAttr
<
float
>
(
"learning_rate"
);
param_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
param_out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
paddle/operators/uniform_random_op.cc
浏览文件 @
409ac4a3
...
@@ -26,16 +26,15 @@ class CPUUniformRandomKernel : public framework::OpKernel {
...
@@ -26,16 +26,15 @@ class CPUUniformRandomKernel : public framework::OpKernel {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
unsigned
int
seed
=
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
GetAttr
<
int
>
(
"seed"
));
static_cast
<
unsigned
int
>
(
context
.
op_
.
GetAttr
<
int
>
(
"seed"
));
std
::
minstd_rand
engine
;
std
::
minstd_rand
engine
;
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
seed
=
std
::
random_device
()();
seed
=
std
::
random_device
()();
}
}
engine
.
seed
(
seed
);
engine
.
seed
(
seed
);
std
::
uniform_real_distribution
<
T
>
dist
(
std
::
uniform_real_distribution
<
T
>
dist
(
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"min"
)),
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"min"
)),
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"max"
)));
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"max"
)));
ssize_t
size
=
framework
::
product
(
tensor
->
dims
());
ssize_t
size
=
framework
::
product
(
tensor
->
dims
());
for
(
ssize_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
ssize_t
i
=
0
;
i
<
size
;
++
i
)
{
data
[
i
]
=
dist
(
engine
);
data
[
i
]
=
dist
(
engine
);
...
...
paddle/operators/uniform_random_op.cu
浏览文件 @
409ac4a3
...
@@ -45,14 +45,13 @@ class GPUUniformRandomKernel : public framework::OpKernel {
...
@@ -45,14 +45,13 @@ class GPUUniformRandomKernel : public framework::OpKernel {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
unsigned
int
seed
=
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
GetAttr
<
int
>
(
"seed"
));
static_cast
<
unsigned
int
>
(
context
.
op_
.
GetAttr
<
int
>
(
"seed"
));
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
std
::
random_device
rd
;
std
::
random_device
rd
;
seed
=
rd
();
seed
=
rd
();
}
}
T
min
=
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"min"
));
T
min
=
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"min"
));
T
max
=
static_cast
<
T
>
(
context
.
op_
.
GetAttr
<
float
>
(
"max"
));
T
max
=
static_cast
<
T
>
(
context
.
GetAttr
<
float
>
(
"max"
));
thrust
::
counting_iterator
<
unsigned
int
>
index_sequence_begin
(
0
);
thrust
::
counting_iterator
<
unsigned
int
>
index_sequence_begin
(
0
);
ssize_t
N
=
framework
::
product
(
tensor
->
dims
());
ssize_t
N
=
framework
::
product
(
tensor
->
dims
());
thrust
::
transform
(
index_sequence_begin
,
index_sequence_begin
+
N
,
thrust
::
transform
(
index_sequence_begin
,
index_sequence_begin
+
N
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录