TMC/TinyMc: Tiny MATLAB (R) - to - C Compiler is a package that includes a command-line converter utility and run-time support library for conversion MATLAB-written projects to C code.
The main project page TMC Compiler is at SourceForge: https://sourceforge.net/p/tmc-m-files-to-c-compiler
The converstion tool runs in too passes. At the first pass user provides a root function name and a list of directories where to search for other functions. The output of the first pass is a list of dependencies files that should be compiled and a file with information about number of input and output arguments of the functions that had been recognized. At the second pass all the dependencies files are converted to C-code and some additional files are generated for runtime initialization.
Features
Generation C-code project from existing MATLAB code
- Maximal portability and minimal dependencies on third-party software libraries
- Supports migration of MEX-files (if its C code is available)
- The generated code uses TMC run-time library
- Flexible extension of build-in functions set
- Supports wide MATLAB syntax subset (cell arrays, structures, 2D matrixes etc.)
- Support of some functions (e.g. roots_qd, leftdivide_qd) implemented with quadruple-precision floating-point (128 bit float) based on quadruple-precision floating-point compilation of CLAPACK (Fortran to C translation of LAPACK) and libquadmath library
- An open-source project
- Free use to produce proprietary software
Applications
- Creation a DLL from MATLAB-code that may be used in C/C++ or Delphi applications (see: Example:calling a DLL generated with TMC from MATLAB source from Delphi application)
- Creation an external code DLL from MATLAB-code for usage in NI LabView (TM). (see: Example: external code DLL for using in LabView)
- Creation an unmanaged code DLL for using in C#/.NET (see: Using TMC-generated DLL from C#)
- Creation a native code library for different CPU. E.g. such a library may implement native methods in a Java-written mobile Android application and perform intensive math computations on ARM platform. (see: Example: TunerDemo application for Android )
- Run MATLAB code on Linux cloud
- Run MATLAB code on Raspberri Pi
- Run MATLAB code on PHP server
- Parallel calculations using MPI interface
Downloads
The most updated sources are in the repository at https://github.com/csafonov/tinymc.The main project page TMC Compiler is at SourceForge: https://sourceforge.net/p/tmc-m-files-to-c-compiler
Licensing
All this software is an open-source:
- Code generator. Available under GPL license.
- Runtime library. Available under BSD 2-Clause license. Third Party Software used in the library may impose additional restrictions, the details may be found in the software documentation. Anyway, a user may produce a proprietary software.
How to use this tool ?
Start from one of code examples, it contains a script to run the conversion tool.
Now have a set of C files for you project. You may create the project manually or use CMake utility. Add TMC run-time support library to the project as a library or directly add its source. Build the project and that is!
The goal of this software is to migrate from MATLAB to C, to build a compact stand-alone portable application that doesn't depend on MATLAB run-time, port it to selected platform, and optimize its performance. The user should locate the time-critical pieces of his code, re-write them in C and replace their m-code by MEX-files. TMC compiler to "glues" the numeric intensive calculations encapsulated in MEX with logics remained in M-files. The process may be iterative.
For questions and any feedback please :
- contact directly the author by e-mail: csafonov@gmail.com
- visit TMC Compiler Facebook page: TMC Compiler - Tinymc - translator from restricted MATLAB to C
Any bug reports, feedbacks and questions will be appreciated.
See also:
TMC run-time support library
The code generated by the compiler is linked to provided run-time support library. You may compile this library and use it in object form or simply add its code to the project, that simplifies the debugging. The library implements basic operations and a minimal subset of build-in functions. The linear algebra operations are implemented by CLAPACK code. User may extend the function set; new function should be written in C and have predefined prototype as described in the documentation. This function is then added to the code.
Installation
There is no special procedure for the tool installation. You need only to unzip the package. The included examples contain scripts for the calling the convertor to generate the C-code.
The language restrictions
The tool does not support GUI and classes. It also implements very little set of funcctions but user may implement the functions by himself. The list of restrictions and known problems is available.
News
Release 1.20 (27.10.2020):
The latest sources and pre-compiled converter are in GitHub repository.
- Bugs are fixed in the support library and in converter
- Supported (~) function output parameter
- Added examples of usage the generated code with C#
- Added code and example of usage with MPI interface
- Added an example of build with CMake and JSON file parser
The following activity is planned:
- Improved support of 3D matrixes
- Develop the multi-threading support
TMC Compiler support
For questions and any feedback please :
- contact directly the author by e-mail: csafonov@gmail.com
- visit TMC Compiler Facebook page: TMC Compiler - Tinymc - translator from restricted MATLAB to C
Any bug reports, feedbacks and questions will be appreciated.
See also:
QA support page: TMC Compiler Support - QA
Some tutorials: https://sourceforge.net/p/tmc-m-files-to-c-compiler/wiki/Home/
Some tutorials: https://sourceforge.net/p/tmc-m-files-to-c-compiler/wiki/Home/
Alternative Matlab/Octave compiler discussion
Articles and tutorials
- Writing MATLAB to C converter: Parser and Code Generator created with Bison/Flex
- Quadruple precision floating-point calculations in C/C++/FORTRAN
Articles and tutorials
- Writing MATLAB to C converter: Parser and Code Generator created with Bison/Flex
- Quadruple precision floating-point calculations in C/C++/FORTRAN
- MATLAB is a registered trademark of Mathworks Inc.
- CVI™, LabVIEW™, National Instruments™ are trademarks of National Instruments Corporation.
- Delphi™ is a trademark of Embarcadero Technologies (now a division of Idera)
2 comments:
Hi! is there any correlation between the size of the matlab code and the size of the binary? I was speculating about trying to stuff some NN code from Matlab onto an embedded system, like an stm32F with 128K ram and 512K flash. (I believe the MCU has an external RAM controller for more ram but...). I know nothing about matlab and little about Neural Nets.
Yes, the size of the generated binary grows with size of the code. I am affraid also that needed dynamic memory size may be too large for this MCU. Such binary is sutable for Raspberry Pi with Linux or smartphone with Android.
Post a Comment