Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
94cf213d
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看板
提交
94cf213d
编写于
2月 01, 2023
作者:
D
DesmonDay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix reference count
上级
d7d490e4
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
14 addition
and
3 deletion
+14
-3
paddle/fluid/framework/dlpack_tensor.cc
paddle/fluid/framework/dlpack_tensor.cc
+9
-2
paddle/fluid/framework/dlpack_tensor.h
paddle/fluid/framework/dlpack_tensor.h
+3
-1
paddle/fluid/pybind/tensor.cc
paddle/fluid/pybind/tensor.cc
+2
-0
未找到文件。
paddle/fluid/framework/dlpack_tensor.cc
浏览文件 @
94cf213d
...
...
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/framework/dlpack_tensor.h"
#include "pybind11/pybind11.h"
#include "paddle/fluid/framework/convert_utils.h"
#include "paddle/fluid/framework/data_type.h"
...
...
@@ -134,8 +135,9 @@ struct DLDeviceVisitor
};
}
// namespace internal
DLPackTensor
::
DLPackTensor
(
const
phi
::
DenseTensor
&
tensor
,
LaneType
lanes
)
{
DLPackTensor
::
DLPackTensor
(
phi
::
DenseTensor
&
tensor
,
LaneType
lanes
)
{
// init data, data buffer
dt_
=
&
tensor
;
t_
.
data
=
const_cast
<
void
*>
(
tensor
.
data
());
// init device, DLDevice type with device_type and device_id
...
...
@@ -188,12 +190,17 @@ DLPackTensor::DLPackTensor(const phi::DenseTensor &tensor, LaneType lanes) {
tensor
->
dl_tensor
=
t_
;
tensor
->
deleter
=
[](
DLManagedTensor
*
arg
)
{
phi
::
DenseTensor
*
tensor_ptr
=
reinterpret_cast
<
phi
::
DenseTensor
*>
(
arg
->
manager_ctx
);
pybind11
::
handle
tensor_handle
=
pybind11
::
cast
(
tensor_ptr
);
tensor_handle
.
dec_ref
();
delete
[]
arg
->
dl_tensor
.
shape
;
delete
[]
arg
->
dl_tensor
.
strides
;
delete
arg
;
};
tensor
->
manager_ctx
=
nullptr
;
tensor
->
manager_ctx
=
dt_
;
return
tensor
;
}
...
...
paddle/fluid/framework/dlpack_tensor.h
浏览文件 @
94cf213d
...
...
@@ -28,7 +28,7 @@ class DLPackTensor {
std
::
remove_reference
<
decltype
(
::
DLTensor
::
shape
[
0
])
>::
type
;
// int64_t
// lanes is only used in CPU to enable vectorization
explicit
DLPackTensor
(
const
phi
::
DenseTensor
&
tensor
,
LaneType
lanes
=
1
);
explicit
DLPackTensor
(
phi
::
DenseTensor
&
tensor
,
LaneType
lanes
=
1
);
inline
operator
const
::
DLTensor
&
()
const
{
return
t_
;
}
...
...
@@ -42,6 +42,8 @@ class DLPackTensor {
// The shape in DLTensor is defined as int64_t*
// Add this member to make TVMTensor init without heap allocation
ShapeType
shape_
[
DDim
::
kMaxRank
];
phi
::
DenseTensor
*
dt_
;
};
}
// namespace framework
...
...
paddle/fluid/pybind/tensor.cc
浏览文件 @
94cf213d
...
...
@@ -474,6 +474,8 @@ void BindTensor(pybind11::module &m) { // NOLINT
.
def
(
"_to_dlpack"
,
[](
phi
::
DenseTensor
&
self
)
{
DLPackTensor
dlpack_tensor
(
self
,
1
);
pybind11
::
handle
tensor_handle
=
pybind11
::
cast
(
&
self
);
tensor_handle
.
inc_ref
();
DLManagedTensor
*
dmt
=
dlpack_tensor
.
ToDLManagedTensor
();
auto
capsule
=
pybind11
::
capsule
(
static_cast
<
void
*>
(
dmt
),
"dltensor"
,
[](
PyObject
*
ptr
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录