Skip to content
Snippets Groups Projects

[Fix] Checking nullptr on Node.cpp and ConstantFolding.cpp

Closed Wissam Boussella requested to merge wboussella/aidge_core:fix_node_constant_folding into dev
2 unresolved threads

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 and ConstantFolding.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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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");
  • 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){
  • 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

    Compare with previous version

  • mentioned in issue #220 (closed)

  • added 6 commits

    • 9d76c6f7 - [Upd] Add pybind recipes for constant of shape and debug log for node_export.py
    • c15af903 - [Upd] New def for constant_folding
    • 7fe72060 - Fix node_export.py
    • e8f4e8f9 - [Upd] removing useless checks
    • 81661628 - check
    • c32bf181 - Merge branch 'fix_node_constant_folding' of...

    Compare with previous version

  • @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))

  • Why did you close this MR? Isn't the nullptr check necessary anymore?

  • Please register or sign in to reply
    Loading