Skip to content
Snippets Groups Projects
Commit ef6ca53d authored by Maxence Naud's avatar Maxence Naud
Browse files

Remove Operator reference to Tensor

- split Input into Data and Attr
- change inputData for Data
- remove getInput/getOutput and input/output member functions
- remove member functions refering to Tensor dimensions
parent 50f86506
No related branches found
No related tags found
2 merge requests!46Remove Operator reference to Tensor,!20Draft: Introduction of Tiling
...@@ -26,39 +26,47 @@ namespace Aidge { ...@@ -26,39 +26,47 @@ namespace Aidge {
class Operator : public std::enable_shared_from_this<Operator> { class Operator : public std::enable_shared_from_this<Operator> {
protected: protected:
std::shared_ptr<OperatorImpl> mImpl; // implementation of the operator std::shared_ptr<OperatorImpl> mImpl; // implementation of the operator
std::map<std::string, std::shared_ptr<Hook>> mHooks; std::map<std::string, std::shared_ptr<Hook>> mHooks;
private: private:
std::string mType; std::string mType;
const IOIndex_t mNbData;
const IOIndex_t mNbAttr;
const IOIndex_t mNbOut;
public: public:
Operator() = delete; Operator() = delete;
Operator(const char* type) : mType(type) {} Operator(const char* type, const IOIndex_t nbData, const IOIndex_t nbAttr, const IOIndex_t nbOut)
virtual std::shared_ptr<Operator> clone() const = 0; : mType(type),
virtual ~Operator(); mNbData(nbData),
mNbAttr(nbAttr),
Operator(const Operator& op): mNbOut(nbOut)
std::enable_shared_from_this<Operator>() {
{ // ctor
mType = op.mType; }
mImpl = nullptr; virtual std::shared_ptr<Operator> clone() const = 0;
// Implementation is never cloned. It is up to the non-abstract Operator copy-constructor to create a new implementation matching the copied Operator implementation. virtual ~Operator();
// See https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/8#note_1214050 for the discussion.
// Hooks are not copied. Operator(const Operator& op):
} std::enable_shared_from_this<Operator>(),
mNbData(op.mNbData),
mNbAttr(op.mNbAttr),
mNbOut(op.mNbOut)
{
mType = op.mType;
mImpl = nullptr;
// Implementation is never cloned. It is up to the non-abstract Operator copy-constructor to create a new implementation matching the copied Operator implementation.
// See https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/merge_requests/8#note_1214050 for the discussion.
// Hooks are not copied.
}
public: public:
virtual void associateInput(const IOIndex_t inputIdx, std::shared_ptr<Data> data) = 0; virtual void associateInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>* data) = 0;
virtual void computeOutputDims() = 0;
virtual bool outputDimsForwarded() const = 0;
virtual std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const = 0; virtual std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const = 0;
virtual std::shared_ptr<Tensor> getInput(const IOIndex_t inputIdx) const = 0;
virtual Tensor& input(const IOIndex_t /*inputIdx*/) const = 0;
virtual std::shared_ptr<Data> getRawOutput(const IOIndex_t outputIdx) const = 0; virtual std::shared_ptr<Data> getRawOutput(const IOIndex_t outputIdx) const = 0;
virtual std::shared_ptr<Tensor> getOutput(const IOIndex_t outputIdx) const = 0;
virtual Tensor& output(const IOIndex_t /*outputIdx*/) const = 0;
std::shared_ptr<Hook> getHook(std::string hookName) { std::shared_ptr<Hook> getHook(std::string hookName) {
return mHooks[hookName]; return mHooks[hookName];
...@@ -121,10 +129,12 @@ public: ...@@ -121,10 +129,12 @@ public:
return mType; return mType;
} }
virtual IOIndex_t nbInputs() const noexcept = 0; inline IOIndex_t nbInputs() const noexcept { return mNbData+mNbAttr; };
virtual IOIndex_t nbDataInputs() const noexcept = 0; inline IOIndex_t nbData() const noexcept { return mNbData; };
virtual IOIndex_t nbOutputs() const noexcept = 0; inline IOIndex_t nbAttr() const noexcept { return mNbAttr; };
static const std::vector<std::string> getInputsName(){ inline IOIndex_t nbOutputs() const noexcept { return mNbOut; };
static const std::vector<std::string> getInputsName(){
return {}; return {};
} }
static const std::vector<std::string> getOutputsName(){ static const std::vector<std::string> getOutputsName(){
......
...@@ -48,8 +48,12 @@ void Aidge::Operator::runHooks() const { ...@@ -48,8 +48,12 @@ void Aidge::Operator::runHooks() const {
} }
} }
void Aidge::Operator::forward() { void Aidge::Operator::forward() {
mImpl->forward(); if(mImpl) {
runHooks(); mImpl->forward();
runHooks();
} else {
printf("backward: No implementation is linked.\n");
}
} }
void Aidge::Operator::backward() { mImpl->backward(); } void Aidge::Operator::backward() { mImpl->backward(); }
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