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
*
********************************************************************************/
#ifndef AIDGE_CORE_OPERATOR_FC_H_
#define AIDGE_CORE_OPERATOR_FC_H_
#include <array>
#include <memory>
#include <vector>
#include "aidge/utils/Types.h"
#include "aidge/graph/Node.hpp"

Maxence Naud
committed
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Registrar.hpp"

Maxence Naud
committed
enum class FCAttr { NoBias };

Maxence Naud
committed
class FC_Op : public OperatorTensor,
std::shared_ptr<OperatorImpl>(const FC_Op &)>,

Maxence Naud
committed
public StaticAttributes<FCAttr, bool> {
static const std::string Type;

Maxence Naud
committed
using Attributes_ = StaticAttributes<FCAttr, bool>;
template <FCAttr e> using attr = typename Attributes_::template attr<e>;

Maxence Naud
committed
FC_Op(bool noBias)

Maxence Naud
committed
: OperatorTensor(Type, 1, 2, 1),

Maxence Naud
committed
Attributes_(attr<FCAttr::NoBias>(noBias))

Maxence Naud
committed
{}
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s), but not its input tensors (the new operator has no input associated).
* @param op Operator to copy.
*/
FC_Op(const FC_Op& op)

Maxence Naud
committed
: OperatorTensor(op),
Attributes_(op)

Maxence Naud
committed
SET_IMPL_MACRO(FC_Op, *this, op.backend());
}else{
mImpl = nullptr;
}
}
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::FC_Op
*/

Maxence Naud
committed
std::shared_ptr<Operator> clone() const override final {
}

Maxence Naud
committed
void associateInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>& data) override final;
bool forwardDims(bool allowDataDependency = false) override final;

Maxence Naud
committed
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
return {"data_input", "weight", "bias"};
}
return {"data_output"};
}

Maxence Naud
committed
inline std::shared_ptr<Node> FC(const DimSize_t inChannels, const DimSize_t outChannels, bool noBias = false, const std::string& name = "") {
// FIXME: properly handle default w&b initialization in every cases

Maxence Naud
committed
auto fc = std::make_shared<Node>(std::make_shared<FC_Op>(noBias), name);
addProducer(fc, 1, {outChannels, inChannels}, "w");
addProducer(fc, 2, {(noBias ? 0 : outChannels)}, "b"); // already sets bias dims
return fc;
}
} // namespace Aidge
namespace {
template <>

Maxence Naud
committed
const char *const EnumStrings<Aidge::FCAttr>::data[] = {"NoBias"};
#endif /* AIDGE_CORE_OPERATOR_FC_H_ */