Skip to content
Snippets Groups Projects
SoftmaxImpl.hpp 2.2 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_SOFTMAXIMPL_H__
#define __AIDGE_CPU_OPERATOR_SOFTMAXIMPL_H__

#include "backend/OperatorImpl.hpp"
#include "operator/Softmax.hpp"
#include "utils/Registrar.hpp"
#include "utils/Types.h"
#include <memory>
#include <vector>

namespace Aidge {
// class Softmax_Op;

// compute kernel registry for forward and backward
class SoftmaxImplForward_cpu
    : public Registrable<SoftmaxImplForward_cpu, std::tuple<DataType, DataType>, void(const DimSize_t, const DimSize_t, const DimSize_t, const void*, void*)> {
};
class SoftmaxImplBackward_cpu
    : public Registrable<SoftmaxImplBackward_cpu, std::tuple<DataType, DataType>, void(const std::size_t, const void*, void*)> {
};

class SoftmaxImpl_cpu : public OperatorImpl {
   private:
    const Softmax_Op& mOp;
    std::array<NbElts_t, 1> mNbConsumedData;
    std::array<NbElts_t, 1> mNbProducedData;

   public:
    SoftmaxImpl_cpu(const Softmax_Op& op) : mOp(op), mNbConsumedData({0}), mNbProducedData({0}) {}

    static std::unique_ptr<SoftmaxImpl_cpu> create(const Softmax_Op& op) {
        return std::make_unique<SoftmaxImpl_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 {
static Registrar<Softmax_Op> registrarSoftmaxImpl_cpu("cpu", Aidge::SoftmaxImpl_cpu::create);
}
}  // namespace Aidge

#endif /* __AIDGE_CPU_OPERATOR_SOFTMAXIMPL_H__ */