Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
14625ffe
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看板
未验证
提交
14625ffe
编写于
9月 24, 2019
作者:
K
Kaipeng Deng
提交者:
GitHub
9月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add elementwise mod support float/double. test=develop (#19570)
上级
5b07ca9c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
4 deletion
+54
-4
paddle/fluid/operators/elementwise/elementwise_mod_op.cc
paddle/fluid/operators/elementwise/elementwise_mod_op.cc
+3
-1
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
+3
-1
paddle/fluid/operators/elementwise/elementwise_mod_op.h
paddle/fluid/operators/elementwise/elementwise_mod_op.h
+29
-0
python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
+19
-2
未找到文件。
paddle/fluid/operators/elementwise/elementwise_mod_op.cc
浏览文件 @
14625ffe
...
@@ -33,4 +33,6 @@ REGISTER_OP_WITHOUT_GRADIENT(elementwise_mod, ops::ElementwiseOp,
...
@@ -33,4 +33,6 @@ REGISTER_OP_WITHOUT_GRADIENT(elementwise_mod, ops::ElementwiseOp,
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
elementwise_mod
,
elementwise_mod
,
ops
::
ElementwiseModKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ElementwiseModKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ElementwiseModKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
);
ops
::
ElementwiseModKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ElementwiseModFPKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ElementwiseModFPKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
);
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
浏览文件 @
14625ffe
...
@@ -19,4 +19,6 @@ namespace plat = paddle::platform;
...
@@ -19,4 +19,6 @@ namespace plat = paddle::platform;
REGISTER_OP_CUDA_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
elementwise_mod
,
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
int
>
,
elementwise_mod
,
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
int
>
,
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
int64_t
>
);
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ElementwiseModFPKernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseModFPKernel
<
plat
::
CUDADeviceContext
,
double
>
);
paddle/fluid/operators/elementwise/elementwise_mod_op.h
浏览文件 @
14625ffe
...
@@ -27,6 +27,11 @@ struct ModFunctor {
...
@@ -27,6 +27,11 @@ struct ModFunctor {
inline
HOSTDEVICE
T
operator
()(
T
a
,
T
b
)
const
{
return
a
%
b
;
}
inline
HOSTDEVICE
T
operator
()(
T
a
,
T
b
)
const
{
return
a
%
b
;
}
};
};
template
<
typename
T
>
struct
ModFunctorFP
{
inline
HOSTDEVICE
T
operator
()(
T
a
,
T
b
)
const
{
return
std
::
fmod
(
a
,
b
);
}
};
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
void
elementwise_mod
(
const
framework
::
ExecutionContext
&
ctx
,
void
elementwise_mod
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
Tensor
*
x
,
const
framework
::
Tensor
*
y
,
const
framework
::
Tensor
*
x
,
const
framework
::
Tensor
*
y
,
...
@@ -36,6 +41,15 @@ void elementwise_mod(const framework::ExecutionContext &ctx,
...
@@ -36,6 +41,15 @@ void elementwise_mod(const framework::ExecutionContext &ctx,
ModFunctor
<
T
>
(),
z
);
ModFunctor
<
T
>
(),
z
);
}
}
template
<
typename
DeviceContext
,
typename
T
>
void
elementwise_mod_fp
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
Tensor
*
x
,
const
framework
::
Tensor
*
y
,
framework
::
Tensor
*
z
)
{
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
ElementwiseComputeEx
<
ModFunctorFP
<
T
>
,
DeviceContext
,
T
>
(
ctx
,
x
,
y
,
axis
,
ModFunctorFP
<
T
>
(),
z
);
}
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseModKernel
:
public
framework
::
OpKernel
<
T
>
{
class
ElementwiseModKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
...
@@ -51,5 +65,20 @@ class ElementwiseModKernel : public framework::OpKernel<T> {
...
@@ -51,5 +65,20 @@ class ElementwiseModKernel : public framework::OpKernel<T> {
}
}
};
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseModFPKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
*
x
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
);
auto
*
y
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"Y"
);
auto
*
z
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
z
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
// dtype of x and y is float or double
elementwise_mod_fp
<
DeviceContext
,
T
>
(
ctx
,
x
,
y
,
z
);
}
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py
浏览文件 @
14625ffe
...
@@ -27,7 +27,6 @@ class TestElementwiseModOp(OpTest):
...
@@ -27,7 +27,6 @@ class TestElementwiseModOp(OpTest):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_mod"
self
.
op_type
=
"elementwise_mod"
self
.
dtype
=
np
.
int32
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
init_dtype
()
self
.
init_dtype
()
self
.
init_input_output
()
self
.
init_input_output
()
...
@@ -50,7 +49,7 @@ class TestElementwiseModOp(OpTest):
...
@@ -50,7 +49,7 @@ class TestElementwiseModOp(OpTest):
self
.
out
=
np
.
mod
(
self
.
x
,
self
.
y
)
self
.
out
=
np
.
mod
(
self
.
x
,
self
.
y
)
def
init_dtype
(
self
):
def
init_dtype
(
self
):
pass
self
.
dtype
=
np
.
int32
def
init_axis
(
self
):
def
init_axis
(
self
):
pass
pass
...
@@ -65,5 +64,23 @@ class TestElementwiseModOp_scalar(TestElementwiseModOp):
...
@@ -65,5 +64,23 @@ class TestElementwiseModOp_scalar(TestElementwiseModOp):
self
.
out
=
np
.
mod
(
self
.
x
,
self
.
y
)
self
.
out
=
np
.
mod
(
self
.
x
,
self
.
y
)
class
TestElementwiseModOpFloat
(
TestElementwiseModOp
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float32
def
init_input_output
(
self
):
self
.
x
=
np
.
random
.
uniform
(
-
1000
,
1000
,
[
10
,
10
]).
astype
(
self
.
dtype
)
self
.
y
=
np
.
random
.
uniform
(
-
100
,
100
,
[
10
,
10
]).
astype
(
self
.
dtype
)
self
.
out
=
np
.
fmod
(
self
.
x
,
self
.
y
)
def
test_check_output
(
self
):
self
.
check_output
(
atol
=
2e-5
)
class
TestElementwiseModOpDouble
(
TestElementwiseModOpFloat
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float64
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录