Home > Blockchain >  Ada state in Image processing and Machine learning
Ada state in Image processing and Machine learning

Time:11-06

I do some math projects with Ada. After that, I found that Ada can interface with low-level, and high-performance languages like Fortran and C/C . It is also good at concurrence processing (I don't know it same with parallel processing or not). Now, I want to do Machine learning and Image processing projects. The speed and memory are very critical for me and must be optimized.

My questions are:

Is Ada has a good library for Machine learning or Image processing or both? How is the speed of math performance in Ada rather than python or Matlab?

Is interfacing between Ada kernel and C/C for Machine learning, and Image processing lead to good speed? How about using the property of concurrence processing?

Can Ada have an interface with Julia and Python?

CodePudding user response:

For the first step (loading your image into memory), you can use the GID open-source library:

https://gen-img-dec.sourceforge.io/

https://github.com/zertovitch/gid

Regarding the processing itself you'll get the same performance as C if you use GNAT.

CodePudding user response:

Image processing/ML library in Ada: I am not aware of any Ada native libraries for that, but you can quite easily use any similar library in C/C . Check also Alire, it is a package manager for Ada. It is quite young (release 1.0 was released in the last few months), but the community is very active.

Processing speed: like C or C , more or less, definitively faster than Matlab or Python, since Ada (like C/C ) is compiled.
With Ada you can sometime have a small speed reduction (some %) because the compiler inserts checks to verify that there are no buffer overflows, values outside bounds, etc. In an overwhelming number of cases, the robustness, security, easy of debug and maintenance that you get from that checks is definitively worth the small speed reduction. If even that few % is critical to you, you can try selectively disabling the checks in the most time consuming part of your code.

Is interfacing between Ada kernel and C/C for Machine learning, and Image processing lead to good speed? To be honest, this question is not perfectly clear to me. I am interpreting it as you are asking if you get good performances by using from Ada a C/C library for ML/Image processing.

Your mileage may vary, of course, but in general I expect the answer to be yes. When compiled there is no overhead in calling C/C functions from Ada, you can have a very small one if you decide to write a "thick layer" that transforms the C-like interface (usually quite low level with pointers and stuff) into a more Ada-ish interface. Usually the translation done by the thick layer amount to do some type casting and moving some data, therefore the overhead is minimal.

About concurrence I guess you mean using Ada tasks with the C/C library. Well, in this case I guess much depends on your computer. ML and Image processing are CPU-intensive tasks, therefore you can gain something only if you have more than one CPU on your computer (if the tasks did some I/O you could move one with a task while another is waiting). Beware: check that the C/C library is task-safe, that is, it can be used by two different tasks at the same time without risk of disrupting its internal structures.
If it is not task-safe, you can maybe use a protected object to provide a "task-safe layer" to your library. In this case I wonder if it is worth the effort, since the library (that I expect will carry out most of the work) could be used only by one task at the time.

Interface with Julia and Python: Honestly I have no experience with this. If Julia and Python have an interface for C code (and usually every script language nowadays does), then you can interface them with Ada too, maybe by using a small C "gateway." One problem that sometimes I experienced with script-C interfaces is that they sometimes rely on C macros for constants or inline functions. Of course, C macros are not visible to Ada and sometimes the simplest solution (IMHO) is to use a small C "gateway" that is able to "see" the macros.

  • Related