A large number of engineering fields uses simulation systems based on differential equations. A recent approach makes use of declarative modeling languages and dedicated compilers to transform them into executable simulation code. This task leverages both mathematical and computer science knowledge: the former for what regards the numerical integration, the latter to create compatible, correct and efficient simulation code. Both fields have already been deeply explored, but the design of the compiler itself didn't receive as much attention throughout the years. Even though the LLVM infrastructure can hugely help in writing a compiler, its actual implementation is still completely up to the developers. Even if freedom may allow for more opportunities, it can also lead to bad decisions, especially regarding future development and integration with other technologies. Recently, a new framework called MLIR has been developed with the objective to provide a structured, reusable and extensible compiler infrastructure; its main characteristics are the definition of dialects, which encapsulate the semantics of the language, and the possibility of their intermix. In this thesis, we will work on the modeling language Modelica and see how a recently born compiler called MARCO can be improved by leveraging the MLIR ecosystem. We will define our own dialect for the Modelica language and see how to convert it to executable code through multiple partial transformations, while at the same time analyzing the resulting benefits. More in detail, we will focus our attention in implementing the support for procedural functions of Modelica, which are not handled by MARCO in its current state, while the existing work about model resolution will be just adapted to work with our dialect, types and operations.

Un gran numero di campi di ingegneria utilizza sistemi di simulazione basati su equazioni differenziali. Un recente approccio utilizza linguaggi di modellazione dichiarativa e compilatori dedicati per trasformarli in codice di simulazione eseguibile. Questo compito sfrutta sia le conoscenze matematiche che quelle informatiche: le prime per quanto riguarda l'integrazione numerica, le seconde per creare un codice di simulazione compatibile, corretto ed efficiente. Entrambi i campi sono già stati esplorati a fondo, ma il design del compilatore stesso non ha ricevuto la stessa attenzione nel corso degli anni. Anche se l'infrastruttura di LLVM può aiutare enormemente nella scrittura di un compilatore, la sua effettiva implementazione è ancora completamente a discrezione degli sviluppatori. Questa libertà può consentire maggiori opportunità, ma può al tempo stesso portare a decisioni sbagliate, specialmente per quanto riguarda le finestre di sviluppo futuro e l'integrazione con altre tecnologie. Recentemente è stato sviluppato un nuovo framework chiamato MLIR con l'obiettivo di fornire un ecosistema strutturato, riutilizzabile ed estendibile per la creazione di compilatori; le sue caratteristiche principali sono la definizione dei dialetti, che racchiudono la semantica del linguaggio, e la possibilità di combinarli durante la generazione del codice. In questa tesi, lavoreremo sul linguaggio di modellazione Modelica e vedremo come un recente compilatore chiamato MARCO può essere migliorato sfruttando l'infrastruttura fornita da MLIR. Definiremo un nostro dialetto per il linguaggio Modelica e vedremo come convertirlo in codice eseguibile attraverso più trasformazioni parziali, e al tempo stesso analizzeremo i benefici che ne derivano. Più in dettaglio, focalizzeremo la nostra attenzione nell'implementazione del supporto per le funzioni procedurali di Modelica, che non sono gestite da MARCO nel suo stato attuale, mentre il lavoro esistente sulla risoluzione dei modelli sarà semplicemente adattato per funzionare con il nostro dialetto, i suoi tipi e le sue operazioni.

Design and implementation of a Modelica compiler with MLIR and LLVM

SCUTTARI, MICHELE
2020/2021

Abstract

A large number of engineering fields uses simulation systems based on differential equations. A recent approach makes use of declarative modeling languages and dedicated compilers to transform them into executable simulation code. This task leverages both mathematical and computer science knowledge: the former for what regards the numerical integration, the latter to create compatible, correct and efficient simulation code. Both fields have already been deeply explored, but the design of the compiler itself didn't receive as much attention throughout the years. Even though the LLVM infrastructure can hugely help in writing a compiler, its actual implementation is still completely up to the developers. Even if freedom may allow for more opportunities, it can also lead to bad decisions, especially regarding future development and integration with other technologies. Recently, a new framework called MLIR has been developed with the objective to provide a structured, reusable and extensible compiler infrastructure; its main characteristics are the definition of dialects, which encapsulate the semantics of the language, and the possibility of their intermix. In this thesis, we will work on the modeling language Modelica and see how a recently born compiler called MARCO can be improved by leveraging the MLIR ecosystem. We will define our own dialect for the Modelica language and see how to convert it to executable code through multiple partial transformations, while at the same time analyzing the resulting benefits. More in detail, we will focus our attention in implementing the support for procedural functions of Modelica, which are not handled by MARCO in its current state, while the existing work about model resolution will be just adapted to work with our dialect, types and operations.
CASELLA, FRANCESCO
CATTANEO, DANIELE
CHERUBIN, STEFANO
LEVA, ALBERTO
SEVA, SILVANO
TERRANEO, FEDERICO
ING - Scuola di Ingegneria Industriale e dell'Informazione
7-ott-2021
2020/2021
Un gran numero di campi di ingegneria utilizza sistemi di simulazione basati su equazioni differenziali. Un recente approccio utilizza linguaggi di modellazione dichiarativa e compilatori dedicati per trasformarli in codice di simulazione eseguibile. Questo compito sfrutta sia le conoscenze matematiche che quelle informatiche: le prime per quanto riguarda l'integrazione numerica, le seconde per creare un codice di simulazione compatibile, corretto ed efficiente. Entrambi i campi sono già stati esplorati a fondo, ma il design del compilatore stesso non ha ricevuto la stessa attenzione nel corso degli anni. Anche se l'infrastruttura di LLVM può aiutare enormemente nella scrittura di un compilatore, la sua effettiva implementazione è ancora completamente a discrezione degli sviluppatori. Questa libertà può consentire maggiori opportunità, ma può al tempo stesso portare a decisioni sbagliate, specialmente per quanto riguarda le finestre di sviluppo futuro e l'integrazione con altre tecnologie. Recentemente è stato sviluppato un nuovo framework chiamato MLIR con l'obiettivo di fornire un ecosistema strutturato, riutilizzabile ed estendibile per la creazione di compilatori; le sue caratteristiche principali sono la definizione dei dialetti, che racchiudono la semantica del linguaggio, e la possibilità di combinarli durante la generazione del codice. In questa tesi, lavoreremo sul linguaggio di modellazione Modelica e vedremo come un recente compilatore chiamato MARCO può essere migliorato sfruttando l'infrastruttura fornita da MLIR. Definiremo un nostro dialetto per il linguaggio Modelica e vedremo come convertirlo in codice eseguibile attraverso più trasformazioni parziali, e al tempo stesso analizzeremo i benefici che ne derivano. Più in dettaglio, focalizzeremo la nostra attenzione nell'implementazione del supporto per le funzioni procedurali di Modelica, che non sono gestite da MARCO nel suo stato attuale, mentre il lavoro esistente sulla risoluzione dei modelli sarà semplicemente adattato per funzionare con il nostro dialetto, i suoi tipi e le sue operazioni.
File allegati
File Dimensione Formato  
Thesis.pdf

Open Access dal 10/09/2022

Descrizione: Tesi
Dimensione 1.19 MB
Formato Adobe PDF
1.19 MB Adobe PDF Visualizza/Apri

I documenti in POLITesi sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.

Utilizza questo identificativo per citare o creare un link a questo documento: https://hdl.handle.net/10589/179218