Skip to content

Commit

Permalink
Add API: Sparse Convolution3D (#41434)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkaihuo committed Apr 15, 2022
1 parent 840d2eb commit 1665594
Show file tree
Hide file tree
Showing 11 changed files with 961 additions and 232 deletions.
6 changes: 3 additions & 3 deletions paddle/phi/kernels/sparse/cpu/convolution_grad_kernel.cc
Expand Up @@ -139,16 +139,16 @@ void Conv3dGradCPUKernel(const CPUContext& dev_ctx,
T* tmp_in_ptr = in_features_ptr + offsets[i] * in_channels;
T* tmp_out_grad_ptr = out_grad_features_ptr + offsets[i] * out_channels;
const T* tmp_kernel_ptr = kernel_ptr + i * in_channels * out_channels;
T* tmp_d_x_ptr = d_x_features_ptr + offsets[i] * out_channels;
T* tmp_d_x_ptr = d_x_features_ptr + offsets[i] * in_channels;
T* tmp_d_kernel_ptr = d_kernel_ptr + i * in_channels * out_channels;

// call gemm: d_kernel = transpose(x) * out_grad
// (in_channels, n) * (n, out_channels)
blas.GEMM(CblasTrans,
CblasNoTrans,
M,
N,
K,
N,
M,
static_cast<T>(1),
tmp_in_ptr,
tmp_out_grad_ptr,
Expand Down
13 changes: 8 additions & 5 deletions paddle/phi/kernels/sparse/cpu/convolution_kernel.cc
Expand Up @@ -50,16 +50,19 @@ void Conv3dCPUKernel(const CPUContext& dev_ctx,
kernel_sizes[i] = kernel_dims[i];
}

phi::funcs::sparse::GetOutShape(
x_dims, kernel_sizes, paddings, dilations, strides, &out_dims);
const int in_channels = kernel_dims[3];
const int out_channels = kernel_dims[4];

std::vector<int> subm_paddings(paddings), subm_strides(strides);
if (subm) {
// the out shape of subm_conv is same as input shape
// reset the padding=kernel_size/2 and strides=1
phi::funcs::sparse::ResetSubmKernelSizeAndStrides(
kernel.dims(), &subm_paddings, &subm_strides);
}

phi::funcs::sparse::GetOutShape(
x_dims, kernel_sizes, subm_paddings, dilations, subm_strides, &out_dims);
const int in_channels = kernel_dims[3];
const int out_channels = kernel_dims[4];

// Second algorithm:
// https://pdfs.semanticscholar.org/5125/a16039cabc6320c908a4764f32596e018ad3.pdf
// 1. product rulebook
Expand Down

0 comments on commit 1665594

Please sign in to comment.