Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3d3bc681
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3d3bc681
编写于
1月 06, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
1月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[PTen]Move manipulation mid to new directory and rename flatten/reshape kernel (#38730)
* move mid api and rename kernel * use empty kernel
上级
ee813e34
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
74 addition
and
94 deletion
+74
-94
paddle/fluid/operators/cast_op.h
paddle/fluid/operators/cast_op.h
+1
-1
paddle/fluid/operators/flatten_op.h
paddle/fluid/operators/flatten_op.h
+3
-3
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+4
-4
paddle/pten/all.h
paddle/pten/all.h
+0
-1
paddle/pten/include/manipulation.h
paddle/pten/include/manipulation.h
+0
-53
paddle/pten/kernels/flatten_kernel.cc
paddle/pten/kernels/flatten_kernel.cc
+9
-9
paddle/pten/kernels/flatten_kernel.h
paddle/pten/kernels/flatten_kernel.h
+18
-5
paddle/pten/kernels/reshape_kernel.cc
paddle/pten/kernels/reshape_kernel.cc
+20
-11
paddle/pten/kernels/reshape_kernel.h
paddle/pten/kernels/reshape_kernel.h
+16
-4
paddle/pten/tests/kernels/test_cast_dev_api.cc
paddle/pten/tests/kernels/test_cast_dev_api.cc
+1
-1
paddle/pten/tests/kernels/test_flatten_dev_api.cc
paddle/pten/tests/kernels/test_flatten_dev_api.cc
+1
-1
paddle/pten/tests/kernels/test_reshape_dev_api.cc
paddle/pten/tests/kernels/test_reshape_dev_api.cc
+1
-1
未找到文件。
paddle/fluid/operators/cast_op.h
浏览文件 @
3d3bc681
...
...
@@ -20,7 +20,7 @@ limitations under the License. */
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/cast_kernel
.h"
namespace
paddle
{
namespace
operators
{
...
...
paddle/fluid/operators/flatten_op.h
浏览文件 @
3d3bc681
...
...
@@ -21,7 +21,7 @@ limitations under the License. */
#include "paddle/fluid/operators/math/pooling.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/flatten_kernel
.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -134,8 +134,8 @@ class FlattenContiguousRangeKernel : public framework::OpKernel<T> {
auto
pt_out
=
paddle
::
experimental
::
MakePtenDenseTensor
(
*
out
);
// call new kernel
pten
::
Flatten
<
T
,
DeviceContext
>
(
dev_ctx
,
*
pt_x
.
get
(),
start_axis
,
stop
_axis
,
pt_out
.
get
());
pten
::
Flatten
Kernel
<
T
,
DeviceContext
>
(
dev_ctx
,
*
pt_x
.
get
(),
start
_axis
,
stop_axis
,
pt_out
.
get
());
}
};
...
...
paddle/fluid/operators/reshape_op.cc
浏览文件 @
3d3bc681
...
...
@@ -21,7 +21,7 @@ limitations under the License. */
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/common/scalar_array.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/reshape_kernel
.h"
namespace
paddle
{
namespace
framework
{
class
InferShapeContext
;
...
...
@@ -438,18 +438,18 @@ class ReshapeKernel {
}
if
(
platform
::
is_cpu_place
(
ctx
.
GetPlace
()))
{
auto
&
dev_ctx
=
ctx
.
device_context
<
platform
::
CPUDeviceContext
>
();
pten
::
Reshape
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
pten
::
Reshape
Kernel
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()))
{
auto
&
dev_ctx
=
ctx
.
device_context
<
platform
::
CUDADeviceContext
>
();
pten
::
Reshape
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
pten
::
Reshape
Kernel
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
}
#endif
#ifdef PADDLE_WITH_XPU
if
(
platform
::
is_xpu_place
(
ctx
.
GetPlace
()))
{
auto
&
dev_ctx
=
ctx
.
device_context
<
platform
::
XPUDeviceContext
>
();
pten
::
Reshape
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
pten
::
Reshape
Kernel
(
dev_ctx
,
*
pt_x
.
get
(),
pt_scalar_shape
,
pt_out
);
}
#endif
// non-inplace need move all result from pt_out to out, inplace need set
...
...
paddle/pten/all.h
浏览文件 @
3d3bc681
...
...
@@ -18,5 +18,4 @@ limitations under the License. */
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/include/linalg.h"
#include "paddle/pten/include/manipulation.h"
#include "paddle/pten/include/math.h"
paddle/pten/include/manipulation.h
已删除
100644 → 0
浏览文件 @
ee813e34
// 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
// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/cast_kernel.h"
#include "paddle/pten/kernels/flatten_kernel.h"
#include "paddle/pten/kernels/reshape_kernel.h"
namespace
pten
{
template
<
typename
T
,
typename
ContextT
>
DenseTensor
Flatten
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
)
{
auto
out_meta
=
FlattenInferMeta
(
x
.
meta
(),
start_axis
,
stop_axis
);
pten
::
DenseTensor
dense_out
(
pten
::
make_intrusive
<
paddle
::
experimental
::
SharedStorage
>
(
dev_ctx
.
GetPlace
()),
std
::
move
(
out_meta
));
Flatten
<
T
,
ContextT
>
(
dev_ctx
,
x
,
start_axis
,
stop_axis
,
&
dense_out
);
return
dense_out
;
}
template
<
typename
T
,
typename
ContextT
>
DenseTensor
Reshape
(
const
ContextT
&
dev_ctx
,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
)
{
auto
out_meta
=
InferMetaFromVecValue
(
x
.
meta
(),
shape
);
pten
::
DenseTensor
dense_out
(
pten
::
make_intrusive
<
paddle
::
experimental
::
SharedStorage
>
(
dev_ctx
.
GetPlace
()),
std
::
move
(
out_meta
));
Reshape
<
ContextT
>
(
dev_ctx
,
x
,
ScalarArray
(
shape
),
&
dense_out
);
return
dense_out
;
}
}
// namespace pten
paddle/pten/kernels/flatten_kernel.cc
浏览文件 @
3d3bc681
...
...
@@ -22,11 +22,11 @@
namespace
pten
{
template
<
typename
T
,
typename
Context
>
void
Flatten
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
,
DenseTensor
*
out
)
{
void
Flatten
Kernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
,
DenseTensor
*
out
)
{
auto
out_dims
=
out
->
dims
();
pten
::
Copy
(
dev_ctx
,
x
,
false
,
out
);
out
->
Resize
(
out_dims
);
...
...
@@ -42,7 +42,7 @@ void FlattenWithXShape(const Context& dev_ctx,
int
stop_axis
,
DenseTensor
*
out
,
DenseTensor
*
xshape
)
{
Flatten
<
T
,
Context
>
(
dev_ctx
,
x
,
start_axis
,
stop_axis
,
out
);
Flatten
Kernel
<
T
,
Context
>
(
dev_ctx
,
x
,
start_axis
,
stop_axis
,
out
);
funcs
::
SetXShape
(
x
,
xshape
);
}
...
...
@@ -51,7 +51,7 @@ void FlattenWithXShape(const Context& dev_ctx,
PT_REGISTER_CTX_KERNEL
(
flatten
,
CPU
,
ALL_LAYOUT
,
pten
::
Flatten
,
pten
::
Flatten
Kernel
,
float
,
double
,
uint8_t
,
...
...
@@ -74,7 +74,7 @@ PT_REGISTER_CTX_KERNEL(flatten_with_xshape,
PT_REGISTER_CTX_KERNEL
(
flatten
,
GPU
,
ALL_LAYOUT
,
pten
::
Flatten
,
pten
::
Flatten
Kernel
,
float
,
paddle
::
platform
::
float16
,
double
,
...
...
@@ -100,7 +100,7 @@ PT_REGISTER_CTX_KERNEL(flatten_with_xshape,
PT_REGISTER_CTX_KERNEL
(
flatten
,
XPU
,
ALL_LAYOUT
,
pten
::
Flatten
,
pten
::
Flatten
Kernel
,
float
,
paddle
::
platform
::
float16
,
double
,
...
...
paddle/pten/kernels/flatten_kernel.h
浏览文件 @
3d3bc681
...
...
@@ -15,15 +15,17 @@ limitations under the License. */
#pragma once
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/empty_kernel.h"
namespace
pten
{
template
<
typename
T
,
typename
Context
>
void
Flatten
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
,
DenseTensor
*
out
);
void
Flatten
Kernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
void
FlattenWithXShape
(
const
Context
&
dev_ctx
,
...
...
@@ -33,4 +35,15 @@ void FlattenWithXShape(const Context& dev_ctx,
DenseTensor
*
out
,
DenseTensor
*
xshape
);
template
<
typename
T
,
typename
Context
>
DenseTensor
Flatten
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
int
start_axis
,
int
stop_axis
)
{
auto
out_meta
=
FlattenInferMeta
(
x
.
meta
(),
start_axis
,
stop_axis
);
auto
dense_out
=
Empty
<
T
,
Context
>
(
dev_ctx
,
std
::
move
(
out_meta
));
FlattenKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
start_axis
,
stop_axis
,
&
dense_out
);
return
dense_out
;
}
}
// namespace pten
paddle/pten/kernels/reshape_kernel.cc
浏览文件 @
3d3bc681
...
...
@@ -22,10 +22,10 @@
namespace
pten
{
template
<
typename
Context
>
void
Reshape
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
ScalarArray
&
shape
,
DenseTensor
*
out
)
{
void
Reshape
Kernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
ScalarArray
&
shape
,
DenseTensor
*
out
)
{
auto
out_meta
=
InferMetaFromVecValue
(
x
.
meta
(),
shape
.
GetData
());
if
(
x
.
data
()
==
out
->
data
()
&&
x
.
numel
()
==
out
->
numel
())
{
out
->
Resize
(
out_meta
.
dims
);
...
...
@@ -43,13 +43,16 @@ void ReshapeWithXShape(const Context& dev_ctx,
DenseTensor
*
xshape
,
DenseTensor
*
out
)
{
funcs
::
SetXShape
(
x
,
xshape
);
Reshape
(
dev_ctx
,
x
,
shape
,
out
);
Reshape
Kernel
(
dev_ctx
,
x
,
shape
,
out
);
}
}
// namespace pten
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
CPU
,
ALL_LAYOUT
,
pten
::
Reshape
<
pten
::
CPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
CPU
,
ALL_LAYOUT
,
pten
::
ReshapeKernel
<
pten
::
CPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape_with_xshape
,
CPU
,
ALL_LAYOUT
,
...
...
@@ -57,8 +60,11 @@ PT_REGISTER_GENERAL_KERNEL(reshape_with_xshape,
ALL_DTYPE
)
{}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
GPU
,
ALL_LAYOUT
,
pten
::
Reshape
<
pten
::
GPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
GPU
,
ALL_LAYOUT
,
pten
::
ReshapeKernel
<
pten
::
GPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape_with_xshape
,
GPU
,
ALL_LAYOUT
,
...
...
@@ -67,8 +73,11 @@ PT_REGISTER_GENERAL_KERNEL(reshape_with_xshape,
#endif
#ifdef PADDLE_WITH_XPU
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
XPU
,
ALL_LAYOUT
,
pten
::
Reshape
<
pten
::
XPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape
,
XPU
,
ALL_LAYOUT
,
pten
::
ReshapeKernel
<
pten
::
XPUContext
>
,
ALL_DTYPE
)
{}
PT_REGISTER_GENERAL_KERNEL
(
reshape_with_xshape
,
XPU
,
ALL_LAYOUT
,
...
...
paddle/pten/kernels/reshape_kernel.h
浏览文件 @
3d3bc681
...
...
@@ -16,14 +16,16 @@ limitations under the License. */
#include "paddle/pten/common/scalar_array.h"
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/include/infermeta.h"
#include "paddle/pten/kernels/empty_kernel.h"
namespace
pten
{
template
<
typename
Context
>
void
Reshape
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
ScalarArray
&
shape
,
DenseTensor
*
out
);
void
Reshape
Kernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
ScalarArray
&
shape
,
DenseTensor
*
out
);
template
<
typename
Context
>
void
ReshapeWithXShape
(
const
Context
&
dev_ctx
,
...
...
@@ -32,4 +34,14 @@ void ReshapeWithXShape(const Context& dev_ctx,
DenseTensor
*
xshape
,
DenseTensor
*
out
);
template
<
typename
T
,
typename
Context
>
DenseTensor
Reshape
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
std
::
vector
<
int64_t
>&
shape
)
{
auto
out_meta
=
InferMetaFromVecValue
(
x
.
meta
(),
shape
);
auto
dense_out
=
Empty
<
T
,
Context
>
(
dev_ctx
,
std
::
move
(
out_meta
));
ReshapeKernel
<
Context
>
(
dev_ctx
,
x
,
ScalarArray
(
shape
),
&
dense_out
);
return
dense_out
;
}
}
// namespace pten
paddle/pten/tests/kernels/test_cast_dev_api.cc
浏览文件 @
3d3bc681
...
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include <gtest/gtest.h>
#include <memory>
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/cast_kernel
.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/common/data_type.h"
...
...
paddle/pten/tests/kernels/test_flatten_dev_api.cc
浏览文件 @
3d3bc681
...
...
@@ -15,7 +15,7 @@ limitations under the License. */
#include <gtest/gtest.h>
#include <memory>
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/flatten_kernel
.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/core/dense_tensor.h"
...
...
paddle/pten/tests/kernels/test_reshape_dev_api.cc
浏览文件 @
3d3bc681
...
...
@@ -15,7 +15,7 @@ limitations under the License. */
#include <gtest/gtest.h>
#include <memory>
#include "paddle/pten/
include/manipulation
.h"
#include "paddle/pten/
kernels/reshape_kernel
.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/core/dense_tensor.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录