diff --git a/include/aidge/operator/Sigmoid.hpp b/include/aidge/operator/Sigmoid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ab97bf3211edb53d65a90d16dba5d0c66dfa33da --- /dev/null +++ b/include/aidge/operator/Sigmoid.hpp @@ -0,0 +1,72 @@ +/******************************************************************************** + * 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_SIGMOID_H_ +#define AIDGE_CORE_OPERATOR_SIGMOID_H_ + +#include <cassert> +#include <memory> +#include <vector> + +#include "aidge/utils/Registrar.hpp" +#include "aidge/operator/OperatorTensor.hpp" +#include "aidge/backend/OperatorImpl.hpp" +#include "aidge/data/Tensor.hpp" +#include "aidge/graph/Node.hpp" +#include "aidge/utils/Types.h" + +namespace Aidge { + +class Sigmoid_Op : public OperatorTensor, + public Registrable<Sigmoid_Op, std::string, std::unique_ptr<OperatorImpl>(const Sigmoid_Op&)> { +public: + static const std::string Type; + + Sigmoid_Op() : OperatorTensor(Type, 1, 0, 1) {} + + /** + * @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. + */ + Sigmoid_Op(const Sigmoid_Op& op) + : OperatorTensor(op) + { + mImpl = op.mImpl ? Registrar<Sigmoid_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr; + } + + /** + * @brief Clone the operator using its copy-constructor. + * @see Operator::Sigmoid_Op + */ + std::shared_ptr<Operator> clone() const override { + return std::make_shared<Sigmoid_Op>(*this); + } + + + void setBackend(const std::string& name, DeviceIdx_t device = 0) override { + mImpl = Registrar<Sigmoid_Op>::create(name)(*this); + mOutputs[0]->setBackend(name, device); + } + + static const std::vector<std::string> getInputsName(){ + return {"data_input"}; + } + static const std::vector<std::string> getOutputsName(){ + return {"data_output"}; + } +}; + +inline std::shared_ptr<Node> Sigmoid(const std::string& name = "") { + return std::make_shared<Node>(std::make_shared<Sigmoid_Op>(), name); +} +} + +#endif /* AIDGE_CORE_OPERATOR_SIGMOID_H_ */ \ No newline at end of file diff --git a/include/aidge/operator/Tanh.hpp b/include/aidge/operator/Tanh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ce0dc12a06d242d215c07dc6593bb7e2cb2c3c8a --- /dev/null +++ b/include/aidge/operator/Tanh.hpp @@ -0,0 +1,72 @@ +/******************************************************************************** + * 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_TANH_H_ +#define AIDGE_CORE_OPERATOR_TANH_H_ + +#include <cassert> +#include <memory> +#include <vector> + +#include "aidge/utils/Registrar.hpp" +#include "aidge/operator/OperatorTensor.hpp" +#include "aidge/backend/OperatorImpl.hpp" +#include "aidge/data/Tensor.hpp" +#include "aidge/graph/Node.hpp" +#include "aidge/utils/Types.h" + +namespace Aidge { + +class Tanh_Op : public OperatorTensor, + public Registrable<Tanh_Op, std::string, std::unique_ptr<OperatorImpl>(const Tanh_Op&)> { +public: + static const std::string Type; + + Tanh_Op() : OperatorTensor(Type, 1, 0, 1) {} + + /** + * @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. + */ + Tanh_Op(const Tanh_Op& op) + : OperatorTensor(op) + { + mImpl = op.mImpl ? Registrar<Tanh_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr; + } + + /** + * @brief Clone the operator using its copy-constructor. + * @see Operator::Tanh_Op + */ + std::shared_ptr<Operator> clone() const override { + return std::make_shared<Tanh_Op>(*this); + } + + + void setBackend(const std::string& name, DeviceIdx_t device = 0) override { + mImpl = Registrar<Tanh_Op>::create(name)(*this); + mOutputs[0]->setBackend(name, device); + } + + static const std::vector<std::string> getInputsName(){ + return {"data_input"}; + } + static const std::vector<std::string> getOutputsName(){ + return {"data_output"}; + } +}; + +inline std::shared_ptr<Node> Tanh(const std::string& name = "") { + return std::make_shared<Node>(std::make_shared<Tanh_Op>(), name); +} +} + +#endif /* AIDGE_CORE_OPERATOR_TANH_H_ */ \ No newline at end of file diff --git a/src/operator/Sigmoid.cpp b/src/operator/Sigmoid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48ed5f8286712c94bcf87f3234e70080652ab141 --- /dev/null +++ b/src/operator/Sigmoid.cpp @@ -0,0 +1,16 @@ +/******************************************************************************** + * 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 <string> + +#include "aidge/operator/Sigmoid.hpp" + +const std::string Aidge::Sigmoid_Op::Type = "Sigmoid"; \ No newline at end of file diff --git a/src/operator/Tanh.cpp b/src/operator/Tanh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de55a6d6c69df5706b945ef9f56027f7a09ce8d7 --- /dev/null +++ b/src/operator/Tanh.cpp @@ -0,0 +1,16 @@ +/******************************************************************************** + * 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 <string> + +#include "aidge/operator/Tanh.hpp" + +const std::string Aidge::Tanh_Op::Type = "Tanh"; \ No newline at end of file