Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
兽拳
Paddle
提交
712ccfbf
P
Paddle
项目概览
兽拳
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
712ccfbf
编写于
1月 25, 2022
作者:
石
石晓伟
提交者:
GitHub
1月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix custom ops, test=develop (#39153)
上级
f07b8cbe
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
43 addition
and
51 deletion
+43
-51
paddle/pten/api/include/tensor.h
paddle/pten/api/include/tensor.h
+6
-0
paddle/pten/api/lib/tensor.cc
paddle/pten/api/lib/tensor.cc
+14
-6
python/paddle/fluid/tests/custom_op/attr_test_op.cc
python/paddle/fluid/tests/custom_op/attr_test_op.cc
+14
-20
python/paddle/fluid/tests/custom_op/concat_and_split.h
python/paddle/fluid/tests/custom_op/concat_and_split.h
+2
-4
python/paddle/fluid/tests/custom_op/custom_conj_op.cc
python/paddle/fluid/tests/custom_op/custom_conj_op.cc
+1
-3
python/paddle/fluid/tests/custom_op/dispatch_test_op.cc
python/paddle/fluid/tests/custom_op/dispatch_test_op.cc
+6
-18
未找到文件。
paddle/pten/api/include/tensor.h
浏览文件 @
712ccfbf
...
...
@@ -505,6 +505,12 @@ class PADDLE_API Tensor final {
* in the development of new dygraph. It may be removed in the future.
*/
std
::
string
name_
{
""
};
/**
* Place type: Return the expected memory location if the Tensor is
* uninitialized.
*/
PlaceType
place_
{
PlaceType
::
kUNK
};
};
}
// namespace experimental
...
...
paddle/pten/api/lib/tensor.cc
浏览文件 @
712ccfbf
...
...
@@ -78,7 +78,8 @@ Tensor::Tensor(const PlaceType &place)
ConvertExtPlaceToInnerPlace
(
place
))),
std
::
move
(
pten
::
DenseTensorMeta
(
pten
::
DataType
::
UNDEFINED
,
framework
::
make_ddim
({}),
pten
::
DataLayout
::
NCHW
)))))
{}
pten
::
DataLayout
::
NCHW
))))),
place_
{
place
}
{}
Tensor
::
Tensor
(
const
PlaceType
&
place
,
const
std
::
vector
<
int64_t
>
&
shape
)
:
impl_
(
std
::
move
(
std
::
make_shared
<
pten
::
DenseTensor
>
(
...
...
@@ -86,7 +87,8 @@ Tensor::Tensor(const PlaceType &place, const std::vector<int64_t> &shape)
ConvertExtPlaceToInnerPlace
(
place
))),
std
::
move
(
pten
::
DenseTensorMeta
(
pten
::
DataType
::
UNDEFINED
,
framework
::
make_ddim
(
shape
),
pten
::
DataLayout
::
NCHW
)))))
{}
pten
::
DataLayout
::
NCHW
))))),
place_
{
place
}
{}
/* Part 2: Dimension, DataType and DataLayout methods */
...
...
@@ -131,17 +133,23 @@ bool Tensor::is_dense_tensor() const {
/* Part 3: Device and Backend methods */
PlaceType
Tensor
::
place
()
const
{
if
(
!
impl_
->
initialized
())
{
return
place_
;
}
else
{
return
ConvertInnerPlaceToExtPlace
(
impl_
->
place
());
}
}
paddle
::
platform
::
Place
Tensor
::
inner_place
()
const
{
return
impl_
->
place
();
}
paddle
::
platform
::
Place
Tensor
::
inner_place
()
const
{
return
ConvertExtPlaceToInnerPlace
(
place
());
}
bool
Tensor
::
is_cpu
()
const
{
return
paddle
::
platform
::
is_cpu_place
(
i
mpl_
->
place
());
return
paddle
::
platform
::
is_cpu_place
(
i
nner_
place
());
}
bool
Tensor
::
is_cuda
()
const
{
return
paddle
::
platform
::
is_gpu_place
(
i
mpl_
->
place
());
return
paddle
::
platform
::
is_gpu_place
(
i
nner_
place
());
}
/* Part 4: Data Access methods */
...
...
python/paddle/fluid/tests/custom_op/attr_test_op.cc
浏览文件 @
712ccfbf
...
...
@@ -137,9 +137,7 @@ std::vector<paddle::Tensor> AttrTestForward(
PD_DISPATCH_FLOATING_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
// Check attrs value
...
...
@@ -177,11 +175,10 @@ std::vector<paddle::Tensor> AttrTestBackward(
const
std
::
vector
<
std
::
string
>&
str_vec_attr
)
{
auto
grad_x
=
paddle
::
Tensor
(
paddle
::
PlaceType
::
kCPU
,
grad_out
.
shape
());
PD_DISPATCH_FLOATING_TYPES
(
grad_out
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
PD_DISPATCH_FLOATING_TYPES
(
grad_out
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
grad_out
.
data
<
data_t
>
(),
grad_x
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
grad_x
.
mutable_data
<
data_t
>
(
),
grad_out
.
size
());
}));
...
...
@@ -206,9 +203,7 @@ std::vector<paddle::Tensor> ConstAttrTestForward(
PD_DISPATCH_FLOATING_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
// Check attrs value
...
...
@@ -246,11 +241,10 @@ std::vector<paddle::Tensor> ConstAttrTestBackward(
const
std
::
vector
<
std
::
string
>&
str_vec_attr
)
{
auto
grad_x
=
paddle
::
Tensor
(
paddle
::
PlaceType
::
kCPU
,
grad_out
.
shape
());
PD_DISPATCH_FLOATING_TYPES
(
grad_out
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
PD_DISPATCH_FLOATING_TYPES
(
grad_out
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
grad_out
.
data
<
data_t
>
(),
grad_x
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
grad_x
.
mutable_data
<
data_t
>
(
),
grad_out
.
size
());
}));
...
...
python/paddle/fluid/tests/custom_op/concat_and_split.h
浏览文件 @
712ccfbf
...
...
@@ -47,7 +47,7 @@ void ConcatCpuKernel(const std::vector<paddle::Tensor>& ins,
int64_t
out_cols
=
0
;
auto
ins_cols
=
GetCols
(
ins
,
out_rows
,
&
out_cols
);
auto
*
out_data
=
out
->
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
);
auto
*
out_data
=
out
->
mutable_data
<
data_t
>
();
int64_t
col_idx
=
0
;
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
int64_t
col_len
=
ins_cols
[
i
];
...
...
@@ -76,9 +76,7 @@ void SplitCpuKernel(const paddle::Tensor& in,
int64_t
col_idx
=
0
;
for
(
size_t
j
=
0
;
j
<
num
;
++
j
)
{
int64_t
col_len
=
out_cols
[
j
];
auto
*
out_data
=
outs
->
at
(
j
).
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
)
+
i
*
col_len
;
auto
*
out_data
=
outs
->
at
(
j
).
mutable_data
<
data_t
>
()
+
i
*
col_len
;
std
::
memcpy
(
out_data
,
in_data
+
col_idx
,
sizeof
(
data_t
)
*
col_len
);
col_idx
+=
col_len
;
}
...
...
python/paddle/fluid/tests/custom_op/custom_conj_op.cc
浏览文件 @
712ccfbf
...
...
@@ -76,9 +76,7 @@ std::vector<paddle::Tensor> ConjFunction(const paddle::Tensor& x) {
PD_DISPATCH_FLOATING_AND_COMPLEX_TYPES
(
x
.
type
(),
"ConjCPUKernel"
,
([
&
]
{
ConjCPUKernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
x
.
size
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
));
x
.
data
<
data_t
>
(),
x
.
size
(),
out
.
mutable_data
<
data_t
>
());
}));
return
{
out
};
...
...
python/paddle/fluid/tests/custom_op/dispatch_test_op.cc
浏览文件 @
712ccfbf
...
...
@@ -32,9 +32,7 @@ std::vector<paddle::Tensor> DispatchTestInterger(const paddle::Tensor& x) {
PD_DISPATCH_INTEGRAL_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
@@ -52,9 +50,7 @@ std::vector<paddle::Tensor> DispatchTestFloatAndInteger(
PD_DISPATCH_FLOATING_AND_INTEGRAL_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
@@ -71,9 +67,7 @@ std::vector<paddle::Tensor> DispatchTestComplex(const paddle::Tensor& x) {
PD_DISPATCH_COMPLEX_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
@@ -91,9 +85,7 @@ std::vector<paddle::Tensor> DispatchTestFloatAndComplex(
PD_DISPATCH_FLOATING_AND_COMPLEX_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
@@ -111,9 +103,7 @@ std::vector<paddle::Tensor> DispatchTestFloatAndIntegerAndComplex(
PD_DISPATCH_FLOATING_AND_INTEGRAL_AND_COMPLEX_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
@@ -130,9 +120,7 @@ std::vector<paddle::Tensor> DispatchTestFloatAndHalf(const paddle::Tensor& x) {
PD_DISPATCH_FLOATING_AND_HALF_TYPES
(
x
.
type
(),
"assign_cpu_kernel"
,
([
&
]
{
assign_cpu_kernel
<
data_t
>
(
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(
paddle
::
PlaceType
::
kCPU
),
x
.
size
());
x
.
data
<
data_t
>
(),
out
.
mutable_data
<
data_t
>
(),
x
.
size
());
}));
return
{
out
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录