Speed issues with Matlab code compiled using SDK compiler for Python

조회 수: 11 (최근 30일)
Eduardo Salazar
Eduardo Salazar 2021년 1월 18일
댓글: Amit Hochman 2022년 7월 19일
Hi there
Wonder if anyone has a view on this. Some code that I need to deploy in Python (v3.7) but created in Matlab (2019a) was compiled using the Compiler SDK to generate the required CTF files. It comprises about 15 independent functions that are executed in a sequential way. Tested in Matlab, the *m native files, which are very efficiently coded, require (for a toy example) about 7 to 8 seconds to complete. When deployed using the MCR in Python the same toy example takes about 50 seconds.
Not only that, the problem is roughly linear in the size of the input variable so using an input twice the size in Matlab uses up 15-18 sec to complete, but slighly below 1 min in Python. Looking at a Profiler run in Matlab it was seen that only two of the routines took roughly 90% of the computation time, what was expected. Deployed in Python, they only took 32% of the computation time. That led us to think we had some form of overhead attached to the MCR (impacting every routine as they were processed sequentially) but, upon inspection, that did not seem to be the issue.
As per Matlab, programs compiled using the Compiler SDK should run "at the same speed as Matlab" but nothing of the sorts is happening.
Perhaps more interestingly, as we increased the dimension of the data input to the routine the computation time in Matlab rose roughly as expected/predicted by theory, yet in Python nothing of sorts seems to happen. That said, Python performance is consistently sub-par as compared to Matlab and we've ran out of gas in thinking what on earth might be going on.
BTW, in both instances we ran things on separate PCs of equivalent configuration. Hardware does not seem to be causing it.
Any ideas?
Thanks

답변 (2개)

Alan Frankel
Alan Frankel 2022년 6월 8일
The performance in R2022a is orders of magnitude better than in previous releases, as described in the release notes. See the item "Performance/Python Package Integration: Improved performance with large multidimensional arrays in Python".
  댓글 수: 1
Amit Hochman
Amit Hochman 2022년 7월 19일
I’m seeing a 2x runtime increase when running in python, using 2022a. I’m stuck in a situation similar to OP; it is quite disappointing.

댓글을 달려면 로그인하십시오.


Yair Altman
Yair Altman 2021년 1월 19일
Perhaps your deployed environment is different from your Matlab &D one. For example, perhaps you can access a GPU on the R&D env but not the deployment one; or perhaps the physical CPU/memory setup is different, or something similar. Try running your deployed Python program on the same R&D computer as the one that runs Matlab, and see what happens. At the very least it would tell you if the problem is the compilation process or the run-time machine.
  댓글 수: 4
Eduardo Salazar
Eduardo Salazar 2021년 1월 31일
편집: Eduardo Salazar 2021년 1월 31일
Certainly. I would have expected some of the Mathworks folks to look into this forum, that would make exchanges all the more productive for everyone?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by