Skip to content
Snippets Groups Projects
Commit 1b2e606d authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Changed Identity to perform actual copy, a required condition for Scheduler

parent 86c9e398
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!186Refactor OperatorImpl for backend/export
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
#include "aidge/utils/ErrorHandling.hpp" #include "aidge/utils/ErrorHandling.hpp"
namespace Aidge { namespace Aidge {
class Identity_OpImpl : public OperatorImpl {
public:
Identity_OpImpl(const Operator& op, const std::string& backend = ""): OperatorImpl(op, backend) {}
void forward() override;
};
/** /**
* @brief Indentity_Op is an helper operator made to ease the declaration of MetaNodes. * @brief Indentity_Op is an helper operator made to ease the declaration of MetaNodes.
...@@ -54,30 +59,8 @@ public: ...@@ -54,30 +59,8 @@ public:
*/ */
std::shared_ptr<Operator> clone() const override; std::shared_ptr<Operator> clone() const override;
// bool forwardDims(bool /*allowDataDependency*/ = false) override final { return true; } // Do nothing void setBackend(const std::string& name, DeviceIdx_t device = 0) override final;
std::set<std::string> getAvailableBackends() const override;
/**
* @brief Check if output dimensions have been computed.
* @note Since Indentity has no output Tensor, this function checks if its
* only input's dimensions have been computed.
*
* @return true Input has dimensions.
* @return false Input has no dimensions or is a nullptr.
*/
bool dimsForwarded() const override final;
void forward() override final;
void backward() override final { }
void setBackend(const std::string& /*name*/, DeviceIdx_t /*device*/ = 0) override final {
// setBackend do nothing, Identity node has no backend it just pass the same Tensor
}
std::set<std::string> getAvailableBackends() const override { return std::set<std::string>(); };
void setDataType(const DataType& /*dataType*/) const override final {
// setDatatype do nothing, Identity node has no backend it just pass the same Tensor
}
static const std::vector<std::string> getInputsName(){ static const std::vector<std::string> getInputsName(){
return {"data_input"}; return {"data_input"};
......
...@@ -13,35 +13,37 @@ ...@@ -13,35 +13,37 @@
#include "aidge/operator/Identity.hpp" #include "aidge/operator/Identity.hpp"
void Aidge::Identity_OpImpl::forward() {
const Identity_Op& op = dynamic_cast<const Identity_Op&>(mOp);
op.getOutput(0)->getImpl()->copy(op.getInput(0)->getImpl()->rawPtr(), op.getInput(0)->size());
}
//////////////////////////////////////////////////
const std::string Aidge::Identity_Op::Type = "Identity"; const std::string Aidge::Identity_Op::Type = "Identity";
Aidge::Identity_Op::Identity_Op() Aidge::Identity_Op::Identity_Op()
: OperatorTensor(Type, {InputCategory::Data}, 1) : OperatorTensor(Type, {InputCategory::Data}, 1)
{ {
mImpl = std::make_shared<OperatorImpl>(*this); mImpl = std::make_shared<Identity_OpImpl>(*this);
} }
Aidge::Identity_Op::Identity_Op(const Aidge::Identity_Op& op) Aidge::Identity_Op::Identity_Op(const Aidge::Identity_Op& op)
: OperatorTensor(op) : OperatorTensor(op)
{ {
mImpl = std::make_shared<OperatorImpl>(*this, op.backend()); mImpl = std::make_shared<Identity_OpImpl>(*this, op.backend());
} }
std::shared_ptr<Aidge::Operator> Aidge::Identity_Op::clone() const { std::shared_ptr<Aidge::Operator> Aidge::Identity_Op::clone() const {
return std::make_shared<Identity_Op>(*this); return std::make_shared<Identity_Op>(*this);
} }
bool Aidge::Identity_Op::dimsForwarded() const { void Aidge::Identity_Op::setBackend(const std::string& name, DeviceIdx_t device) {
const auto& input0 = getInput(0); mOutputs[0]->setBackend(name, device);
return input0 ? (input0->undefined() ? false :
input0->dims() == getOutput(0)->dims()) :
false;
} }
void Aidge::Identity_Op::forward() { std::set<std::string> Aidge::Identity_Op::getAvailableBackends() const {
// Perform a shallow copy return Registrar<Identity_Op>::getKeys();
*(mOutputs[0]) = *(mInputs[0]);
runHooks();
} }
std::shared_ptr<Aidge::Node> Aidge::Identity(const std::string& name) { std::shared_ptr<Aidge::Node> Aidge::Identity(const std::string& name) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment