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

[Add] 'Operator::backend()' member function and move Tensor dependence from...

[Add] 'Operator::backend()' member function and move Tensor dependence from header to source file when possible in operator
parent a66ae913
No related branches found
No related tags found
No related merge requests found
Showing
with 138 additions and 243 deletions
......@@ -12,15 +12,11 @@
#ifndef AIDGE_CORE_OPERATOR_ADD_H_
#define AIDGE_CORE_OPERATOR_ADD_H_
#include <numeric>
#include <vector>
#include <cmath>
#include <memory>
#include <string>
#include <vector>
#include "aidge/utils/Registrar.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/utils/Types.h"
#include "aidge/utils/ErrorHandling.hpp"
......@@ -44,15 +40,7 @@ public:
* @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.
*/
Add_Op(const Add_Op& op)
: OperatorTensor(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Add_Op, *this, op.mOutputs[0]->getImpl()->backend());
}else{
mImpl = nullptr;
}
}
Add_Op(const Add_Op& op);
/**
* @brief Clone the operator using its copy-constructor.
......@@ -74,10 +62,7 @@ public:
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Add_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName() {
return {"data_input_0", "data_input_n"};
......
......@@ -13,14 +13,18 @@
#define AIDGE_CORE_OPERATOR_AVGPOOLING_H_
#include <array>
#include <numeric>
#include <cmath> // std::floor
#include <cstddef> // std::size_t
#include <string>
#include <utility> // std::pair
#include <vector>
#include <cmath>
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/ArrayHelpers.hpp"
#include "aidge/utils/ErrorHandling.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
......@@ -60,9 +64,9 @@ public:
: OperatorTensor(op),
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(AvgPooling_Op<DIM>, *this, op.mOutputs[0]->getImpl()->backend());
}else{
if (op.mImpl) {
SET_IMPL_MACRO(AvgPooling_Op<DIM>, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......@@ -101,8 +105,7 @@ public:
std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>>
computeReceptiveField(const std::vector<DimSize_t>& firstEltDims,
const std::vector<DimSize_t>& outputDims,
const IOIndex_t outputIdx = 0) const override final
{
const IOIndex_t outputIdx = 0) const override final {
if (outputIdx != 0) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Conv_Op Operator has got only one output Tensor.");
}
......@@ -153,8 +156,8 @@ public:
}
};
template <DimIdx_t DIM>
const std::string AvgPooling_Op<DIM>::Type = "AvgPooling";
template <Aidge::DimIdx_t DIM>
const std::string Aidge::AvgPooling_Op<DIM>::Type = "AvgPooling";
template <std::array<DimSize_t, 1>::size_type DIM>
inline std::shared_ptr<Node> AvgPooling(const std::array<DimSize_t, DIM> &kernel_dims,
......
......@@ -55,7 +55,7 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(BatchNorm_Op<DIM>, *this, op.mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(BatchNorm_Op<DIM>, *this, op.backend());
}else{
mImpl = nullptr;
}
......
......@@ -39,7 +39,11 @@ public:
Cast_Op(const Cast_Op& op)
: OperatorTensor(op)
{
mImpl = op.mImpl ? Registrar<Cast_Op>::create(mOutputs[0]->getImpl()->backend())(*this) : nullptr;
if (op.mImpl) {
SET_IMPL_MACRO(Cast_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
/**
......@@ -50,12 +54,7 @@ public:
return std::make_shared<Cast_Op>(*this);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
if (Registrar<Cast_Op>::exists({name})) {
mImpl = Registrar<Cast_Op>::create({name})(*this);
}
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
void forward() override;
......
......@@ -12,16 +12,16 @@
#ifndef AIDGE_CORE_OPERATOR_CONCAT_H_
#define AIDGE_CORE_OPERATOR_CONCAT_H_
#include <numeric>
#include <vector>
#include <cmath>
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>
#include "aidge/utils/Registrar.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/utils/ErrorHandling.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
......@@ -56,7 +56,7 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Concat_Op, *this, op.mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(Concat_Op, *this, op.backend());
}else{
mImpl = nullptr;
}
......@@ -70,51 +70,9 @@ public:
return std::make_shared<Concat_Op>(*this);
}
// Data operator[](const char* inputName) override final {
// std::shared_ptr<Tensor> in = (strcmp(inputName, "data")) ? mInputs[0] :
// (strcmp(inputName, "weight") ? mInputs[1] :
// (strcmp(inputName, "bias") ? mInputs[2] :
// nullptr));
// assert((in!=nullptr) && "No such parameter");
// return *in;
// }
void computeOutputDims() override final;
void computeOutputDims() override final {
// Every input is non-empty with the same number of dimensions
bool associated = (getInput(0) != nullptr);
associated &= !(getInput(0)->empty()) && (getAttr<ConcatAttr::Axis>() < getInput(0)->nbDims()); // do not compute anything if no input
auto outputDims = getInput(0)->dims();
const auto firstInputNbDims = getInput(0) -> nbDims();
for (IOIndex_t i = 1; i < nbInputs(); ++i) {
if (!getInput(i)) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #{} should be associated with a Tensor", type(), i);
}
if (getInput(i)->nbDims() == firstInputNbDims) {
for (DimSize_t dim = 0; dim < firstInputNbDims; ++dim) {
if (dim == getAttr<ConcatAttr::Axis>()) {
outputDims[dim] += getInput(i)->dims()[dim];
}
else {
associated &= (getInput(i)->dims()[dim] == outputDims[dim]);
}
}
}
else {
associated = false;
break;
}
}
if (associated) {
getOutput(0)->resize(outputDims);
}
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Concat_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input_0", "data_input_n"};
......
......@@ -13,17 +13,20 @@
#define AIDGE_CORE_OPERATOR_CONV_H_
#include <array>
#include <cmath>
#include <cstddef>
#include <numeric>
#include <cmath> // std::floor
#include <cstddef> // std::size_t
#include <string>
#include <utility> // std::pair
#include <vector>
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/ArrayHelpers.hpp"
#include "aidge/utils/ErrorHandling.hpp"
#include "aidge/utils/Registrar.hpp" // SET_IMPL_MACRO
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
......@@ -77,9 +80,9 @@ public:
: OperatorTensor(op),
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Conv_Op<DIM>, *this, op.mOutputs[0]->getImpl()->backend());
}else{
if (op.mImpl) {
SET_IMPL_MACRO(Conv_Op<DIM>, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......@@ -134,8 +137,10 @@ public:
}
}
std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>> computeReceptiveField(const std::vector<DimSize_t>& firstEltDims, const std::vector<DimSize_t>& outputDims, const IOIndex_t outputIdx = 0) const override {
std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>>
computeReceptiveField(const std::vector<DimSize_t>& firstEltDims,
const std::vector<DimSize_t>& outputDims,
const IOIndex_t outputIdx = 0) const override {
if (outputIdx != 0) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "Conv_Op Operator has got only one output Tensor.");
}
......@@ -191,6 +196,7 @@ std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>> co
AIDGE_THROW_OR_ABORT(std::runtime_error, "Given outputDim out of range or output dim not forwarded yet.");
}
void setBackend(const std::string &name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Conv_Op<DIM>, *this, name);
mOutputs[0]->setBackend(name, device);
......
......@@ -13,14 +13,17 @@
#define AIDGE_CORE_OPERATOR_CONVDEPTHWISE_H_
#include <array>
#include <cmath>
#include <numeric>
#include <cmath> // std::floor
#include <cstddef> // std::size_t
#include <string>
#include <utility> // std::pair
#include <vector>
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/ArrayHelpers.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
......@@ -72,7 +75,7 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(ConvDepthWise_Op<DIM>, *this, op.mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(ConvDepthWise_Op<DIM>, *this, op.backend());
}else{
mImpl = nullptr;
}
......
......@@ -12,14 +12,13 @@
#ifndef AIDGE_CORE_OPERATOR_DIV_H_
#define AIDGE_CORE_OPERATOR_DIV_H_
#include <cassert>
#include <memory>
#include <string>
#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"
......@@ -40,9 +39,9 @@ public:
Div_Op(const Div_Op& op)
: OperatorTensor(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Div_Op, *this, op.mOutputs[0]->getImpl()->backend());
}else{
if (op.mImpl) {
SET_IMPL_MACRO(Div_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......@@ -57,11 +56,7 @@ public:
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Div_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input_1", "data_input_2"};
......
......@@ -12,16 +12,14 @@
#ifndef AIDGE_CORE_OPERATOR_ERF_H_
#define AIDGE_CORE_OPERATOR_ERF_H_
#include <cassert>
#include <memory>
#include <string>
#include <vector>
#include "aidge/utils/Registrar.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/data/Data.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
......@@ -40,9 +38,9 @@ public:
Erf_Op(const Erf_Op& op)
: OperatorTensor(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Erf_Op, *this, op.mOutputs[0]->getImpl()->backend());
}else{
if (op.mImpl) {
SET_IMPL_MACRO(Erf_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......@@ -55,10 +53,7 @@ public:
return std::make_shared<Erf_Op>(*this);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Erf_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input"};
......
......@@ -13,13 +13,10 @@
#define AIDGE_CORE_OPERATOR_FC_H_
#include <array>
#include <cmath>
#include <numeric>
#include <memory>
#include <vector>
#include "aidge/utils/Types.h"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
......@@ -58,7 +55,7 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(FC_Op, *this, op.mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(FC_Op, *this, op.backend());
}else{
mImpl = nullptr;
}
......@@ -68,46 +65,15 @@ public:
* @brief Clone the operator using its copy-constructor.
* @see Operator::FC_Op
*/
std::shared_ptr<Operator> clone() const override {
std::shared_ptr<Operator> clone() const override final {
return std::make_shared<FC_Op>(*this);
}
void associateInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>& data) override final {
assert(inputIdx < 3 && "operators supports only 3 inputs");
assert(data->type() == Tensor::Type && "input data must be of Tensor type");
// TODO: FIXME: check this, because data dims may not be initialized at this point...
//if (inputIdx == 2) {
// assert(std::dynamic_pointer_cast<Tensor>(data)->size() == ((this->template getAttr<FCAttr::NoBias>()) == false ? static_cast<std::size_t>(this->template getAttr<FCAttr::OutChannels>()) : 0));
// assert(std::dynamic_pointer_cast<Tensor>(data)->nbDims() == 1);
//}
mInputs[inputIdx] = std::dynamic_pointer_cast<Tensor>(data);
if (inputIdx == 0 && getInput(0)->nbDims() == 1)
mInputs[inputIdx]->resize({1, getInput(inputIdx)->size()});
}
void associateInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>& data) override final;
void computeOutputDims() override final {
bool associated = true;
for (IOIndex_t i = 0; i < nbInputs(); ++i) {
if (!getInput(i)) {
AIDGE_THROW_OR_ABORT(std::runtime_error, "{}: input #{} should be associated with a Tensor", type(), i);
}
associated &= !(getInput(i)->empty());
}
if (associated) {
// <batch, OutChannels>
mOutputs[0]->resize({getInput(0)->dims()[0], this->template getAttr<FCAttr::OutChannels>()});
}
}
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(FC_Op, *this, name);
mOutputs[0]->setBackend(name, device);
// By default, automatically set backend for weight and bias inputs
getInput(1)->setBackend(name, device);
getInput(2)->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input", "weight", "bias"};
......
......@@ -12,16 +12,14 @@
#ifndef AIDGE_CORE_OPERATOR_GATHER_H_
#define AIDGE_CORE_OPERATOR_GATHER_H_
#include <cassert>
#include <cstdint> // std::int64_t
#include <memory>
#include <string>
#include <vector>
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/data/Data.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
......@@ -59,8 +57,8 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(Gather_Op, *this, op.mOutputs[0]->getImpl()->backend());
}else{
SET_IMPL_MACRO(Gather_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......@@ -75,10 +73,7 @@ public:
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Gather_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input"};
......
......@@ -15,8 +15,6 @@
#include <memory>
#include <vector>
#include <string>
#include <cassert>
#include <cstring>
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
......@@ -38,8 +36,8 @@ private:
public:
GenericOperator_Op(const std::string& type, IOIndex_t nbData, IOIndex_t nbParam, IOIndex_t nbOut)
: OperatorTensor(type, nbData, nbParam, nbOut)
{
mImpl = std::make_shared<OperatorImpl>(*this);
{
mImpl = std::make_shared<OperatorImpl>(*this, "");
}
/**
......@@ -49,9 +47,11 @@ public:
GenericOperator_Op(const GenericOperator_Op& op)
: OperatorTensor(op)
{
mImpl = std::make_shared<OperatorImpl>(*this);
mImpl = std::make_shared<OperatorImpl>(*this, op.backend());
}
~GenericOperator_Op() = default;
/**
* @brief Clone the operator using its copy-constructor.
* @see Operator::GenericOperator_Op
......@@ -60,50 +60,20 @@ public:
return std::make_shared<GenericOperator_Op>(*this);
}
public:
void computeOutputDims() override final;
bool outputDimsForwarded() const override final;
void setBackend(const std::string & /*name*/, DeviceIdx_t /*device*/ = 0) override { fmt::print("setBackend: not available yet.\n"); }
void setDataType(const DataType& /*datatype*/) const override { fmt::print("setDataType: not available yet.\n"); }
// Helper functions that can be used with setComputeOutputDims():
static const ComputeDimsFunc Identity;
static const ComputeDimsFunc InputIdentity(IOIndex_t inputIdx, IOIndex_t nbOutputs);
inline void setComputeOutputDims(ComputeDimsFunc func) {
mComputeOutputDims = func;
}
void computeOutputDims() override final {
if (mComputeOutputDims) {
std::vector<std::vector<size_t>> inputsDims(nbInputs(), std::vector<size_t>());
for (std::size_t i = 0; i < nbInputs(); ++i) {
if (getInput(i)) {
inputsDims[i] = getInput(i)->dims();
}
}
const auto& outputsDims = mComputeOutputDims(inputsDims);
assert(outputsDims.size() == nbOutputs() && "The provided ComputeDimsFunc function returns the wrong number of outputs");
for (std::size_t i = 0; i < nbOutputs(); ++i) {
mOutputs[i]->resize(outputsDims[i]);
}
}
else {
assert(false && "Cannot compute output dim of a GenericOperator");
}
}
bool outputDimsForwarded() const override final {
if (mComputeOutputDims) {
return !(mOutputs[0]->empty());
}
else {
assert(false && "GenericOperator cannot forward dims");
return false;
}
}
~GenericOperator_Op() = default;
void setBackend(const std::string & /*name*/, DeviceIdx_t /*device*/ = 0) override { fmt::print("setBackend: not available yet.\n"); }
void setDataType(const DataType& /*datatype*/) const override { fmt::print("setDataType: not available yet.\n"); }
};
/**
......
......@@ -40,9 +40,9 @@ public:
static const std::string Type;
Identity_Op()
: OperatorTensor(Type, 1, 0, 1)
: OperatorTensor(Type, 1, 0, 1)
{
mImpl = std::make_shared<OperatorImpl>(*this);
mImpl = std::make_shared<OperatorImpl>(*this, "");
}
/**
......@@ -52,7 +52,7 @@ public:
Identity_Op(const Identity_Op& op)
: OperatorTensor(op)
{
mImpl = std::make_shared<OperatorImpl>(*this);
mImpl = std::make_shared<OperatorImpl>(*this, op.backend());
}
/**
......@@ -65,11 +65,16 @@ public:
void computeOutputDims() override final {} // Do nothing
/**
* @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 outputDimsForwarded() const override final {
if (mInputs[0])
return !mInputs[0]->empty();
else
return false;
return mInputs[0] ? !mInputs[0]->empty() : false;
}
......
......@@ -55,8 +55,8 @@ public:
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(LeakyReLU_Op, *this, op.mOutputs[0]->getImpl()->backend());
}else{
SET_IMPL_MACRO(LeakyReLU_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......
......@@ -17,7 +17,6 @@
#include <vector>
#include "aidge/utils/Types.h"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/utils/Registrar.hpp"
......@@ -39,7 +38,11 @@ public:
*/
MatMul_Op(const MatMul_Op& op) : OperatorTensor(op)
{
mImpl = op.mImpl ? Registrar<MatMul_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr;
if (op.mImpl){
SET_IMPL_MACRO(MatMul_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
/**
......@@ -64,10 +67,7 @@ public:
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override final {
SET_IMPL_MACRO(MatMul_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override final;
static const std::vector<std::string> getInputsName() {
return {"data_input1", "data_input2"};
......@@ -82,4 +82,4 @@ inline std::shared_ptr<Node> MatMul(const std::string& name = "") {
}
} // namespace Aidge
#endif /* AIDGE_CORE_OPERATOR__MATMUL_H_ */
#endif /* AIDGE_CORE_OPERATOR_MATMUL_H_ */
......@@ -13,16 +13,20 @@
#define AIDGE_CORE_OPERATOR_MAXPOOLING_H_
#include <array>
#include <numeric>
#include <cmath> // std::ceil, std::floor
#include <cstddef> // std::size_t
#include <functional>
#include <memory>
#include <stdexcept> // std::runtime_error
#include <vector>
#include <cmath>
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/operator/Producer.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/ArrayHelpers.hpp"
#include "aidge/utils/ErrorHandling.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
......@@ -64,9 +68,9 @@ public:
: OperatorTensor(op),
Attributes_(op)
{
if (op.mImpl){
SET_IMPL_MACRO(MaxPooling_Op<DIM>, *this, op.mOutputs[0]->getImpl()->backend());
}else{
if (op.mImpl) {
SET_IMPL_MACRO(MaxPooling_Op<DIM>, *this, op.backend());
} else {
mImpl = nullptr;
}
}
......
......@@ -54,7 +54,7 @@ public:
: OperatorTensor(op),
Attributes_(op)
{
mImpl = op.mImpl ? Registrar<Memorize_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr;
mImpl = op.mImpl ? Registrar<Memorize_Op>::create(op.backend())(*this) : nullptr;
mOutputs[1] = mOutputs[0];
}
......
......@@ -12,10 +12,18 @@
#ifndef AIDGE_CORE_OPERATOR_METAOPERATOR_H_
#define AIDGE_CORE_OPERATOR_METAOPERATOR_H_
#include "aidge/operator/OperatorTensor.hpp"
#include <array>
#include <memory>
#include <string>
#include "aidge/data/Data.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/graph/GraphView.hpp"
#include "aidge/graph/OpArgs.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/scheduler/Scheduler.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/Types.h"
namespace Aidge {
class MetaOperator_Op : public OperatorTensor,
......@@ -28,7 +36,7 @@ public:
std::weak_ptr<Node> mUpperNode;
public:
MetaOperator_Op(const char *type, const std::shared_ptr<GraphView>& graph);
MetaOperator_Op(const std::string& type, const std::shared_ptr<GraphView>& graph);
/**
* @brief Copy-constructor. Copy the operator attributes and its output tensor(s), but not its input tensors (the new operator has no input associated).
......
......@@ -19,7 +19,6 @@
#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"
......@@ -43,7 +42,11 @@ public:
Mul_Op(const Mul_Op& op)
: OperatorTensor(op)
{
mImpl = op.mImpl ? Registrar<Mul_Op>::create(op.mOutputs[0]->getImpl()->backend())(*this) : nullptr;
if (op.mImpl) {
SET_IMPL_MACRO(Mul_Op, *this, op.backend());
} else {
mImpl = nullptr;
}
}
/**
......@@ -56,10 +59,7 @@ public:
void computeOutputDims() override final;
void setBackend(const std::string& name, DeviceIdx_t device = 0) override {
SET_IMPL_MACRO(Mul_Op, *this, name);
mOutputs[0]->setBackend(name, device);
}
void setBackend(const std::string& name, DeviceIdx_t device = 0) override;
static const std::vector<std::string> getInputsName(){
return {"data_input_1", "data_input_2"};
......
......@@ -81,7 +81,7 @@ public:
virtual void associateInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>& data) = 0;
/**
* @brief Set the specified input by performing a deep copy of the given data.
* @brief Set the specified input value by performing a deep copy of the given data.
* The pointer itself is not changed, thus keeping the current connections.
* @param inputIdx Index of the input to set.
* @param data Data to copy.
......@@ -90,7 +90,7 @@ public:
virtual void setInput(const IOIndex_t inputIdx, std::shared_ptr<Data>&& data) = 0;
virtual std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const = 0;
/**
* @brief Set the specified output by performing a deep copy of the given data.
* @brief Set the specified output value by performing a deep copy of the given data.
* The pointer itself is not changed, thus keeping the current connections.
* @param inputIdx Index of the input to set.
*/
......@@ -110,6 +110,9 @@ public:
///////////////////////////////////////////////////////
// IMPLEMENTATION
///////////////////////////////////////////////////////
std::string backend() const noexcept {
return mImpl ? mImpl->backend() : "";
}
virtual void setBackend(const std::string& name, DeviceIdx_t device = 0) = 0;
virtual void setDataType(const DataType& dataType) const = 0;
......
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