Artificial intelligence (AI) is developing rapidly and is expanding into more and more areas. It can be found in chatbots, image processing systems, and increasingly also in vehicles. Specifically, artificial neural networks – a central element of machine learning – open up new possibilities, ranging from virtual sensors to complex decision-making logic. This raises a crucial question: How can we transfer neural networks from the development environment to an electronic control unit (ECU) of a vehicle?

Why are neural networks taking off now?

The beginnings of artificial neural networks date back to the 1940s. However, it was the combination of powerful hardware – especially graphics processing units (GPU), which are optimized for parallel calculations – and open-source frameworks for machine learning such as TensorFlow, PyTorch, and Keras that enabled their breakthrough.

These frameworks offer ready-made building blocks and an active community, which makes it much easier to get started with the development of neural networks. With just a few lines of code in an easily accessible programming language such as Python, an initial model can be quickly created that can be trained in a short time with GPU acceleration or in the cloud. Subsequently, both the architecture and the hyperparameters and features of the data set to be used can then be specifically adapted.

These developments open up new areas of application in the automotive sector. In addition to computationally intensive use cases such as voice assistants, much smaller neural networks are also used in vehicles, for example, for virtual sensors. These models have far fewer parameters and are so compact that they can be run directly on ECUs. This leads to several advantages:

  • Rapid development: Neural networks can replace complex algorithms, whose development for an ECU can take days or weeks.
  • Cost benefits: In suitable applications, hardware sensors can be replaced by virtual sensors based on neural networks, which predict sensor data and reduce both manufacturing costs and maintenance requirements.
  • Reliability: Closed calculation models enable stable run times and therefore robust real-time applications.

Want to efficiently integrate virtual sensors into your ECU? We can help you.

How can neural networks be used on ECUs?

Efficient development and fast training make neural networks interesting for many applications. However, a trained model alone is not enough. It must also be possible to use it where the data is generated. This requires small AI algorithms or models that no longer run in the cloud, but directly on individual devices with very limited performance.

What works smoothly in the development environment cannot simply be executed on an existing computing unit in the vehicle – for example, a control unit in the peripheral area of a domain-centered electrics/electronics (E/E) architecture. Embedded systems such as ECUs only have limited memory, bandwidth, and computing capacities.

There are two basic methods for running a neural network on an embedded system:

  1. Interpretation: The model is provided as a file and interpreted by a run-time environment. This approach is flexible, as models can be exchanged quickly. However, the run-time environment requires additional memory and computing power.
  2. C/C++ code: The model is translated into lean C or C++ code. If the model is adapted, the C/C++ code must be recreated, but this can be done efficiently with the right tools.

Why is C/C++ code the better choice for implementing a neural network on an ECU?

ECUs are highly specialized embedded systems that operate under strict real-time requirements and have limited resources. If a neural network is interpreter-based, the necessary run-time environment requires additional memory and additional computing power, as already mentioned. This increases the effort required to ensure strictly predictable timing behavior, which is a particular disadvantage for applications with deterministic real-time requirements.

C/C++ code, on the other hand, is compiled directly, runs without an interpreter, and is therefore leaner because it is tailored precisely to the respective model. This makes it overall faster and more predictable than generically designed interpreters. These aspects can be particularly crucial for safety-critical functions in the vehicle, where every millisecond counts. Depending on the application, however, the focus is on different requirements: In some cases, the run time has priority, in others a low memory requirement is more important.

A good code generator efficiently generates the required C/C++ code from the trained model and provides the necessary options for application-dependent optimizations. The advantages of automatic code generation are by no means new – they have already proven themselves in the automotive industry over many years, in areas such as AUTOSAR and model-based development, and they can also offer an efficient and reliable path forward in the AI context.

What security standards need to be considered when generating code for neural networks?

The integration of artificial neural networks into ECUs poses both technical and regulatory challenges. In addition to the regulatory requirements for training, data, and AI development, e.g., ISO/PAS 8800, the use of neural networks in ECUs is subject to additional requirements for the ECU software. In the automotive industry, certification of the development process in accordance with ISO 26262 is often required. This results in requirements for the code, which can be met by complying with the MISRA C Guidelines, among other things. Automatic tests, suitable workflows, and an appropriately certified code generator can ensure that the generated code meets these requirements.

In addition, the standards require extensive testing of the software on the target hardware. If the code is optimized or the model is quantized, i.e., converted to a lower numerical accuracy, it must be checked whether the functionality is retained. Back-to-back tests of the software can provide early feedback – even before tests are performed on the ECU itself. In this case, the code that is to run on the ECU is compared with the original model. Back-to-back tests can, for example, be carried out immediately after code generation with the help of tools.

How do neural networks fit into automotive tool chains as software components?

Neural networks are rarely developed as a stand-alone solution. They fulfill a specific function within a larger software architecture. In order to be used productively, they must therefore be seamlessly integrated into existing tool chains and software architectures.

Especially in the automotive industry, these tool chains have long been established and are based on proven standards. You can expect familiar artifacts such as AUTOSAR-compatible software components or models that are available as Functional Mock-up Units (FMU) or virtual electronic control units (V-ECU).

Generated C/C++ code offers a decisive advantage here: It can be integrated into model-based development processes and further processed with tools such as TargetLink or Simulink®. This transforms a trained neural network into a standard-compliant software component that fits into the overall process – without any breaks in the tool chain.

Standardized interfaces, deterministic runtimes, and tool-assisted verification ensure reliable C/C++ code generation for neural networks on embedded hardware.

A Look at Practice

dSPACE has almost 30 years of experience with safety-critical systems and offers customers state-of-the-art hardware and software solutions that enable software development according to the latest standards. This expertise is consistently incorporated into the integration of neural networks into modern development processes.

What does this look like in practice? In this hands-on walkthrough, we will show you how to integrate C code for a neural network into a TargetLink model to make it available for the model-based development process. This approach makes it possible to use standardized interfaces and proven processes for safety-critical systems in the context of AI algorithms.

Conclusion: The Best Way to Integrate Neural Networks into ECUs

Neural networks have developed from a theoretical idea into a key technology that is used in numerous applications today. Although their efficient development and fast training make them attractive, integrating them into resource-limited embedded systems such as ECUs can be challenging – especially for applications such as virtual sensors.

The direct use of C/C++ code is a central component of this approach: It enables efficient, deterministic, and standard-compliant implementations, which are essential for safety-critical applications. With the right tool chain, neural networks can be seamlessly integrated into established development processes and used productively as standard-compliant software components.

Outlook: Why is this topic so important right now?

The automotive industry is undergoing continuous change: Electrification, autonomous driving, and connected vehicles are placing ever-greater demands on the intelligence and flexibility of systems. Edge AI is the key to processing data directly where it is generated and facilitating fast, local decisions. At the same time, the requirements for safety, compliance with standards, and efficiency are increasing.

Those who master these challenges will lay the foundations for the next generation of vehicle functions and gain a decisive competitive advantage.

Curious to find out more?

We would be happy to offer you an interactive session with our experts, in which we will delve deep into your questions, exchange technical insights, and examine specific use cases together using a demo. This gives you individual insights that are tailored precisely to your needs.

Interested in a personal demo? Feel free to contact us:

About the Authors

Lars Wallbaum

Lars Wallbaum

Software Developer TargetLink, dSPACE

Sören Grannemann

Sören Grannemann

Product Manager Code Generation, dSPACE

Stay up-to-date with our dSPACE direct newsletter service.

With our dSPACE newsletter service, we will keep you informed about current use cases and new solutions and products, as well as trainings and events. Sign up here for a free subscription.

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.