Newer
Older
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include <cassert>
#include <numeric> // std::accumulate
#include "aidge/operator/BatchNorm.hpp"
#include "aidge/backend/cpu/operator/BatchNormImpl.hpp"
#include "aidge/backend/cpu/operator/BatchNormImpl_forward_kernels.hpp"
Aidge::NbElts_t Aidge::BatchNormImpl2D_cpu::getNbRequiredProtected(IOIndex_t /*inputIdx*/) const {
// this implementation can be in-place
return 0;
}
void Aidge::BatchNormImpl2D_cpu::forward() {
assert(mOp.getInput(0) && "missing input #0");
assert(mOp.getInput(1) && "missing input #1");
assert(mOp.getInput(2) && "missing input #2");
assert(mOp.getInput(3) && "missing input #3");
assert(mOp.getInput(4) && "missing input #4");
assert(mOp.getOutput(0)->nbDims() == 4);
// Find the correct kernel type
auto kernelFunc =
Registrar<BatchNormImpl2DForward_cpu>::create({mOp.getInput(0)->dataType(), mOp.getInput(1)->dataType(),
mOp.getOutput(0)->dataType()});
// Call kernel
kernelFunc(dynamic_cast<const BatchNorm_Op<2>&>(mOp).getStaticAttributes(),
mOp.getInput(0)->dims<4>(),
mOp.getInput(0)->getImpl()->rawPtr(),
mOp.getInput(1)->getImpl()->rawPtr(),
mOp.getInput(2)->getImpl()->rawPtr(),
mOp.getInput(3)->getImpl()->rawPtr(),
mOp.getInput(4)->getImpl()->rawPtr(),
mOp.getOutput(0)->getImpl()->rawPtr(),
true);
}