Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
950cc60d
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看板
提交
950cc60d
编写于
8月 22, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add minus
上级
d3f219aa
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
145 addition
and
1 deletion
+145
-1
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+2
-1
paddle/framework/pybind.cc
paddle/framework/pybind.cc
+1
-0
paddle/operators/CMakeLists.txt
paddle/operators/CMakeLists.txt
+1
-0
paddle/operators/minus_op.cc
paddle/operators/minus_op.cc
+84
-0
paddle/operators/minus_op.cu
paddle/operators/minus_op.cu
+18
-0
paddle/operators/minus_op.h
paddle/operators/minus_op.h
+39
-0
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
950cc60d
...
...
@@ -56,5 +56,6 @@ cc_library(paddle_pybind SHARED
uniform_random_op
gaussian_random_op
fill_zeros_like_op
scale_op
)
scale_op
minus_op
)
endif
(
WITH_PYTHON
)
paddle/framework/pybind.cc
浏览文件 @
950cc60d
...
...
@@ -44,6 +44,7 @@ USE_OP(gaussian_random);
USE_OP
(
uniform_random
);
USE_OP
(
scale
);
USE_OP_ITSELF
(
identity
);
USE_OP
(
minus
);
namespace
paddle
{
namespace
framework
{
...
...
paddle/operators/CMakeLists.txt
浏览文件 @
950cc60d
...
...
@@ -69,3 +69,4 @@ op_library(recurrent_op SRCS recurrent_op.cc rnn/recurrent_op_utils.cc
op_library
(
uniform_random_op
SRCS uniform_random_op.cc uniform_random_op.cu
)
op_library
(
scale_op SRCS scale_op.cc scale_op.cu DEPS net_op
)
op_library
(
minus_op SRCS minus_op.cc minus_op.cu DEPS scale_op
)
paddle/operators/minus_op.cc
0 → 100644
浏览文件 @
950cc60d
/* 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. */
#include "paddle/operators/minus_op.h"
#include "paddle/operators/net_op.h"
namespace
paddle
{
namespace
operators
{
class
MinusOp
:
public
framework
::
OperatorWithKernel
{
public:
MinusOp
(
const
std
::
string
&
type
,
const
VarNameMap
&
inputs
,
const
VarNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
OperatorWithKernel
(
type
,
inputs
,
outputs
,
attrs
)
{}
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
*
left_tensor
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
right_tensor
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Y"
);
PADDLE_ENFORCE_EQ
(
framework
::
product
(
left_tensor
->
dims
()),
framework
::
product
(
right_tensor
->
dims
()),
"Minus operator must take two tensor with same num of elements"
);
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
)
->
Resize
(
left_tensor
->
dims
());
}
};
class
MinusOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
MinusOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"The left tensor of minus operator."
).
NotInGradient
();
AddInput
(
"Y"
,
"The right tensor of minus operator."
).
NotInGradient
();
AddOutput
(
"Out"
,
"The output tensor of minus operator."
).
NotInGradient
();
AddComment
(
R"DOC(Minus Operator
Equation: Out = X - Y
)DOC"
);
}
};
template
<
typename
AttrType
>
class
MinusGradOp
:
public
NetOp
{
public:
MinusGradOp
(
const
std
::
string
&
type
,
const
VarNameMap
&
inputs
,
const
VarNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
auto
out_grad
=
Input
(
framework
::
GradVarName
(
"Out"
));
auto
x_grad
=
Output
(
framework
::
GradVarName
(
"X"
));
auto
y_grad
=
Output
(
framework
::
GradVarName
(
"Y"
));
// x_grad = out_grad
AddOp
(
framework
::
OpRegistry
::
CreateOp
(
"identity"
,
{{
"X"
,
{
out_grad
}}},
{{
"Out"
,
{
x_grad
}}},
{}));
framework
::
AttributeMap
scale_attr
;
scale_attr
[
"scale"
]
=
static_cast
<
AttrType
>
(
-
1
);
AddOp
(
framework
::
OpRegistry
::
CreateOp
(
"scale"
,
{{
"X"
,
{
out_grad
}}},
{{
"Out"
,
{
y_grad
}}},
scale_attr
));
}
};
}
// namespace operators
}
// namespace paddle
USE_OP
(
scale
);
USE_OP_ITSELF
(
identity
);
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
minus
,
ops
::
MinusOp
,
ops
::
MinusOpMaker
,
minus_grad
,
ops
::
MinusGradOp
<
float
>
);
REGISTER_OP_CPU_KERNEL
(
minus
,
ops
::
MinusKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/minus_op.cu
0 → 100644
浏览文件 @
950cc60d
/* 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. */
#include "paddle/operators/minus_op.h"
REGISTER_OP_GPU_KERNEL
(
minus
,
paddle
::
operators
::
MinusKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
paddle/operators/minus_op.h
0 → 100644
浏览文件 @
950cc60d
/* 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. */
#pragma once
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
Place
,
typename
T
>
class
MinusKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
left_tensor
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
right_tensor
=
context
.
Input
<
framework
::
Tensor
>
(
"Y"
);
auto
*
out_tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
out_tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
&
dev
=
context
.
GetEigenDevice
<
Place
>
();
framework
::
EigenVector
<
T
>::
Flatten
(
*
out_tensor
).
device
(
dev
)
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
left_tensor
)
-
framework
::
EigenVector
<
T
>::
Flatten
(
*
right_tensor
);
}
};
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录