|
| 1 | +--- |
| 2 | +title: "Supporting STL Concurrency Primitives in CLAD" |
| 3 | +layout: post |
| 4 | +excerpt: "Support for STL concurrency features in CLAD is a useful feature for applications utilizing cpu threads. Many applications of autodifferentiation benefit from parallel or concurrent processing, and support for some STL concurrency primitives such as threads and basic synchronization primitives may considerably simplify the user's design." |
| 5 | +sitemap: false |
| 6 | +author: Petro Mozil |
| 7 | +permalink: blogs/gsoc25_/ |
| 8 | +banner_image: /images/blog/gsoc-banner.png |
| 9 | +date: 2025-05-18 |
| 10 | +tags: gsoc llvm clang audo-differentiation |
| 11 | +--- |
| 12 | + |
| 13 | +## About me |
| 14 | + |
| 15 | +I am Petro Mozil, a student participating in the Google Summer of Code program in 2025. |
| 16 | +I will work on adding support of STL conurrency primitives to CLAD. |
| 17 | + |
| 18 | +## Problem description |
| 19 | + |
| 20 | +`Clad` is a plugin for automatic differentiation for the `clang` compiler. |
| 21 | +Automatic differentiation is a term for multiple techniques of deriving a mathematical function non-analytically. Some of the ways of doing this include simply calculating the derivatiev numberically or by deriving a function by a set of rules, symbolically. |
| 22 | + |
| 23 | +`Clad` provides an interface that returns an object that containd the derivative of a given function. There might be problems with some functions, if they are to be derived. For example, one would not derive `printf`, and neither would they derive `std::tread` - those are exceptions, and should be handled differently from mathematical functions. |
| 24 | + |
| 25 | +The main goals of this project are to implement support for automatically derive functions that contain `std::thread` so that the user wouldn't have to separate the multi-processing logic from the mathematical functions - such a feature would be a great time-saver for production of multi-processing code. |
| 26 | + |
| 27 | +## Objectives |
| 28 | + |
| 29 | +The objectives for thi project include adding support for multiple objects in STL, such as `std::thread`, `std::atomic`, `std::mutex`. |
| 30 | + |
| 31 | +The first, and, likely, most important part of the project is to add support for `std::thread` - this will include deriving not the `std::thread` constructor, but deriving the function suppliend for the thread. |
| 32 | + |
| 33 | +Support for mutexes is a bit more straighforward - though `clad` creates a second object to represent the derived value, it shouldn't do so for a mutex. It is a matter of having a custom derivative for `std::mutex`. |
| 34 | + |
| 35 | +Atomics will likely involve moer effort - they would require custom derivatives for `compare_exchange` functions as well as their methods. |
| 36 | + |
| 37 | +If time allows, I would also like to add support for `std::condition_variable`, `std::lock_guard`, `std::unique_lock` and `std::jthread`, and most of those would also only involve a custom derivative. |
| 38 | + |
| 39 | + |
| 40 | +## Conclusion |
| 41 | + |
| 42 | +A a result of this project, support for the concurrency primitives is expected. Clad should seamlessly derive functions with concurrency primitives in them. |
| 43 | +Though this project does not focus on features immediately reuired from `clad`, it should result in making easier the lives of those, who use clad for high-perf computing. |
| 44 | + |
| 45 | +## Related links |
| 46 | + |
| 47 | +- [LLVM Repository](https://github.com/llvm/llvm-project) |
| 48 | +- [CLAD repository](https://github.com/vgvassilev/clad) |
| 49 | +- [Project description](https://hepsoftwarefoundation.org/gsoc/2025/proposal_Clad-STLConcurrency.html) |
| 50 | +- [My github](https://github.com/pmozil) |
0 commit comments