Skip to content
Snippets Groups Projects

[Fix] Producer clone and Tensor copy

Merged Maxence Naud requested to merge fix_207-producer-clone into dev
1 unresolved thread
1 file
+ 8
3
Compare changes
  • Side-by-side
  • Inline
+ 8
3
@@ -44,7 +44,7 @@ Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, boo
@@ -44,7 +44,7 @@ Aidge::Producer_Op::Producer_Op(const std::shared_ptr<Aidge::Tensor> tensor, boo
attr<ProdAttr::Constant>(constant)))
attr<ProdAttr::Constant>(constant)))
{
{
mOutputs[0] = tensor; // copy the pointer of the Tensor
mOutputs[0] = tensor; // copy the pointer of the Tensor
if (mOutputs[0]->getImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
if (mOutputs[0] && mOutputs[0]->hasImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
}
}
else {
else {
@@ -61,7 +61,7 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
@@ -61,7 +61,7 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
: OperatorTensor(op),
: OperatorTensor(op),
mAttributes(op.mAttributes)
mAttributes(op.mAttributes)
{
{
mOutputs[0] = std::make_shared<Tensor>(*(op.getOutput(0)));
*mOutputs[0] = *(op.getOutput(0));
if (mOutputs[0]->getImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
if (mOutputs[0]->getImpl() && Registrar<Producer_Op>::exists({mOutputs[0]->getImpl()->backend()})){
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
SET_IMPL_MACRO(Producer_Op, *this, mOutputs[0]->getImpl()->backend());
}
}
@@ -71,7 +71,12 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
@@ -71,7 +71,12 @@ Aidge::Producer_Op::Producer_Op(const Aidge::Producer_Op& op)
}
}
std::shared_ptr<Aidge::Operator> Aidge::Producer_Op::clone() const {
std::shared_ptr<Aidge::Operator> Aidge::Producer_Op::clone() const {
return std::make_shared<Producer_Op>(*this);
// mOutput cannot be nullptr because of OperatorTensor constructor
 
std::shared_ptr<Tensor> newTensor = std::make_shared<Tensor>(mOutputs[0]->clone());
 
 
std::shared_ptr<Producer_Op> newOp = std::make_shared<Producer_Op>(newTensor, constant());
 
 
return newOp;
}
}
void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
void Aidge::Producer_Op::setBackend(const std::string& name, Aidge::DeviceIdx_t device) {
Loading