MATLAB to C/C++ Made Easy - MATLAB
Video length is 47:38

MATLAB to C/C++ Made Easy

Overview

In this webinar, we demonstrate the workflow for generating readable and portable C/C++ code from your MATLAB algorithms using MATLAB Coder. Using the command line approach or the MATLAB Coder app, you can introduce implementation requirements to your algorithms written in MATLAB and generate readable source code, standalone compiled executable, or a library that can be shared across your organization.

MathWorks engineers also explore how you can automatically generate MEX functions to accelerate computationally intensive portions of your MATLAB code by running it at compiled speed, or use it to verify the behavior of the generated code back in MATLAB.

Highlights

Watch this webinar to learn how to: 

  1. Generate C/C++ from MATLAB code that can be compiled from desktop systems to embedded devices such as ARM Cortex-A
  2. Generate C/C++ from deep learning networks along with pre- and postprocessing code as inference engines for Intel Xeon CPUs or ARM Cortex-A processors
  3. Generate C/C++ as MEX-files to accelerate compute-intensive portions of your MATLAB algorithm in MATLAB

About the Presenter

Bill Chou is the Product Marketing Manager for MATLAB Coder and has been working with MathWorks code generation technologies for over 14 years. Bill holds an M.S. degree in Electrical Engineering from the University of Southern California and a B.A.Sc degree in Electrical Engineering from the University of British Columbia.

Recorded: 16 Dec 2020

Hello, and welcome to the presentation on MATLAB to C and C++ made easy. My name is Bill Chow. And over the next 30 or 40 minutes, I'll take you through how you can use MATLAB Coder to generate readable and portable C and C++ code.

So here's the agenda. We're going to start with the motivation of why users want to translate from MATLAB to C and C++ and some of the challenges of the manual translation process. So from there, we'll introduce MATLAB Coder and the recommended three-step workflow for generating code.

Then we will take a look at some of the use cases, including integrating algorithms into source code and libraries into external programs, acceleration through MEX, and also prototyping by generating executables. And finally, we'll wrap up by talking about how you can integrate with Simulink, Embedded Coder, GPU Coder, and some of the other deployment solutions out there. So let's get to it.

So why are engineers translating MATLAB algorithms to C and C++ today? So one of the use cases is that they need to implement C and C++ code on processors or maybe handoff to software engineers for integration with a larger program. They may be integrating their MATLAB algorithms with existing C and C++ environments that use source code or through static and dynamic libraries. You might be prototyping MATLAB algorithms on desktops as standalone executables or maybe accelerating some of your user-written MATLAB algorithms within MATLAB itself.

So in terms of deploying MATLAB algorithms, there is a couple of things to think about. So within MATLAB, you could be performing data analysis and visualization. You could be developing your core algorithms and also creating complete applications that include graphical user interfaces.

Now, if you want to deploy the complete application, you can use the MATLAB compiler and compiler SDK in order to deploy the complete application. Now, on the other hand, if you're just looking at deploying the numerical portion of your algorithm, then you can take a look at using MATLAB Coder that generates C and C++ code. So for the rest of this presentation, we're going to talk about the MATLAB Coder approach.

So what are some of the challenges of manually translating your algorithms to C and C++ code? So with this approach, once you've developed your algorithms in MATLAB, either you or somebody else will need to manually rewrite the same designs in C and C++. And because these languages are inherently different, there are going to be many functional and behavioral differences introducing the design.

The primary problem with this approach is that you have to maintain two separate implementations that are not automatically in sync with each other. So if your requirement changed during the development process, which almost always happens, it's quite inefficient to go back and modify your C and C++ code and test it all over again in order to ensure that functionally it's the same as the original MATLAB algorithms. So coding errors are usually introduced the manual translation process, and that leads to longer testing times and no guarantee that all bugs into introduced are caught.

And finally, the entire process is quite time consuming and costly. And it's expensive to maintain not only separate algorithms in two different languages, but also separate test benches in C and C++ that may not get implemented. So with automatic translation of your MATLAB algorithms to C and C++, you can spend much less time writing and debugging low level C and C++ code and more time tuning your algorithms.

So once you're happy with your MATLAB code, you can start by generating MEX files that automatically bring back into MATLAB to either verify the compiled execution or to simply speed up your code in some cases. So from there, you can generate source code, executables, or libraries automatically. And with this approach, you can maintain one golden reference in MATLAB, and that helps you to get to your C and C++ code much faster.

And of course, having a single reference makes it much easier to change as your requirements change throughout your development process. And you also get to test it more systematically and thoroughly to account for more real world scenarios. So what does that look like?

And we'll start by looking at a simple example that introduce the basics of MATLAB Coder. So here, I'm inside of MATLAB. And I have a very simple algorithm, myMult.

All it does is takes two inputs, a and b, and multiplies it together. It gives you the output. In addition to this file, we have a very simple test bench, which is just calling the function and multiplying the numbers 3 and 4 together. And you get 12 as you expect.

So we're ready to generate code. And once we go and launch the MATLAB Coder application, here you can see one of the first things we need to do is tell MATLAB Coder what file we want to generate code for. So once we've entered that, because we're generating C and C++ code, we need to specify the data types and sizes of our inputs.

So we can do it manually, like what you see here. Or simpler way is we can enter the test bench that I have, click on Auto Define Input Types, and MATLAB Coder will automatically infer the data types and sizes of both of my inputs. So from there, it's always good to run a check on runtime issues. And MATLAB Coder will basically built a MEX file, run it, and see if there are any runtime issues.

So everything passed, no problem. At this point, we're ready to start generating code. So we can generate either source code compiled to a MEX file, or maybe a static or dynamic library, or even an executable. So in this case, I'm going to generate source code.

And I'll click on Generate. And over here, we're all done. Let's take a look at our code generation report. So the bottom left is all the files that we generated. And in the generated C code, as you can see, it's very simple a times b, which is exactly how we would write it in C code.

Now, suppose I want to make some changes, as we're about to see. So instead of multiplying two scalar numbers, let's say requirements change. And now, we have to deal with multiplying matrices together.

So if we change that, we can see that multiplication runs inside of MATLAB. And we get an output matrix of size 3 by 5, which is all good. Now, coming back into MATLAB, what we've done and I want to highlight is that we didn't change anything in myMult. So all we did is we changed the test bench.

So now, if we want to regenerate code, we have to come back to defining input types. And instead of our inputs being the singular values, we'll run auto define. And it detects that we're working with matrices.

So by default, it's going to work with matrices up to that particular size. But for now, I want to change it to work with only this exact size matrices coming in. So I've changed that. I'll go ahead and regenerate code.

Code generation was successful. So let's take a look at the generated code. So taking a look at myMult.c, you can see that the generated code has been updated to work with multiplying two sets of matrices together.

So that was a quick, simple example and obviously very trivial. But this just shows some of the basics of MATLAB Coder. But what if we're working with something a little bit more complex?

So some of you might be working by writing MATLAB classes. And MATLAB Coder can handle that just fine. So let's take a look.

So here we have a simple class, and it's derived from our MATLAB handle class. All it's doing is it's taking two sets of inputs. These are coordinates. And it's going to give us the distance of our two points in space.

So here is the constructor. And set inputs is where we set the coordinates of our two inputs. Get result is giving us the result of our computation. And we have a method compute, which is computing the distance between points x and points y. And finally, there's also another method for getting the size.

Now, our actual algorithm, myAlg, we're going to take an input. We're going to then instantiate simple class. From there, we'll set the coordinates of my two points. We'll compute it. Then we will get the distance from get result.

And here is a quick simple test bench that will run it. And as you can see, points A and B, we want to compute the distance between those two points. And that's going to be the square root 2.

So this is running inside of MATLAB without any issues. So we can go ahead into the MATLAB Coder app to start generating code. So I'll just quickly mention, as I type this in, that everything I'm showing you inside the MATLAB Coder app you can convert it into a script, so that you can run this programmatically without going through the GUI.

So here the Code Generation Readiness tool identify an issue. And here you can see that code generation. MATLAB Coder doesn't support try catch blocks yet. So we'll go ahead, comment that out, make that save. And here, the Code Generation Readiness tool says there are no more issues, so we can go ahead.

So just like before, we'll go ahead and use the auto define feature in order to specify the data types and sizes of our inputs. So here you can see that. From there, it's always good to run and check for any sort of runtime issues that may come up. So I'll check for, for example, out of bounds arrays. So no issues there, let's go to the next stage.

So again, we can generate code for a variety of sizes. Since we're working with MATLAB classes, we'll generate C++ class. So here we go. We've gone ahead and generated code. And let's take a look at the code generation report.

So here, myAlg.cpp, it looks more or less like how we've written our code instead of MATLAB. So it's instantiating an instance of the class, setting the input, running the compute, and finally getting a result back from our computations. And if we look at simpleClass.cpp itself, again it looks pretty similar to what we expected. Here's the compute method, which is running through and getting the square root of our x and y-coordinates of our two inputs.

And coming further down, get result is just returning the output value Z. There's our initialization, which is setting it to be 0, 0 for both inputs at the beginning. That's setting the input coordinates from that method. So that's pretty straightforward. And that's more or less how the generated code would look.

OK, so we took a look at the basics of MATLAB Coder, including taking a look at how you can write MATLAB classes and generates C++ classes from that. Next, let's talk about the recommended three-step workflow for using MATLAB Coder. So the algorithms that you're working with obviously won't be as simple as those two very basic examples that we just saw.

So in order to successfully translate these more complex and real world algorithms, we have this recommended three-step workflow to use MATLAB Coder. So that first step is to prepare your MATLAB algorithm for generation. And here, you're going to examine and modify your original MATLAB code to introduce implementation constraints that are needed for C and also use the MATLAB language features that are supported for code generation.

The second step is to test if the MATLAB code that you just modified is ready for code generation using default settings. And if it's successful, MATLAB will generate a MEX file. And if not, you'll go back and iterate with the previous step to get your algorithm to a point where you can successfully generate the MEX function from your MATLAB algorithm.

And the third step, once you've gone through those two points, is you can generate either C and C++ source code or keep the MEX function from the previous step. And obviously, once you're able to generate code, you can further iterate to modify your MATLAB code to optimize for better performance in the generated C and C++ code. You can optimize it for look and feel, or you can optimize the MEX function for even better performance.

So looking at this three-step process, that first step in the workflow is preparing your MATLAB algorithm code generation. And what that really means is to take a look at some of the implementation considerations that we rarely pay attention to when coding in MATLAB, but are required for any C and C++ coding. So what are some of these considerations?

Let's take a look at an example of a simple function. We'll just call it foo.m that multiplies two inputs. This is that simple example that we saw a little bit earlier.

So as we saw in MATLAB, this single line of code can have different meanings, right? It could mean element by element multiplication. It could actually be a dot product or, in the latter case, matrix multiplication.

And if you think about it, these inputs could also mean different things. It could be different data types. It could be, for example, real or complex numbers.

So as you can see, MATLAB is a powerful algorithm development environment, precisely because you, as the algorithm developer, won't have to worry about these various implementation details. Within MATLAB, it's taken care of for you. But when you're writing C or C++ code for this pretty simple line of MATLAB code, you have to explicitly specify what all these different operations mean.

So at the end of the day, what this means is, this simple line of code, that returns b multiplied by c. Or it could be six lines of code with three for loops that multiply the two matrices together. So really, when you're thinking about implementing your MATLAB algorithms in C and C++, you have to pay close attention to how it will look like in C and C++.

So there are essentially four types of considerations you'll need to be aware of. The first is polymorphism. And as we show in the previous simple example, the same piece of MATLAB code can be used for element by element multiplication or for more complex matrix multiplication.

So for C and C++ code, you also need a separate prototype for each of these different forms. So we'll have to think about that a little bit. So the next point is specifying whether your data is statically or dynamically allocated.

So MATLAB is dynamically typed. This means that you'll never need to worry about declaring memory for the data that you create and use. But on the other hand, lower level languages, like C and C++, is statically typed. So you'll always have to explicitly specify the size of your data, or else you'll have to work with using dynamic memory allocation.

Then there's also a difference in processing arrays. So MATLAB uses compact optimized single line expressions, but lower level languages, like C and C++ code, use for loops. There's also a difference in zero-based indexing in C and C++ versus one-based indexing in MATLAB.

And finally, you have to specify data types for your input and output arguments as well as internal variables when you're coding in C and C++. So the effect of specifying all these different implementation requirements is that these seven lines of code for kalman filter can turn into 107 lines of C and C++ code for specific implementations. So having gone through all of that, let's take a look at example of specifying implementation constraints.

And we'll do so by looking at the Newton/Raphson algorithm, which is well-known numerical algorithm for finding the square root of a number. So we can call nrt.m, like so. And here it will find the fourth root of number of 256. And the answer is 4, which is what we expect it to.

We can also feed in a third input variable, which is going to be the tolerance of numerical calculations. And so if we try to find the fourth root of the number 10, it's 1.7783. So let's take a look at nrt.m.

So inside of that, you can see there are two important variables and a possible third variable, which is going to be the tolerance. And looking further down, you can see that it's calling another file, newtonSearchAlgorithm.m. And if we look inside of here, there are a couple of things to point out.

One of the first things is that there's an initial guess right at the beginning, equals 1. And there's a big while loop. And within this while loop, it will break or it will stop after a maximum of 50 iterations. And within each iteration, it's going to go through and compute the square of that function there and its derivative.

So aside from those two files, we'll also have the third file, a very simple test bench which just runs in nrt, as you can see there. So everything works in MATLAB. Let's go ahead and generate code again.

And again, here's the MATLAB Coder app. Once we've specified the function we want to generate code for, here you see the Code Readiness tool flagged an issue. Let's take a look at that.

So as you can see here, it says the variable h needs to be fully defined. And as you can see initially or during each iteration of the while loop, the size of h will expand. And if we look at the code, we'll see that it's going to expand to a maximum of 50 elements.

And so in order to deal with this particular issue, we can see that we can predefine or preallocate the variable h. And so we can make it have a maximum of 50 values right off the bat. So once we make this update MATLAB Coder and the Code Generation Readiness tool will say there's no further issues, and so we can move forward.

So again, we'll use the test bench and use the auto define feature to figure out the data types and sizes of our three inputs. For this time, we're going to skip the Code Generation Readiness tool. Everything will keep it more or less as a default and will generate source code.

So Code Generation was successful. Let's take a look at the generated code. So here on the left, you'll see nrt.c. And inside of that-- actually let's go to the header file. And we'll take a look at function nrt.

If you look through it, you can see the MATLAB comments that we had in there also carried over as comments in C code. Here's that big while loop, which has been turned into a do while loop. And instead of it, you can see at those places it will break after 50 iterations.

So that's a pretty good start. We were able to generate C code. But, here, you'll see we generated a whole bunch of other files in here. And those files are actually dealing with functions or numbers like Inf or NaN: Not A Number. So let's try to get rid of some of those extra files that we don't need.

Inside the code generation options, there's a check mark for supporting non-finite numbers. We can go ahead and uncheck that. If you close that out, we can go ahead and generate code again.

Here, you can see that everything more or less hasn't changed, but we've removed those extra files from being generated as well. So we're down to about eight or nine files. So that's pretty good.

Now, one other thing that we can take a look at is, inside of nrt.c towards the end, there is a bunch of extra code. And we're wondering where that came from. So if we go back, take a look, see all that bits of pieces of extra code. So where did that actually come from?

So if we were to trace back to our original nrt.m file here, you'll see that most of it came from this particular line of MATLAB code, iterations equals length find. We can turn on the code traceability option. Clicking on that one line of MATLAB code, you can see that that generated about 15 or 20 lines of C code.

So let's see if there's a way we can reduce the number of C code that's generated from that. Now, if we consider the algorithm there and we think about it a little bit, there's an easier way to get it. So suppose we have an input variable of five elements.

And if we were to type the same command, length find-- let's say we want to find values less than 0.5. The output is just a scalar. And all it's telling us is how many elements are there in this array that is less than 0.5.

So there is a simpler way to do the same operation. Instead of find, we can use as sum command. And that's going to give us the exact same scalar output that we were expecting. So let's go ahead and replace it with the sum command instead. And from there, let's go ahead and regenerate code.

So code generation was successful. Let's take a look. So further down here, we'll turn on code traceability. And in iterations, you'll see that, instead of the 15 or 20 lines of code, we're generating about half of that, about 10 or so lines of C code. So doing tricks like that will help us to reduce the number of lines of code in the generated code.

So one other the thing is you've noticed, in our original MATLAB code, we actually had two files, nrt.m and Newton search algorithm. But in the generated C code, we end up with only one file, nrt.c. So in terms of changing the way our generated code looks and feels, as you can see there, we can go ahead and take a look at inserting this line of code, coder.inline never.

So inside of here, what we can do is we can go ahead and insert that line of code, which will tell MATLAB Coder to not inline the code in that particular file. And once we generate C code, let's take a look at the report. You'll see that we still have our two files instead of MATLAB.

But now, in our generate C code, we also have two sets of files, nrt.c, which then calls newtonSearchAlgorithm.c. So I hope that quick overview gives you an idea of things you could do inside of MATLAB to tune it for look and feel as well as tuning for performance.

So because of the various factors we need to consider when writing or generating C code, it makes sense that not everything in MATLAB would be available for generating code. So only a subset of the MATLAB language is supported for code generation. And that subset is the subset that makes the most sense to convert to C and C++ code.

So over the releases, we've been growing this subset. For example, we're supporting the ability to generate code from classes into C++ classes. We supported generating code from deep learning networks. And we're continuing to support more and more of the MATLAB language and toolboxes.

And speaking of toolboxes, we've been growing that subset as well. And so here you can see, over the past five or so years, we've grown that to now supporting over 25 functions and 26 toolboxes for MATLAB Coder. OK. So having gone through that the basic workflow, let's take a look at some of the use cases that you can look for using MATLAB coder.

So what can you really use MATLAB Coder for? They're really for use cases. You can integrate your MATLAB algorithms with existing C++ environments, such as custom simulators through the use of source code or static libraries.

You can generate MEX files and run them in place of your original MATLAB code to possibly accelerate your algorithms. You can prototype MATLAB algorithms on desktops as standalone executables by providing a main function. And finally, you can implement your C and C++ code on embedded processors or maybe hand them off to software engineers by integrating to custom projects.

So let me share a couple of customer examples. In the first set here, these are customers who integrated the generated code into custom applications that's running on a variety of different platforms.

So for example, Baker Hughes, they work on oil and gas drilling. And in this particular application, they were working with signal processing algorithms on signals that are brought in from this underground drilling rig, as you can see here. The generated code was integrated into an application running on the desktop that is then deployed into the field.

With Qualcomm, this particular project is working on 5G simulations. And with their particular generated code, they were able to run it on a desktop application again. And they were able to integrate it with the rest of the system where parts of the system is running on the piece of hardware that you see here.

With dorsaVi, they work on health monitoring for athletes who are recovering from injury. And they do have an embedded device, which you see on the leg of the person in the picture. But that signal is actually sent back to a desktop machine that is then applied for further processing. And so with the generated code, it was actually integrated into a C# application that's running on the desktop.

In a second set of customers, these folks were working with generating code and then implementing the algorithms on embedded processors. So Idneo is a company that works on processing and determining the blood type of patients given a card like this. So this card is fed into an Android device that then processes and determines the blood type. So the algorithm they were working on, they generate code for it, and then it deployed it onto the Android device.

Delphi, on the other hand, were working with radar applications. And so for their simulation, they went ahead, generated code, and ran it on an arm device. Finally, with Respiri, the application is running these applications on either an iPhone or Android phone. And the device would be able to process signals that's being sent by that little piece of hardware you see at the bottom.

And what it would tell the person using the device is whether they're having issues with asthma. And so, again, the algorithms, they generated code from the MATLAB algorithms using MATLAB Coder. And then they integrated it into the Android application and also the iOS app as well.

OK, so having looked at some of these use cases, let's take a look at an example of using MATLAB Coder. So in this example, I'm going to talk about using deep learning and deploying onto a Raspberry Pi. And what this application is going to do is help us to detect defective products that may be on the assembly line.

So here, we are instead of MATLAB. And our top level function is target function. And one of the inputs is our images from a webcam. From there, it's going to do some preprocessing in order to extract the region of interest.

From there, it's going to feed in into a deep learning network and, also, give us a cam heat map. And from there, do some post-processing to draw a bounding box around the defective product. And also, use the heat map to tell us which part of that image is a problem.

So cnn_predict is the deep learning portion of it. In here, it's doing it for prediction and also looking at activation. This particular line of code is just telling MATLAB Coder the deep learning network that is being used in doing forward inference.

And we have a simple test bench that is just bringing a sample image, running our top level target function, and showing it on the screen, as you can see here. So with this sample image you can see with this hex screw, the deep learning network has detected the fact that it's defective. And there seems to be some problem on the bottom left corner.

So the deep learning network itself is derived from SqueezeNet, which has around 69 layers or so. You can see all the different layer types, ReLu layers, convolution layers, and several others. We did modify some of the last layers to work with our particular example.

So everything's working inside of MATLAB. Let's go ahead and generate code for that. So we'll do the same things.

We'll call the test bench in order to infer our input data types and sizes. So all that's taken care of for us. The image there-- 240 by 360 or so.

We'll skip the check for runtime error for now. And because we're going to deploy onto a Raspberry Pi, we're going to build it as an executable. Because this is deep learning network, we're going to switch over to C++.

And there we can specify that we're targeting a Raspberry Pi. And inside of our code generation options, we need to specify the deep learning target library. So for Raspberry Pi, that's targeting the arm compute library. And we're going to specify an armv7 architecture.

And for now, we're just going to generate code. So we can take a look at what that looks like. So once we've generated code, let's take a look.

And you can see there's a bunch of functions in there for the deep learning network. But here's our top level C++ targetFunction.cpp. And here's the target function itself.

Again, it mirrors what we saw inside of MATLAB. There's the preprocessing function a little further down. That's running the forward inference, the prediction. That's giving us the activations.

Here's the cam heat map, which is giving kind of a heat map of where the issues are. And finally, that's the post-processing step. So there's a lot of code, we're just going to take a look at a few of things here.

Here's the for prediction part. And the deep learning network is actually a C++ object. So for forward inference, that's the way it's being called in order to run forward inference.

And once we've loaded, compiled it, and run it on the Raspberry Pi, working on a webcam, you can see that we can bring in different sets of these hex screws. If it's OK, it's going to give us that little tag, OK. And if there's issues, then it's going to flag it for us. So that's a quick example of running, in this case, a deep learning algorithm on the Raspberry Pi in order to detect defective products.

So we talked about integrating software and implementing software on embedded processors, but let's take a look at another use case, accelerating algorithms inside of MATLAB. So because MATLAB is an interpretive language, it's not quite as fast as compiled languages like C and C++. So you know, when we're talking about this type of use case, it's important to keep in mind that there are a variety of different acceleration strategies.

So when you're thinking about accelerating your MATLAB algorithms, you can start by looking at using different approaches to solve the same problem. So what we looked at before in the Newton/Raphson example, instead of, for example, using the find command, maybe there are other algorithms that we can use, perhaps using matrix inversion instead of QR or SVD.

We can also take advantage of platforms as we create more efficient implementations. So what this means could be hand coding specific functions versus taking advantage of optimized libraries, like BLAS or LAPACK, for the particular function or the particular platform that we're looking at. And of course, we can also leverage additional computational resources.

So this means using more cores and CPUs, maybe looking at other different types of hardware, like GPUs or FPGAs, in order to accelerate our algorithms. So keeping those acceleration strategies in mind, let's see how MATLAB tools can help speed up execution. So with this particular block of user code, one of the first steps you can do is to use factorization and preallocation, in order to optimize your MATLAB code.

So there are tools instead of MATLAB, like the profiler and code analyzer that can help you understand how to further optimize your algorithms. And if you have a desktop with multicore processors or GPUs or maybe even have access to clusters, then you can, of course, use the parallel computing products to distribute your algorithms across different cores and PCs.

You can take a look at using system objects. And these are highly efficient object-oriented implementation of algorithms for streaming data processing. So if you're working with signal processing maybe using communication systems toolbox many of these system objects are precompiled, so that they can provide you faster execution compared to regular MATLAB functions in most instances.

And if you tried all the above and still need better performance, instead of manually translating your MATLAB code to C and C++, you can, of course, use MATLAB Coder to automatically generate MEX functions that are compiled implementations of your MATLAB algorithms that you can run back inside of MATLAB.

Now, when you're thinking about acceleration, the speed of factors will vary depending on your algorithms. So for example, if you're working with signal precision, you can expect to see larger speed-ups compared to double precision, because MATLAB is actually quite efficient with double precision. Now, if you're working with a fixed-point algorithm, then you would see a much higher speed-up. Because fixed point operations in MATLAB are emulated, and so they're not as fast as floating point computations.

So you might see speed-ups in cases where you have many for loops with a lot of states in numerical computation. But on the other hand, if you can vectorized your code, then you might not see too much of a speed pump when using MATLAB Coder. And finally, in cases where you are using built-in functions that are already optimized for execution-- so this could be using FFTs-- then you're potentially not going to see a significant speed-up in the compiled executable.

OK. So having gone through all those different places or parts of the presentation, let's kind of wrap it up and see how you can use MATLAB Coder with some of the other products out there. So all the demos that I've shown, they require just MATLAB Coder. You can extend these features by using Embedded Coder with MATLAB Coder.

So what Embedded Coder provides is advanced options to control the speed, memory, code appearance, hardware specific authorizations, software and processor loop verification, execution profiling. And it also provides bidirectional traceability, which we took a look at by looking at the defined function in the Newton/Raphson example. So Embedded Coder provides all these different capabilities.

Now, if you're working with MATLAB code inside of Simulink, you can also use the MATLAB Function block in order to bring your MATLAB code into the Simulink environment. And you can, of course, leverage all the additional tools that's available in the Simulink environment on your MATLAB code.

And finally, if you have access to GPUs and you want to accelerate your MATLAB algorithms on these GPUs, whether it's working with deep learning applications or maybe just non-deep learning applications where you want to just be able to speed up the computation on the GPU cores, so in that case, you can use GPU Coder. And GPU Coder is an extension of MATLAB Coder, which provides you with the ability to generate CUDA kernels that will speed-up on NVIDIA GPUs.

GPU coder also provides automated deployment to NVIDIA GPUs, including the Jetson and DRIVE platforms, which means that it's just much easier for you to get your algorithms running on these embedded Jetson and DRIVE platforms.

So coming back to the world of C and C++ code, there may be instances where you need to deploy your MATLAB algorithms outside of MATLAB. And in some of these instances, maybe you don't need the C or C++ source code. So if your final goal is really to generate a shared library or an executable that you need to share with others without really requiring or sharing the source code, then the MATLAB Compiler could be a good option for you.

MATLAB Compiler enables you to share standalone applications that you created in MATLAB. This includes all the graphical user interfaces that you may have created inside of MATLAB. And on top of that, you can also use MATLAB Compiler SDK to integrate your MATLAB algorithms with applications that are written in C, Java, or .NET.

And finally, you can use the MATLAB Parallel Server to deploy custom analytics in enterprise applications. One thing to note is that all of these outputs require the MATLAB Runtime to run on the deployed machine. The MATLAB Runtime is freely downloadable, and you can distribute applications created from any of these products without any royalties.

So here's the table that compares the MATLAB Coder and MATLAB Compiler, so that you can choose the right products for your needs. So if you took a look at this table, one of the distinctions of MATLAB Coder is that it generates portable and readable C and C++ source code. It does support a subset of the language and toolboxes. But in both cases, the licensing model is that you can deploy the generated code or the complete application using the compiler royalty-free. And there are extensions to both of these using a Embedded Coder and MATLAB Parallel Server.

So for more information, you can always visit the product page. And a recorded version of this presentation will be made available within the next couple of days. You can also contact your MathWorks account manager to request a trial license. And here, we can help you with a guided evaluation where one of our highly knowledgeable application engineers will guide you through the product and really walk you through its capabilities as it pertains to your specific application and needs.

So with that, I'd like to first thank you for your time and attention. We're going to spend a couple of minutes to compile your questions, and we'll go on to our questions and answers segment in just a few minutes. We'll be right back.

View more related videos