Skip to content

Commit 24d5fdd

Browse files
MihailMihovvgvassilev
authored andcommitted
Add constexpr and consteval support for Clad project introduction blog
1 parent efbe610 commit 24d5fdd

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: "Support for constexpr and consteval in Clad"
3+
layout: post
4+
excerpt: "A GSoC 2024 project with the goal of adding support for constant expressions to Clad"
5+
sitemap: false
6+
author: Mihail Mihov
7+
permalink: blogs/gsoc24_mihail_mihov_introduction_blog/
8+
banner_image: /images/blog/gsoc-banner.png
9+
date: 2024-06-05
10+
tags: gsoc clad clang c++
11+
---
12+
13+
### Introduction
14+
15+
I am Mihail Mihov, a student during the 2024 Google Summer of Code. I will be
16+
working on the project "Add support for consteval and constexpr functions in
17+
clad".
18+
19+
**Mentors**: Vaibhav Thakkar, Vassil Vassilev, Petro Zarytskyi
20+
21+
22+
### Briefly about Clad
23+
24+
In mathematics and computer algebra, automatic differentiation (AD) is a set of
25+
techniques to numerically evaluate the derivative of a function specified by a
26+
computer program. Automatic differentiation is an alternative technique to
27+
Symbolic differentiation and Numerical differentiation (the method of finite
28+
differences). Clad is based on Clang which provides the necessary facilities
29+
for code transformation. The AD library can differentiate non-trivial
30+
functions.
31+
32+
### Personal Motivation
33+
34+
I have always liked mathematics and I also have some experience with compilers
35+
and find them very interesting, so when I found this project I knew that I
36+
would enjoy it. It combines many things that I like and I believe that doing
37+
something that I enjoy makes it much more likely that I will do well. C++ is
38+
also the first programming language that I learned so it will forever be more
39+
special to me.
40+
41+
### Importance of this project
42+
43+
Not having support for constexpr or consteval functions could be a deal-breaker
44+
to many projects, as these keywords have been around for some time now and the
45+
number of projects that use them will only increase. Also working on this
46+
project will require investigating what can and can't be compile-time evaluated
47+
and I think that we could learn something new about the already existing
48+
code-generation that can be improved.
49+
50+
### Goals of the project
51+
52+
The main goal of this project is to support differentiating functions that are
53+
marked as constexpr and consteval and to possibly keep the same guarantees for
54+
the generated derivatives.
55+
56+
At the end of the project Clad should work on most constexpr and consteval
57+
functions from the C++ standard library and most other functions that a user
58+
could pass in.
59+
60+
### Implementation Details and Plans
61+
62+
Implementing this project will be mainly split into doing it for forward and for
63+
reverse mode, as these are the two options that Clad has for differentiating a
64+
function. For each of these parts I will have to look into both constexpr and
65+
consteval as they do have some differences that need to be solved separately.
66+
67+
68+
Implementing this project will need to start at clad's CladFunction which is
69+
the function type that Clad generates and is what in the end should be
70+
compile-time evaluated if possible. The cases where keeping the constexpr
71+
properties might not be possible is when loops are involved and we would need
72+
to implement good diagnostics in such cases, to inform the user that the code
73+
may not be evaluated as they would expect.
74+
75+
### Conclusion
76+
77+
This project should be very useful for Clad, by allowing a wider range of projects
78+
to use it. Along the way it's possible that there will be interesting findings which
79+
can be used to further improve Clad.
80+
81+
### Related Links
82+
83+
- [Clad repository](https://github.com/vgvassilev/clad.git)
84+
- [Clad documentation](https://clad.readthedocs.io)
85+
- [My GitHub Profile](https://github.com/mihailmihov)
86+
87+

0 commit comments

Comments
 (0)