Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vgvassilev/clad
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e1575bb4a4f123ed17d3d6190c0c5f5ed832db9
Choose a base ref
..
head repository: vgvassilev/clad
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3fe7769d8b056206d94f6625bf928482b2118966
Choose a head ref
Showing with 2,967 additions and 992 deletions.
  1. +21 −15 CMakeLists.txt
  2. +1 −1 VERSION
  3. +1 −1 demos/ErrorEstimation/CustomModel/README.md
  4. +1 −1 demos/ErrorEstimation/PrintModel/README.md
  5. +20 −47 docs/internalDocs/ReleaseNotes.md
  6. +8 −0 include/clad/Differentiator/BuiltinDerivatives.h
  7. +1 −0 include/clad/Differentiator/CladUtils.h
  8. +20 −9 include/clad/Differentiator/DiffPlanner.h
  9. +54 −0 include/clad/Differentiator/KokkosBuiltins.h
  10. +28 −39 include/clad/Differentiator/NewTape.h
  11. +13 −3 include/clad/Differentiator/ReverseModeVisitor.h
  12. +0 −2 include/clad/Differentiator/VisitorBase.h
  13. +38 −28 lib/Differentiator/BaseForwardModeVisitor.cpp
  14. +16 −0 lib/Differentiator/CladUtils.cpp
  15. +26 −0 lib/Differentiator/DiffPlanner.cpp
  16. +19 −2 lib/Differentiator/PushForwardModeVisitor.cpp
  17. +212 −108 lib/Differentiator/ReverseModeVisitor.cpp
  18. +15 −17 lib/Differentiator/TBRAnalyzer.cpp
  19. +3 −5 lib/Differentiator/TBRAnalyzer.h
  20. +2 −5 lib/Differentiator/VisitorBase.cpp
  21. +1 −1 requirements.txt
  22. +30 −0 shell.nix
  23. +146 −58 test/Arrays/ArrayInputsReverseMode.C
  24. +11 −3 test/CUDA/GradientCuda.cu
  25. +7 −7 test/ErrorEstimation/Assignments.C
  26. +7 −7 test/ErrorEstimation/BasicOps.C
  27. +4 −4 test/ErrorEstimation/ConditonalStatements.C
  28. +37 −13 test/ErrorEstimation/LoopsAndArrays.C
  29. +40 −8 test/ErrorEstimation/LoopsAndArraysExec.C
  30. +56 −0 test/FirstDerivative/CallArguments.C
  31. +16 −0 test/FirstDerivative/FunctionCalls.C
  32. +6 −6 test/FirstDerivative/FunctionCallsWithResults.C
  33. +3 −3 test/FirstDerivative/FunctionsInNamespaces.C
  34. +37 −1 test/FirstDerivative/Variables.C
  35. +1 −1 test/ForwardMode/MemberFunctions.C
  36. +8 −8 test/ForwardMode/NonDifferentiable.C
  37. +32 −2 test/ForwardMode/Pointer.C
  38. +34 −34 test/ForwardMode/UserDefinedTypes.C
  39. +59 −61 test/Gradient/Assignments.C
  40. +42 −17 test/Gradient/FunctionCalls.C
  41. +22 −11 test/Gradient/Gradients.C
  42. +1,405 −378 test/Gradient/Loops.C
  43. +2 −2 test/Gradient/MemberFunctions.C
  44. +187 −0 test/Gradient/NonDifferentiable.C
  45. +51 −0 test/Gradient/NonDifferentiableError.C
  46. +16 −8 test/Gradient/Pointers.C
  47. +12 −4 test/Gradient/Switch.C
  48. +11 −3 test/Gradient/TestTypeConversion.C
  49. +44 −12 test/Gradient/UserDefinedTypes.C
  50. +37 −29 test/Misc/RunDemos.C
  51. +1 −1 test/NthDerivative/CustomDerivatives.C
  52. +1 −0 unittests/Kokkos/CMakeLists.txt
  53. +4 −5 unittests/Kokkos/TestUtils.h
  54. +73 −0 unittests/Kokkos/ViewAccess.cpp
  55. +25 −22 unittests/Kokkos/ViewBasics.cpp
36 changes: 21 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -324,28 +324,34 @@ if (NOT CLAD_BUILD_STATIC_ONLY)
add_subdirectory(demos/ErrorEstimation/CustomModel)
add_subdirectory(demos/ErrorEstimation/PrintModel)

# Change the default compiler to the clang which we run clad upon. Our unittests
# need to use a supported by clad compiler. Note that's a huge hack and it is
# not guaranteed to work with cmake.
set(stored_cxx_compiler ${CMAKE_CXX_COMPILER})
set(stored_cxx_flags ${CMAKE_CXX_FLAGS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Filter some unsupported flags by clang.
string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-Wno-class-memaccess" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if (NOT CLAD_DISABLE_TESTS OR CLAD_ENABLE_BENCHMARKS)
# Change the default compiler to the clang which we run clad upon. Our unittests
# need to use a supported by clad compiler. Note that's a huge hack and it is
# not guaranteed to work with cmake.
set(stored_cxx_compiler ${CMAKE_CXX_COMPILER})
set(stored_cxx_flags ${CMAKE_CXX_FLAGS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Filter some unsupported flags by clang.
string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-Wno-class-memaccess" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

add_subdirectory(unittests)
add_subdirectory(test)
if (NOT CLAD_DISABLE_TESTS)
add_subdirectory(unittests)
add_subdirectory(test)
endif()

# Add benchmarking infrastructure.
if (CLAD_ENABLE_BENCHMARKS)
add_subdirectory(benchmark)
endif(CLAD_ENABLE_BENCHMARKS)

# Restore the default compiler.
set(CMAKE_CXX_COMPILER ${stored_cxx_compiler})
set(CMAKE_CXX_FLAGS ${stored_cxx_flags})
if (stored_cxx_compiler)
# Restore the default compiler.
set(CMAKE_CXX_COMPILER ${stored_cxx_compiler})
set(CMAKE_CXX_FLAGS ${stored_cxx_flags})
endif()
endif()

# Workaround for MSVS10 to avoid the Dialog Hell
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6~dev
1.7~dev
2 changes: 1 addition & 1 deletion demos/ErrorEstimation/CustomModel/README.md
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ The code is: void func_grad(float x, float y, float *_d_x, float *_d_y, double &
_final_error += _d_z * z;
z = _t0;
float _r_d0 = _d_z;
_d_z -= _r_d0;
_d_z = 0;
*_d_x += _r_d0;
*_d_y += _r_d0;
}
2 changes: 1 addition & 1 deletion demos/ErrorEstimation/PrintModel/README.md
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ The code is: void func_grad(float x, float y, float *_d_x, float *_d_y, double &
_final_error += _d_z * z;
z = _t0;
float _r_d0 = _d_z;
_d_z -= _r_d0;
_d_z = 0;
*_d_x += _r_d0;
*_d_y += _r_d0;
}
67 changes: 20 additions & 47 deletions docs/internalDocs/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ Introduction
============

This document contains the release notes for the automatic differentiation
plugin for clang Clad, release 1.5. Clad is built on top of
plugin for clang Clad, release 1.7. Clad is built on top of
[Clang](http://clang.llvm.org) and [LLVM](http://llvm.org>) compiler
infrastructure. Here we describe the status of Clad in some detail, including
major improvements from the previous release and new feature work.
@@ -11,7 +11,7 @@ Note that if you are reading this file from a git checkout,
this document applies to the *next* release, not the current one.


What's New in Clad 1.5?
What's New in Clad 1.7?
========================

Some of the major new features and improvements to Clad are listed here. Generic
@@ -26,52 +26,36 @@ External Dependencies

Forward Mode & Reverse Mode
---------------------------
* Add support for C-style memory alloc and free
*

Forward Mode
------------
*

Reverse Mode
------------
* Replace array_ref with pointers in gradient signature
* Initial support for new and delete operations in reverse mode
*

CUDA
----
*

Error Estimation
----------------
* Only track sizes of independent arrays
* Remove .size() from error estimation
* Simplify error estimation by removing `_EERepl_` and `_delta_`
*

Misc
----
* Teach binder to use the newest available version of clad
* Simplify pullback calls by replacing `_grad`/`_r` pairs with single `_r`
variables
* Delay the differentiation process until the end of TU -- Clad now can operate
just like clang and visit the entire translation unit to construct a precise
differentiation plan
* Remove extra lines generated when using clad::array or array_ref
* Added timings report if `-ftime-report` flag is enabled
*

Fixed Bugs
----------

[248](https://github.com/vgvassilev/clad/issues/248)
[350](https://github.com/vgvassilev/clad/issues/350)
[704](https://github.com/vgvassilev/clad/issues/704)
[715](https://github.com/vgvassilev/clad/issues/715)
[765](https://github.com/vgvassilev/clad/issues/765)
[769](https://github.com/vgvassilev/clad/issues/769)
[790](https://github.com/vgvassilev/clad/issues/790)
[792](https://github.com/vgvassilev/clad/issues/792)
[798](https://github.com/vgvassilev/clad/issues/798)
[805](https://github.com/vgvassilev/clad/issues/805)
[854](https://github.com/vgvassilev/clad/issues/854)
[865](https://github.com/vgvassilev/clad/issues/865)
[867](https://github.com/vgvassilev/clad/issues/867)
[886](https://github.com/vgvassilev/clad/issues/886)
[887](https://github.com/vgvassilev/clad/issues/887)
[890](https://github.com/vgvassilev/clad/issues/890)
[897](https://github.com/vgvassilev/clad/issues/897)
[XXX](https://github.com/vgvassilev/clad/issues/XXX)

<!---Get release bugs. Check for close, fix, resolve
git log v1.6..master | grep -i "close" | grep '#' | sed -E 's,.*\#([0-9]*).*,\[\1\]\(https://github.com/vgvassilev/clad/issues/\1\),g' | sort
--->

Special Kudos
=============
@@ -83,17 +67,6 @@ FirstName LastName (#commits)

A B (N)

petro.zarytskyi (30)
Vaibhav Thakkar (24)
Vassil Vassilev (21)
mcbarton (6)
Mihail Mihov (4)
dependabot[bot] (2)
Atell Krasnopolski (2)
Alexander Penev (2)
sauravUppoor (1)
kchristin22 (1)
Warren Jacinto (1)
Jonas Hahnfeld (1)
Deeptendu Santra (1)
Christina Koutsou (1)
<!---Find contributor list for this release
git log --pretty=format:"%an" v1.6...master | sort | uniq -c | sort -rn | sed -E 's,^ *([0-9]+) (.*)$,\2 \(\1\),'
--->
8 changes: 8 additions & 0 deletions include/clad/Differentiator/BuiltinDerivatives.h
Original file line number Diff line number Diff line change
@@ -20,6 +20,14 @@ namespace clad {
template <typename T, typename U> struct ValueAndPushforward {
T value;
U pushforward;

// Define the cast operator from ValueAndPushforward<T, U> to
// ValueAndPushforward<V, w> where V is convertible to T and W is
// convertible to U.
template <typename V = T, typename W = U>
operator ValueAndPushforward<V, W>() const {
return {static_cast<V>(value), static_cast<W>(pushforward)};
}
};

/// It is used to identify constructor custom pushforwards. For
1 change: 1 addition & 0 deletions include/clad/Differentiator/CladUtils.h
Original file line number Diff line number Diff line change
@@ -317,6 +317,7 @@ namespace clad {
void SetSwitchCaseSubStmt(clang::SwitchCase* SC, clang::Stmt* subStmt);

bool IsLiteral(const clang::Expr* E);
bool IsZeroOrNullValue(const clang::Expr* E);

bool IsMemoryFunction(const clang::FunctionDecl* FD);
bool IsMemoryDeallocationFunction(const clang::FunctionDecl* FD);
29 changes: 20 additions & 9 deletions include/clad/Differentiator/DiffPlanner.h
Original file line number Diff line number Diff line change
@@ -8,21 +8,30 @@
#include "clad/Differentiator/ParseDiffArgsTypes.h"

namespace clang {
class ASTContext;
class CallExpr;
class CompilerInstance;
class DeclGroupRef;
class Expr;
class FunctionDecl;
class ParmVarDecl;
class Sema;
class Type;
class CallExpr;
class CompilerInstance;
class DeclGroupRef;
class Expr;
class FunctionDecl;
class ParmVarDecl;
class Sema;
class Type;
} // namespace clang

namespace clad {

/// A struct containing information about request to differentiate a function.
struct DiffRequest {
private:
/// Based on To-Be-Recorded analysis performed before differentiation, tells
/// UsefulToStoreGlobal whether a variable with a given SourceLocation has to
/// be stored before being changed or not.
mutable struct TbrRunInfo {
std::set<clang::SourceLocation> ToBeRecorded;
bool HasAnalysisRun = false;
} m_TbrRunInfo;

public:
/// Function to be differentiated.
const clang::FunctionDecl* Function = nullptr;
/// Name of the base function to be differentiated. Can be different from
@@ -118,6 +127,8 @@ struct DiffRequest {
res += "__TBR";
return res;
}

bool shouldBeRecorded(clang::Expr* E) const;
};

using DiffInterval = std::vector<clang::SourceRange>;
54 changes: 54 additions & 0 deletions include/clad/Differentiator/KokkosBuiltins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This header file contains the implementation of the Kokkos framework
// differentiation support in Clad in the form of custom pushforwards and
// pullbacks. Please include it manually to enable Clad for Kokkos code.

#ifndef CLAD_DIFFERENTIATOR_KOKKOSBUILTINS_H
#define CLAD_DIFFERENTIATOR_KOKKOSBUILTINS_H

#include <Kokkos_Core.hpp>
#include "clad/Differentiator/Differentiator.h"

namespace clad::custom_derivatives {
namespace class_functions {
/// Kokkos arrays
template <class DataType, class... ViewParams>
clad::ValueAndPushforward<Kokkos::View<DataType, ViewParams...>,
Kokkos::View<DataType, ViewParams...>>
constructor_pushforward(
clad::ConstructorPushforwardTag<Kokkos::View<DataType, ViewParams...>>,
const ::std::string& name, const size_t& idx0, const size_t& idx1,
const size_t& idx2, const size_t& idx3, const size_t& idx4,
const size_t& idx5, const size_t& idx6, const size_t& idx7,
const ::std::string& d_name, const size_t& d_idx0, const size_t& d_idx1,
const size_t& d_idx2, const size_t& d_idx3, const size_t& d_idx4,
const size_t& d_idx5, const size_t& d_idx6, const size_t& d_idx7) {
return {Kokkos::View<DataType, ViewParams...>(name, idx0, idx1, idx2, idx3,
idx4, idx5, idx6, idx7),
Kokkos::View<DataType, ViewParams...>(
"_diff_" + name, idx0, idx1, idx2, idx3, idx4, idx5, idx6, idx7)};
}
} // namespace class_functions

/// Kokkos functions
namespace Kokkos {
template <typename View1, typename View2, typename T>
inline void deep_copy_pushforward(const View1& dst, const View2& src, T param,
const View1& d_dst, const View2& d_src,
T d_param) {
deep_copy(dst, src);
deep_copy(d_dst, d_src);
}

template <class ExecPolicy, class FunctorType>
inline void
parallel_for_pushforward(const ::std::string& str, const ExecPolicy& policy,
const FunctorType& functor, const ::std::string& d_str,
const ExecPolicy& d_policy,
const FunctorType& d_functor) {
// TODO: implement parallel_for_pushforward
return;
}
} // namespace Kokkos
} // namespace clad::custom_derivatives

#endif // CLAD_DIFFERENTIATOR_KOKKOSBUILTINS_H
Loading