Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
c5ccff73
P
Paddle
项目概览
OPTHREE
/
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,发现更多精彩内容 >>
未验证
提交
c5ccff73
编写于
11月 16, 2021
作者:
石
石晓伟
提交者:
GitHub
11月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
supports the slice of upper tensor, test=develop (#37215)
上级
f49c2c23
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
22 deletion
+35
-22
paddle/pten/core/compat_utils.h
paddle/pten/core/compat_utils.h
+33
-0
paddle/pten/core/dense_tensor.h
paddle/pten/core/dense_tensor.h
+0
-6
paddle/pten/core/tensor_meta.h
paddle/pten/core/tensor_meta.h
+2
-1
paddle/pten/tests/core/test_dense_tensor.cc
paddle/pten/tests/core/test_dense_tensor.cc
+0
-15
未找到文件。
paddle/pten/core/compat_utils.h
浏览文件 @
c5ccff73
...
...
@@ -45,6 +45,39 @@ class CompatibleDenseTensorUtils {
static_cast
<
paddle
::
experimental
::
SharedStorage
*>
(
tensor
->
storage_
.
get
())
->
Reset
();
}
static
DenseTensor
Slice
(
DenseTensor
*
tensor
,
int64_t
begin_idx
,
int64_t
end_idx
)
{
tensor
->
check_memory_size
();
PADDLE_ENFORCE_GE
(
begin_idx
,
0
,
paddle
::
platform
::
errors
::
OutOfRange
(
"The start row index must be greater than 0."
"But received the start index is d%."
,
begin_idx
));
PADDLE_ENFORCE_LE
(
end_idx
,
tensor
->
dims
()[
0
],
paddle
::
platform
::
errors
::
OutOfRange
(
"The end row index is out of bound."
));
PADDLE_ENFORCE_LT
(
begin_idx
,
end_idx
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The start row index must be less than the end row index."
"But received the start index = %d, the end index = %d."
,
begin_idx
,
end_idx
));
DenseTensor
ret
=
DenseTensor
(
copy_intrusive
(
tensor
->
storage_
),
tensor
->
meta_
);
if
(
tensor
->
dims
()[
0
]
!=
1
)
{
ret
.
meta_
.
dims
[
0
]
=
end_idx
-
begin_idx
;
ret
.
meta_
.
offset
=
tensor
->
meta_
.
offset
+
begin_idx
*
(
tensor
->
numel
()
/
tensor
->
dims
()[
0
])
*
paddle
::
experimental
::
SizeOf
(
tensor
->
data_type
());
}
return
ret
;
}
};
}
// namespace pten
paddle/pten/core/dense_tensor.h
浏览文件 @
c5ccff73
...
...
@@ -174,12 +174,6 @@ class DenseTensor : public TensorBase,
/// \return The const data pointer value of raw type.
const
void
*
data
()
const
;
/// \brief Get the shallow clone of current tensor.
/// \return The shallow clone of current tensor.
DenseTensor
shallow_clone
()
const
{
return
DenseTensor
(
copy_intrusive
(
storage_
),
meta_
);
}
private:
friend
class
CompatibleDenseTensorUtils
;
...
...
paddle/pten/core/tensor_meta.h
浏览文件 @
c5ccff73
...
...
@@ -57,6 +57,7 @@ struct DenseTensorMeta {
const
DataType
type
{
DataType
::
UNDEFINED
};
const
DataLayout
layout
{
DataLayout
::
NCHW
};
LoD
lod
;
size_t
offset
{
0
};
};
inline
DenseTensorMeta
::
DenseTensorMeta
(
DataType
type
,
const
DDim
&
dims
)
...
...
@@ -86,7 +87,7 @@ inline bool operator==(const DenseTensorMeta& lhs, const DenseTensorMeta& rhs) {
bool
ret
=
true
;
return
ret
&&
(
lhs
.
is_scalar
==
rhs
.
is_scalar
)
&&
(
lhs
.
dims
==
rhs
.
dims
)
&&
(
lhs
.
type
==
rhs
.
type
)
&&
(
lhs
.
layout
==
rhs
.
layout
)
&&
(
lhs
.
lod
==
rhs
.
lod
);
(
lhs
.
lod
==
rhs
.
lod
)
&&
(
lhs
.
offset
==
rhs
.
offset
)
;
}
}
// namespace pten
paddle/pten/tests/core/test_dense_tensor.cc
浏览文件 @
c5ccff73
...
...
@@ -125,20 +125,5 @@ TEST(dense_tensor, resize) {
CHECK_EQ
(
storage
->
size
(),
6u
);
}
TEST
(
dense_tensor
,
shallow_clone
)
{
const
DDim
dims
({
1
,
2
});
const
DataType
dtype
{
DataType
::
INT8
};
const
DataLayout
layout
{
DataLayout
::
NHWC
};
const
std
::
vector
<
std
::
vector
<
size_t
>>
lod
{};
DenseTensorMeta
meta
(
dtype
,
dims
,
layout
,
lod
);
auto
alloc
=
std
::
make_shared
<
FancyAllocator
>
();
DenseTensor
tensor_0
(
alloc
,
meta
);
auto
tensor_1
=
tensor_0
.
shallow_clone
();
CHECK
(
tensor_0
.
meta
()
==
tensor_1
.
meta
());
CHECK
(
tensor_0
.
release
()
==
tensor_1
.
release
());
}
}
// namespace tests
}
// namespace pten
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录