Skip to content

[core] Segfault in the logOutputs() Method (GraphView.cpp)

I encountered a segfault in the Aidge::GraphView::logOutputs function when the data was on the GPU. The issue was caused by the use of getRawOutput(outIdx), which does not properly handle GPU memory and leads to a crash.

Replaced: fmt::print(fp.get(), "{}\n", nodePtr->getOperator()->getRawOutput(outIdx)->toString().c_str());

With:

std::shared_ptr<Aidge::Tensor> oTensor = std::static_pointer_cast<OperatorTensor>(nodePtr->getOperator())->getOutput(outIdx);
std::shared_ptr<Tensor> fallback;
const Tensor& localTensor = oTensor->refCastFrom(fallback, DataType::Float64, "cpu");
fmt::print(fp.get(), "{}\n", localTensor.toString().c_str());

This ensures that the data is properly cast to CPU memory before being used for logging.

Steps to reproduce: Run logOutputs() on a graph with data stored on the GPU. Before the fix: results in a segfault. After the fix: the function executes correctly.

Edited by Noam Zerah