Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Sep 8, 2024
2 parents fb07f8e + 50a0b5f commit 37e9e47
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 31 deletions.
31 changes: 31 additions & 0 deletions docs/userDocs/source/user/DevelopersDocumentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,37 @@ Now, to ssh into the GitHub runner do, simply do::

No username or password is required.

Please note that there are some specifics of debugging the "Architecture" check. If you need to build Clad after logging into this particular GitHub runner (the one performing the "Arch / architecture (x86)" check), please perform the following steps first.

In the debug output on GitHub (typically displayed in purple), find the line:

.. code-block:: bash
/home/runner/rootfs/alpine-edge-x86/abin/alpine.sh /home/runner/work/_temp/%UNIQUE_FILENAME%
Copy the name of the second file in that line (everything after the spacebar) and do:

.. code-block:: bash
bash
vim /home/runner/work/_temp/%UNIQUE_FILENAME%
So you need to switch to bash to have access to some text editors and then inside Vim (or any other editor you find there, you can even use ``cat`` for this), you need to edit the contents of this file to only contain the following:

.. code-block:: bash
export CC=/usr/bin/clang-17
export CXX=/usr/bin/clang++-17
sh
Basically, you need to replace the last several lines with just ``sh``. Now do,

.. code-block:: bash
/home/runner/rootfs/alpine-edge-x86/abin/alpine.sh /home/runner/work/_temp/%UNIQUE_FILENAME%
After this you're able to do ``cd build && make check-clad`` and build Clad on that runner.

Debugging x86 builds locally
============================

Expand Down
14 changes: 7 additions & 7 deletions include/clad/Differentiator/DiffPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ struct DiffRequest {

// Define the hash function for DiffRequest.
template <> struct std::hash<clad::DiffRequest> {
std::size_t operator()(const clad::DiffRequest& DR) const {
// Use the function pointer as the hash of the DiffRequest, it
// is sufficient to break a reasonable number of collisions.
if (DR.Function->getPreviousDecl())
return std::hash<const void*>{}(DR.Function->getPreviousDecl());
return std::hash<const void*>{}(DR.Function);
}
std::size_t operator()(const clad::DiffRequest& DR) const {
// Use the function pointer as the hash of the DiffRequest, it
// is sufficient to break a reasonable number of collisions.
if (DR.Function->getPreviousDecl())
return std::hash<const void*>{}(DR.Function->getPreviousDecl());
return std::hash<const void*>{}(DR.Function);
}
};

#endif
29 changes: 11 additions & 18 deletions include/clad/Differentiator/KokkosBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ struct diff_parallel_for_MDP_call_dispatch<Policy, FunctorType, void, 2> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
"_diff_" + str, policy, [&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, 0, 0);
});
}
Expand All @@ -214,8 +213,7 @@ struct diff_parallel_for_MDP_call_dispatch<Policy, FunctorType, void, 3> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
"_diff_" + str, policy, [&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0);
});
}
Expand All @@ -237,8 +235,7 @@ struct diff_parallel_for_MDP_call_dispatch<Policy, FunctorType, void, 4> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
"_diff_" + str, policy, [&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0);
});
}
Expand All @@ -260,8 +257,7 @@ struct diff_parallel_for_MDP_call_dispatch<Policy, FunctorType, void, 5> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
"_diff_" + str, policy, [&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0, 0);
});
}
Expand All @@ -282,12 +278,11 @@ template <class Policy, class FunctorType>
struct diff_parallel_for_MDP_call_dispatch<Policy, FunctorType, void, 6> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0, 0,
0);
});
::Kokkos::parallel_for("_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(
args..., &d_functor, 0, 0, 0, 0, 0, 0);
});
}
};

Expand Down Expand Up @@ -326,8 +321,7 @@ struct diff_parallel_for_OP_call_dispatch<Policy, FunctorType, void> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](auto&&... args) {
"_diff_" + str, policy, [&functor, &d_functor](auto&&... args) {
functor.operator_call_pushforward(args..., &d_functor, {});
});
}
Expand All @@ -350,8 +344,7 @@ struct diff_parallel_for_int_call_dispatch<Policy, FunctorType, true> {
static void run(const ::std::string& str, const Policy& policy,
const FunctorType& functor, const FunctorType& d_functor) {
::Kokkos::parallel_for(
"_diff_" + str, policy,
[&functor, &d_functor](const int i) {
"_diff_" + str, policy, [&functor, &d_functor](const int i) {
functor.operator_call_pushforward(i, &d_functor, 0);
});
}
Expand Down
85 changes: 85 additions & 0 deletions include/clad/Differentiator/STLBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,91 @@ void constructor_pullback(::std::vector<T>* v, S count, U val,
d_v->clear();
}

template <typename T, ::std::size_t N>
clad::ValueAndAdjoint<T&, T&> operator_subscript_reverse_forw(
::std::array<T, N>* arr, typename ::std::array<T, N>::size_type idx,
::std::array<T, N>* d_arr, typename ::std::array<T, N>::size_type d_idx) {
return {(*arr)[idx], (*d_arr)[idx]};
}
template <typename T, ::std::size_t N, typename P>
void operator_subscript_pullback(
::std::array<T, N>* arr, typename ::std::array<T, N>::size_type idx, P d_y,
::std::array<T, N>* d_arr, typename ::std::array<T, N>::size_type* d_idx) {
(*d_arr)[idx] += d_y;
}
template <typename T, ::std::size_t N>
clad::ValueAndAdjoint<T&, T&> at_reverse_forw(
::std::array<T, N>* arr, typename ::std::array<T, N>::size_type idx,
::std::array<T, N>* d_arr, typename ::std::array<T, N>::size_type d_idx) {
return {(*arr)[idx], (*d_arr)[idx]};
}
template <typename T, ::std::size_t N, typename P>
void at_pullback(::std::array<T, N>* arr,
typename ::std::array<T, N>::size_type idx, P d_y,
::std::array<T, N>* d_arr,
typename ::std::array<T, N>::size_type* d_idx) {
(*d_arr)[idx] += d_y;
}
template <typename T, ::std::size_t N>
void fill_reverse_forw(::std::array<T, N>* a,
const typename ::std::array<T, N>::value_type& u,
::std::array<T, N>* d_a,
const typename ::std::array<T, N>::value_type& d_u) {
a->fill(u);
d_a->fill(0);
}
template <typename T, ::std::size_t N>
void fill_pullback(::std::array<T, N>* arr,
const typename ::std::array<T, N>::value_type& u,
::std::array<T, N>* d_arr,
typename ::std::array<T, N>::value_type* d_u) {
for (size_t i = 0; i < N; ++i) {
typename ::std::array<T, N>::value_type r_d0 = (*d_arr)[i];
(*d_arr)[i] = 0;
*d_u += r_d0;
}
}
template <typename T, ::std::size_t N>
clad::ValueAndAdjoint<T&, T&>
back_reverse_forw(::std::array<T, N>* arr, ::std::array<T, N>* d_arr) noexcept {
return {arr->back(), d_arr->back()};
}
template <typename T, ::std::size_t N>
void back_pullback(::std::array<T, N>* arr,
typename ::std::array<T, N>::value_type d_u,
::std::array<T, N>* d_arr) noexcept {
(*d_arr)[d_arr->size() - 1] += d_u;
}
template <typename T, ::std::size_t N>
clad::ValueAndAdjoint<T&, T&>
front_reverse_forw(::std::array<T, N>* arr,
::std::array<T, N>* d_arr) noexcept {
return {arr->front(), d_arr->front()};
}
template <typename T, ::std::size_t N>
void front_pullback(::std::array<T, N>* arr,
typename ::std::array<T, N>::value_type d_u,
::std::array<T, N>* d_arr) {
(*d_arr)[0] += d_u;
}
template <typename T, ::std::size_t N>
void size_pullback(::std::array<T, N>* a, ::std::array<T, N>* d_a) noexcept {}
template <typename T, ::std::size_t N>
::clad::ValueAndAdjoint<::std::array<T, N>, ::std::array<T, N>>
constructor_reverse_forw(::clad::ConstructorReverseForwTag<::std::array<T, N>>,
const ::std::array<T, N>& arr,
const ::std::array<T, N>& d_arr) {
::std::array<T, N> a = arr;
::std::array<T, N> d_a = d_arr;
return {a, d_a};
}
template <typename T, ::std::size_t N>
void constructor_pullback(::std::array<T, N>* a, const ::std::array<T, N>& arr,
::std::array<T, N>* d_a, ::std::array<T, N>* d_arr) {
for (size_t i = 0; i < N; ++i)
(*d_arr)[i] += (*d_a)[i];
}

} // namespace class_functions
} // namespace custom_derivatives
} // namespace clad
Expand Down
9 changes: 5 additions & 4 deletions lib/Differentiator/DiffPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,12 @@ namespace clad {
i < e && paramIdx < FD->getNumParams(); ++i) {
const auto* param = DVI[i].param;
while (paramIdx < FD->getNumParams() &&
FD->getParamDecl(paramIdx) != param)
++paramIdx;
FD->getParamDecl(paramIdx) != param) {
++paramIdx;
}
if (paramIdx != FD->getNumParams())
// Update the parameter to point to the definition parameter.
DVI[i].param = Function->getParamDecl(paramIdx);
// Update the parameter to point to the definition parameter.
DVI[i].param = Function->getParamDecl(paramIdx);
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ namespace clad {
(isa<CXXOperatorCallExpr>(ENoCasts) &&
cast<CXXOperatorCallExpr>(ENoCasts)->getNumArgs() == 2) ||
isa<ConditionalOperator>(ENoCasts) ||
isa<CXXBindTemporaryExpr>(ENoCasts))
isa<CXXBindTemporaryExpr>(ENoCasts)) {
return m_Sema.ActOnParenExpr(E->getBeginLoc(), E->getEndLoc(), E).get();
}
return E;
}

Expand Down
Loading

0 comments on commit 37e9e47

Please sign in to comment.