Skip to content

Conversation

@lmoneta
Copy link
Member

@lmoneta lmoneta commented Sep 5, 2025

This PR introduces a time-based profiler for the SOFIE inference engine. It provides developers with the tools to analyze the performance of generated C++ models by measuring the execution time of each individual operator, as well as the total inference time.

Changes or fixes:

A new option, SOFIE::Options::kProfile, is added to the RModel::Generate() method to enable the feature.
When enabled, a new RModelProfiler helper class instruments the generated doInfer() method with std::chrono timers.
Utility functions like PrintProfilingResults() and GetOpAvgTime() are added to the generated Session struct to access the collected timing data.
Checklist:

Tested changes locally by running inference in a loop and verifying the timing results.
updated the docs (if necessary)

This PR replaces #19558 by fixing the conflicts with rebasing to master

@dpiparo
Copy link
Member

dpiparo commented Sep 5, 2025

Is there perhaps a way in which we could test this new nice feature?

@github-actions
Copy link

github-actions bot commented Sep 5, 2025

Test Results

    20 files      20 suites   3d 11h 19m 38s ⏱️
 3 792 tests  3 781 ✅  1 💤 10 ❌
72 892 runs  72 789 ✅ 17 💤 86 ❌

For more details on these failures, see this check.

Results for commit 32d38a2.

♻️ This comment has been updated with latest results.

@lmoneta
Copy link
Member Author

lmoneta commented Sep 5, 2025

Yes, I think we should add a tutorial for this, generting code instrumented with timers and then producing the results.
@olia110 can you add this new tutorial?

@olia110
Copy link
Contributor

olia110 commented Sep 5, 2025

Yes, thank you. I will look how to add some testing and will add a tutorial.

Add missing support for Dynamic tensors for some operators.
With this commit a full support for dynamic tensor is available for ParticleNet model.
Fix also a bug in Concat operator when the concat axis is not the first one
Since we use now for boolean tensors a std::vector<uint8_t> it is not needed to
have a special treatment when the output ttype of the operator is a boolean
(e.g. in Comparison)
…ensors

Add a new function in SOFIE_common OrganizeMemory which computes the total memory and the offset for each tensor given tensor begin /end life and size.

Fix also some small issue with dynamic tensor.
One is for the bias of Gemm and Conv. The broadcasting of bias is done for dynamic tensor in the Session constructor only if needed. For the broadcasted tensor  there is no need to create a new tensor, but the existing one is resized to the  broadcasted needed size using vector::resize
… broadcasting

The assert that was generated when broadcasting dynamic tensors was not correct
Apply also other fixes for the SOFIE tests and add a new test for StackMul
The order execution ws not set for tensor inputs to operators added using the
GNN Sofie classes. This is now fixed and the correct memory mangement can be performed.
SOme fixes are needed for the test, since the session is not used for this tests.
Need also to force using Session in case of Dynamic tensors

Fix also a warning in Gemm operator and RModel
@lmoneta lmoneta force-pushed the olha_sofie_profiler branch 2 times, most recently from f5d5684 to ff6a141 Compare January 7, 2026 15:13
…on ctor

Do an alphabetical order of Session shape parameters for dynamic tensors, otherwise they may get a random order. Observed different order on different platforms

Add some small improvements in the generated code (add nunber and shape informations) when generating Gemm code
@lmoneta lmoneta force-pushed the olha_sofie_profiler branch from ff6a141 to a121471 Compare January 7, 2026 15:21
…on ctor

Avoid creating a broadcasted bias tensor which uses lots of memory.
Do broadcasting of the bias on the fly before computing Gemm by using the output tensor.
This saves a large amount of memory on models using large Gemm calss like the atlas GNN model used for tracking
@lmoneta lmoneta force-pushed the olha_sofie_profiler branch from a121471 to 1585356 Compare January 8, 2026 18:12
lmoneta and others added 3 commits January 9, 2026 10:15
Add alias tensors to cope with identity operators.
In this case just a pointer assignment is performed by the operator.
Exclude this tensors in the allocation and take care of them in the dynamic memory pool

Optimise Slice operator when slice is an identity and also ScatterElements
Compute also the error on the average when printing results and sort them in decreasing order in time
@lmoneta lmoneta force-pushed the olha_sofie_profiler branch from 1585356 to 32d38a2 Compare January 9, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants