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
*
********************************************************************************/

Maxence Naud
committed
#include "aidge/operator/Producer.hpp"
#include <cstddef>
#include <array>
#include <memory>
#include <string>

Maxence Naud
committed
#include "aidge/backend/OperatorImpl.hpp"
#include "aidge/data/Tensor.hpp"
#include "aidge/operator/OperatorTensor.hpp"
#include "aidge/utils/Registrar.hpp"
#include "aidge/utils/StaticAttributes.hpp"
#include "aidge/utils/Types.h"
const std::string Aidge::Producer_Op::Type = "Producer";

Maxence Naud
committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, bool constant)
: OperatorTensor(Type, 0, 0, 1),
Attributes_(attr<ProdAttr::Constant>(constant))
{
mOutputs[0] = tensor; // copy the pointer of the Tensor
mImpl = (tensor->hasImpl()) ?
std::make_shared<OperatorImpl>(*this, tensor->getImpl()->backend()) :
nullptr;
}
/**
* @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 OperatorTensor to copy.
*/
Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
: OperatorTensor(op),
Attributes_(op)
{
mOutputs[0] = std::make_shared<Tensor>(*(op.getOutput(0)));
if (mOutputs[0]->hasImpl()) {
if (Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
setImpl(Registrar<Producer_Op>::create(mOutputs[0]->getImpl()->backend())(*this));
}
else {
mImpl = std::make_shared<OperatorImpl>(*this, mOutputs[0]->getImpl()->backend());
}
} else {
mImpl = nullptr;
}
}
void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
if (Registrar<Producer_Op>::exists(name)) {
setImpl(Registrar<Producer_Op>::create(name)(*this));
} else {
mImpl = std::make_shared<OperatorImpl>(*this, name);
}
mOutputs[0]->setBackend(name, device);
}