Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
0b82fb32
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
0b82fb32
编写于
9月 14, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
9月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Sparse]Remove unused code (#46021)
上级
61012a76
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
2 addition
and
247 deletion
+2
-247
paddle/phi/api/lib/CMakeLists.txt
paddle/phi/api/lib/CMakeLists.txt
+2
-8
paddle/phi/api/lib/sparse_api_custom_impl.cc
paddle/phi/api/lib/sparse_api_custom_impl.cc
+0
-202
paddle/phi/api/lib/sparse_api_custom_impl.h
paddle/phi/api/lib/sparse_api_custom_impl.h
+0
-32
paddle/phi/api/yaml/generator/intermediate_api_gen.py
paddle/phi/api/yaml/generator/intermediate_api_gen.py
+0
-1
paddle/phi/api/yaml/generator/sparse_api_gen.py
paddle/phi/api/yaml/generator/sparse_api_gen.py
+0
-1
paddle/phi/api/yaml/generator/sparse_bw_api_gen.py
paddle/phi/api/yaml/generator/sparse_bw_api_gen.py
+0
-1
paddle/phi/tests/core/test_sparse_coo_tensor.cc
paddle/phi/tests/core/test_sparse_coo_tensor.cc
+0
-1
paddle/phi/tests/core/test_sparse_csr_tensor.cc
paddle/phi/tests/core/test_sparse_csr_tensor.cc
+0
-1
未找到文件。
paddle/phi/api/lib/CMakeLists.txt
浏览文件 @
0b82fb32
...
@@ -370,11 +370,6 @@ cc_library(
...
@@ -370,11 +370,6 @@ cc_library(
SRCS api_custom_impl.cc
SRCS api_custom_impl.cc
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta
phi_data_transform
)
phi_data_transform
)
cc_library
(
sparse_api_custom_impl
SRCS sparse_api_custom_impl.cc
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform
tensor_copy
)
cc_library
(
cc_library
(
phi_function_api
phi_function_api
...
@@ -396,12 +391,11 @@ cc_library(
...
@@ -396,12 +391,11 @@ cc_library(
cc_library
(
cc_library
(
sparse_api
sparse_api
SRCS
${
sparse_api_source_file
}
SRCS
${
sparse_api_source_file
}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils
sparse_api_custom_impl
)
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils
)
cc_library
(
cc_library
(
sparse_bw_api
sparse_bw_api
SRCS
${
sparse_bw_api_source_file
}
SRCS
${
sparse_bw_api_source_file
}
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api
DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api
)
sparse_api_custom_impl
)
cc_library
(
cc_library
(
phi_dygraph_api
phi_dygraph_api
SRCS
${
dygraph_api_source_file
}
SRCS
${
dygraph_api_source_file
}
...
...
paddle/phi/api/lib/sparse_api_custom_impl.cc
已删除
100644 → 0
浏览文件 @
61012a76
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/api/lib/sparse_api_custom_impl.h"
#include <memory>
#include "glog/logging.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/core/kernel_registry.h"
namespace
paddle
{
namespace
experimental
{
namespace
sparse
{
Tensor
to_sparse_coo_impl
(
const
Tensor
&
x
,
const
int64_t
sparse_dim
)
{
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_COO
)
{
return
x
;
}
// 1. Get kernel signature and kernel
std
::
string
kernel_name
=
"dense_to_coo"
;
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_CSR
)
{
kernel_name
=
"csr_to_coo"
;
}
auto
kernel_key_set
=
ParseKernelKeyByInputArgs
(
x
);
auto
kernel_key
=
kernel_key_set
.
GetHighestPriorityKernelKey
();
auto
kernel_result
=
phi
::
KernelFactory
::
Instance
().
SelectKernelOrThrowError
(
kernel_name
,
kernel_key
);
const
auto
&
kernel
=
kernel_result
.
kernel
;
VLOG
(
6
)
<<
"add API kernel key: "
<<
kernel_key
;
VLOG
(
6
)
<<
"to API kernel: "
<<
kernel
;
// 2. Get Device Context
auto
*
dev_ctx
=
GetDeviceContextByBackend
(
kernel_key
.
backend
());
auto
kernel_context
=
phi
::
KernelContext
(
dev_ctx
);
// 3. Auto data transform
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_CSR
)
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
SparseCsrTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
}
else
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
kernel_context
.
EmplaceBackAttr
(
sparse_dim
);
}
// 4. InferMeta
auto
indices_meta
=
phi
::
DenseTensorMeta
(
phi
::
DataType
::
INT64
,
{
1
},
phi
::
DataLayout
::
NCHW
);
auto
elements_meta
=
phi
::
DenseTensorMeta
(
x
.
dtype
(),
{
1
},
x
.
layout
());
// 5. Prepare outputs
// create empty SparseCooTensor
phi
::
DenseTensor
non_zero_indices
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
indices_meta
));
phi
::
DenseTensor
non_zero_elements
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
elements_meta
));
auto
coo
=
std
::
make_shared
<
phi
::
SparseCooTensor
>
(
non_zero_indices
,
non_zero_elements
,
x
.
dims
());
kernel_context
.
EmplaceBackOutput
(
coo
.
get
());
Tensor
out
;
out
.
set_impl
(
coo
);
// 6. Call kernel
kernel
(
&
kernel_context
);
return
out
;
}
Tensor
to_sparse_csr_impl
(
const
Tensor
&
x
)
{
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_CSR
)
{
return
x
;
}
// 1. Get kernel signature and kernel
std
::
string
kernel_name
=
"dense_to_csr"
;
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_COO
)
{
kernel_name
=
"coo_to_csr"
;
}
auto
kernel_key_set
=
ParseKernelKeyByInputArgs
(
x
);
auto
kernel_key
=
kernel_key_set
.
GetHighestPriorityKernelKey
();
auto
kernel_result
=
phi
::
KernelFactory
::
Instance
().
SelectKernelOrThrowError
(
kernel_name
,
kernel_key
);
const
auto
&
kernel
=
kernel_result
.
kernel
;
VLOG
(
6
)
<<
"add API kernel key: "
<<
kernel_key
;
VLOG
(
6
)
<<
"to API kernel: "
<<
kernel
;
// 2. Get Device Context
auto
*
dev_ctx
=
GetDeviceContextByBackend
(
kernel_key
.
backend
());
auto
kernel_context
=
phi
::
KernelContext
(
dev_ctx
);
// 3. Auto data transform
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_COO
)
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
SparseCooTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
}
else
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
DenseTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
}
// 4. InferMeta
auto
crows_meta
=
phi
::
DenseTensorMeta
(
phi
::
DataType
::
INT64
,
{
1
},
phi
::
DataLayout
::
NCHW
);
auto
cols_meta
=
phi
::
DenseTensorMeta
(
phi
::
DataType
::
INT64
,
{
1
},
phi
::
DataLayout
::
NCHW
);
auto
elements_meta
=
phi
::
DenseTensorMeta
(
x
.
dtype
(),
{
1
},
x
.
layout
());
// 5. Prepare outputs
// create empty SparseCooTensor
phi
::
DenseTensor
non_zero_crows
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
crows_meta
));
phi
::
DenseTensor
non_zero_cols
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
cols_meta
));
phi
::
DenseTensor
non_zero_elements
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
elements_meta
));
auto
csr
=
std
::
make_shared
<
phi
::
SparseCsrTensor
>
(
non_zero_crows
,
non_zero_cols
,
non_zero_elements
,
x
.
dims
());
kernel_context
.
EmplaceBackOutput
(
csr
.
get
());
Tensor
out
;
out
.
set_impl
(
csr
);
// 6. Call kernel
kernel
(
&
kernel_context
);
return
out
;
}
Tensor
to_dense_impl
(
const
Tensor
&
x
)
{
if
(
x
.
layout
()
!=
phi
::
DataLayout
::
SPARSE_CSR
&&
x
.
layout
()
!=
phi
::
DataLayout
::
SPARSE_COO
)
{
return
x
;
}
// 1. Get kernel signature and kernel
std
::
string
kernel_name
=
"coo_to_dense"
;
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_CSR
)
{
kernel_name
=
"csr_to_dense"
;
}
auto
kernel_key_set
=
ParseKernelKeyByInputArgs
(
x
);
auto
kernel_key
=
kernel_key_set
.
GetHighestPriorityKernelKey
();
auto
kernel_result
=
phi
::
KernelFactory
::
Instance
().
SelectKernelOrThrowError
(
kernel_name
,
kernel_key
);
const
auto
&
kernel
=
kernel_result
.
kernel
;
VLOG
(
6
)
<<
"add API kernel key: "
<<
kernel_key
;
VLOG
(
6
)
<<
"to API kernel: "
<<
kernel
;
// 2. Get Device Context
auto
*
dev_ctx
=
GetDeviceContextByBackend
(
kernel_key
.
backend
());
auto
kernel_context
=
phi
::
KernelContext
(
dev_ctx
);
// 3. Auto data transform
if
(
x
.
layout
()
==
phi
::
DataLayout
::
SPARSE_COO
)
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
SparseCooTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
}
else
{
auto
input
=
std
::
dynamic_pointer_cast
<
phi
::
SparseCsrTensor
>
(
x
.
impl
());
kernel_context
.
EmplaceBackInput
(
input
.
get
());
}
// 4. InferMeta
auto
dense_meta
=
phi
::
DenseTensorMeta
(
x
.
dtype
(),
x
.
dims
(),
x
.
layout
());
// 5. Prepare outputs
// create empty SparseCooTensor
auto
dense_out
=
std
::
make_shared
<
phi
::
DenseTensor
>
(
std
::
make_shared
<
phi
::
Allocation
>
(),
std
::
move
(
dense_meta
));
kernel_context
.
EmplaceBackOutput
(
dense_out
.
get
());
Tensor
out
;
out
.
set_impl
(
dense_out
);
// 6. Call kernel
kernel
(
&
kernel_context
);
return
out
;
}
}
// namespace sparse
}
// namespace experimental
}
// namespace paddle
paddle/phi/api/lib/sparse_api_custom_impl.h
已删除
100644 → 0
浏览文件 @
61012a76
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/phi/api/include/tensor.h"
#include "paddle/phi/common/backend.h"
namespace
paddle
{
namespace
experimental
{
namespace
sparse
{
Tensor
to_dense_impl
(
const
Tensor
&
x
);
Tensor
to_sparse_coo_impl
(
const
Tensor
&
x
,
const
int64_t
sparse_dim
);
Tensor
to_sparse_csr_impl
(
const
Tensor
&
x
);
}
// namespace sparse
}
// namespace experimental
}
// namespace paddle
paddle/phi/api/yaml/generator/intermediate_api_gen.py
浏览文件 @
0b82fb32
...
@@ -43,7 +43,6 @@ def source_include(header_file_path):
...
@@ -43,7 +43,6 @@ def source_include(header_file_path):
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/data_transform.h"
#include "paddle/phi/api/lib/data_transform.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/sparse_api_custom_impl.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/infermeta/binary.h"
#include "paddle/phi/infermeta/binary.h"
#include "paddle/phi/infermeta/multiary.h"
#include "paddle/phi/infermeta/multiary.h"
...
...
paddle/phi/api/yaml/generator/sparse_api_gen.py
浏览文件 @
0b82fb32
...
@@ -229,7 +229,6 @@ def source_include(header_file_path):
...
@@ -229,7 +229,6 @@ def source_include(header_file_path):
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/data_transform.h"
#include "paddle/phi/api/lib/data_transform.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/sparse_api_custom_impl.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
"""
"""
...
...
paddle/phi/api/yaml/generator/sparse_bw_api_gen.py
浏览文件 @
0b82fb32
...
@@ -111,7 +111,6 @@ def source_include(header_file_path):
...
@@ -111,7 +111,6 @@ def source_include(header_file_path):
#include "paddle/phi/api/include/sparse_api.h"
#include "paddle/phi/api/include/sparse_api.h"
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/api_gen_utils.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/kernel_dispatch.h"
#include "paddle/phi/api/lib/sparse_api_custom_impl.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
"""
"""
...
...
paddle/phi/tests/core/test_sparse_coo_tensor.cc
浏览文件 @
0b82fb32
...
@@ -52,7 +52,6 @@ TEST(sparse_coo_tensor, construct) {
...
@@ -52,7 +52,6 @@ TEST(sparse_coo_tensor, construct) {
CHECK_EQ
(
sparse
.
numel
(),
9
);
CHECK_EQ
(
sparse
.
numel
(),
9
);
CHECK
(
sparse
.
dims
()
==
dense_dims
);
CHECK
(
sparse
.
dims
()
==
dense_dims
);
CHECK
(
sparse
.
dtype
()
==
DataType
::
FLOAT32
);
CHECK
(
sparse
.
dtype
()
==
DataType
::
FLOAT32
);
CHECK
(
sparse
.
layout
()
==
DataLayout
::
SPARSE_COO
);
CHECK
(
sparse
.
place
()
==
phi
::
CPUPlace
());
CHECK
(
sparse
.
place
()
==
phi
::
CPUPlace
());
}
}
...
...
paddle/phi/tests/core/test_sparse_csr_tensor.cc
浏览文件 @
0b82fb32
...
@@ -62,7 +62,6 @@ TEST(sparse_csr_tensor, construct) {
...
@@ -62,7 +62,6 @@ TEST(sparse_csr_tensor, construct) {
CHECK_EQ
(
sparse
.
numel
(),
9
);
CHECK_EQ
(
sparse
.
numel
(),
9
);
CHECK
(
sparse
.
dims
()
==
dense_dims
);
CHECK
(
sparse
.
dims
()
==
dense_dims
);
CHECK
(
sparse
.
dtype
()
==
DataType
::
FLOAT32
);
CHECK
(
sparse
.
dtype
()
==
DataType
::
FLOAT32
);
CHECK
(
sparse
.
layout
()
==
DataLayout
::
SPARSE_CSR
);
CHECK
(
sparse
.
place
()
==
paddle
::
platform
::
CPUPlace
());
CHECK
(
sparse
.
place
()
==
paddle
::
platform
::
CPUPlace
());
CHECK
(
sparse
.
initialized
()
==
true
);
CHECK
(
sparse
.
initialized
()
==
true
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录