Code Generation Adapting Loop Structures for External Functions

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current methods for generating production code from block diagrams in electronic control units (ECUs) are inefficient, particularly when implementing lookup-table functionality, as they do not automatically adapt to custom external functions, leading to suboptimal performance and longer development times.

Innovation Solution

A method that determines the size of input and required signals for external functions in block diagrams and generates production code accordingly, either enclosing or not enclosing loops, to seamlessly integrate with custom lookup-table functionality, allowing for efficient reuse of external functions and optimized code generation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If production code is generated using standard lookup-table implementation, then code generation is simple and fast, but performance is suboptimal when custom external functions are required

Engineering Contradiction:
Improvecode generation speedVSAvoidperformance optimization
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The code generator dynamically adapts its code generation strategy based on the type of lookup table. For standard LUTs, it generates simple array-based code for fast execution. For custom LUTs requiring external functions, it automatically generates code that invokes these external functions with appropriate data type conversions and loop structures, optimizing performance for computationally expensive operations.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The system changes implementation parameters based on LUT characteristics. It detects whether a LUT requires custom external functions and automatically adjusts the code generation parameters, including data type conversions, loop unrolling factors, and function invocation patterns, to achieve optimal performance for each specific case.

Inventive Principle:
Principle #35Parameter changes

2Reliability

If custom external functions are used for lookup tables, then performance is improved for computationally expensive operations, but code complexity increases due to interface adaptation requirements

Engineering Contradiction:
Improveperformance optimizationVSAvoidcode structure complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The code generator performs self-service by automatically detecting the requirements of custom external functions and generating the necessary interface adaptation code. It autonomously handles data type conversions, loop structure generation, and function parameter matching without requiring manual intervention, thereby managing complexity internally while presenting a simple interface to users.

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The system introduces intermediary code structures that mediate between the block diagram abstraction and the custom external function implementation. It generates intermediate representation code that includes automatic data type conversions and parameter mappings, serving as a bridge that simplifies the integration of custom functions while maintaining performance optimization.

Inventive Principle:
Principle #24Intermediary (Mediator)

3Reliability

If manual code adaptation is performed for external functions, then performance optimization is achieved, but development time increases

Engineering Contradiction:
Improveperformance optimizationVSAvoiddevelopment time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The code generator performs preliminary actions by pre-defining templates and patterns for external function integration. It has pre-prepared code structures for common external function types, including standard data type conversions and loop patterns, which are automatically applied during code generation, eliminating the need for manual adaptation work and reducing development time.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system automates the entire code adaptation process, performing self-service by automatically generating optimized code for custom external functions. It detects external function requirements, generates appropriate invocation code with correct parameters and data types, and optimizes loop structures automatically, completely eliminating manual code adaptation efforts and significantly reducing development time.

Inventive Principle:
Principle #25Self-service

4Ease of operation

If lookup tables are evaluated multiple times per control cycle, then functional requirements are met, but performance degrades due to repeated computationally expensive calculations

Engineering Contradiction:
Improvefunctional correctnessVSAvoidcontrol cycle performance
Core Design Contradiction:
Ease of operationVSProductivity

Solution Approach 1:

The code generator implements preliminary action by generating pre-computation structures and caching mechanisms. It creates code that pre-calculates values when possible and caches results for repeated evaluations within a control cycle, reducing the need to re-execute expensive external functions and improving overall control cycle performance while maintaining functional correctness.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS9841954B1Method and system for automatic code generation
Publication Date: 2017.12.12 DSPACE SE & CO KG
  • US9841954B1 patent drawing
  • US9841954B1 patent drawing
  • US9841954B1 patent drawing

AI summary

A method for generating production code from a block diagram in a technical computing environment on a host computer. A first block receives a first input signal that has a plurality of elements. A size of a first required signal of the external function is determined and compared to a size of the first input signal. When the size of the first required signal corresponds to the size of an element in the first input signal a production code is generated enclosing a call of the external function by a loop consecutively addressing each of the plurality of elements in the first input signal. When the size of the first required signal corresponds to the size of the first input signal a production code is generated having a call of the external function without enclosing loop over the elements in the first input signal.