Skip to content
Snippets Groups Projects
ConvDepthWiseImpl.hpp 2.79 KiB
Newer Older
Cyril Moineau's avatar
Cyril Moineau 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
 *
 ********************************************************************************/

#ifndef  __AIDGE_CPU_OPERATOR_CONVDEPTHWISEIMPL_H__
#define __AIDGE_CPU_OPERATOR_CONVDEPTHWISEIMPL_H__

#include <array>
#include <memory>
#include <tuple>
#include <vector>

#include "backend/OperatorImpl.hpp"
#include "operator/ConvDepthWise.hpp"
#include "utils/Registrar.hpp"
#include "utils/Types.h"

namespace Aidge {
// class ConvDepthWise_Op;

// compute kernel registry for forward and backward
class ConvDepthWiseImpl2DForward_cpu
    : public Registrable<ConvDepthWiseImpl2DForward_cpu,
                         std::tuple<DataType, DataType, DataType, DataType>,
                         void(const ConvDepthWise_Op<2>::Parameters &, const std::array<DimSize_t, 4> &, const void *,
                              const void *, const void *, void *)> {};
class ConvDepthWiseImpl2DBackward_cpu
    : public Registrable<ConvDepthWiseImpl2DBackward_cpu,
                         std::tuple<DataType, DataType, DataType, DataType>,
                         void(const ConvDepthWise_Op<2>::Parameters &, const std::array<DimSize_t, 4> &, const void *,
                              const void *, const void *, void *)> {};

class ConvDepthWiseImpl2D_cpu : public OperatorImpl {
   private:
    const ConvDepthWise_Op<2> &mOp;
    std::array<NbElts_t, 3> mNbConsumedData;
    std::array<NbElts_t, 1> mNbProducedData;

   public:
    ConvDepthWiseImpl2D_cpu(const ConvDepthWise_Op<2> &op) : mOp(op), mNbConsumedData({0, 0, 0}), mNbProducedData({0}) {}

    static std::unique_ptr<ConvDepthWiseImpl2D_cpu> create(const ConvDepthWise_Op<2> &op) {
        return std::make_unique<ConvDepthWiseImpl2D_cpu>(op);
    }

   public:
    NbElts_t getNbRequiredData(const IOIndex_t inputIdx) const override final;
    NbElts_t getNbRequiredProtected(const IOIndex_t inputIdx) const override final;
    NbElts_t getRequiredMemory(__attribute__((unused)) const IOIndex_t outputIdx, const std::vector<DimSize_t> &inputsSize) const override final;
    NbElts_t getNbConsumedData(const IOIndex_t inputIdx) const override final;
    NbElts_t getNbProducedData(const IOIndex_t outputIdx) const override final;
Cyril Moineau's avatar
Cyril Moineau committed

    void forward();

    void backward();
};

namespace {
// add cpu backend to ConvDepthWise_Op<2> implementation registry
static Registrar<ConvDepthWise_Op<2>> registrarConvDepthWiseImpl2D_cpu("cpu", Aidge::ConvDepthWiseImpl2D_cpu::create);
}  // namespace
}  // namespace Aidge

#endif /* __AIDGE_CPU_OPERATOR_CONVDEPTHWISEIMPL_H__ */