Tensor update issue
I noticed in a lot of place, the output Tensor is updated by creating a new Tensor and setting as the operator output. This is really computationnally heavy:
// set the attributes
clipOp->max() = max;
clipOp->min() = min;
// Retrieve the previous min/max tensors
auto minTensor = std::static_pointer_cast<OperatorTensor>(clipNode->getOperator())->getInput(1);
auto maxTensor = std::static_pointer_cast<OperatorTensor>(clipNode->getOperator())->getInput(2);
// Create the new min/max tensors
std::shared_ptr<Tensor> newMinTensor = std::make_shared<Tensor>(min);
newMinTensor->toBackend(minTensor->backend());
newMinTensor->toDformat(minTensor->dformat());
newMinTensor->toDtype(minTensor->dtype());
std::shared_ptr<Tensor> newMaxTensor = std::make_shared<Tensor>(max);
newMaxTensor->toBackend(maxTensor->backend());
newMaxTensor->toDformat(maxTensor->dformat());
newMaxTensor->toDtype(maxTensor->dtype());
// Set the tensors of the producer
auto minProducer = clipNode->getParent(1);
minProducer->getOperator()->setOutput(0, newMinTensor);
auto maxProducer = clipNode->getParent(2);
maxProducer->getOperator()->setOutput(0, newMaxTensor);
Instead, you can simply update the Tensor has follow:
auto minTensor = std::static_pointer_cast<OperatorTensor>(clipNode->getOperator())->getInput(1);
auto maxTensor = std::static_pointer_cast<OperatorTensor>(clipNode->getOperator())->getInput(2);
minTensor->copyCastFrom(std::make_shared<Tensor>(min));
maxTensor->copyCastFrom(std::make_shared<Tensor>(max))
I started to update some functions in !67 (merged) but I let you do the other changes :)
Edited by Cyril Moineau