Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5c95e5c8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5c95e5c8
编写于
9月 06, 2022
作者:
O
OccupyMars2025
提交者:
GitHub
9月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
take some notes about sparse API (#45720)
上级
23def396
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
13 deletion
+13
-13
paddle/fluid/pybind/eager_functions.cc
paddle/fluid/pybind/eager_functions.cc
+3
-3
paddle/fluid/pybind/eager_utils.cc
paddle/fluid/pybind/eager_utils.cc
+5
-5
paddle/phi/api/include/tensor.h
paddle/phi/api/include/tensor.h
+1
-1
paddle/phi/core/dense_tensor.h
paddle/phi/core/dense_tensor.h
+1
-1
paddle/phi/core/tensor_base.h
paddle/phi/core/tensor_base.h
+3
-3
未找到文件。
paddle/fluid/pybind/eager_functions.cc
浏览文件 @
5c95e5c8
...
@@ -523,8 +523,8 @@ static PyObject* eager_api_sparse_coo_tensor(PyObject* self,
...
@@ -523,8 +523,8 @@ static PyObject* eager_api_sparse_coo_tensor(PyObject* self,
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
non_zero_indices
.
impl
());
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
non_zero_indices
.
impl
());
auto
dense_elements
=
auto
dense_elements
=
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
non_zero_elements
.
impl
());
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
non_zero_elements
.
impl
());
// TODO(zhangkaihuo): After creat
e SparseTensor, call coalesced() to sort and
// TODO(zhangkaihuo): After creat
ing SparseCooTensor, call coalesced() to sort
// merge duplicate indices
//
and
merge duplicate indices
std
::
shared_ptr
<
phi
::
SparseCooTensor
>
coo_tensor
=
std
::
shared_ptr
<
phi
::
SparseCooTensor
>
coo_tensor
=
std
::
make_shared
<
phi
::
SparseCooTensor
>
(
std
::
make_shared
<
phi
::
SparseCooTensor
>
(
*
dense_indices
,
*
dense_elements
,
phi
::
make_ddim
(
dense_shape
));
*
dense_indices
,
*
dense_elements
,
phi
::
make_ddim
(
dense_shape
));
...
@@ -537,7 +537,7 @@ static PyObject* eager_api_sparse_coo_tensor(PyObject* self,
...
@@ -537,7 +537,7 @@ static PyObject* eager_api_sparse_coo_tensor(PyObject* self,
autograd_meta
->
SetStopGradient
(
static_cast
<
bool
>
(
stop_gradient
));
autograd_meta
->
SetStopGradient
(
static_cast
<
bool
>
(
stop_gradient
));
if
(
!
autograd_meta
->
GetMutableGradNode
())
{
if
(
!
autograd_meta
->
GetMutableGradNode
())
{
VLOG
(
3
)
<<
"Tensor("
<<
name
VLOG
(
3
)
<<
"Tensor("
<<
name
<<
")
have not GradNode, add GradNodeAccumulation for
it."
;
<<
")
doesn't have GradNode, add GradNodeAccumulation to
it."
;
autograd_meta
->
SetGradNode
(
autograd_meta
->
SetGradNode
(
std
::
make_shared
<
egr
::
GradNodeAccumulation
>
(
autograd_meta
));
std
::
make_shared
<
egr
::
GradNodeAccumulation
>
(
autograd_meta
));
}
}
...
...
paddle/fluid/pybind/eager_utils.cc
浏览文件 @
5c95e5c8
...
@@ -92,7 +92,7 @@ int TensorDtype2NumpyDtype(phi::DataType dtype) {
...
@@ -92,7 +92,7 @@ int TensorDtype2NumpyDtype(phi::DataType dtype) {
}
}
bool
PyObject_CheckLongOrConvertToLong
(
PyObject
**
obj
)
{
bool
PyObject_CheckLongOrConvertToLong
(
PyObject
**
obj
)
{
if
(
(
PyLong_Check
(
*
obj
)
&&
!
PyBool_Check
(
*
obj
)
))
{
if
(
PyLong_Check
(
*
obj
)
&&
!
PyBool_Check
(
*
obj
))
{
return
true
;
return
true
;
}
}
...
@@ -129,7 +129,7 @@ bool PyObject_CheckStr(PyObject* obj) { return PyUnicode_Check(obj); }
...
@@ -129,7 +129,7 @@ bool PyObject_CheckStr(PyObject* obj) { return PyUnicode_Check(obj); }
bool
CastPyArg2AttrBoolean
(
PyObject
*
obj
,
ssize_t
arg_pos
)
{
bool
CastPyArg2AttrBoolean
(
PyObject
*
obj
,
ssize_t
arg_pos
)
{
if
(
obj
==
Py_None
)
{
if
(
obj
==
Py_None
)
{
return
false
;
// To be compatible with QA integration testing. Some
return
false
;
// To be compatible with QA integration testing. Some
// test case pass in None.
// test case
s
pass in None.
}
else
if
(
obj
==
Py_True
)
{
}
else
if
(
obj
==
Py_True
)
{
return
true
;
return
true
;
}
else
if
(
obj
==
Py_False
)
{
}
else
if
(
obj
==
Py_False
)
{
...
@@ -305,7 +305,7 @@ std::vector<int> CastPyArg2VectorOfInt(PyObject* obj, size_t arg_pos) {
...
@@ -305,7 +305,7 @@ std::vector<int> CastPyArg2VectorOfInt(PyObject* obj, size_t arg_pos) {
Py_ssize_t
len
=
PyList_Size
(
obj
);
Py_ssize_t
len
=
PyList_Size
(
obj
);
PyObject
*
item
=
nullptr
;
PyObject
*
item
=
nullptr
;
for
(
Py_ssize_t
i
=
0
;
i
<
len
;
i
++
)
{
for
(
Py_ssize_t
i
=
0
;
i
<
len
;
i
++
)
{
item
=
PyList_G
etItem
(
obj
,
i
);
item
=
PyList_G
ET_ITEM
(
obj
,
i
);
if
(
PyObject_CheckLongOrConvertToLong
(
&
item
))
{
if
(
PyObject_CheckLongOrConvertToLong
(
&
item
))
{
result
.
emplace_back
(
static_cast
<
int
>
(
PyLong_AsLong
(
item
)));
result
.
emplace_back
(
static_cast
<
int
>
(
PyLong_AsLong
(
item
)));
}
else
{
}
else
{
...
@@ -321,13 +321,13 @@ std::vector<int> CastPyArg2VectorOfInt(PyObject* obj, size_t arg_pos) {
...
@@ -321,13 +321,13 @@ std::vector<int> CastPyArg2VectorOfInt(PyObject* obj, size_t arg_pos) {
Py_ssize_t
len
=
PyTuple_Size
(
obj
);
Py_ssize_t
len
=
PyTuple_Size
(
obj
);
PyObject
*
item
=
nullptr
;
PyObject
*
item
=
nullptr
;
for
(
Py_ssize_t
i
=
0
;
i
<
len
;
i
++
)
{
for
(
Py_ssize_t
i
=
0
;
i
<
len
;
i
++
)
{
item
=
PyTuple_G
etItem
(
obj
,
i
);
item
=
PyTuple_G
ET_ITEM
(
obj
,
i
);
if
(
PyObject_CheckLongOrConvertToLong
(
&
item
))
{
if
(
PyObject_CheckLongOrConvertToLong
(
&
item
))
{
result
.
emplace_back
(
static_cast
<
int
>
(
PyLong_AsLong
(
item
)));
result
.
emplace_back
(
static_cast
<
int
>
(
PyLong_AsLong
(
item
)));
}
else
{
}
else
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"argument (position %d) must be "
"argument (position %d) must be "
"list of
bool
, but got %s at pos %d"
,
"list of
int
, but got %s at pos %d"
,
arg_pos
+
1
,
arg_pos
+
1
,
reinterpret_cast
<
PyTypeObject
*>
(
item
->
ob_type
)
->
tp_name
,
reinterpret_cast
<
PyTypeObject
*>
(
item
->
ob_type
)
->
tp_name
,
i
));
i
));
...
...
paddle/phi/api/include/tensor.h
浏览文件 @
5c95e5c8
...
@@ -574,7 +574,7 @@ class PADDLE_API Tensor final {
...
@@ -574,7 +574,7 @@ class PADDLE_API Tensor final {
* unified to Tensor, but Tensor itself is heterogeneous.
* unified to Tensor, but Tensor itself is heterogeneous.
*
*
* Tensor can generally be represented by void* and size_t, place.
* Tensor can generally be represented by void* and size_t, place.
* This is suitable for most scenarios including CPU, GPU, HIP,
C
PU, etc.,
* This is suitable for most scenarios including CPU, GPU, HIP,
N
PU, etc.,
* but there are a few cases where this definition cannot be described,
* but there are a few cases where this definition cannot be described,
* such as the Tensor representation in third-party lib such as Metal,
* such as the Tensor representation in third-party lib such as Metal,
* OpenCL, etc., as well as some special Tensor implementations, including
* OpenCL, etc., as well as some special Tensor implementations, including
...
...
paddle/phi/core/dense_tensor.h
浏览文件 @
5c95e5c8
...
@@ -29,7 +29,7 @@ namespace phi {
...
@@ -29,7 +29,7 @@ namespace phi {
class
DenseTensorUtils
;
class
DenseTensorUtils
;
/// \brief The Dense tensor store values in a contiguous sequential block
/// \brief The Dense tensor store
s
values in a contiguous sequential block
/// of memory where all values are represented. Tensors or multi-dimensional
/// of memory where all values are represented. Tensors or multi-dimensional
/// arrays are used in math operators.
/// arrays are used in math operators.
/// During the entire life cycle of a DenseTensor, its device type and key
/// During the entire life cycle of a DenseTensor, its device type and key
...
...
paddle/phi/core/tensor_base.h
浏览文件 @
5c95e5c8
...
@@ -55,12 +55,12 @@ class TensorBase {
...
@@ -55,12 +55,12 @@ class TensorBase {
virtual
bool
valid
()
const
=
0
;
virtual
bool
valid
()
const
=
0
;
/// \brief Test whether the storage is allocated.
/// \brief Test whether the storage is allocated.
/// return Whether the storage is allocated.
///
\
return Whether the storage is allocated.
virtual
bool
initialized
()
const
=
0
;
virtual
bool
initialized
()
const
=
0
;
// TODO(Aurelius84): This interface is under intermediate state now.
// TODO(Aurelius84): This interface is under intermediate state now.
// We will remove DataType argument in the future. Please DO NOT
// We will remove DataType argument in the future. Please DO NOT
// rely on Datatype to
much when design and implement other feature
.
// rely on Datatype to
o much when designing and implementing other features
.
/// \brief Allocate memory with requested size from allocator.
/// \brief Allocate memory with requested size from allocator.
/// \return The mutable data pointer value of type T.
/// \return The mutable data pointer value of type T.
...
@@ -70,7 +70,7 @@ class TensorBase {
...
@@ -70,7 +70,7 @@ class TensorBase {
/// \brief Return the type information of the derived class to support
/// \brief Return the type information of the derived class to support
/// safely downcast in non-rtti environment.
/// safely downcast in non-rtti environment.
/// return The type information of the derived class.
///
\
return The type information of the derived class.
TypeInfo
<
TensorBase
>
type_info
()
const
{
return
type_info_
;
}
TypeInfo
<
TensorBase
>
type_info
()
const
{
return
type_info_
;
}
private:
private:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录