From 24260c655377cbed8b4fabeb66462978bd8ad302 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sat, 27 Sep 2025 13:15:19 +0000 Subject: [PATCH 1/2] [clad] Power can take arguments of different types. --- math/mathcore/inc/Math/CladDerivator.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/math/mathcore/inc/Math/CladDerivator.h b/math/mathcore/inc/Math/CladDerivator.h index e91795532a393..044b8eb70e412 100644 --- a/math/mathcore/inc/Math/CladDerivator.h +++ b/math/mathcore/inc/Math/CladDerivator.h @@ -151,8 +151,8 @@ ValueAndPushforward Log2_pushforward(T x, T d_x) return {::TMath::Log2(x), (1.0 / (x * ::TMath::Log(2.0))) * d_x}; } -template -ValueAndPushforward Power_pushforward(T x, T y, T d_x, T d_y) +template +ValueAndPushforward Power_pushforward(T x, U y, T d_x, U d_y) { T pushforward = y * ::TMath::Power(x, y - 1) * d_x; if (d_y) { @@ -161,8 +161,8 @@ ValueAndPushforward Power_pushforward(T x, T y, T d_x, T d_y) return {::TMath::Power(x, y), pushforward}; } -template -void Power_pullback(T x, T y, U p, clad::array_ref d_x, clad::array_ref d_y) +template +void Power_pullback(T x, U y, V p, clad::array_ref d_x, clad::array_ref d_y) { auto t = pow_pushforward(x, y, 1, 0); *d_x += t.pushforward * p; From 122d0d07a9242a831d120b35398c4e2363617825 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 21 Sep 2025 14:12:34 +0000 Subject: [PATCH 2/2] [clad] Bump to v2.1 Clad 2.1 introduces major advancements in reverse mode differentiation, bringing smarter handling of loops, assignments, and method calls, alongside the new clad::restore_tracker for functions that modify their inputs. Forward mode gains static scheduling for Hessians and higher-order derivatives, while CUDA support expands with custom derivatives for key Thrust algorithms such as reduce, transform, and transform_reduce, plus optimizations that reduce unnecessary GPU atomics. The release also strengthens error estimation, simplifies adjoint initialization, improves tape efficiency, and enhances diagnostics. With a migration to C++17, support extended up to clang-21, and numerous bug fixes, Clad 2.1 delivers faster, safer, and more reliable automatic differentiation across CPU and GPU workflows. --- .../cling/tools/plugins/clad/CMakeLists.txt | 18 ++++---- .../Add-missing-exception-include.patch | 43 ------------------- 2 files changed, 9 insertions(+), 52 deletions(-) delete mode 100644 interpreter/cling/tools/plugins/clad/patches/Add-missing-exception-include.patch diff --git a/interpreter/cling/tools/plugins/clad/CMakeLists.txt b/interpreter/cling/tools/plugins/clad/CMakeLists.txt index 29db505c62ce7..a0eb7ceead096 100644 --- a/interpreter/cling/tools/plugins/clad/CMakeLists.txt +++ b/interpreter/cling/tools/plugins/clad/CMakeLists.txt @@ -74,17 +74,17 @@ if (DEFINED CLAD_SOURCE_DIR) list(APPEND _clad_extra_settings SOURCE_DIR ${CLAD_SOURCE_DIR}) else() list(APPEND _clad_extra_settings GIT_REPOSITORY https://github.com/vgvassilev/clad.git) - list(APPEND _clad_extra_settings GIT_TAG v2.0) + list(APPEND _clad_extra_settings GIT_TAG v2.1) endif() -# list(APPEND _clad_patches_list "patch1.patch" "patch2.patch") -list(APPEND _clad_patches_list "Add-missing-exception-include.patch") -set(_clad_patch_command - ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/interpreter/cling/tools/plugins/clad/patches - && git checkout -q - && git apply --ignore-space-change --ignore-whitespace ${_clad_patches_list} - ) +## list(APPEND _clad_patches_list "patch1.patch" "patch2.patch") +#list(APPEND _clad_patches_list "") +#set(_clad_patch_command +# ${CMAKE_COMMAND} -E copy_directory +# ${CMAKE_SOURCE_DIR}/interpreter/cling/tools/plugins/clad/patches +# && git checkout -q +# && git apply --ignore-space-change --ignore-whitespace ${_clad_patches_list} +# ) ExternalProject_Add( clad diff --git a/interpreter/cling/tools/plugins/clad/patches/Add-missing-exception-include.patch b/interpreter/cling/tools/plugins/clad/patches/Add-missing-exception-include.patch deleted file mode 100644 index e9fec668f45c9..0000000000000 --- a/interpreter/cling/tools/plugins/clad/patches/Add-missing-exception-include.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 6f7cc80d755cc8472a9c574317fa3ce35b9adb03 Mon Sep 17 00:00:00 2001 -From: Jonas Rembser -Date: Tue, 29 Jul 2025 11:39:55 +0200 -Subject: [PATCH] Add missing includes in case `NDEBUG` is not defined - ---- - include/clad/Differentiator/BaseForwardModeVisitor.h | 4 ++++ - include/clad/Differentiator/ReverseModeVisitor.h | 4 ++++ - 2 files changed, 8 insertions(+) - -diff --git a/include/clad/Differentiator/BaseForwardModeVisitor.h b/include/clad/Differentiator/BaseForwardModeVisitor.h -index c9e6dc4..83439ea 100644 ---- a/include/clad/Differentiator/BaseForwardModeVisitor.h -+++ b/include/clad/Differentiator/BaseForwardModeVisitor.h -@@ -16,6 +16,10 @@ - #include - #include - -+#ifndef NDEBUG -+#include // for std::terminate -+#endif -+ - namespace clad { - /// A visitor for processing the function code in forward mode. - /// Used to compute derivatives by clad::differentiate. -diff --git a/include/clad/Differentiator/ReverseModeVisitor.h b/include/clad/Differentiator/ReverseModeVisitor.h -index 5374171..b0e6dd4 100644 ---- a/include/clad/Differentiator/ReverseModeVisitor.h -+++ b/include/clad/Differentiator/ReverseModeVisitor.h -@@ -30,6 +30,10 @@ - #include - #include - -+#ifndef NDEBUG -+#include // for std::terminate -+#endif -+ - namespace llvm { - template class SmallVectorImpl; - } --- -2.50.1 -