-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
721 lines (571 loc) · 25 KB
/
main.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
%%%% Modèle proposé par [email protected] %%%%
%%%% màj : 27/01/2023 %%%%
\documentclass[english,12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[default,oldstyle, scale=.95]{opensans}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{csquotes}
\usepackage{caption}
\captionsetup[figure]{font=small,labelfont=small}
\usepackage{xcolor}
\definecolor{Prune}{RGB}{99,0,60} % l14-33 : couleurs de la charte graphique upsaclay
\definecolor{B1}{RGB}{49,62,72}
\definecolor{C1}{RGB}{124,135,143}
\definecolor{D1}{RGB}{213,218,223}
\definecolor{A2}{RGB}{198,11,70}
\definecolor{B2}{RGB}{237,20,91}
\definecolor{C2}{RGB}{238,52,35}
\definecolor{D2}{RGB}{243,115,32}
\definecolor{A3}{RGB}{124,42,144}
\definecolor{B3}{RGB}{125,106,175}
\definecolor{C3}{RGB}{198,103,29}
\definecolor{D3}{RGB}{254,188,24}
\definecolor{A4}{RGB}{0,78,125}
\definecolor{B4}{RGB}{14,135,201}
\definecolor{C4}{RGB}{0,148,181}
\definecolor{D4}{RGB}{70,195,210}
\definecolor{A5}{RGB}{0,128,122}
\definecolor{B5}{RGB}{64,183,105}
\definecolor{C5}{RGB}{140,198,62}
\definecolor{D5}{RGB}{213,223,61}
\usepackage[absolute]{textpos}
\usepackage{appendix}
\usepackage{array}
\usepackage{biblatex}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{float}
\usepackage{geometry}
\usepackage{glossaries}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{mdframed}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{subcaption}
\usepackage{svg}
\usepackage{tikz}
\usepackage{titlesec}
\usepackage{xspace}
% \renewcommand{\FrenchLabelItem}{\textbullet}
% pour ne garder que les n°de page en milieu-bas
% et supprimer les indications de chapitre en marge haute
\pagestyle{plain}
% Fichiers biblio
\addbibresource{bibliography/biblio.bib}
\addbibresource{bibliography/comptime.bib}
\addbibresource{bibliography/ctbench.bib}
\addbibresource{bibliography/hpcs2018.bib}
\addbibresource{bibliography/metalanguages.bib}
\addbibresource{bibliography/metalibraries.bib}
\addbibresource{bibliography/parallelism.bib}
\addbibresource{bibliography/poacher.bib}
\addbibresource{bibliography/simd.bib}
% Commandes pour la these de Jules
\providecommand{\cpp}{\textsc{C++}\xspace}
\providecommand{\ctbench}{\textsc{ctbench}\xspace}
\providecommand{\eg}{\textit{e.g.}\xspace}
\providecommand{\grapher}{\textsc{grapher}\xspace}
\providecommand{\ie}{\textit{i.e.}\xspace}
\hypersetup{
colorlinks=true, % toujours garder colorlinks=true
linkcolor=black,
urlcolor=A5
}
\lstset{
frame=single,
basicstyle={\ttfamily\footnotesize},
numberstyle=\tiny\color{C1},
keywordstyle=\color{B2},
commentstyle=\color{D4},
stringstyle=\color{A3},
breaklines=true,
tabsize=2,
showstringspaces=false
}
\lstdefinelanguage{cmake}{
morekeywords={STRING, BOOL, CACHE, REQUIRED},
morecomment=[l]{\#},
morestring=[b]"
}
\lstdefinelanguage{dlang}{
morekeywords={static, if, typeof, int},
morecomment=[l]{\#},
morestring=[b]"
}
\lstdefinelanguage{rust}{
morekeywords={let, mut, expr},
morecomment=[l]{//},
morestring=[b]"
}
\lstdefinelanguage{javascript}{
morekeywords={},
morecomment=[l]{},
morestring=[b]"
}
\lstdefinelanguage{json}{
morekeywords={},
morecomment=[l]{},
morestring=[b]"
}
\lstdefinelanguage{terra}{
morekeywords={function, return, terra, end, var},
morecomment=[l]{--},
morestring=[b]"
}
\makeglossaries
\newglossaryentry{litval}{
name=literal value,
plural=literal values,
description=A value that does not hold any pointer to dynamic memory.
}
\newglossaryentry{constexpr}{
name=constexpr,
description=A value or function that can be used in a constant expression.
}
\newglossaryentry{consteval}{
name=constant evaluation,
plural=constant evaluations,
description=The evaluation of an expression that is performed at compile time.
}
\newglossaryentry{bf}{
name=Brainfuck,
description={An esoteric language in which basic
commands are encoded as single characters.}
}
\newglossaryentry{ir}{
name=intermediate representation,
description={An internal data structure used by compilers
for the representation of programs.}
}
\newglossaryentry{pbg}{
name=pass by generator,
description={An indirect value passing technique which consists in passing
generator functions instead of their results.}
}
\newglossaryentry{tmp}{
name=template metaprogramming,
description={The use of templates for the implementation of metaprograms.}
}
\newglossaryentry{et}{
name=expression template,
description={The representation of mathematical expressions in the form of
template arborescences.}
}
\newacronym{api}{API}{Application Programming Interface}
\newacronym{ast}{AST}{Abstract Syntax Tree}
\newacronym{avx}{AVX}{Advanced Vector Extensions}
\newacronym{blas}{BLAS}{Basic Linear Algebra Subprograms}
\newacronym{ctpg}{CTPG}{Compile Time Parser Generator}
\newacronym{ctre}{CTRE}{Compile Time Regular Expression}
\newacronym{dsel}{DSEL}{Domain-Specific Embedded Language}
\newacronym{dsl}{DSL}{Domain-Specific Language}
\newacronym{erb}{ERB}{Embedded Ruby}
\newacronym{gemv}{GEMV}{General Matrix Vector multiply}
\newacronym{hpc}{HPC}{High Performance Computing}
\newacronym{jit}{JIT}{Just-In-Time}
\newacronym{nttp}{NTTP}{Non-Type Template Parameter}
\newacronym{pcre}{PCRE}{Perl Compatible Regular Expression}
\newacronym{rpn}{RPN}{Reverse Polish Notation}
\newacronym{sfinae}{SFINAE}{Substitution Failure Is Not An Error}
\newacronym{tml}{TML}{Tiny Math Language}
\newacronym{cpu}{CPU}{Central Processing Unit}
\newacronym{gpu}{GPU}{Graphical Processing Unit}
\newacronym{mimd}{MIMD}{Multiple Instruction Multiple Data stream}
\newacronym{misd}{MISD}{Multiple Instruction Single Data stream}
\newacronym{simd}{SIMD}{Single Instruction Multiple Data stream}
\newacronym{sisd}{SISD}{Single Instruction Single Data stream}
\newacronym{simt}{SIMT}{Single Instruction Multiple Threads}
\newacronym{numa}{NUMA}{Non-Unified Memory Architecture}
\newacronym{uma}{UMA}{Unified Memory Architecture}
% ==============================================================================
\usepackage{subfiles} % Garder a la fin
\begin{document}
\begin{titlepage}
%\thispagestyle{empty}
\newgeometry{left=6cm,bottom=2cm, top=1cm, right=1cm}
\tikz[remember picture,overlay]
\node[opacity=1,inner sep=0pt] at (-13mm,-135mm){
\includegraphics{ups/frame.pdf}
};
%*****************************************************
%******** NUMÉRO D'ORDRE DE LA THÈSE À COMPLÉTER *****
%******** POUR LE SECOND DÉPOT *****
%*****************************************************
\color{white}
\begin{picture}(0,0)
\put(-152,-743){\rotatebox{90}{\Large \textsc{THESE DE DOCTORAT}}} \\
\put(-120,-743){\rotatebox{90}{NNT : 2024UPASG050}}
\end{picture}
%*****************************************************
%******************** TITRE **************************
%*****************************************************
\flushright
\vspace{10mm} % à régler éventuellement
\color{Prune}
\fontsize{22}{26}\selectfont
\Huge Advanced techniques for high performance code generation\\
\normalsize
\color{black}
\Large{\textit{Techniques avanc\'ees de g\'en\'eration de code pour la performance}} \\
%*****************************************************
\fontsize{8}{12}\selectfont
\vspace{1.5cm}
\normalsize
\textbf{Thèse de doctorat de l'université Paris-Saclay} \\
\vspace{6mm}
\small École doctorale n$^{\circ}$580: sciences et technologies de l'information et de la communication (STIC)\\
\small Spécialité de doctorat: Informatique\\
\small Graduate School: Informatique et sciences du numérique. Référent: Faculté des sciences d’Orsay\\
\vspace{6mm}
\footnotesize Thèse préparée dans l'unités de recherche
\textbf{Laboratoire interdisciplinaire des sciences du numérique (Université Paris-Saclay, CNRS)}, sous la direction de \textbf{Joel FALCOU},
Maître de conférences\\
\vspace{15mm}
\textbf{Thèse soutenue à Paris-Saclay, le 24 septembre 2024, par}\\
\bigskip
\Large {\color{Prune} \textbf{Jules P\'ENUCHOT}}
%************************************
\vspace{\fill} % ALIGNER LE TABLEAU EN BAS DE PAGE
%************************************
\bigskip
\flushleft
\small {\color{Prune} \textbf{Composition du jury}}\\
{\color{Prune} \scriptsize {Membres du jury avec voix délibérative}} \\
\vspace{2mm}
\scriptsize
\begin{tabular}{|p{7cm}l}
\arrayrulecolor{Prune}
\textbf{Christine PAULIN-MOHRING} & Pr\'esidente \\
Professeure des universit\'es, Universit\'e Paris-Saclay & \\
\textbf{David HILL} & Rapporteur \& Examinateur \\
Professeur des universit\'es, Universit\'e Clermont-Auvergne & \\
\textbf{Thierry G\'ERAUD} & Rapporteur \& Examinateur \\
Professeur, EPITA Research Laboratory & \\
\textbf{Amina GUERMOUCHE} & Examinatrice \\
Ma\^itresse de conf\'erences, Universit\'e de Bordeaux & \\
\end{tabular}
\end{titlepage}
% page des résumés à garder en 2ème page.
% Si les résumés sont trop longs pour tenir sur une seule et même page,
% on peut mettre un résumé par page
\thispagestyle{empty}
\newgeometry{top=1.5cm, bottom=1.25cm, left=2cm, right=2cm}
\noindent
\includegraphics[height=2.45cm]{ups/logo_STIC.png}
\vspace{1cm}
%*****************************************************
\small
\begin{mdframed}[linecolor=Prune,linewidth=1]
\textbf{Titre:} Techniques avanc\'ees de g\'en\'eration de code pour
la performance
\noindent \textbf{Mots clés:}
M\'etaprogrammation, compilation, C++, HPC, parall\'elisme, constexpr, SIMD,
optimisation, programmation g\'en\'erique, programmation g\'en\'erative,
templates, langage d\'edi\'e
\vspace{-.5cm}
\begin{multicols}{2}
\noindent \textbf{Résumé:}
En r\'eponse \`a la demande croissante de puissance de calcul,
les constructeurs de mat\'eriel proposent de nouvelles architectures
parall\`eles de tr\`es diff\'erentes natures, et ayant chacune leurs propres
API et mod\`ele de programmation.
Cela rend les applications haute performance plus complexes \`a d\'evelopper
avec des m\'ethodes de programmation traditionnelles, d'autant plus lorsque
plusieurs architectures sont cibl\'ees.
En r\'eponse \`a cette demande, des biblioth\`eques exploitant la
g\'en\'eration de code \`a la compilation furent d\'evelopp\'ees pour faciliter
la programmation haute performance avec des abstractions de haut niveau tels
que les langages d\'edi\'es externes.
Dans cette th\`ese, nous explorons en premier temps les techniques de
m\'etaprogrammation existant \`a travers un large panel de langages, puis nous
\'evaluons les techniques actuelles de m\'etaprogrammation de templates C++
dans le cadre de la g\'en\'eration de noyaux de calculs de type BLAS.
Nous couvrons ensuite de nouvelles techniques de m\'etaprogrammation bas\'ees
sur l'ex\'ecution de code C++ \`a la compilation en impl\'ementant des parsers
pour deux langages: Brainfuck, et un langage appel\'e Tiny Math Language (TML).
Le parser Brainfuck est fourni avec plusieurs backends de g\'en\'eration de code
pour \'etudier diff\'erentes techniques de g\'en\'eration de code, tandis que
TML est utilis\'e pour \'etudier la g\'en\'eration de code en utilisant des
biblioth\`eques portables haute performance.
Pour \'evaluer l'impact de ces diverses techniques de m\'etaprorgammation,
nous proposons une nouvelle m\'ethodologie de benchmarking qui exploite
le profiler int\'egr\'e de Clang, ce qui permet l'analyse de performance
en temps de compilation au-del\`a des mesures de performance en bo\^ite noire.
\end{multicols}
\end{mdframed}
\clearpage
\thispagestyle{empty}
\newgeometry{top=1.5cm, bottom=1.25cm, left=2cm, right=2cm}
\noindent
\includegraphics[height=2.45cm]{ups/logo_STIC.png}
\vspace{1cm}
%*****************************************************
\small
\begin{mdframed}[linecolor=Prune,linewidth=1]
\textbf{Title:} Advanced techniques for high performance code generation
\noindent \textbf{Keywords:}
Metaprogramming, compilation, C++, HPC, parallelism, constexpr, SIMD,
optimization, generic programming, generative programming,
templates, domain-specific language
\begin{multicols}{2}
\noindent \textbf{Abstract:}
As a response to an increasing demand for computing performance,
hardware manufacturers propose new parallel hardware architectures
of very different nature, each with their own API and programming model.
This makes high performance applications more complex to develop
with traditional programming practices, especially when multiple architectures
are targeted.
As a response, libraries leveraging compile-time code generation were developed
to facilitate portable high performance programming with high level abstractions
such as Domain-Specific Embedded Languages (DSELs).
In this thesis, we first explore existing metaprogramming practices across
a wide variety of languages, then evaluate current C++ template metaprogramming
techniques in the framework of BLAS-like kernel generation.
We then cover new metaprogramming techniques based on compile-time
C++ code execution by implementing compile-time parsers for two languages:
Brainfuck, and a language called Tiny Math Language (TML).
The Brainfuck parser is provided with several code generation backends
to study and compare different code generation techniques, whereas TML is used
to study code generation using portable high performance computing libraries.
In order to assess the compile-time impact of these various metaprogramming
techniques, we propose a new benchmarking method that uses
Clang's built-in profiler, enabling compile-time performance scaling analysis
beyond black-box benchmarking.
\end{multicols}
\end{mdframed}
\titleformat{\chapter}[hang]{\bfseries\Large\color{Prune}}{\thechapter\ -}{.1ex}
{\vspace{0.1ex}}[\vspace{1ex}]\titlespacing{\chapter}{0pc}{0ex}{0.5pc}
\titleformat{\section}[hang]{\bfseries\normalsize}{\thesection\ .}{0.5pt}
{\vspace{0.1ex}}[\vspace{0.1ex}]\titlespacing{\section}{1.5pc}{4ex plus .1ex minus .2ex}{.8pc}
\titleformat{\subsection}[hang]{\bfseries\small}{\thesubsection\ .}{1pt}
{\vspace{0.1ex}}[\vspace{0.1ex}]\titlespacing{\subsection}{3pc}{2ex plus .1ex minus .2ex}{.1pc}
\newgeometry{top=4cm, bottom=4cm, left=2cm, right=2cm}
\tableofcontents
\newgeometry{top=4cm, bottom=4cm, left=4cm, right=4cm}
% ------------------------------------------------------------------------------
% Commandes pour la these de Jules
% ------------------------------------------------------------------------------
% These de Jules
\chapter*{
R\'esum\'e en Fran\c{c}ais
}
\addcontentsline{toc}{chapter}{R\'esum\'e en Fran\c{c}ais}
\subfile{french-condensed.tex}
\chapter*{
Acknowledgements
}
\addcontentsline{toc}{chapter}{Acknowledgements}
Thanks to \textbf{Christine Paulin} for presiding the jury,
as well as \textbf{David Hill}, \textbf{Thierry G\'eraud} for being
reporters on this thesis, and \textbf{Amina Guermouche}
for being an examiner of it.
I would also like to thank \textbf{Sylvain Conchon and Steven Martin} for
the creation of the Magist\`ere d'Informatique,
and thanks to \textbf{Sarah Cohen-Boulakia} for being responsible for it and
leading me to my first reseach internship.
Thanks to \textbf{Jean-Thierry Laprest\'e} and \textbf{Daniel \'Etiemble}
for their proofreading.
And of course, thanks to \textbf{Jo\"el Falcou} for his support that has been
valorizing, careful, and devoted since my first research internship.
Thanks to \textbf{Amal Khabou} for her help during
the preparation of my first conference.
Thanks to \textbf{Hartmut Kaiser} for welcoming me at Louisiana State
University, thanks to \textbf{Adrian and Cory Lemoine} for their kind support
during a very difficult and striking event in Baton Rouge, and of course thanks
to \textbf{the rest of the STE||AR Group} for the friendships I made along the
way.
Thanks to \textbf{Paul Keir}, for his friendly and caring partnership.
Thanks to \textbf{Luke D'Alessandro}, for sharing parameter passing techniques
that enabled me to develop the code generators I present in this thesis.
Thanks to \textbf{my parents} for fostering my passion for computer science
and for supporting me throughout my childhood and my student years,
including my years as a PhD student.
Thanks to \textbf{Antoine Lanco and Alexandrina Korneva} for their
companionship, the party decorations, the parties in open fields,
and the fields of pizza.
Thanks to \textbf{Marie Debard} for being supportive when I was worried for
the financing of my thesis.
\chapter*{
Introduction
}
\addcontentsline{toc}{chapter}{Introduction}
\subfile{introduction.tex}
\part{
Metaprogramming for High Performance Computing
}
\chapter{
Metaprogramming
}
In this chapter, I will first give an overview of metaprogramming in
various languages. Then I will focus on the state of the art
of \cpp metaprogramming, and finally give examples of applications
of such techniques being used in the context of \gls{hpc} libraries.
\subfile{1-current-metaprogramming/1-metaprog-and-hpc-overview.tex}
\subfile{1-current-metaprogramming/2-cpp-constructs.tex}
\section{
Conclusion
}
Metaprogramming surfaced in many forms and in many languages such as Lisp or C
macros, long before \cpp templates came to exist.
It still persists as an advanced but widespread practice across many languages,
ranging from basic preprocessing to dynamic code generation and compilation.
Template metaprogramming has been the de facto standard for \cpp meta-programming
as many libraries use it to implement high performance or highly specialized
libraries that benefit from compile-time evaluation and code generation.
This is especially true for \gls{hpc} libraries that benefit the most from
partial evaluation.
The language \cpp later evolved to provide host language availability for
metaprogramming with the introduction and evolution of \gls{constexpr}
programming, similar to what Lisp macros have been pioneering.
This new way of writing \cpp metaprograms will be explored throughout
the second part of this thesis. Meanwhile, we are going to investigate the
actual benefits of such techniques by applying them to the basic building blocks
of \gls{hpc} applications: linear algebra kernels.
\chapter{
Code generation at low level
}
\label{lbl:gemv}
\subfile{1-current-metaprogramming/3-gemv.tex}
\part{
C++ metaprogramming beyond templates
}
\chapter{
Compile time benchmarking method
}
With \gls{tmp} libraries like Eigen\cite{eigen}, Blaze\cite{blazelib},
or CTRE \cite{ctre} becoming more widespread,
there is an increasing interest for compile time computation.
These needs might grow
even larger as \cpp embeds more features over time to support and extend this
kind of practices, like compile time containers \cite{more-constexpr-containers}
or static reflection\cite{static-reflection}. However, there is still no clear
cut method to compare the performance impact of different metaprogramming
strategies.
As new \cpp features allow for new techniques with alleged
better compile time performance, no scientific process can back up those claims.
In this chapter, I introduce \textbf{ctbench}, which is a set of tools for
compile time benchmarking and analysis in \cpp. It provides developer-friendly
tools
to define and run benchmarks, then aggregate, filter out, and plot the data to
analyze them. As such, \ctbench aims to be a foundational layer of a proper
scientific method for analyzing compile time program behavior.
\\
ctbench puts an emphasis on software quality.
The goal was not just to develop a plotting tool for a single
compilation time analysis, but to provide a repeatable process
along with a robust implementation to improve compilation time
performance analysis as a whole.
% The use of a GitHub CI for building and testing the project guarantees that
% project remains functional at all times on all supported platforms.
% As of writing, the project is continuously built and tested for Ubuntu 23.04
% and Arch Linux. The test environment is fully reproducible as well thanks to
% the use of Docker for its setup.
\ctbench was presented at CPPP 2021 \cite{ctbench-cppp21},
and at Meeting \cpp 2022 \cite{meetingcpp22}. It was also published
at the Journal of Open Source Science \cite{Penuchot2023}. It is currently
available as an open source
project\footnote{\url{https://github.com/jpenuchot/ctbench}} and as a package
through the Arch User
Repository\footnote{\url{https://aur.archlinux.org/packages/ctbench-git}}
and vcpkg\footnote{\url{https://vcpkg.io/en/packages}}.
\subfile{2-compilation-time-analysis/1-state-of-the-art.tex}
\subfile{2-compilation-time-analysis/2-ctbench-design.tex}
\subfile{2-compilation-time-analysis/3-ctbench-in-action.tex}
\clearpage%
\section{
Conclusion
}
Deep analysis of compile time scaling becomes necessary to understand
compile time performance of metaprogramming techniques.
Until now, no tool was really able to combine the depth of profiling data
analysis with variable size compile time benchmarking.
Moreover, there was no tool that could really fit in scientific work
where reproductibility is a necessity.
ctbench answers that need as a simple, powerful, and extensible
open-source solution that is peer-reviewed and distributed as a reusable
software package.
Such level of detail and granularity in the analysis of compile-time benchmarks
was never reached before, and may help us set better practices to improve the
compile-time performance of metaprograms, and give better insight on compiler
performance as well.
\chapter{
Constexpr parsing for HPC
}
% \begin{abstract}
% Design of high performance, high abstraction libraries in \cpp often take
% advantages of techniques like template metaprogramming or \glspl{et}
% to design \glspl{dsel}. However, such techniques are limited by the natural syntax
% of \cpp. In this thesis, we explore the benefits of using \cpp23 compile time
% computation features to provide compile time string based \glspl{dsel} that can then
% use arbitrary syntax.
% \end{abstract}
\section{Introduction}
\cpp is often touted as a \textit{Zero-Cost Abstraction} langage due to some of
its design philosophy and its ability to compile high level abstractions into
very efficient binary code. Some more radical techniques can be used to
force the compiler to interpret \cpp code as a \gls{dsel}.
In the field of \acrlong{hpc}, \cpp users are often driven to use
libraries built on top of those idioms like Eigen\cite{eigen} or
Blaze\cite{blazelib,iglberger2012_2}. They all suffer from a major limitation:
by being tied to the natural \cpp syntax, they can't express nor embed arbitrary
languages.
In this chapter, we try to demonstrate that the new features of \cpp23 related
to compile time programming are able to help developers designing \glspl{dsel}
with arbitrary syntax by leveraging \gls{constexpr} computations, compile time
dynamic objects and lazy evaluation through lambda functions.
After contextualizing our contribution in the general \glspl{dsel} domain,
this chapter will explain the core new techniques enabled by \cpp23
and how we can apply to build two different \glspl{dsel} with their own
non-\cpp syntax. We'll also explore the performances of those \glspl{dsel}
in term of compile time to assess their usability in parallel programming.
\subfile{3-new-approaches-to-metaprogramming/1-technical-background.tex}
\subfile{3-new-approaches-to-metaprogramming/2-constexpr-codegen-techniques.tex}
\chapter{
Applied constexpr parsing
}
Now that the idea of using \gls{constexpr} functions to generate code
was proven to work, it is time to put it into practice and observe
the viability of its integration in a high performance computing
development cycle.
I will present two examples in this chapter:
the first one is a \gls{constexpr} Brainfuck parser that serves as a simple
use case for experimenting different methods to generate code from
\gls{constexpr} \glspl{ast}.
These observations guided the implementation of the second example, which is a
\gls{constexpr} parser for simple math languages. If features a code generation
backend that supports high performance code generation via Blaze.
\subfile{3-new-approaches-to-metaprogramming/3-brainfuck.tex}
\subfile{3-new-approaches-to-metaprogramming/4-math-parsing.tex}
\clearpage%
\section{Conclusion}
The Brainfuck example shows that using \gls{constexpr} programming to embed
large programs written in arbitrary languages in \cpp can be achieved.
\gls{ast} serialization makes it possible to store parsing results
and avoid running into quadratic compilation time issues, as long as
the code generation methods do not rely on heavy metaprogramming methods.
The case of \gls{tml} also shows that \gls{ast} serialization
by itself is not a magic bullet to avoid running into compilation time
scaling issues.
The compilation time offset of \gls{tml} parsing, despite being reasonable
within the bounds of expected use cases for \gls{tml}, was quadratic.
These results show that more effort is needed to determine which metaprogramming
techniques should be avoided to avoid runaway compilation times,
and how \cpp library code or modifications to the \cpp language itself
could facilitate scalable code generation from \gls{constexpr} function results.
\chapter*{Conclusion \& perspectives}
\subfile{conclusion.tex}
\clearpage
\printbibliography
\part*{Glossaries and Appendices}
\printglossaries
\begin{appendices}
\appendix
\subfile{3-new-approaches-to-metaprogramming/appendix.tex}
\end{appendices}
\end{document}