Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
4d536678
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看板
未验证
提交
4d536678
编写于
11月 12, 2021
作者:
石
石晓伟
提交者:
GitHub
11月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust the COLUMNS=128; (#37120)
上级
9396f286
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
10 deletion
+49
-10
paddle/pten/api/lib/utils/storage.h
paddle/pten/api/lib/utils/storage.h
+11
-1
paddle/pten/core/allocator.h
paddle/pten/core/allocator.h
+4
-5
paddle/pten/core/dense_tensor.cc
paddle/pten/core/dense_tensor.cc
+14
-0
paddle/pten/core/dense_tensor.h
paddle/pten/core/dense_tensor.h
+9
-3
paddle/pten/core/storage.h
paddle/pten/core/storage.h
+8
-0
paddle/pten/tests/core/test_dense_tensor.cc
paddle/pten/tests/core/test_dense_tensor.cc
+3
-1
未找到文件。
paddle/pten/api/lib/utils/storage.h
浏览文件 @
4d536678
...
...
@@ -34,6 +34,11 @@ class ExternalStorage : public pten::Storage {
"The external shared storage cannot be reallocated."
));
}
void
Clear
()
override
{
data_
.
Clear
();
size_
=
0
;
}
size_t
size
()
const
noexcept
override
{
return
size_
;
}
const
paddle
::
platform
::
Place
&
place
()
const
override
{
return
data_
.
place
();
...
...
@@ -41,7 +46,7 @@ class ExternalStorage : public pten::Storage {
bool
OwnsMemory
()
const
noexcept
override
{
return
false
;
}
private:
const
int64_t
size_
{
0
};
int64_t
size_
{
0
};
};
class
SharedStorage
:
public
pten
::
Storage
{
...
...
@@ -65,6 +70,11 @@ class SharedStorage : public pten::Storage {
"The external shared storage cannot be reallocated."
));
}
void
Clear
()
override
{
data_
.
Clear
();
size_
=
0
;
}
size_t
size
()
const
noexcept
override
{
return
size_
;
}
const
paddle
::
platform
::
Place
&
place
()
const
override
{
return
data_
.
place
();
...
...
paddle/pten/core/allocator.h
浏览文件 @
4d536678
...
...
@@ -73,9 +73,9 @@ class Allocation final {
operator
bool
()
const
noexcept
{
return
data_
||
ctx_
.
Get
();
}
const
Place
&
place
()
const
noexcept
{
return
place_
;
}
void
Clear
()
noexcept
{
data_
=
nullptr
;
void
Clear
()
{
ctx_
.
Clear
();
data_
=
nullptr
;
}
/// \brief Statically cast the void pointer of the context object to
...
...
@@ -107,12 +107,11 @@ class Allocation final {
swap
(
*
this
,
other
);
return
*
this
;
}
~
Context
()
{
~
Context
()
{
Clear
();
}
void
Clear
()
{
if
(
deleter_
)
{
deleter_
(
ctx_
);
}
}
void
Clear
()
noexcept
{
ctx_
=
nullptr
;
deleter_
=
nullptr
;
}
...
...
paddle/pten/core/dense_tensor.cc
浏览文件 @
4d536678
...
...
@@ -113,6 +113,20 @@ void DenseTensor::check_memory_size() const {
bytes
));
}
void
DenseTensor
::
Resize
(
const
DDim
&
dims
)
{
if
(
product
(
dims
)
==
product
(
meta_
.
dims
))
{
set_dims
(
dims
);
}
else
{
meta_
.
dims
=
dims
;
storage_
->
Clear
();
}
}
void
DenseTensor
::
set_dims
(
const
DDim
&
dims
)
{
CHECK
(
product
(
dims
)
==
product
(
meta_
.
dims
));
meta_
.
dims
=
dims
;
}
#define DATA_MEMBER_FUNC_INSTANTIATION(dtype) \
template dtype* DenseTensor::mutable_data(); \
template const dtype* DenseTensor::data() const;
...
...
paddle/pten/core/dense_tensor.h
浏览文件 @
4d536678
...
...
@@ -119,10 +119,16 @@ class DenseTensor : public TensorBase,
/// \return Whether the storage is shared with other objects.
bool
IsSharedWith
(
const
DenseTensor
&
b
)
const
;
/// \brief Change the dims information in the metadata, and the corresponding
/// memory allocation will occur when the `mutable_data` is called.
/// \brief Change the dims information in the metadata. If the new size is
/// inconsistent with the original value, the storage area will be released
/// to avoid wrong access.
/// \param dims The new dims of the dense tensor.
void
Resize
(
const
DDim
&
dims
)
noexcept
{
meta_
.
dims
=
dims
;
}
void
Resize
(
const
DDim
&
dims
);
/// \brief Change the dims information in the metadata.
/// \param dims The new dims of the dense tensor. The product of the dims
/// elements must be consistent with the original value.
void
set_dims
(
const
DDim
&
dims
);
/// \brief Returns the actual storage size occupied by tensor, may be larger
/// than its shape dims.
...
...
paddle/pten/core/storage.h
浏览文件 @
4d536678
...
...
@@ -44,6 +44,8 @@ class Storage : public intrusive_ref_counter<Storage> {
/// \return The mutable data pointer of the storage.
void
*
data
()
const
noexcept
{
return
data_
.
operator
->
();
}
virtual
void
Clear
()
=
0
;
virtual
size_t
size
()
const
=
0
;
virtual
const
Place
&
place
()
const
=
0
;
virtual
bool
OwnsMemory
()
const
=
0
;
...
...
@@ -68,6 +70,12 @@ class TensorStorage : public Storage {
void
Realloc
(
size_t
size
)
override
;
size_t
size
()
const
noexcept
override
{
return
size_
;
}
void
Clear
()
override
{
data_
.
Clear
();
size_
=
0
;
}
const
Place
&
place
()
const
override
{
return
data_
.
place
();
}
bool
OwnsMemory
()
const
noexcept
override
{
return
true
;
}
const
std
::
shared_ptr
<
Allocator
>&
allocator
()
const
noexcept
{
...
...
paddle/pten/tests/core/test_dense_tensor.cc
浏览文件 @
4d536678
...
...
@@ -115,7 +115,9 @@ TEST(dense_tensor, resize) {
CHECK_EQ
(
tensor_0
.
memory_size
(),
2u
);
tensor_0
.
check_memory_size
();
tensor_0
.
Resize
({
1
,
2
,
3
});
CHECK_EQ
(
tensor_0
.
memory_size
(),
2u
);
CHECK_EQ
(
tensor_0
.
memory_size
(),
0u
);
tensor_0
.
set_dims
({
2
,
3
});
CHECK_EQ
(
tensor_0
.
memory_size
(),
0u
);
tensor_0
.
mutable_data
<
int8_t
>
();
CHECK_EQ
(
tensor_0
.
memory_size
(),
6u
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录