Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
10171806
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
10171806
编写于
6月 23, 2021
作者:
L
limingshu
提交者:
GitHub
6月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support Mod in elementwise system (#33052)
上级
5f198a6e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
49 addition
and
3 deletion
+49
-3
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
+49
-2
paddle/fluid/operators/elementwise/elementwise_mod_op.h
paddle/fluid/operators/elementwise/elementwise_mod_op.h
+0
-1
未找到文件。
paddle/fluid/operators/elementwise/elementwise_mod_op.cu
浏览文件 @
10171806
...
@@ -12,13 +12,60 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,13 +12,60 @@ 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 "paddle/fluid/operators/elementwise/elementwise_mod_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_mod_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_broadcast.cu.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/fluid/platform/float16.h"
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
namespace
plat
=
paddle
::
platform
;
namespace
paddle
{
namespace
operators
{
template
<
typename
T
,
typename
Enable
=
void
>
struct
CudaModFunctor
{
inline
HOSTDEVICE
T
operator
()(
const
T
*
args
)
const
{
T
res
=
args
[
0
]
%
args
[
1
];
// Accoding to #PR26732: in dividen % divsor
// remainder shall have the same sign as divsor.
if
((
res
!=
0
)
&&
((
args
[
1
]
^
res
)
<
0
))
res
+=
args
[
1
];
return
res
;
}
};
template
<
typename
T
>
struct
CudaModFunctor
<
T
,
typename
std
::
enable_if_t
<
std
::
is_floating_point
<
T
>::
value
>>
{
inline
HOSTDEVICE
T
operator
()(
const
T
*
args
)
const
{
T
res
=
fmod
(
args
[
0
],
args
[
1
]);
// Accoding to #PR26732: in dividen % divsor
// remainder shall have the same sign as divsor.
if
((
res
!=
0
)
&&
((
res
<
0
)
!=
(
args
[
1
]
<
0
)))
res
+=
args
[
1
];
return
res
;
}
};
template
<
typename
T
>
class
ElementwiseModKernel
<
platform
::
CUDADeviceContext
,
T
>
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
std
::
vector
<
const
framework
::
Tensor
*>
ins
;
std
::
vector
<
framework
::
Tensor
*>
outs
;
const
auto
&
cuda_ctx
=
ctx
.
template
device_context
<
platform
::
CUDADeviceContext
>();
int
axis
=
PackTensorsIntoVector
<
T
>
(
ctx
,
&
ins
,
&
outs
);
LaunchElementwiseCudaKernel
<
ElementwiseType
::
kBinary
,
T
,
T
>
(
cuda_ctx
,
ins
,
&
outs
,
axis
,
CudaModFunctor
<
T
>
());
}
};
}
// namespace operators
}
// namespace paddle
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
::
ElementwiseMod
FP
Kernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
float
>
,
ops
::
ElementwiseMod
FP
Kernel
<
plat
::
CUDADeviceContext
,
double
>
);
ops
::
ElementwiseModKernel
<
plat
::
CUDADeviceContext
,
double
>
);
paddle/fluid/operators/elementwise/elementwise_mod_op.h
浏览文件 @
10171806
...
@@ -16,7 +16,6 @@ limitations under the License. */
...
@@ -16,7 +16,6 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
#include "paddle/fluid/operators/elementwise/elementwise_op_function.h"
#include "paddle/fluid/operators/math/blas.h"
#include "paddle/fluid/operators/math/blas.h"
namespace
paddle
{
namespace
paddle
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录