Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
982d5ff7
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看板
未验证
提交
982d5ff7
编写于
11月 18, 2022
作者:
Z
zhangyikun02
提交者:
GitHub
11月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cast and gradient_accumulator support double for xpu, test=kunlun (#47800)
上级
635958d9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
16 deletion
+52
-16
paddle/fluid/imperative/gradient_accumulator.cc
paddle/fluid/imperative/gradient_accumulator.cc
+27
-7
paddle/fluid/platform/device/xpu/xpu2_op_list.h
paddle/fluid/platform/device/xpu/xpu2_op_list.h
+2
-0
paddle/phi/kernels/xpu/cast_kernel.cc
paddle/phi/kernels/xpu/cast_kernel.cc
+12
-6
python/paddle/fluid/tests/unittests/xpu/test_adadelta_op_xpu.py
.../paddle/fluid/tests/unittests/xpu/test_adadelta_op_xpu.py
+1
-2
python/paddle/fluid/tests/unittests/xpu/test_cast_op_xpu.py
python/paddle/fluid/tests/unittests/xpu/test_cast_op_xpu.py
+10
-1
未找到文件。
paddle/fluid/imperative/gradient_accumulator.cc
浏览文件 @
982d5ff7
...
...
@@ -31,6 +31,7 @@
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/selected_rows_functor.h"
#ifdef PADDLE_WITH_XPU
#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "xpu/refactor/math.h"
#endif
#ifdef PADDLE_WITH_ASCEND_CL
...
...
@@ -92,13 +93,30 @@ void XPUTensorAddFunctor(const platform::Place& place,
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
));
const
XPUType
*
x
=
reinterpret_cast
<
const
XPUType
*>
(
src
.
data
<
T
>
());
XPUType
*
y
=
reinterpret_cast
<
XPUType
*>
(
dst
->
mutable_data
<
T
>
(
place
));
int
r
=
xpu
::
add
<
XPUType
>
(
ctx
->
x_context
(),
x
,
y
,
y
,
static_cast
<
int
>
(
src
.
numel
()));
PADDLE_ENFORCE_EQ
(
r
,
XPU_SUCCESS
,
platform
::
errors
::
External
(
"XPU add kernel return wrong value[%d %s]"
,
r
,
XPUAPIErrorMsg
[
r
]));
int
r
=
-
1
;
int
numel
=
static_cast
<
int
>
(
src
.
numel
());
if
(
std
::
is_same
<
T
,
double
>::
value
)
{
xpu
::
ctx_guard
RAII_GUARD
(
ctx
->
x_context
());
float
*
x_cast_to_fp32
=
RAII_GUARD
.
alloc
<
float
>
(
numel
);
PADDLE_ENFORCE_XDNN_NOT_NULL
(
x_cast_to_fp32
);
float
*
y_cast_to_fp32
=
RAII_GUARD
.
alloc
<
float
>
(
numel
);
PADDLE_ENFORCE_XDNN_NOT_NULL
(
y_cast_to_fp32
);
r
=
xpu
::
cast
<
XPUType
,
float
>
(
ctx
->
x_context
(),
x
,
x_cast_to_fp32
,
numel
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"cast"
);
r
=
xpu
::
cast
<
XPUType
,
float
>
(
ctx
->
x_context
(),
y
,
y_cast_to_fp32
,
numel
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"cast"
);
r
=
xpu
::
add
<
float
>
(
ctx
->
x_context
(),
x_cast_to_fp32
,
y_cast_to_fp32
,
y_cast_to_fp32
,
numel
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"add"
);
r
=
xpu
::
cast
<
float
,
XPUType
>
(
ctx
->
x_context
(),
y_cast_to_fp32
,
y
,
numel
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"cast"
);
}
else
{
r
=
xpu
::
add
<
XPUType
>
(
ctx
->
x_context
(),
x
,
y
,
y
,
numel
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"add"
);
}
}
#endif
...
...
@@ -286,6 +304,8 @@ void TensorAdd(const VarType& src, VarType* dst) {
}
else
if
(
data_type
==
framework
::
DataTypeTrait
<
platform
::
float16
>::
DataType
())
{
XPUTensorAddFunctor
<
platform
::
float16
>
(
place
,
src_tensor
,
dst_tensor
);
}
else
if
(
data_type
==
framework
::
DataTypeTrait
<
double
>::
DataType
())
{
XPUTensorAddFunctor
<
double
>
(
place
,
src_tensor
,
dst_tensor
);
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Gradient accumulation of data type (%s) on place (%s) is not "
...
...
paddle/fluid/platform/device/xpu/xpu2_op_list.h
浏览文件 @
982d5ff7
...
...
@@ -103,7 +103,9 @@ XPUOpMap& get_kl2_ops() {
{
"cast"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP64
,
XPUPlace
()),
pOpKernelType
(
vartype
::
BOOL
,
XPUPlace
()),
pOpKernelType
(
vartype
::
UINT8
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT64
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
())})},
{
"check_finite_and_unscale"
,
...
...
paddle/phi/kernels/xpu/cast_kernel.cc
浏览文件 @
982d5ff7
...
...
@@ -14,6 +14,7 @@
#include "paddle/phi/kernels/cast_kernel.h"
#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/enforce.h"
...
...
@@ -80,16 +81,19 @@ void CastKernel(const Context& dev_ctx,
dev_ctx
.
template
Alloc
<
uint8_t
>(
out
),
numel
);
break
;
case
phi
::
DataType
::
FLOAT64
:
r
=
xpu
::
cast_v2
<
XPUInTDType
,
double
>
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUInTDType
*>
(
in_data
),
dev_ctx
.
template
Alloc
<
double
>(
out
),
numel
);
break
;
default:
PADDLE_THROW
(
phi
::
errors
::
Unavailable
(
"Not supported cast %d -> %d"
,
x
.
dtype
(),
out_dtype
));
}
PADDLE_ENFORCE_EQ
(
r
,
XPU_SUCCESS
,
phi
::
errors
::
External
(
"XPU CAST API return wrong value[%d %s]."
,
r
,
XPUAPIErrorMsg
[
r
]));
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"cast_v2"
);
}
}
// namespace phi
...
...
@@ -101,6 +105,8 @@ PD_REGISTER_KERNEL(cast,
float
,
phi
::
dtype
::
float16
,
int64_t
,
bool
)
{
bool
,
uint8_t
,
double
)
{
kernel
->
OutputAt
(
0
).
SetDataType
(
paddle
::
experimental
::
DataType
::
UNDEFINED
);
}
python/paddle/fluid/tests/unittests/xpu/test_adadelta_op_xpu.py
浏览文件 @
982d5ff7
...
...
@@ -18,7 +18,6 @@ import sys
sys
.
path
.
append
(
".."
)
from
op_test
import
OpTest
import
paddle
import
paddle.fluid
as
fluid
from
op_test_xpu
import
XPUOpTest
...
...
@@ -88,7 +87,7 @@ class XPUTestAdadelta(XPUOpTestWrapper):
def
test_check_output
(
self
):
self
.
check_output
()
class
TestAdadeltaOp2
(
OpTest
):
class
TestAdadeltaOp2
(
XPU
OpTest
):
'''Test Adadelta op with default attribute values'''
def
setUp
(
self
):
...
...
python/paddle/fluid/tests/unittests/xpu/test_cast_op_xpu.py
浏览文件 @
982d5ff7
...
...
@@ -36,6 +36,7 @@ typeid_dict = {
'float16'
:
int
(
core
.
VarDesc
.
VarType
.
FP16
),
'bool'
:
int
(
core
.
VarDesc
.
VarType
.
BOOL
),
'uint8'
:
int
(
core
.
VarDesc
.
VarType
.
UINT8
),
'float64'
:
int
(
core
.
VarDesc
.
VarType
.
FP64
),
}
...
...
@@ -47,7 +48,15 @@ class XPUTestCastOp(XPUOpTestWrapper):
def
dynamic_create_class
(
self
):
base_class
=
self
.
TestCastOp
classes
=
[]
for
out_type
in
{
'float16'
,
'float32'
,
'int32'
,
'int64'
,
'uint8'
}:
for
out_type
in
{
'float16'
,
'float32'
,
'int32'
,
'int64'
,
'uint8'
,
'bool'
,
'float64'
,
}:
class_name
=
'XPUTestCastOp_outtype_'
+
out_type
attr_dict
=
{
'out_typename'
:
out_type
}
classes
.
append
([
class_name
,
attr_dict
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录