Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8163faaa
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
8163faaa
编写于
4月 28, 2023
作者:
S
superwinner1
提交者:
GitHub
4月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Hackathon No.55】add fmin BF16 test (#53100)
* 'fmin' * 'fix' * 'fix'
上级
4001f7ae
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
1 deletion
+44
-1
paddle/phi/kernels/funcs/elementwise_functor.h
paddle/phi/kernels/funcs/elementwise_functor.h
+12
-0
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
+1
-0
paddle/phi/kernels/kps/elementwise_kernel.cu
paddle/phi/kernels/kps/elementwise_kernel.cu
+1
-0
python/paddle/fluid/tests/unittests/test_fmin_op.py
python/paddle/fluid/tests/unittests/test_fmin_op.py
+30
-1
未找到文件。
paddle/phi/kernels/funcs/elementwise_functor.h
浏览文件 @
8163faaa
...
@@ -14,6 +14,7 @@ limitations under the License. */
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#pragma once
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/enforce.h"
...
@@ -190,6 +191,17 @@ struct FMinFunctor<dtype::float16> {
...
@@ -190,6 +191,17 @@ struct FMinFunctor<dtype::float16> {
}
}
};
};
template
<
>
struct
FMinFunctor
<
dtype
::
bfloat16
>
{
inline
HOSTDEVICE
dtype
::
bfloat16
operator
()(
const
dtype
::
bfloat16
a
,
const
dtype
::
bfloat16
b
)
const
{
float
float_a
=
static_cast
<
float
>
(
a
);
float
float_b
=
static_cast
<
float
>
(
b
);
auto
result
=
std
::
fmin
(
float_a
,
float_b
);
return
static_cast
<
dtype
::
bfloat16
>
(
result
);
}
};
template
<
>
template
<
>
struct
FMinFunctor
<
int
>
{
struct
FMinFunctor
<
int
>
{
inline
HOSTDEVICE
int
operator
()(
const
int
a
,
const
int
b
)
const
{
inline
HOSTDEVICE
int
operator
()(
const
int
a
,
const
int
b
)
const
{
...
...
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
浏览文件 @
8163faaa
...
@@ -108,6 +108,7 @@ PD_REGISTER_KERNEL(fmin_grad,
...
@@ -108,6 +108,7 @@ PD_REGISTER_KERNEL(fmin_grad,
double
,
double
,
int
,
int
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
int64_t
)
{}
int64_t
)
{}
PD_REGISTER_KERNEL
(
maximum_grad
,
PD_REGISTER_KERNEL
(
maximum_grad
,
...
...
paddle/phi/kernels/kps/elementwise_kernel.cu
浏览文件 @
8163faaa
...
@@ -166,6 +166,7 @@ PD_REGISTER_KERNEL(fmin,
...
@@ -166,6 +166,7 @@ PD_REGISTER_KERNEL(fmin,
double
,
double
,
int
,
int
,
float16
,
float16
,
bfloat16
,
int64_t
)
{}
int64_t
)
{}
PD_REGISTER_KERNEL
(
heaviside
,
PD_REGISTER_KERNEL
(
heaviside
,
...
...
python/paddle/fluid/tests/unittests/test_fmin_op.py
浏览文件 @
8163faaa
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle
from
paddle.fluid
import
core
from
paddle.fluid
import
core
...
@@ -243,6 +243,35 @@ class TestElementwiseFmin3Op(OpTest):
...
@@ -243,6 +243,35 @@ class TestElementwiseFmin3Op(OpTest):
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
)
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
)
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
"core is not compiled with CUDA and not support the bfloat16"
,
)
class
TestFminBF16OP
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_fmin"
self
.
python_api
=
paddle
.
fmin
self
.
dtype
=
np
.
uint16
x
=
np
.
random
.
uniform
(
1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
[
13
,
17
]).
astype
(
"float32"
)
y
=
x
+
sgn
*
np
.
random
.
uniform
(
1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
out
=
np
.
fmin
(
x
,
y
)
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
x
),
'Y'
:
convert_float_to_uint16
(
y
),
}
self
.
outputs
=
{
'Out'
:
convert_float_to_uint16
(
out
)}
def
test_check_output
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_output_with_place
(
place
)
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
,
'Y'
],
'Out'
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
paddle
.
enable_static
()
paddle
.
enable_static
()
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录