[Fix] Checking nullptr on Node.cpp and ConstantFolding.cpp
Context
In the context of using expand_metaops(), adapt_to_backend() and constant_folding() to export arm_cortex_m with the LibCMSIS_NN backend, I encountered SIGSEGV when using two expand_metaops() or two constant_folding() in a row.
Example
model = aidge_core.sequential([
aidge_core.Conv2D(in_channels=2, out_channels = 2, kernel_dims = [1,1], name = 'conv', stride_dims= [1, 1], dilation_dims = [1, 1], no_bias= False),
aidge_quantization.Quantizer(scalingFactor = 0.005, clip_min = -128.0, clip_max = 127.0, name="scale")
])
model.set_datatype(aidge_core.dtype.float32)
model.set_backend("cpu")
model.save("PreFuse")
print("Fuse ConvScaling")
aidge_core.fuse_to_metaops(model, "Conv2D->Quantizer", "PaddedConvScalingRelu")
model.compile('cpu',aidge_core.dtype.float32, dims=[input_dims])
model.save("PostFuse")
scheduler = aidge_core.SequentialScheduler(model)
scheduler.generate_scheduling()
from aidge_export_arm_cortexm.export_registry import ExportLibAidgeARM, ExportLibCMSISNN
for node in model.get_nodes():
aidge_core.Log.debug(f"Setting backend {ExportLibCMSISNN._name} to {node.name()}[{node.type()}].")
node.get_operator().set_backend(ExportLibCMSISNN._name)
aidge_core.adapt_to_backend(model)
model.save("adapt_to_backend")
aidge_core.constant_folding(model)
aidge_core.constant_folding(model)
model.save("constant_folding")
# aidge_core.remove_constantOfShape(model)
aidge_core.expand_metaops(model)
aidge_core.expand_metaops(model)
model.save("exploded")
print("print")
Modified files
-
Node.cpp
andConstantFolding.cpp
, nullptr methods can no longer be accessed ;
Observations
With this MR, nullptr methods can no longer be accessed, but the problems may come from the calling functions.
Merge request reports
Activity
390 390 } 391 391 for (IOIndex_t i = 0; i < nbOutputs(); ++i) { 392 392 for (std::pair<std::shared_ptr<Node>, IOIndex_t> child : output(i)) { 393 child.first->removeParent(child.second); 393 if(child.first != nullptr && child.first->getParents().size() > 0) child.first->removeParent(child.second); 394 else Log::debug("No child.first"); - Comment on lines +393 to +394
Debug log is unecessary.
child.first->getParents().size() > 0
check is weird, you are in the parent node you get the output and then check that the output has a parent? changed this line in version 2 of the diff
32 32 candidates.insert(childs.begin(), childs.end()); 33 33 } 34 34 } 35 35 36 36 for (const auto& node : candidates) { 37 37 bool foldable = true; 38 38 auto replaceGraph = std::make_shared<GraphView>(); 39 for (const auto& input : node->inputs()) { 40 if (input.first) { 41 if (input.first->type() != Producer_Op::Type) { 42 foldable = false; 43 break; 44 } 39 if( node != nullptr && node->inputs().size()>0){ Why not just use a continue statement?
This would prevent the extra indent.
Edited by Cyril Moineauchanged this line in version 2 of the diff
assigned to @wboussella
added 9 commits
- c090d609 - [Upd] Add pybind recipes for constant of shape and debug log for node_export.py
- dfd8dc63 - [Upd] New def for constant_folding
- ac54157a - Apply 1 suggestion(s) to 1 file(s)
- 8518133f - Fix node_export.py
- 4fb26f05 - Merge branch 'pybind_and_export' of gitlab.eclipse.org:wboussella/aidge_core into pybind_and_export
- 901ca04c - Merge commit '3391a6a4' into dev
- b662bbd9 - Merge commit '4fb26f05' into dev
- 258ee6ed - [Upd] removing useless checks
- 7978595c - check
Toggle commit listmentioned in issue #220 (closed)
added 6 commits
Toggle commit listadded StatusDelayed label
@wboussella Could you 1) Rebase your MR and 2) Removed unrelated changes in node_export.py and pybind_Recipes.cpp (already covered in !288 (closed))