Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9da48da
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b9da48da
编写于
3月 31, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
3月 31, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Opt the compilation of sparse kernel (#41086)
上级
ac5548a2
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
45 addition
and
23 deletion
+45
-23
cmake/phi.cmake
cmake/phi.cmake
+3
-0
paddle/phi/kernels/sparse/activation_grad_kernel.cc
paddle/phi/kernels/sparse/activation_grad_kernel.cc
+1
-1
paddle/phi/kernels/sparse/activation_grad_kernel.h
paddle/phi/kernels/sparse/activation_grad_kernel.h
+0
-0
paddle/phi/kernels/sparse/activation_kernel.cc
paddle/phi/kernels/sparse/activation_kernel.cc
+1
-1
paddle/phi/kernels/sparse/activation_kernel.h
paddle/phi/kernels/sparse/activation_kernel.h
+0
-0
paddle/phi/tests/kernels/test_sparse_activation_dev_api.cc
paddle/phi/tests/kernels/test_sparse_activation_dev_api.cc
+2
-2
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
+4
-0
python/paddle/tensor/to_string.py
python/paddle/tensor/to_string.py
+34
-19
未找到文件。
cmake/phi.cmake
浏览文件 @
b9da48da
...
@@ -116,6 +116,9 @@ function(kernel_library TARGET)
...
@@ -116,6 +116,9 @@ function(kernel_library TARGET)
if
(
"
${
kernel_library_SUB_DIR
}
"
STREQUAL
"selected_rows"
)
if
(
"
${
kernel_library_SUB_DIR
}
"
STREQUAL
"selected_rows"
)
set
(
target_suffix
"_sr"
)
set
(
target_suffix
"_sr"
)
endif
()
endif
()
if
(
"
${
kernel_library_SUB_DIR
}
"
STREQUAL
"sparse"
)
set
(
target_suffix
"_sp"
)
endif
()
list
(
LENGTH kernel_library_SRCS kernel_library_SRCS_len
)
list
(
LENGTH kernel_library_SRCS kernel_library_SRCS_len
)
# one kernel only match one impl file in each backend
# one kernel only match one impl file in each backend
...
...
paddle/phi/kernels/sparse/
sparse_
activation_grad_kernel.cc
→
paddle/phi/kernels/sparse/activation_grad_kernel.cc
浏览文件 @
b9da48da
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
activation_grad_kernel.h"
#include "paddle/phi/kernels/sparse/activation_grad_kernel.h"
#include "paddle/phi/kernels/activation_grad_kernel.h"
#include "paddle/phi/kernels/activation_grad_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
...
...
paddle/phi/kernels/sparse/
sparse_
activation_grad_kernel.h
→
paddle/phi/kernels/sparse/activation_grad_kernel.h
浏览文件 @
b9da48da
文件已移动
paddle/phi/kernels/sparse/
sparse_
activation_kernel.cc
→
paddle/phi/kernels/sparse/activation_kernel.cc
浏览文件 @
b9da48da
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/phi/kernels/sparse/
sparse_
activation_kernel.h"
#include "paddle/phi/kernels/sparse/activation_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/copy_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
...
...
paddle/phi/kernels/sparse/
sparse_
activation_kernel.h
→
paddle/phi/kernels/sparse/activation_kernel.h
浏览文件 @
b9da48da
文件已移动
paddle/phi/tests/kernels/test_sparse_activation_dev_api.cc
浏览文件 @
b9da48da
...
@@ -24,8 +24,8 @@ limitations under the License. */
...
@@ -24,8 +24,8 @@ limitations under the License. */
#include "paddle/phi/kernels/activation_grad_kernel.h"
#include "paddle/phi/kernels/activation_grad_kernel.h"
#include "paddle/phi/kernels/activation_kernel.h"
#include "paddle/phi/kernels/activation_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/sparse/
sparse_
activation_grad_kernel.h"
#include "paddle/phi/kernels/sparse/activation_grad_kernel.h"
#include "paddle/phi/kernels/sparse/
sparse_
activation_kernel.h"
#include "paddle/phi/kernels/sparse/activation_kernel.h"
#include "paddle/phi/kernels/sparse/sparse_utils_kernel.h"
#include "paddle/phi/kernels/sparse/sparse_utils_kernel.h"
namespace
phi
{
namespace
phi
{
...
...
python/paddle/fluid/tests/unittests/test_sparse_utils_op.py
浏览文件 @
b9da48da
...
@@ -33,6 +33,7 @@ class TestSparseUtils(unittest.TestCase):
...
@@ -33,6 +33,7 @@ class TestSparseUtils(unittest.TestCase):
stop_gradient
=
False
stop_gradient
=
False
coo
=
core
.
eager
.
sparse_coo_tensor
(
dense_indices
,
dense_elements
,
coo
=
core
.
eager
.
sparse_coo_tensor
(
dense_indices
,
dense_elements
,
dense_shape
,
stop_gradient
)
dense_shape
,
stop_gradient
)
print
(
coo
)
print
(
coo
)
def
test_create_sparse_csr_tensor
(
self
):
def
test_create_sparse_csr_tensor
(
self
):
...
@@ -49,6 +50,7 @@ class TestSparseUtils(unittest.TestCase):
...
@@ -49,6 +50,7 @@ class TestSparseUtils(unittest.TestCase):
csr
=
core
.
eager
.
sparse_csr_tensor
(
dense_crows
,
dense_cols
,
csr
=
core
.
eager
.
sparse_csr_tensor
(
dense_crows
,
dense_cols
,
dense_elements
,
dense_shape
,
dense_elements
,
dense_shape
,
stop_gradient
)
stop_gradient
)
print
(
csr
)
print
(
csr
)
def
test_to_sparse_coo
(
self
):
def
test_to_sparse_coo
(
self
):
...
@@ -58,6 +60,7 @@ class TestSparseUtils(unittest.TestCase):
...
@@ -58,6 +60,7 @@ class TestSparseUtils(unittest.TestCase):
non_zero_elements
=
[
1
,
2
,
3
,
4
,
5
]
non_zero_elements
=
[
1
,
2
,
3
,
4
,
5
]
dense_x
=
paddle
.
to_tensor
(
x
)
dense_x
=
paddle
.
to_tensor
(
x
)
out
=
dense_x
.
to_sparse_coo
(
2
)
out
=
dense_x
.
to_sparse_coo
(
2
)
print
(
out
)
assert
np
.
array_equal
(
out
.
non_zero_indices
().
numpy
(),
assert
np
.
array_equal
(
out
.
non_zero_indices
().
numpy
(),
non_zero_indices
)
non_zero_indices
)
assert
np
.
array_equal
(
out
.
non_zero_elements
().
numpy
(),
assert
np
.
array_equal
(
out
.
non_zero_elements
().
numpy
(),
...
@@ -81,6 +84,7 @@ class TestSparseUtils(unittest.TestCase):
...
@@ -81,6 +84,7 @@ class TestSparseUtils(unittest.TestCase):
non_zero_elements
)
non_zero_elements
)
dense_tensor
=
out
.
to_dense
()
dense_tensor
=
out
.
to_dense
()
print
(
dense_tensor
)
assert
np
.
array_equal
(
dense_tensor
.
numpy
(),
x
)
assert
np
.
array_equal
(
dense_tensor
.
numpy
(),
x
)
...
...
python/paddle/tensor/to_string.py
浏览文件 @
b9da48da
...
@@ -286,21 +286,34 @@ def _format_dense_tensor(tensor, indent):
...
@@ -286,21 +286,34 @@ def _format_dense_tensor(tensor, indent):
def
sparse_tensor_to_string
(
tensor
,
prefix
=
'Tensor'
):
def
sparse_tensor_to_string
(
tensor
,
prefix
=
'Tensor'
):
indent
=
len
(
prefix
)
+
1
indent
=
len
(
prefix
)
+
1
_template
=
"{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient},
\n
{indent}{data})"
if
tensor
.
is_sparse_coo
():
if
tensor
.
is_sparse_coo
():
_template
=
"{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient},
\n
{indent}{indices},
\n
{indent}{values})"
indices_tensor
=
tensor
.
non_zero_indices
()
indices_tensor
=
tensor
.
non_zero_indices
()
elements_tensor
=
tensor
.
non_zero_elements
()
elements_tensor
=
tensor
.
non_zero_elements
()
indices_data
=
_format_dense_tensor
(
indices_tensor
,
indent
)
indices_data
=
'indices='
+
_format_dense_tensor
(
indices_tensor
,
indent
elements_data
=
_format_dense_tensor
(
elements_tensor
,
indent
)
+
len
(
'indices='
))
data
=
'non_zero_indices='
+
indices_data
+
',
\n
non_zero_elements='
+
elements_data
values_data
=
'values='
+
_format_dense_tensor
(
elements_tensor
,
indent
+
len
(
'values='
))
return
_template
.
format
(
prefix
=
prefix
,
shape
=
tensor
.
shape
,
dtype
=
tensor
.
dtype
,
place
=
tensor
.
_place_str
,
stop_gradient
=
tensor
.
stop_gradient
,
indent
=
' '
*
indent
,
indices
=
indices_data
,
values
=
values_data
)
else
:
else
:
_template
=
"{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient},
\n
{indent}{crows},
\n
{indent}{cols},
\n
{indent}{values})"
crows_tensor
=
tensor
.
non_zero_crows
()
crows_tensor
=
tensor
.
non_zero_crows
()
cols_tensor
=
tensor
.
non_zero_cols
()
cols_tensor
=
tensor
.
non_zero_cols
()
elements_tensor
=
tensor
.
non_zero_elements
()
elements_tensor
=
tensor
.
non_zero_elements
()
crows_data
=
_format_dense_tensor
(
crows_tensor
,
indent
)
crows_data
=
'crows='
+
_format_dense_tensor
(
crows_tensor
,
indent
+
cols_data
=
_format_dense_tensor
(
cols_tensor
,
indent
)
len
(
'crows='
))
elements_data
=
_format_dense_tensor
(
elements_tensor
,
indent
)
cols_data
=
'cols='
+
_format_dense_tensor
(
cols_tensor
,
indent
+
data
=
'non_zero_crows='
+
crows_data
+
',
\n
non_zero_cols='
+
cols_data
+
',
\n
non_zero_elements='
+
elements_data
len
(
'cols='
))
values_data
=
'values='
+
_format_dense_tensor
(
elements_tensor
,
indent
+
len
(
'values='
))
return
_template
.
format
(
return
_template
.
format
(
prefix
=
prefix
,
prefix
=
prefix
,
...
@@ -309,7 +322,9 @@ def sparse_tensor_to_string(tensor, prefix='Tensor'):
...
@@ -309,7 +322,9 @@ def sparse_tensor_to_string(tensor, prefix='Tensor'):
place
=
tensor
.
_place_str
,
place
=
tensor
.
_place_str
,
stop_gradient
=
tensor
.
stop_gradient
,
stop_gradient
=
tensor
.
stop_gradient
,
indent
=
' '
*
indent
,
indent
=
' '
*
indent
,
data
=
data
)
crows
=
crows_data
,
cols
=
cols_data
,
values
=
values_data
)
def
tensor_to_string
(
tensor
,
prefix
=
'Tensor'
):
def
tensor_to_string
(
tensor
,
prefix
=
'Tensor'
):
...
@@ -317,11 +332,11 @@ def tensor_to_string(tensor, prefix='Tensor'):
...
@@ -317,11 +332,11 @@ def tensor_to_string(tensor, prefix='Tensor'):
_template
=
"{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient},
\n
{indent}{data})"
_template
=
"{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient},
\n
{indent}{data})"
if
not
tensor
.
_is_initialized
():
return
"Tensor(Not initialized)"
if
tensor
.
is_sparse
():
if
tensor
.
is_sparse
():
return
sparse_tensor_to_string
(
tensor
,
prefix
)
return
sparse_tensor_to_string
(
tensor
,
prefix
)
if
not
tensor
.
_is_dense_tensor_hold_allocation
():
return
"Tensor(Not initialized)"
else
:
else
:
data
=
_format_dense_tensor
(
tensor
,
indent
)
data
=
_format_dense_tensor
(
tensor
,
indent
)
return
_template
.
format
(
return
_template
.
format
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录