Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
50870a62
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
提交
50870a62
编写于
9月 06, 2017
作者:
T
Tao Luo
提交者:
GitHub
9月 06, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3881 from luotao1/op_refine
Op refine for making build system more automatic
上级
c1075126
8ef17ea6
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
99 addition
and
94 deletion
+99
-94
paddle/framework/grad_op_builder_test.cc
paddle/framework/grad_op_builder_test.cc
+2
-2
paddle/operators/CMakeLists.txt
paddle/operators/CMakeLists.txt
+31
-27
paddle/operators/add_op.cc
paddle/operators/add_op.cc
+2
-3
paddle/operators/add_op.cu
paddle/operators/add_op.cu
+1
-4
paddle/operators/identity_op.cc
paddle/operators/identity_op.cc
+54
-0
paddle/operators/scale_op.cc
paddle/operators/scale_op.cc
+1
-30
paddle/operators/scatter_op.cu
paddle/operators/scatter_op.cu
+0
-20
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+1
-1
python/paddle/v2/framework/tests/test_add_two_op.py
python/paddle/v2/framework/tests/test_add_two_op.py
+1
-1
python/paddle/v2/framework/tests/test_gradient_checker.py
python/paddle/v2/framework/tests/test_gradient_checker.py
+1
-1
python/paddle/v2/framework/tests/test_net.py
python/paddle/v2/framework/tests/test_net.py
+2
-2
python/paddle/v2/framework/tests/test_operator.py
python/paddle/v2/framework/tests/test_operator.py
+2
-2
python/paddle/v2/framework/tests/test_recurrent_op.py
python/paddle/v2/framework/tests/test_recurrent_op.py
+1
-1
未找到文件。
paddle/framework/grad_op_builder_test.cc
浏览文件 @
50870a62
...
...
@@ -3,7 +3,7 @@
#include "paddle/framework/op_registry.h"
#include "paddle/framework/operator.h"
USE_OP
(
add
_two
);
USE_OP
(
add
);
namespace
paddle
{
namespace
framework
{
...
...
@@ -41,7 +41,7 @@ namespace f = paddle::framework;
TEST
(
GradOpBuilder
,
AddTwo
)
{
std
::
shared_ptr
<
f
::
OperatorBase
>
add_op
(
f
::
OpRegistry
::
CreateOp
(
"add
_two
"
,
{{
"X"
,
{
"x"
}},
{
"Y"
,
{
"y"
}}},
{{
"Out"
,
{
"out"
}}},
{}));
"add"
,
{{
"X"
,
{
"x"
}},
{
"Y"
,
{
"y"
}}},
{{
"Out"
,
{
"out"
}}},
{}));
std
::
shared_ptr
<
f
::
OperatorBase
>
grad_add_op
=
f
::
OpRegistry
::
CreateGradOp
(
*
add_op
);
EXPECT_EQ
(
grad_add_op
->
Inputs
().
size
(),
4UL
);
...
...
paddle/operators/CMakeLists.txt
浏览文件 @
50870a62
...
...
@@ -14,6 +14,15 @@ function(op_library TARGET)
cmake_parse_arguments
(
op_library
"
${
options
}
"
"
${
oneValueArgs
}
"
"
${
multiValueArgs
}
"
${
ARGN
}
)
list
(
LENGTH op_library_SRCS op_library_SRCS_len
)
if
(
${
op_library_SRCS_len
}
EQUAL 0
)
if
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
TARGET
}
.cc
)
list
(
APPEND cc_srcs
${
TARGET
}
.cc
)
endif
()
if
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
TARGET
}
.cu
)
list
(
APPEND cu_srcs
${
TARGET
}
.cu
)
endif
()
else
()
foreach
(
src
${
op_library_SRCS
}
)
if
(
${
src
}
MATCHES
".*
\\
.cu$"
)
list
(
APPEND cu_srcs
${
src
}
)
...
...
@@ -23,18 +32,13 @@ function(op_library TARGET)
message
(
FATAL_ERROR
"
${
TARGET
}
Source file
${
src
}
should only be .cc or .cu"
)
endif
()
endforeach
()
endif
()
list
(
LENGTH cc_srcs cc_srcs_len
)
if
(
${
cc_srcs_len
}
EQUAL 0
)
message
(
FATAL_ERROR
"The op library
${
TARGET
}
should contains at least one .cc file"
)
endif
()
list
(
LENGTH cu_srcs cu_srcs_len
)
list
(
LENGTH op_library_DEPS dep_len
)
if
(
${
cu_srcs_len
}
EQUAL 0 AND
${
dep_len
}
EQUAL 0
)
message
(
WARNING
"The op library
${
TARGET
}
not support GPU!"
)
endif
()
if
(
WITH_GPU
)
nv_library
(
${
TARGET
}
SRCS
${
cc_srcs
}
${
cu_srcs
}
DEPS
${
op_library_DEPS
}
${
op_common_deps
}
)
...
...
@@ -46,22 +50,22 @@ endfunction()
add_subdirectory
(
math
)
list
(
REMOVE_ITEM GENERAL
_OPS
net
_op
set
(
DEPS
_OPS
identity
_op
minus_op
mul_op
recurrent_op
scale_op
)
op_library
(
net_op SRCS net_op.cc
)
op_library
(
minus_op SRCS minus_op.cc minus_op.cu DEPS scale_op
)
op_library
(
mul_op SRCS mul_op.cc mul_op.cu DEPS math_function
)
op_library
(
identity_op DEPS scale_op
)
op_library
(
minus_op DEPS scale_op
)
op_library
(
mul_op DEPS math_function
)
op_library
(
recurrent_op SRCS recurrent_op.cc rnn/recurrent_op_utils.cc
DEPS framework_proto tensor operator net_op
)
op_library
(
scale_op
SRCS scale_op.cc scale_op.cu
DEPS net_op
)
op_library
(
scale_op DEPS net_op
)
list
(
REMOVE_ITEM GENERAL_OPS
${
DEPS_OPS
}
)
foreach
(
src
${
GENERAL_OPS
}
)
op_library
(
${
src
}
SRCS
${
src
}
.cc
${
src
}
.cu
)
op_library
(
${
src
}
)
endforeach
()
set
(
GLOB_OP_LIB
${
OP_LIBRARY
}
CACHE INTERNAL
"Global OP library"
)
...
...
paddle/operators/add_op.cc
浏览文件 @
50870a62
...
...
@@ -57,7 +57,6 @@ class AddOpGrad : public framework::OperatorWithKernel {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
add
_two
,
ops
::
AddOp
,
ops
::
AddOpMaker
,
add_two
_grad
,
ops
::
AddOpGrad
);
REGISTER_OP
(
add
,
ops
::
AddOp
,
ops
::
AddOpMaker
,
add
_grad
,
ops
::
AddOpGrad
);
REGISTER_OP_CPU_KERNEL
(
add_two
,
ops
::
AddKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
add
,
ops
::
AddKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/add_op.cu
浏览文件 @
50870a62
...
...
@@ -12,10 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License. */
#define EIGEN_USE_GPU
#include "paddle/framework/op_registry.h"
#include "paddle/operators/add_op.h"
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
add_two
,
ops
::
AddKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
add
,
ops
::
AddKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
paddle/operators/
gather_op.cu
→
paddle/operators/
identity_op.cc
浏览文件 @
50870a62
...
...
@@ -12,9 +12,43 @@
See the License for the specific language governing permissions and
limitations under the License. */
#define EIGEN_USE_GPU
#include "paddle/operators/gather_op.h"
#include "paddle/operators/net_op.h"
#include "paddle/operators/scale_op.h"
namespace
paddle
{
namespace
operators
{
// identity is a alias of scale op. This is also a example for creating a alias
// operator.
template
<
typename
AttrType
>
class
IdentityOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
IdentityOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"input tensor of identity op"
);
AddOutput
(
"Out"
,
"output tensor of identity op"
);
AddComment
(
"identity operator. Just a alias of scale op which scale = 1.0"
);
}
};
template
<
typename
AttrType
>
class
IdentityOp
:
public
NetOp
{
public:
IdentityOp
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
const
framework
::
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"scale"
,
{{
"X"
,
{
Input
(
"X"
)}}},
{{
"Out"
,
{
Output
(
"Out"
)}}},
{{
"scale"
,
static_cast
<
AttrType
>
(
1
)}}));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
gather
,
ops
::
GatherOpKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_WITHOUT_GRADIENT
(
identity
,
ops
::
IdentityOp
<
float
>
,
ops
::
IdentityOpMaker
<
float
>
);
paddle/operators/scale_op.cc
浏览文件 @
50870a62
...
...
@@ -48,7 +48,7 @@ The equation is: Out = scale*X
}
};
//
Identity Op's gradient is identity
op, too.
//
Scale Op's gradient is scale
op, too.
// Grad(Out=scale(X)) => Grad(X) = scale(Grad(Out))
template
<
typename
AttrType
>
class
ScaleGradOp
:
public
NetOp
{
...
...
@@ -65,33 +65,6 @@ class ScaleGradOp : public NetOp {
}
};
// identity is a alias of scale op. This is also a example for creating a alias
// operator.
template
<
typename
AttrType
>
class
IdentityOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
IdentityOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"input tensor of identity op"
);
AddOutput
(
"Out"
,
"output tensor of identity op"
);
AddComment
(
"identity operator. Just a alias of scale op which scale = 1.0"
);
}
};
template
<
typename
AttrType
>
class
IdentityOp
:
public
NetOp
{
public:
IdentityOp
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
const
framework
::
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"scale"
,
{{
"X"
,
{
Input
(
"X"
)}}},
{{
"Out"
,
{
Output
(
"Out"
)}}},
{{
"scale"
,
static_cast
<
AttrType
>
(
1
)}}));
}
};
}
// namespace operators
}
// namespace paddle
...
...
@@ -101,5 +74,3 @@ REGISTER_OP(scale, ops::ScaleOp, ops::ScaleOpMaker<float>, scale_grad,
ops
::
ScaleGradOp
<
float
>
);
REGISTER_OP_CPU_KERNEL
(
scale
,
ops
::
ScaleKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_WITHOUT_GRADIENT
(
identity
,
ops
::
IdentityOp
<
float
>
,
ops
::
IdentityOpMaker
<
float
>
);
paddle/operators/scatter_op.cu
已删除
100644 → 0
浏览文件 @
c1075126
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#define EIGEN_USE_GPU
#include "paddle/operators/scatter_op.h"
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
scatter
,
ops
::
ScatterOpKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
paddle/pybind/pybind.cc
浏览文件 @
50870a62
...
...
@@ -30,7 +30,7 @@ limitations under the License. */
namespace
py
=
pybind11
;
USE_OP
(
add
_two
);
USE_OP
(
add
);
USE_OP
(
onehot_cross_entropy
);
USE_OP
(
sgd
);
USE_OP
(
mul
);
...
...
python/paddle/v2/framework/tests/test_add_two_op.py
浏览文件 @
50870a62
...
...
@@ -11,7 +11,7 @@ class TestAddOp(unittest.TestCase):
__metaclass__
=
OpTestMeta
def
setUp
(
self
):
self
.
type
=
"add
_two
"
self
.
type
=
"add"
self
.
inputs
=
{
'X'
:
numpy
.
random
.
random
((
102
,
105
)).
astype
(
"float32"
),
'Y'
:
numpy
.
random
.
random
((
102
,
105
)).
astype
(
"float32"
)
...
...
python/paddle/v2/framework/tests/test_gradient_checker.py
浏览文件 @
50870a62
...
...
@@ -7,7 +7,7 @@ from gradient_checker import get_numeric_gradient
class
GetNumericGradientTest
(
unittest
.
TestCase
):
def
test_add_op
(
self
):
add_op
=
Operator
(
'add
_two
'
,
X
=
"X"
,
Y
=
"Y"
,
Out
=
"Z"
)
add_op
=
Operator
(
'add'
,
X
=
"X"
,
Y
=
"Y"
,
Out
=
"Z"
)
x
=
numpy
.
random
.
random
((
10
,
1
)).
astype
(
"float32"
)
y
=
numpy
.
random
.
random
((
10
,
1
)).
astype
(
"float32"
)
...
...
python/paddle/v2/framework/tests/test_net.py
浏览文件 @
50870a62
...
...
@@ -15,7 +15,7 @@ def fc(X, W, Y):
class
TestNet
(
unittest
.
TestCase
):
def
test_net_all
(
self
):
net
=
core
.
Net
.
create
()
op1
=
Operator
(
"add
_two
"
,
X
=
"X"
,
Y
=
"Y"
,
Out
=
"Out"
)
op1
=
Operator
(
"add"
,
X
=
"X"
,
Y
=
"Y"
,
Out
=
"Out"
)
net
.
append_op
(
op1
)
net2
=
core
.
Net
.
create
()
...
...
@@ -26,7 +26,7 @@ class TestNet(unittest.TestCase):
expected
=
'''
Op(plain_net), inputs:{all[W, X, Y]}, outputs:{all[Out, fc.out, pre_activation]}.
Op(add
_two
), inputs:{X[X], Y[Y]}, outputs:{Out[Out]}.
Op(add), inputs:{X[X], Y[Y]}, outputs:{Out[Out]}.
Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
Op(mul), inputs:{X[X], Y[W]}, outputs:{Out[pre_activation]}.
...
...
python/paddle/v2/framework/tests/test_operator.py
浏览文件 @
50870a62
...
...
@@ -193,10 +193,10 @@ class TestOpDescCreationMethod(unittest.TestCase):
class
TestOpCreations
(
unittest
.
TestCase
):
def
test_all
(
self
):
add_op
=
op
.
Operator
(
"add
_two
"
,
X
=
"a"
,
Y
=
"b"
,
Out
=
"z"
)
add_op
=
op
.
Operator
(
"add"
,
X
=
"a"
,
Y
=
"b"
,
Out
=
"z"
)
self
.
assertIsNotNone
(
add_op
)
# Invoke C++ DebugString()
self
.
assertEqual
(
'Op(add
_two
), inputs:{X[a], Y[b]}, outputs:{Out[z]}.'
,
self
.
assertEqual
(
'Op(add), inputs:{X[a], Y[b]}, outputs:{Out[z]}.'
,
str
(
add_op
))
...
...
python/paddle/v2/framework/tests/test_recurrent_op.py
浏览文件 @
50870a62
...
...
@@ -146,7 +146,7 @@ class TestRecurrentOp(unittest.TestCase):
stepnet
=
core
.
Net
.
create
()
x_fc_op
=
Operator
(
"mul"
,
X
=
"x@alias"
,
Y
=
"W"
,
Out
=
"Wx"
)
h_fc_op
=
Operator
(
"mul"
,
X
=
"h@pre"
,
Y
=
"U"
,
Out
=
"Uh"
)
sum_op
=
Operator
(
"add
_two
"
,
X
=
"Wx"
,
Y
=
"Uh"
,
Out
=
"sum"
)
sum_op
=
Operator
(
"add"
,
X
=
"Wx"
,
Y
=
"Uh"
,
Out
=
"sum"
)
sig_op
=
Operator
(
"sigmoid"
,
X
=
"sum"
,
Y
=
"h@alias"
)
for
op
in
[
x_fc_op
,
h_fc_op
,
sum_op
,
sig_op
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录