Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
87443831
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看板
未验证
提交
87443831
编写于
7月 15, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
7月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Standard sparse conv name (#44353)
上级
0dafbb03
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
278 addition
and
217 deletion
+278
-217
paddle/phi/api/yaml/sparse_api.yaml
paddle/phi/api/yaml/sparse_api.yaml
+1
-1
paddle/phi/api/yaml/sparse_bw_api.yaml
paddle/phi/api/yaml/sparse_bw_api.yaml
+1
-1
paddle/phi/kernels/sparse/conv_grad_kernel.h
paddle/phi/kernels/sparse/conv_grad_kernel.h
+25
-26
paddle/phi/kernels/sparse/conv_kernel.h
paddle/phi/kernels/sparse/conv_kernel.h
+62
-0
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
+40
-40
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
+32
-32
paddle/phi/kernels/sparse/cpu/convolution.h
paddle/phi/kernels/sparse/cpu/convolution.h
+1
-1
paddle/phi/kernels/sparse/gpu/conv_grad_kernel.cu
paddle/phi/kernels/sparse/gpu/conv_grad_kernel.cu
+40
-40
paddle/phi/kernels/sparse/gpu/conv_kernel.cu
paddle/phi/kernels/sparse/gpu/conv_kernel.cu
+34
-34
paddle/phi/kernels/sparse/gpu/convolution.cu.h
paddle/phi/kernels/sparse/gpu/convolution.cu.h
+1
-1
paddle/phi/tests/api/test_sparse_conv_api.cc
paddle/phi/tests/api/test_sparse_conv_api.cc
+1
-1
paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc
paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc
+40
-40
未找到文件。
paddle/phi/api/yaml/sparse_api.yaml
浏览文件 @
87443831
...
...
@@ -84,7 +84,7 @@
args
:
(Tensor x, Tensor kernel, int[] paddings, int[] dilations, int[] strides, int groups, bool subm)
output
:
Tensor(out), Tensor(rulebook)
kernel
:
func
:
sparse_conv3d
{sparse_coo, dense -> sparse_coo, dense}
func
:
conv3d_coo
{sparse_coo, dense -> sparse_coo, dense}
layout
:
x
intermediate
:
rulebook
backward
:
conv3d_grad
...
...
paddle/phi/api/yaml/sparse_bw_api.yaml
浏览文件 @
87443831
...
...
@@ -76,7 +76,7 @@
args
:
(Tensor x, Tensor kernel, Tensor rulebook, Tensor out_grad, int[] paddings, int[] dilations, int[] strides, int groups, bool subm)
output
:
Tensor(x_grad), Tensor(kernel_grad)
kernel
:
func
:
sparse_conv3d
_grad{sparse_coo, dense, dense, sparse_coo -> sparse_coo, dense}
func
:
conv3d_coo
_grad{sparse_coo, dense, dense, sparse_coo -> sparse_coo, dense}
-
backward_api
:
coo_to_dense_grad
forward
:
coo_to_dense(Tensor x) -> Tensor(out)
...
...
paddle/phi/kernels/sparse/conv
olution
_grad_kernel.h
→
paddle/phi/kernels/sparse/conv_grad_kernel.h
浏览文件 @
87443831
...
...
@@ -17,27 +17,26 @@ limitations under the License. */
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/sparse/convolution_kernel.h"
namespace
phi
{
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
Conv3dGradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
);
void
Conv3d
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
);
template
<
typename
T
,
typename
Context
>
std
::
tuple
<
SparseCooTensor
,
DenseTensor
>
Conv3dGrad
(
std
::
tuple
<
SparseCooTensor
,
DenseTensor
>
Conv3d
Coo
Grad
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
...
...
@@ -52,18 +51,18 @@ std::tuple<SparseCooTensor, DenseTensor> Conv3dGrad(
DenseTensor
kernel_grad
;
// TODO(zhangkaihuo): call InferMeta func here
Conv3dGradKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
&
x_grad
,
&
kernel_grad
);
Conv3d
Coo
GradKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
&
x_grad
,
&
kernel_grad
);
return
std
::
make_tuple
(
x_grad
,
kernel_grad
);
}
...
...
paddle/phi/kernels/sparse/conv
olution
_kernel.h
→
paddle/phi/kernels/sparse/conv_kernel.h
浏览文件 @
87443831
...
...
@@ -23,38 +23,38 @@ namespace phi {
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
Conv3dKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
);
void
Conv3d
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
);
template
<
typename
T
,
typename
Context
>
SparseCooTensor
Conv3d
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
DenseTensor
*
rulebook
)
{
SparseCooTensor
Conv3d
Coo
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
DenseTensor
*
rulebook
)
{
SparseCooTensor
coo
;
Conv3dKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
&
coo
,
rulebook
);
Conv3d
Coo
Kernel
<
T
,
Context
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
&
coo
,
rulebook
);
return
coo
;
}
...
...
paddle/phi/kernels/sparse/cpu/conv
olution
_grad_kernel.cc
→
paddle/phi/kernels/sparse/cpu/conv_grad_kernel.cc
浏览文件 @
87443831
...
...
@@ -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
limitations under the License. */
#include "paddle/phi/kernels/sparse/conv
olution
_grad_kernel.h"
#include "paddle/phi/kernels/sparse/conv_grad_kernel.h"
#include "paddle/phi/core/visit_type.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
...
...
@@ -31,18 +31,18 @@ namespace sparse {
// x_grad = out_grad * transpose(kenrel)
// kernel_grad = transpose(x) * out_grad
template
<
typename
T
,
typename
IntT
=
int
>
void
Conv3dGradCPUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
void
Conv3d
Coo
GradCPUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
const
auto
&
kernel_dims
=
kernel
.
dims
();
const
int
kernel_size
=
kernel_dims
[
0
]
*
kernel_dims
[
1
]
*
kernel_dims
[
2
];
const
int
in_channels
=
kernel_dims
[
3
];
...
...
@@ -178,42 +178,42 @@ void Conv3dGradCPUKernel(const CPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
Conv3dGradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
void
Conv3d
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dGradCPUKernel"
,
([
&
]
{
Conv3dGradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
x_grad
,
kernel_grad
);
x
.
non_zero_indices
().
dtype
(),
"Conv3d
Coo
GradCPUKernel"
,
([
&
]
{
Conv3d
Coo
GradCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
x_grad
,
kernel_grad
);
}));
}
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_conv3d
_grad
,
PD_REGISTER_KERNEL
(
conv3d_coo
_grad
,
CPU
,
ALL_LAYOUT
,
phi
::
sparse
::
Conv3dGradKernel
,
phi
::
sparse
::
Conv3d
Coo
GradKernel
,
float
,
double
)
{
kernel
->
InputAt
(
0
).
SetDataLayout
(
phi
::
DataLayout
::
SPARSE_COO
);
...
...
paddle/phi/kernels/sparse/cpu/conv
olution
_kernel.cc
→
paddle/phi/kernels/sparse/cpu/conv_kernel.cc
浏览文件 @
87443831
...
...
@@ -27,16 +27,16 @@ namespace sparse {
* out: (N, D, H, W, OC)
**/
template
<
typename
T
,
typename
IntT
=
int
>
void
Conv3dCPUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
void
Conv3dC
ooC
PUKernel
(
const
CPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
// update padding and dilation
// Currently, only support x.layout is NDHWC, groups = 1
// if x.layout != NDHWC then transpose(x), transpose(weight)
...
...
@@ -151,28 +151,28 @@ void Conv3dCPUKernel(const CPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
Conv3dKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
void
Conv3d
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dCPUKernel"
,
([
&
]
{
Conv3dCPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
out
,
rulebook
);
x
.
non_zero_indices
().
dtype
(),
"Conv3dC
ooC
PUKernel"
,
([
&
]
{
Conv3dC
ooC
PUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
out
,
rulebook
);
}));
}
...
...
@@ -180,6 +180,6 @@ void Conv3dKernel(const Context& dev_ctx,
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_conv3d
,
CPU
,
ALL_LAYOUT
,
phi
::
sparse
::
Conv3d
Kernel
,
float
,
double
)
{
conv3d_coo
,
CPU
,
ALL_LAYOUT
,
phi
::
sparse
::
Conv3dCoo
Kernel
,
float
,
double
)
{
kernel
->
InputAt
(
0
).
SetDataLayout
(
phi
::
DataLayout
::
SPARSE_COO
);
}
paddle/phi/kernels/sparse/cpu/convolution.h
浏览文件 @
87443831
...
...
@@ -21,7 +21,7 @@ limitations under the License. */
#include "paddle/phi/core/sparse_coo_tensor.h"
#include "paddle/phi/core/tensor_meta.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/sparse/conv
olution
_kernel.h"
#include "paddle/phi/kernels/sparse/conv_kernel.h"
namespace
phi
{
namespace
sparse
{
...
...
paddle/phi/kernels/sparse/gpu/conv
olution
_grad_kernel.cu
→
paddle/phi/kernels/sparse/gpu/conv_grad_kernel.cu
浏览文件 @
87443831
...
...
@@ -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
limitations under the License. */
#include "paddle/phi/kernels/sparse/conv
olution
_grad_kernel.h"
#include "paddle/phi/kernels/sparse/conv_grad_kernel.h"
#include "glog/logging.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
...
...
@@ -39,18 +39,18 @@ namespace sparse {
// x_grad = out_grad * transpose(kenrel)
// kernel_grad = transpose(x) * out_grad
template
<
typename
T
,
typename
IntT
>
void
Conv3dGradGPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
void
Conv3d
Coo
GradGPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
const
auto
&
kernel_dims
=
kernel
.
dims
();
const
int
kernel_size
=
kernel_dims
[
0
]
*
kernel_dims
[
1
]
*
kernel_dims
[
2
];
const
int
in_channels
=
kernel_dims
[
3
];
...
...
@@ -220,42 +220,42 @@ void Conv3dGradGPUKernel(const GPUContext& dev_ctx,
}
template
<
typename
T
,
typename
Context
>
void
Conv3dGradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
void
Conv3d
Coo
GradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
DenseTensor
&
rulebook
,
const
SparseCooTensor
&
out_grad
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
kernel_grad
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dGradGPUKernel"
,
([
&
]
{
Conv3dGradGPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
x_grad
,
kernel_grad
);
x
.
non_zero_indices
().
dtype
(),
"Conv3d
Coo
GradGPUKernel"
,
([
&
]
{
Conv3d
Coo
GradGPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
rulebook
,
out_grad
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
x_grad
,
kernel_grad
);
}));
}
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_conv3d
_grad
,
PD_REGISTER_KERNEL
(
conv3d_coo
_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
Conv3dGradKernel
,
phi
::
sparse
::
Conv3d
Coo
GradKernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{
...
...
paddle/phi/kernels/sparse/gpu/conv
olution
_kernel.cu
→
paddle/phi/kernels/sparse/gpu/conv_kernel.cu
浏览文件 @
87443831
...
...
@@ -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
limitations under the License. */
#include "paddle/phi/kernels/sparse/conv
olution
_kernel.h"
#include "paddle/phi/kernels/sparse/conv_kernel.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
...
...
@@ -27,16 +27,16 @@ namespace phi {
namespace
sparse
{
template
<
typename
T
,
typename
IntT
>
void
Conv3dGPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
void
Conv3d
Coo
GPUKernel
(
const
GPUContext
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
// update padding and dilation
// Currently, only support x.layout is NDHWC, groups = 1
// if x.layout != NDHWC then transpose(x), transpose(weight)
...
...
@@ -190,38 +190,38 @@ void Conv3dGPUKernel(const GPUContext& dev_ctx,
* out: (N, D, H, W, OC)
**/
template
<
typename
T
,
typename
Context
>
void
Conv3dKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
void
Conv3d
Coo
Kernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
kernel
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
dilations
,
const
std
::
vector
<
int
>&
strides
,
const
int
groups
,
const
bool
subm
,
SparseCooTensor
*
out
,
DenseTensor
*
rulebook
)
{
PD_VISIT_INTEGRAL_TYPES
(
x
.
non_zero_indices
().
dtype
(),
"Conv3dGPUKernel"
,
([
&
]
{
Conv3dGPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
out
,
rulebook
);
x
.
non_zero_indices
().
dtype
(),
"Conv3d
Coo
GPUKernel"
,
([
&
]
{
Conv3d
Coo
GPUKernel
<
T
,
data_t
>
(
dev_ctx
,
x
,
kernel
,
paddings
,
dilations
,
strides
,
groups
,
subm
,
out
,
rulebook
);
}));
}
}
// namespace sparse
}
// namespace phi
PD_REGISTER_KERNEL
(
sparse_conv3d
,
PD_REGISTER_KERNEL
(
conv3d_coo
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
Conv3dKernel
,
phi
::
sparse
::
Conv3d
Coo
Kernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{
...
...
paddle/phi/kernels/sparse/gpu/convolution.cu.h
浏览文件 @
87443831
...
...
@@ -28,7 +28,7 @@ limitations under the License. */
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/sparse/utils.cu.h"
#include "paddle/phi/kernels/primitive/compute_primitives.h"
#include "paddle/phi/kernels/sparse/conv
olution
_kernel.h"
#include "paddle/phi/kernels/sparse/conv_kernel.h"
namespace
phi
{
namespace
sparse
{
...
...
paddle/phi/tests/api/test_sparse_conv_api.cc
浏览文件 @
87443831
...
...
@@ -23,7 +23,7 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
PD_DECLARE_KERNEL
(
sparse_conv3d
,
CPU
,
ALL_LAYOUT
);
PD_DECLARE_KERNEL
(
conv3d_coo
,
CPU
,
ALL_LAYOUT
);
template
<
typename
T
>
void
TestConv3dBase
(
const
std
::
vector
<
int
>&
indices
,
...
...
paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc
浏览文件 @
87443831
...
...
@@ -23,8 +23,8 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/sparse/coalesce_kernel.h"
#include "paddle/phi/kernels/sparse/conv
olution
_grad_kernel.h"
#include "paddle/phi/kernels/sparse/conv
olution
_kernel.h"
#include "paddle/phi/kernels/sparse/conv_grad_kernel.h"
#include "paddle/phi/kernels/sparse/conv_kernel.h"
namespace
phi
{
namespace
tests
{
...
...
@@ -114,15 +114,15 @@ void TestConv3dBase(const std::vector<IntT>& indices,
if
(
!
std
::
is_same
<
T
,
phi
::
dtype
::
float16
>::
value
)
{
DenseTensor
rulebook
=
phi
::
Empty
(
dev_ctx_cpu
,
DenseTensorMeta
(
indices_dtype
,
{
1
},
DataLayout
::
NCHW
));
SparseCooTensor
out
=
sparse
::
Conv3d
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
kernel_tensor
,
paddings
,
dilations
,
strides
,
1
,
subm
,
&
rulebook
);
SparseCooTensor
out
=
sparse
::
Conv3d
Coo
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
kernel_tensor
,
paddings
,
dilations
,
strides
,
1
,
subm
,
&
rulebook
);
ASSERT_EQ
(
correct_out_dims
.
size
(),
out
.
dims
().
size
());
for
(
int
i
=
0
;
i
<
correct_out_dims
.
size
();
i
++
)
{
...
...
@@ -139,16 +139,16 @@ void TestConv3dBase(const std::vector<IntT>& indices,
if
(
backward
)
{
std
::
tuple
<
SparseCooTensor
,
DenseTensor
>
grads
=
sparse
::
Conv3dGrad
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
kernel_tensor
,
rulebook
,
out
,
paddings
,
dilations
,
strides
,
1
,
subm
);
sparse
::
Conv3d
Coo
Grad
<
T
>
(
dev_ctx_cpu
,
x_tensor
,
kernel_tensor
,
rulebook
,
out
,
paddings
,
dilations
,
strides
,
1
,
subm
);
f_verify
(
std
::
get
<
0
>
(
grads
).
non_zero_elements
().
data
<
T
>
(),
features_grad
);
f_verify
(
std
::
get
<
1
>
(
grads
).
data
<
T
>
(),
kernel_grad
);
}
...
...
@@ -198,15 +198,15 @@ void TestConv3dBase(const std::vector<IntT>& indices,
DenseTensor
d_rulebook
=
phi
::
Empty
(
dev_ctx_gpu
,
DenseTensorMeta
(
indices_dtype
,
{
1
},
DataLayout
::
NCHW
));
SparseCooTensor
d_out
=
sparse
::
Conv3d
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
d_kernel_tensor
,
paddings
,
dilations
,
strides
,
1
,
subm
,
&
d_rulebook
);
SparseCooTensor
d_out
=
sparse
::
Conv3d
Coo
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
d_kernel_tensor
,
paddings
,
dilations
,
strides
,
1
,
subm
,
&
d_rulebook
);
SparseCooTensor
tmp_d_out
=
sparse
::
Coalesce
<
T
>
(
dev_ctx_gpu
,
d_out
);
...
...
@@ -242,16 +242,16 @@ void TestConv3dBase(const std::vector<IntT>& indices,
if
(
backward
)
{
std
::
tuple
<
SparseCooTensor
,
DenseTensor
>
grads
=
sparse
::
Conv3dGrad
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
d_kernel_tensor
,
d_rulebook
,
d_out
,
paddings
,
dilations
,
strides
,
1
,
subm
);
sparse
::
Conv3d
Coo
Grad
<
T
>
(
dev_ctx_gpu
,
d_x_tensor
,
d_kernel_tensor
,
d_rulebook
,
d_out
,
paddings
,
dilations
,
strides
,
1
,
subm
);
DenseTensor
d_features_grad
=
std
::
get
<
0
>
(
grads
).
non_zero_elements
();
DenseTensor
d_kernel_grad
=
std
::
get
<
1
>
(
grads
);
DenseTensor
h_features_grad
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录