Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ConcatImpl.cpp 2.10 KiB
/********************************************************************************
 * 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 <vector>

#include "aidge/utils/Types.h"
#include "aidge/backend/cpu/data/GetCPUPtr.h"
#include "aidge/data/Data.hpp"
#include "aidge/data/Tensor.hpp"

#include "aidge/backend/cpu/operator/ConcatImpl.hpp"
#include "aidge/backend/cpu/operator/ConcatImpl_forward_kernels.hpp"

void  Aidge::ConcatImpl_cpu::forward() {
    assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(0)) && "missing input in Concat operator");
    DataType datatypeFirstInput = std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->dataType();
    for (IOIndex_t i = 1; i < mOp.nbInputs(); ++i) {
        assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(i)) && "missing input in Concat operator");
        assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(i))->dataType() == datatypeFirstInput);
    }

    auto kernelFunc = Registrar<ConcatImplForward_cpu>::create({
        datatypeFirstInput,
        std::static_pointer_cast<Tensor>(mOp.getRawOutput(0))->dataType()});

    std::vector<const void*> opInputs;
    std::vector<DimSize_t> opInputAxis;
    for (IOIndex_t i = 0; i < mOp.nbInputs(); ++i) {
        opInputs.push_back(getCPUPtr(mOp.getRawInput(i)));
        opInputAxis.push_back(std::static_pointer_cast<Tensor>(mOp.getRawInput(i))->dims()[dynamic_cast<const Concat_Op&>(mOp).template getAttr<DimSize_t>("Axis")]);
    }

    kernelFunc(dynamic_cast<const Concat_Op&>(mOp).getStaticAttributes(),
               std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->dims(),
               opInputAxis,
               opInputs,
               getCPUPtr(mOp.getRawOutput(0)));
}

void  Aidge::ConcatImpl_cpu::backward() { fmt::print("Not implemented yet.\n"); }