Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0efcae86
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看板
未验证
提交
0efcae86
编写于
1月 12, 2022
作者:
Z
Zhang Ting
提交者:
GitHub
1月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[part 3]change type of function args (#38887)
* code clean * [part 3]change type of function args
上级
f1201482
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
44 addition
and
70 deletion
+44
-70
paddle/fluid/operators/controlflow/bitwise_op.h
paddle/fluid/operators/controlflow/bitwise_op.h
+15
-15
paddle/fluid/operators/controlflow/compare_all_op.h
paddle/fluid/operators/controlflow/compare_all_op.h
+1
-1
paddle/fluid/operators/controlflow/compare_op.h
paddle/fluid/operators/controlflow/compare_op.h
+6
-6
paddle/fluid/operators/controlflow/logical_op.cu
paddle/fluid/operators/controlflow/logical_op.cu
+4
-24
paddle/fluid/operators/controlflow/logical_op.h
paddle/fluid/operators/controlflow/logical_op.h
+18
-24
未找到文件。
paddle/fluid/operators/controlflow/bitwise_op.h
浏览文件 @
0efcae86
...
...
@@ -22,19 +22,19 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
#define BITWISE_BINARY_FUNCTOR(func, expr, bool_expr)
\
template <typename T>
\
struct Bitwise##func##Functor {
\
using ELEM_TYPE = T;
\
HOSTDEVICE T operator()(const T
& a, const T&
b) const { return a expr b; } \
};
\
\
template <>
\
struct Bitwise##func##Functor<bool> {
\
using ELEM_TYPE = bool;
\
HOSTDEVICE bool operator()(const bool
& a, const bool&
b) const { \
return a bool_expr b;
\
}
\
#define BITWISE_BINARY_FUNCTOR(func, expr, bool_expr) \
template <typename T> \
struct Bitwise##func##Functor { \
using ELEM_TYPE = T; \
HOSTDEVICE T operator()(const T
a, const T
b) const { return a expr b; } \
}; \
\
template <> \
struct Bitwise##func##Functor<bool> { \
using ELEM_TYPE = bool; \
HOSTDEVICE bool operator()(const bool
a, const bool
b) const { \
return a bool_expr b; \
} \
};
BITWISE_BINARY_FUNCTOR
(
And
,
&
,
&&
)
...
...
@@ -45,13 +45,13 @@ BITWISE_BINARY_FUNCTOR(Xor, ^, !=)
template
<
typename
T
>
struct
BitwiseNotFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
T
operator
()(
const
T
&
a
)
const
{
return
~
a
;
}
HOSTDEVICE
T
operator
()(
const
T
a
)
const
{
return
~
a
;
}
};
template
<
>
struct
BitwiseNotFunctor
<
bool
>
{
using
ELEM_TYPE
=
bool
;
HOSTDEVICE
bool
operator
()(
const
bool
&
a
)
const
{
return
!
a
;
}
HOSTDEVICE
bool
operator
()(
const
bool
a
)
const
{
return
!
a
;
}
};
template
<
typename
DeviceContext
,
typename
Functor
>
...
...
paddle/fluid/operators/controlflow/compare_all_op.h
浏览文件 @
0efcae86
...
...
@@ -28,7 +28,7 @@ namespace operators {
template
<
typename
T
>
struct
EqualReduceFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
if
(
std
::
is_floating_point
<
T
>::
value
)
{
// This branch will be optimized while compiling if T is integer. It is
// safe to cast a and b to double.
...
...
paddle/fluid/operators/controlflow/compare_op.h
浏览文件 @
0efcae86
...
...
@@ -25,31 +25,31 @@ namespace operators {
template
<
typename
T
>
struct
LessThanFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
<
b
;
}
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
return
a
<
b
;
}
};
template
<
typename
T
>
struct
LessEqualFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
<=
b
;
}
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
return
a
<=
b
;
}
};
template
<
typename
T
>
struct
GreaterThanFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
>
b
;
}
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
return
a
>
b
;
}
};
template
<
typename
T
>
struct
GreaterEqualFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
>=
b
;
}
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
return
a
>=
b
;
}
};
template
<
typename
T
>
struct
EqualFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
if
(
std
::
is_floating_point
<
T
>::
value
)
{
// This branch will be optimized while compiling if T is integer. It is
// safe to cast a and b to double.
...
...
@@ -63,7 +63,7 @@ struct EqualFunctor {
template
<
typename
T
>
struct
NotEqualFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
HOSTDEVICE
bool
operator
()(
const
T
a
,
const
T
b
)
const
{
return
!
EqualFunctor
<
T
>
()(
a
,
b
);
}
};
...
...
paddle/fluid/operators/controlflow/logical_op.cu
浏览文件 @
0efcae86
...
...
@@ -18,26 +18,6 @@ namespace plat = paddle::platform;
namespace
paddle
{
namespace
operators
{
#define LOGICAL_BINARY_FUNCTOR(func_name, op) \
template <typename T> \
struct func_name { \
using ELEMENT_TYPE = T; \
HOSTDEVICE bool operator()(const T* args) const { \
return static_cast<bool>(args[0]) op static_cast<bool>(args[1]); \
} \
};
LOGICAL_BINARY_FUNCTOR
(
CudaOrFunctor
,
||
)
LOGICAL_BINARY_FUNCTOR
(
CudaAndFunctor
,
&&
)
LOGICAL_BINARY_FUNCTOR
(
CudaXorFunctor
,
^
)
#undef LOGICAL_BINARY_FUNCTOR
template
<
typename
T
>
struct
CudaNotFunctor
{
using
ELEMENT_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
*
args
)
const
{
return
!
args
[
0
];
}
};
template
<
typename
Functor
>
class
BinaryLogicalOpKernel
<
platform
::
CUDADeviceContext
,
Functor
>
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEMENT_TYPE
>
{
...
...
@@ -76,8 +56,8 @@ class BinaryLogicalOpKernel<platform::CUDADeviceContext, Functor>
ops::BinaryLogicalOpKernel<plat::CUDADeviceContext, ops::func<float>>, \
ops::BinaryLogicalOpKernel<plat::CUDADeviceContext, ops::func<double>>);
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_or
,
Cuda
OrFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_and
,
Cuda
AndFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_xor
,
Cuda
XorFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_not
,
Cuda
NotFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_or
,
Logical
OrFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_and
,
Logical
AndFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_xor
,
Logical
XorFunctor
)
REGISTER_LOGICAL_CUDA_KERNEL
(
logical_not
,
Logical
NotFunctor
)
#undef REGISTER_LOGICAL_CUDA_KERNEL
paddle/fluid/operators/controlflow/logical_op.h
浏览文件 @
0efcae86
...
...
@@ -19,38 +19,32 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
struct
LogicalAndFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
&&
b
;
}
};
#define LOGICAL_BINARY_FUNCTOR(func_name, op) \
template <typename T> \
struct func_name { \
using ELEMENT_TYPE = T; \
HOSTDEVICE bool operator()(const T a, const T b) const { \
return static_cast<bool>(a) op static_cast<bool>(b); \
} \
};
template
<
typename
T
>
struct
LogicalOrFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
||
b
;
}
};
LOGICAL_BINARY_FUNCTOR
(
LogicalOrFunctor
,
||
)
LOGICAL_BINARY_FUNCTOR
(
LogicalAndFunctor
,
&&
)
LOGICAL_BINARY_FUNCTOR
(
LogicalXorFunctor
,
^
)
#undef LOGICAL_BINARY_FUNCTOR
template
<
typename
T
>
struct
LogicalNotFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
)
const
{
return
!
a
;
}
};
template
<
typename
T
>
struct
LogicalXorFunctor
{
using
ELEM_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
&
a
,
const
T
&
b
)
const
{
return
(
a
||
b
)
&&
!
(
a
&&
b
);
}
using
ELEMENT_TYPE
=
T
;
HOSTDEVICE
bool
operator
()(
const
T
a
)
const
{
return
!
a
;
}
};
template
<
typename
DeviceContext
,
typename
Functor
>
class
BinaryLogicalOpKernel
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEM_TYPE
>
{
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEM
ENT
_TYPE
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
using
T
=
typename
Functor
::
ELEM_TYPE
;
using
T
=
typename
Functor
::
ELEM
ENT
_TYPE
;
auto
*
x
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
y
=
context
.
Input
<
framework
::
Tensor
>
(
"Y"
);
auto
*
out
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
...
...
@@ -62,10 +56,10 @@ class BinaryLogicalOpKernel
template
<
typename
DeviceContext
,
typename
Functor
>
class
UnaryLogicalOpKernel
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEM_TYPE
>
{
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEM
ENT
_TYPE
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
using
T
=
typename
Functor
::
ELEM_TYPE
;
using
T
=
typename
Functor
::
ELEM
ENT
_TYPE
;
auto
*
x
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
out
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
Functor
unary_func
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录