text
stringlengths
0
2.2M
input_data, output_data,
indices_data,
nslices,
itime, iwidth, iheight,
otime, owidth, oheight,
kT, kW, kH,
dT, dW, dH,
pT, pW, pH,
dilationT, dilationW, dilationH);
}
);
}
else { /* batch mode */
const int64_t nbatch = input.size(0);
const int64_t istride = nslices * itime * iwidth * iheight;
const int64_t ostride = nslices * otime * owidth * oheight;
/* resize output */
output.resize_({nbatch, nslices, otime, oheight, owidth});
/* indices will contain ti,i,j locations for each output point */
indices.resize_({nbatch, nslices, otime, oheight, owidth});
AT_DISPATCH_FLOATING_TYPES(input.scalar_type(),
"max_pool3d_with_indices_cpu",
[&] {
scalar_t *input_data = input.data_ptr<scalar_t>();
scalar_t *output_data = output.data_ptr<scalar_t>();
int64_t *indices_data = indices.data_ptr<int64_t>();
max_pool3d_with_indices_out_frame(
input_data,
output_data,
indices_data,
nbatch,
nslices,
istride, ostride,
itime, iwidth, iheight,
otime, owidth, oheight,
kT, kW, kH,
dT, dW, dH,
pT, pW, pH,
dilationT, dilationW, dilationH);
}
);
}
}
template <typename scalar_t>
static void max_pool3d_with_indices_backward_single_out_frame(
scalar_t *gradInput_p,
scalar_t *gradOutput_p,
int64_t *indz_p,
int64_t nslices,
int64_t itime,
int64_t iwidth,
int64_t iheight,
int64_t otime,
int64_t owidth,
int64_t oheight,
int dT,
int dW,
int dH,
int pT,
int pW,
int pH,
int dilationT,
int dilationW,
int dilationH)
{
at::parallel_for(0, nslices, 0, [&](int64_t start, int64_t end) {
for (const auto k : c10::irange(start, end)) {
scalar_t *gradInput_p_k = gradInput_p + k * itime * iwidth * iheight;
scalar_t *gradOutput_p_k = gradOutput_p + k * otime * owidth * oheight;
int64_t *indz_p_k = indz_p + k * otime * owidth * oheight;
/* calculate max points */
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
int64_t ti, i, j;
for (ti = 0; ti < otime; ti++)
{
for (i = 0; i < oheight; i++)
{
for (j = 0; j < owidth; j++)
{
/* retrieve position of max */
int64_t index = ti * oheight * owidth + i * owidth + j;
int64_t maxp = indz_p_k[index];
if (maxp != -1) {
/* update gradient */
gradInput_p_k[maxp] += gradOutput_p_k[index];
}
}
}
}
}
});
}
template <typename scalar_t>