Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ef5344cb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
ef5344cb
编写于
8月 31, 2022
作者:
R
risemeup1
提交者:
GitHub
8月 31, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move clip XPU kernel to PHI,test=kunlun (#45568)
* move clip XPU kernel to PHI,test=kunlun * delete clip_op_xpu.cc,test=kunlun
上级
230fd50f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
82 deletion
+49
-82
paddle/fluid/operators/clip_op_xpu.cc
paddle/fluid/operators/clip_op_xpu.cc
+0
-82
paddle/phi/kernels/xpu/clip_kernel.cc
paddle/phi/kernels/xpu/clip_kernel.cc
+49
-0
未找到文件。
paddle/fluid/operators/clip_op_xpu.cc
已删除
100644 → 0
浏览文件 @
230fd50f
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
template
<
typename
DeviceContext
,
typename
T
>
class
ClipXPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
*
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
max
=
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"max"
));
if
(
ctx
.
HasInput
(
"Max"
))
{
Tensor
max_cpu
;
auto
*
max_t
=
ctx
.
Input
<
Tensor
>
(
"Max"
);
auto
*
max_data
=
max_t
->
data
<
T
>
();
if
(
platform
::
is_xpu_place
(
max_t
->
place
()))
{
paddle
::
framework
::
TensorCopySync
(
*
max_t
,
platform
::
CPUPlace
(),
&
max_cpu
);
max_data
=
max_cpu
.
data
<
T
>
();
}
max
=
max_data
[
0
];
}
auto
min
=
ctx
.
Attr
<
float
>
(
"min"
);
if
(
ctx
.
HasInput
(
"Min"
))
{
Tensor
min_cpu
;
auto
*
min_t
=
ctx
.
Input
<
Tensor
>
(
"Min"
);
auto
*
min_data
=
min_t
->
data
<
T
>
();
if
(
platform
::
is_xpu_place
(
min_t
->
place
()))
{
paddle
::
framework
::
TensorCopySync
(
*
min_t
,
platform
::
CPUPlace
(),
&
min_cpu
);
min_data
=
min_cpu
.
data
<
T
>
();
}
min
=
min_data
[
0
];
}
using
XPUDataType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
&
dev_ctx
=
ctx
.
template
device_context
<
DeviceContext
>();
auto
x_data
=
reinterpret_cast
<
const
XPUDataType
*>
(
x
->
data
<
T
>
());
auto
out_data
=
reinterpret_cast
<
XPUDataType
*>
(
out
->
data
<
T
>
());
int
r
=
xpu
::
clip_v2
(
dev_ctx
.
x_context
(),
x_data
,
out_data
,
x
->
numel
(),
min
,
max
);
PADDLE_ENFORCE_EQ
(
r
,
XPU_SUCCESS
,
platform
::
errors
::
External
(
"XPU API(clip_v2) return wrong "
"value[%d %s]"
,
r
,
XPUAPIErrorMsg
[
r
]));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_XPU_KERNEL
(
clip
,
ops
::
ClipXPUKernel
<
plat
::
XPUDeviceContext
,
float
>
);
#endif
paddle/phi/kernels/xpu/clip_kernel.cc
0 → 100644
浏览文件 @
ef5344cb
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/clip_kernel.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/backends/xpu/xpu_header.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
ClipKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
Scalar
&
min
,
const
Scalar
&
max
,
DenseTensor
*
out
)
{
dev_ctx
.
template
Alloc
<
T
>(
out
);
using
XPUDataType
=
typename
XPUTypeTrait
<
T
>::
Type
;
auto
x_data
=
reinterpret_cast
<
const
XPUDataType
*>
(
x
.
data
<
T
>
());
auto
out_data
=
reinterpret_cast
<
XPUDataType
*>
(
out
->
data
<
T
>
());
int
r
=
xpu
::
clip_v2
(
dev_ctx
.
x_context
(),
x_data
,
out_data
,
x
.
numel
(),
min
.
to
<
float
>
(),
max
.
to
<
float
>
());
PADDLE_ENFORCE_EQ
(
r
,
XPU_SUCCESS
,
phi
::
errors
::
External
(
"XPU API(clip_v2) return wrong "
"value[%d %s]"
,
r
,
XPUAPIErrorMsg
[
r
]));
}
}
// namespace phi
PD_REGISTER_KERNEL
(
clip
,
XPU
,
ALL_LAYOUT
,
phi
::
ClipKernel
,
float
)
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录