Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9ed58bff
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看板
未验证
提交
9ed58bff
编写于
8月 23, 2023
作者:
W
Wang Xin
提交者:
GitHub
8月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move c_identity to phi (#56215)
上级
5c6ae96b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
224 addition
and
95 deletion
+224
-95
paddle/fluid/operators/collective/c_identity_op.cc
paddle/fluid/operators/collective/c_identity_op.cc
+10
-13
paddle/fluid/operators/collective/c_identity_op.h
paddle/fluid/operators/collective/c_identity_op.h
+0
-57
paddle/fluid/operators/custom_device_common_op_registry.cc
paddle/fluid/operators/custom_device_common_op_registry.cc
+35
-12
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+14
-0
paddle/phi/infermeta/unary.h
paddle/phi/infermeta/unary.h
+6
-0
paddle/phi/kernels/c_identity_kernel.h
paddle/phi/kernels/c_identity_kernel.h
+16
-13
paddle/phi/kernels/cpu/c_identity_kernel.cc
paddle/phi/kernels/cpu/c_identity_kernel.cc
+43
-0
paddle/phi/kernels/gpu/c_identity_kernel.cu
paddle/phi/kernels/gpu/c_identity_kernel.cu
+30
-0
paddle/phi/kernels/impl/c_identity_kernel_impl.h
paddle/phi/kernels/impl/c_identity_kernel_impl.h
+41
-0
paddle/phi/kernels/xpu/c_identity_kernel.cc
paddle/phi/kernels/xpu/c_identity_kernel.cc
+29
-0
未找到文件。
paddle/fluid/operators/collective/c_identity_op.cc
浏览文件 @
9ed58bff
...
...
@@ -12,7 +12,10 @@ 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/fluid/operators/collective/c_identity_op.h"
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -79,20 +82,14 @@ class CIdentityOpGradMaker : public framework::SingleGradOpMaker<T> {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
DECLARE_INFER_SHAPE_FUNCTOR
(
c_identity
,
CIdentityShapeFunctor
,
PD_INFER_META
(
phi
::
CIdentityInferMeta
));
REGISTER_OPERATOR
(
c_identity
,
ops
::
CIdentityOp
,
ops
::
CIdentityOpGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
CIdentityOpGradMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
CIdentityOpMaker
);
PD_REGISTER_STRUCT_KERNEL
(
c_identity
,
CPU
,
ALL_LAYOUT
,
ops
::
CIdentityOpCPUKernel
,
float
,
double
,
int
,
int64_t
,
plat
::
float16
)
{}
ops
::
CIdentityOpMaker
,
CIdentityShapeFunctor
);
paddle/fluid/operators/collective/c_identity_op.h
已删除
100644 → 0
浏览文件 @
5c6ae96b
/* Copyright (c) 2021 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. */
#pragma once
#include <algorithm>
#include <utility>
#include <vector>
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
T
,
typename
DeviceContext
>
class
CIdentityOpCPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
UNUSED
)
const
override
{
PADDLE_THROW
(
platform
::
errors
::
Unavailable
(
"Do not support c_identity for cpu kernel now."
));
}
};
template
<
typename
T
,
typename
DeviceContext
>
class
CIdentityOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
x
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"X"
);
auto
out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Out"
);
int
rid
=
ctx
.
Attr
<
int
>
(
"ring_id"
);
PADDLE_ENFORCE_GE
(
rid
,
0
,
platform
::
errors
::
InvalidArgument
(
"The ring_id (%d) for c_identity op must be non-negative."
,
rid
));
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
paddle
::
framework
::
TensorCopy
(
*
x
,
out
->
place
(),
out
);
}
};
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/custom_device_common_op_registry.cc
浏览文件 @
9ed58bff
...
...
@@ -15,7 +15,6 @@ limitations under the License. */
#include "paddle/fluid/operators/custom_device_common_op_registry.h"
#include "paddle/fluid/distributed/collective/process_group.h"
#include "paddle/fluid/operators/collective/c_concat_op.h"
#include "paddle/fluid/operators/collective/c_identity_op.h"
#include "paddle/fluid/operators/load_combine_op.h"
#include "paddle/fluid/operators/run_program_op.h"
#include "paddle/fluid/operators/save_combine_op.h"
...
...
@@ -147,6 +146,25 @@ class CConcatOpCustomDeviceKernel : public framework::OpKernel<T> {
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
CIdentityOpCustomDeviceKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
x
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"X"
);
auto
out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Out"
);
int
rid
=
ctx
.
Attr
<
int
>
(
"ring_id"
);
PADDLE_ENFORCE_GE
(
rid
,
0
,
platform
::
errors
::
InvalidArgument
(
"The ring_id (%d) for c_identity op must be non-negative."
,
rid
));
ctx
.
device_context
().
Alloc
<
T
>
(
out
);
paddle
::
framework
::
TensorCopy
(
*
x
,
out
->
place
(),
out
);
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
CSplitOpCustomDeviceKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
...
...
@@ -1363,17 +1381,22 @@ void RegisterCustomDeviceCommonKernel(const std::string& dev_type) {
REGISTER_OP_CUSTOM_DEVICE_KERNEL
(
c_identity
,
device_type
,
paddle
::
operators
::
CIdentityOpKernel
<
float
,
paddle
::
platform
::
CustomDeviceContext
>
,
paddle
::
operators
::
CIdentityOpKernel
<
double
,
paddle
::
platform
::
CustomDeviceContext
>
,
paddle
::
operators
::
CIdentityOpKernel
<
int
,
paddle
::
platform
::
CustomDeviceContext
>
,
paddle
::
operators
::
CIdentityOpKernel
<
int64_t
,
paddle
::
platform
::
CustomDeviceContext
>
,
paddle
::
operators
::
CIdentityOpKernel
<
paddle
::
platform
::
float16
,
paddle
::
platform
::
CustomDeviceContext
>
)
{}
paddle
::
operators
::
CIdentityOpCustomDeviceKernel
<
paddle
::
platform
::
CustomDeviceContext
,
float
>
,
paddle
::
operators
::
CIdentityOpCustomDeviceKernel
<
paddle
::
platform
::
CustomDeviceContext
,
double
>
,
paddle
::
operators
::
CIdentityOpCustomDeviceKernel
<
paddle
::
platform
::
CustomDeviceContext
,
int
>
,
paddle
::
operators
::
CIdentityOpCustomDeviceKernel
<
paddle
::
platform
::
CustomDeviceContext
,
int64_t
>
,
paddle
::
operators
::
CIdentityOpCustomDeviceKernel
<
paddle
::
platform
::
CustomDeviceContext
,
paddle
::
platform
::
float16
>
)
{}
REGISTER_OP_CUSTOM_DEVICE_KERNEL
(
c_sync_calc_stream
,
device_type
,
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
9ed58bff
...
...
@@ -461,6 +461,20 @@ void ClipByNormInferMeta(const MetaTensor& x, float max_norm, MetaTensor* out) {
out
->
share_lod
(
x
);
}
void
CIdentityInferMeta
(
const
MetaTensor
&
x
,
int
ring_id
,
bool
use_calc_stream
,
bool
use_model_parallel
,
MetaTensor
*
out
)
{
PADDLE_ENFORCE_GE
(
ring_id
,
0
,
errors
::
InvalidArgument
(
"The ring_id (%d) for c_identity must be non-negative."
,
ring_id
));
out
->
set_dims
(
x
.
dims
());
out
->
set_dtype
(
x
.
dtype
());
}
void
CreateLikeInferMeta
(
const
MetaTensor
&
x
,
DataType
dtype
,
MetaTensor
*
out
)
{
out
->
set_dims
(
x
.
dims
());
out
->
set_dtype
(
dtype
==
DataType
::
UNDEFINED
?
x
.
dtype
()
:
dtype
);
...
...
paddle/phi/infermeta/unary.h
浏览文件 @
9ed58bff
...
...
@@ -102,6 +102,12 @@ void ClassCenterSampleInferMeta(const MetaTensor& label,
void
ClipByNormInferMeta
(
const
MetaTensor
&
x
,
float
max_norm
,
MetaTensor
*
out
);
void
CIdentityInferMeta
(
const
MetaTensor
&
x
,
int
ring_id
,
bool
use_calc_stream
,
bool
use_model_parallel
,
MetaTensor
*
out
);
void
CreateLikeInferMeta
(
const
MetaTensor
&
x
,
DataType
dtype
,
MetaTensor
*
out
);
void
CropInferMeta
(
const
MetaTensor
&
x
,
...
...
paddle/
fluid/operators/collective/c_identity_op_xpu.cc
→
paddle/
phi/kernels/c_identity_kernel.h
浏览文件 @
9ed58bff
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2023 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/fluid/operators/collective/c_identity_op.h"
#pragma once
#include "paddle/phi/core/dense_tensor.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
namespace
phi
{
PD_REGISTER_STRUCT_KERNEL
(
c_identity
,
XPU
,
ALL_LAYOUT
,
ops
::
CIdentityOpKernel
,
float
,
double
,
int
,
int64_t
,
plat
::
float16
)
{}
template
<
typename
T
,
typename
Context
>
void
CIdentityKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
ring_id
,
bool
use_calc_stream
,
bool
use_model_parallel
,
DenseTensor
*
out
);
}
// namespace phi
paddle/phi/kernels/cpu/c_identity_kernel.cc
0 → 100644
浏览文件 @
9ed58bff
/* Copyright (c) 2023 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/c_identity_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
CIdentityKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
ring_id
,
bool
use_calc_stream
,
bool
use_model_parallel
,
DenseTensor
*
out
)
{
PADDLE_THROW
(
errors
::
Unavailable
(
"Do not support c_identity for cpu kernel now."
));
}
}
// namespace phi
PD_REGISTER_KERNEL
(
c_identity
,
CPU
,
ALL_LAYOUT
,
phi
::
CIdentityKernel
,
float
,
double
,
int
,
int64_t
,
phi
::
dtype
::
float16
)
{}
paddle/
fluid/operators/collective/c_identity_op.cu.cc
→
paddle/
phi/kernels/gpu/c_identity_kernel.cu
浏览文件 @
9ed58bff
/* Copyright (c) 202
1
PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 202
3
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.
...
...
@@ -12,21 +12,19 @@ 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/fluid/operators/collective/c_identity_op.h"
#include "paddle/phi/kernels/c_identity_kernel.h"
#include "paddle/phi/kernels/impl/c_identity_kernel_impl.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
PD_REGISTER_STRUCT_KERNEL
(
c_identity
,
GPU
,
ALL_LAYOUT
,
ops
::
CIdentityOpKernel
,
float
,
double
,
int
,
int64_t
,
#if NCCL_VERSION_CODE >= 21000 && CUDA_VERSION >= 11000
plat
::
bfloat16
,
#endif
plat
::
float16
)
{
}
PD_REGISTER_KERNEL
(
c_identity
,
GPU
,
ALL_LAYOUT
,
phi
::
CIdentityKernel
,
float
,
double
,
int
,
int64_t
,
phi
::
dtype
::
bfloat16
,
phi
::
dtype
::
float16
)
{}
paddle/phi/kernels/impl/c_identity_kernel_impl.h
0 → 100644
浏览文件 @
9ed58bff
// Copyright (c) 2023 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.
#pragma once
#include "paddle/phi/kernels/c_identity_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
phi
{
template
<
typename
T
,
typename
Context
>
void
CIdentityKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
ring_id
,
bool
use_calc_stream
,
bool
use_model_parallel
,
DenseTensor
*
out
)
{
PADDLE_ENFORCE_GE
(
ring_id
,
0
,
errors
::
InvalidArgument
(
"The ring_id (%d) for c_identity op must be non-negative."
,
ring_id
));
dev_ctx
.
template
Alloc
<
T
>(
out
);
phi
::
Copy
(
dev_ctx
,
x
,
dev_ctx
.
GetPlace
(),
false
,
out
);
}
}
// namespace phi
paddle/phi/kernels/xpu/c_identity_kernel.cc
0 → 100644
浏览文件 @
9ed58bff
/* Copyright (c) 2023 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/c_identity_kernel.h"
#include "paddle/phi/kernels/impl/c_identity_kernel_impl.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
PD_REGISTER_KERNEL
(
c_identity
,
XPU
,
ALL_LAYOUT
,
phi
::
CIdentityKernel
,
float
,
double
,
int
,
int64_t
,
phi
::
dtype
::
float16
)
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录