Skip to content
Snippets Groups Projects
Commit 6308e639 authored by Cyril Moineau's avatar Cyril Moineau
Browse files

[MaxPooling] Adapt MaxPoolImpl to latest change on attributes.

parent 4507c66d
No related branches found
No related tags found
No related merge requests found
......@@ -29,11 +29,11 @@ namespace Aidge {
class MaxPoolingImpl2DForward_cpu
: public Registrable<MaxPoolingImpl2DForward_cpu,
std::tuple<DataType, DataType>,
void(const MaxPooling_Op<2>::Parameters &, const std::array<DimSize_t, 4> &, const void *, void *)> {};
void(const MaxPooling_Op<2>::Attrs &, const std::array<DimSize_t, 4> &, const void *, void *)> {};
class MaxPoolingImpl2DBackward_cpu
: public Registrable<MaxPoolingImpl2DBackward_cpu,
std::tuple<DataType, DataType>,
void(const MaxPooling_Op<2>::Parameters &, const std::array<DimSize_t, 4> &, const void *, void *)> {};
void(const MaxPooling_Op<2>::Attrs &, const std::array<DimSize_t, 4> &, const void *, void *)> {};
class MaxPoolingImpl2D_cpu : public OperatorImpl {
private:
......
......@@ -26,13 +26,13 @@ namespace Aidge {
* @brief Forward kernel for 2D MaxPoolingolution on CPU backend.
* @tparam I Input data type.
* @tparam O Output data type.
* @param params tuple of Parameters from the Operator
* @param attrs tuple of Attributes from the Operator
* @param dims Array of input dimensions.
* @param input_ const input Tensor.
* @param output_ Output Tensor.
*/
template <class I, class O>
void MaxPoolingImpl2D_cpu_forward_kernel(const MaxPooling_Op<2>::Parameters &params,
void MaxPoolingImpl2D_cpu_forward_kernel(const MaxPooling_Op<2>::Attrs &attrs,
const std::array<DimSize_t, 4> &dims,
const void *input_,
void *output_) {
......@@ -40,15 +40,18 @@ void MaxPoolingImpl2D_cpu_forward_kernel(const MaxPooling_Op<2>::Parameters &par
const I *input = static_cast<const I *>(input_);
O *output = static_cast<O *>(output_);
std::array<DimSize_t, 2> strideDims = std::get<0>(attrs);
std::array<DimSize_t, 2> kernelDims = std::get<1>(attrs);
std::array<DimSize_t, 4> paddingDims = std::get<2>(attrs);
// output H size
const std::size_t oxSize =
static_cast<std::size_t>(std::floor(static_cast<float>(dims[2] + std::get<2>(params)[0] + std::get<2>(params)[2] - std::get<1>(params)[0] + std::get<0>(params)[0]) /
static_cast<float>(std::get<0>(params)[0])));
static_cast<std::size_t>(std::floor(static_cast<float>(dims[2] + paddingDims[0] + paddingDims[2] - kernelDims[0] + strideDims[0]) /
static_cast<float>(strideDims[0])));
// output W size
const std::size_t oySize =
static_cast<std::size_t>(std::floor(static_cast<float>(dims[3] + std::get<2>(params)[1] + std::get<2>(params)[3] - std::get<1>(params)[1] + std::get<0>(params)[1]) /
static_cast<float>(std::get<0>(params)[1])));
static_cast<std::size_t>(std::floor(static_cast<float>(dims[3] + paddingDims[1] + paddingDims[3] - kernelDims[1] + strideDims[1]) /
static_cast<float>(strideDims[1])));
// TODO: kernel computation
// output (batch, outCh, Xout, Yout)
......@@ -61,16 +64,16 @@ void MaxPoolingImpl2D_cpu_forward_kernel(const MaxPooling_Op<2>::Parameters &par
const std::size_t oIndex = (ch + batch*dims[1]) * oxSize * oySize;
const std::size_t iIndex = (ch + batch*dims[1]) * dims[2] * dims[3];
for (std::size_t ox = 0; ox < oxSize; ++ox) {
const signedsize difx = static_cast<signedsize>(std::get<2>(params)[0] - ox * std::get<0>(params)[0]);
const signedsize difx = static_cast<signedsize>(paddingDims[0] - ox * strideDims[0]);
const std::size_t sxMin = static_cast<std::size_t>(std::max(difx, signedsize(0)));
const std::size_t sxMax = (static_cast<signedsize>(dims[2]) + difx) < 0 ? 0 : ((dims[2] + difx) > std::get<1>(params)[0] ? std::get<1>(params)[0] : dims[2] + difx);
const std::size_t sxMax = (static_cast<signedsize>(dims[2]) + difx) < 0 ? 0 : ((dims[2] + difx) > kernelDims[0] ? kernelDims[0] : dims[2] + difx);
for (std::size_t oy = 0; oy < oySize; ++oy) {
const signedsize dify = static_cast<signedsize>(std::get<2>(params)[1] - oy * std::get<0>(params)[1]);
const signedsize dify = static_cast<signedsize>(paddingDims[1] - oy * strideDims[1]);
const std::size_t syMin = static_cast<std::size_t>(std::max(dify, signedsize(0)));
const std::size_t syMax = (static_cast<signedsize>(dims[3]) + dify) < 0 ? 0 : ((dims[3] + dify) > std::get<1>(params)[1] ? std::get<1>(params)[1] : dims[3] + dify);
const std::size_t syMax = (static_cast<signedsize>(dims[3]) + dify) < 0 ? 0 : ((dims[3] + dify) > kernelDims[1] ? kernelDims[1] : dims[3] + dify);
const std::size_t oIndexFull = oIndex + ox*oySize + oy;
const std::size_t ix = ox * std::get<0>(params)[0];
const std::size_t iy = oy * std::get<0>(params)[1];
const std::size_t ix = ox * strideDims[0];
const std::size_t iy = oy * strideDims[1];
I poolValue(0.0);
bool valid = false;
......
......@@ -70,7 +70,7 @@ void Aidge::MaxPoolingImpl2D_cpu::forward() {
Registrar<MaxPoolingImpl2DForward_cpu>::create({mOp.getInput(0)->dataType(), mOp.getOutput(0)->dataType()});
// Call kernel
kernelFunc(mOp.getParams(),
kernelFunc(mOp.getStaticAttributes(),
mOp.getInput(0)->dims<4>(),
mOp.getInput(0)->getImpl()->rawPtr(),
mOp.getOutput(0)->getImpl()->rawPtr());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment