static void THNN_(VolumetricAdaptiveAveragePooling_updateGradInput_frame)( real *gradInput_p, real *gradOutput_p, int64_t sizeD, int64_t isizeT, int64_t isizeH, int64_t isizeW, int64_t osizeT, int64_t osizeH, int64_t osizeW) { int64_t d; #pragma omp parallel for private(d) for (d = 0; d < sizeD; d++) { real *gradInput_p_d = gradInput_p + d*isizeT*isizeW*isizeH; real *gradOutput_p_d = gradOutput_p + d*osizeT*osizeW*osizeH; /* calculate average */ int64_t ot, oh, ow; for(ot = 0; ot < osizeT; ot++) { int istartT = START_IND(ot, osizeT, isizeT); int iendT = END_IND(ot, osizeT, isizeT); int kT = iendT - istartT; for(oh = 0; oh < osizeH; oh++) { int istartH = START_IND(oh, osizeH, isizeH); int iendH = END_IND(oh, osizeH, isizeH); int kH = iendH - istartH; for(ow = 0; ow < osizeW; ow++) { int istartW = START_IND(ow, osizeW, isizeW); int iendW = END_IND(ow, osizeW, isizeW); int kW = iendW - istartW; real grad_delta = gradOutput_p_d[ot*osizeH*osizeW + oh*osizeW + ow] / kT / kH / kW; int it, ih, iw; for(it = istartT; it < iendT; it++) { for(ih = istartH; ih < iendH; ih++) { for(iw = istartW; iw < iendW; iw++) { /* update gradient */ gradInput_p_d[it*isizeH*isizeW + ih*isizeW + iw] += grad_delta; } } } } } } } }
static void THNN_(VolumetricAdaptiveAveragePooling_updateOutput_frame)( real *input_p, real *output_p, int64_t sizeD, int64_t isizeT, int64_t isizeH, int64_t isizeW, int64_t osizeT, int64_t osizeH, int64_t osizeW, int64_t istrideD, int64_t istrideT, int64_t istrideH, int64_t istrideW) { int64_t d; #pragma omp parallel for private(d) for (d = 0; d < sizeD; d++) { /* loop over output */ int64_t ot, oh, ow; for(ot = 0; ot < osizeT; ot++) { int istartT = START_IND(ot, osizeT, isizeT); int iendT = END_IND(ot, osizeT, isizeT); int kT = iendT - istartT; for(oh = 0; oh < osizeH; oh++) { int istartH = START_IND(oh, osizeH, isizeH); int iendH = END_IND(oh, osizeH, isizeH); int kH = iendH - istartH; for(ow = 0; ow < osizeW; ow++) { int istartW = START_IND(ow, osizeW, isizeW); int iendW = END_IND(ow, osizeW, isizeW); int kW = iendW - istartW; /* local pointers */ real *ip = input_p + d*istrideD + istartT*istrideT + istartH*istrideH + istartW*istrideW; real *op = output_p + d*osizeT*osizeH*osizeW + ot*osizeH*osizeW + oh*osizeW + ow; /* compute local average: */ real sum = 0; int it, ih, iw; for(it = 0; it < kT; it++) { for(ih = 0; ih < kH; ih++) { for(iw = 0; iw < kW; iw++) { real val = *(ip + it*istrideT + ih*istrideH + iw*istrideW); sum += val; } } } /* set output to local average */ *op = sum / kT / kH / kW; } } } } }
static void THNN_(VolumetricAdaptiveMaxPooling_updateOutput_frame)( real *input_p, real *output_p, THIndex_t *ind_p, int64_t sizeD, int64_t isizeT, int64_t isizeH, int64_t isizeW, int64_t osizeT, int64_t osizeH, int64_t osizeW, int64_t istrideD, int64_t istrideT, int64_t istrideH, int64_t istrideW) { int64_t d; #pragma omp parallel for private(d) for (d = 0; d < sizeD; d++) { /* loop over output */ int64_t ot, oh, ow; for(ot = 0; ot < osizeT; ot++) { int64_t istartT = START_IND(ot, osizeT, isizeT); int64_t iendT = END_IND(ot, osizeT, isizeT); int64_t kT = iendT - istartT; for(oh = 0; oh < osizeH; oh++) { int64_t istartH = START_IND(oh, osizeH, isizeH); int64_t iendH = END_IND(oh, osizeH, isizeH); int64_t kH = iendH - istartH; for(ow = 0; ow < osizeW; ow++) { int64_t istartW = START_IND(ow, osizeW, isizeW); int64_t iendW = END_IND(ow, osizeW, isizeW); int64_t kW = iendW - istartW; /* local pointers */ real *ip = input_p + d*istrideD + istartT *istrideT + istartH*istrideH + istartW*istrideW; real *op = output_p + d*osizeT*osizeH*osizeW + ot*osizeH*osizeW + oh*osizeW + ow; THIndex_t *indp = ind_p + d*osizeT*osizeH*osizeW + ot*osizeH*osizeW + oh*osizeW + ow; /* compute local max: */ int64_t maxindex = -1; real maxval = -FLT_MAX; int64_t it, ih, iw; for(it = 0; it < kT; it++) { for(ih = 0; ih < kH; ih++) { for(iw = 0; iw < kW; iw++) { real val = *(ip + it*istrideT + ih*istrideH + iw*istrideW); if ((val > maxval) || std::isnan(val)) { maxval = val; maxindex = (it+istartT)*isizeH*isizeW + (ih+istartH)*isizeW + (iw+istartW); } } } } /* set output to local max */ *op = maxval; /* store location of max */ *indp = maxindex + TH_INDEX_BASE; } } } } }