Skip to content
Snippets Groups Projects
ReshapeImpl.cpp 1.42 KiB
Newer Older
Houssem ROUIS's avatar
Houssem ROUIS committed
/********************************************************************************
 * 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 "aidge/backend/cpu/operator/ReshapeImpl.hpp"
#include "aidge/backend/cpu/operator/ReshapeImpl_forward_kernels.hpp"
#include "aidge/data/Tensor.hpp"
Houssem ROUIS's avatar
Houssem ROUIS committed
#include "aidge/operator/Reshape.hpp"
#include "aidge/utils/Types.h"
#include "aidge/utils/ErrorHandling.hpp"
Houssem ROUIS's avatar
Houssem ROUIS committed

Aidge::NbElts_t Aidge::ReshapeImpl_cpu::getNbRequiredProtected(const Aidge::IOIndex_t /*inputIdx*/) const {
    // this implementation can be in-place
    return 0;
}

void Aidge::ReshapeImpl_cpu::forward() {
    const Reshape_Op& op_ = static_cast<const Reshape_Op&>(mOp);
    AIDGE_ASSERT(op_.getInput(0)->size() == op_.getOutput(0)->size(),
                    "input must have the same overall size as shape");
Houssem ROUIS's avatar
Houssem ROUIS committed

    // Find the correct kernel type
    auto kernelFunc = Registrar<ReshapeImplForward_cpu>::create({
        op_.getInput(0)->dataType(),
        op_.getOutput(0)->dataType()});
Houssem ROUIS's avatar
Houssem ROUIS committed

    // Call kernel
    kernelFunc(op_.getInput(0)->size(),
               op_.getInput(0)->getImpl()->rawPtr(),
               op_.getOutput(0)->getImpl()->rawPtr());
Houssem ROUIS's avatar
Houssem ROUIS committed
}