Skip to content

Commit

Permalink
move by pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Dec 4, 2023
1 parent 9d81388 commit 359d087
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 5 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ if(ENABLE_NATIVE_COMPILATION)
check_cxx_compiler_flag("-mprefer-vector-width=512" VEC512)
if(VEC512)
target_compile_options(${PROJECT_NAME} PRIVATE -mprefer-vector-width=512)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -mtune-ctrl=avx512_move_by_pieces)
endif()
endif()
endif()
endif()
endif()
Expand Down
20 changes: 8 additions & 12 deletions benchmark/dual_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ template <std::floating_point T, ptrdiff_t N> struct ManualDual<T, N, true> {
auto grad() -> P & { return partials; }
};
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator*(const ManualDual<T, N, B> &a,
const ManualDual<T, N, B> &b)
[[gnu::always_inline]] constexpr auto operator*(ManualDual<T, N, B> a,
ManualDual<T, N, B> b)
-> ManualDual<T, N, B> {
if constexpr ((!B) && (!std::floating_point<T>)&&(N == 2))
return {a.value * b.value,
Expand All @@ -80,32 +80,28 @@ template <typename T, ptrdiff_t N, bool B>
else return {a.value * b.value, a.value * b.partials + b.value * a.partials};
}
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator*(const ManualDual<T, N, B> &a,
const T &b)
[[gnu::always_inline]] constexpr auto operator*(ManualDual<T, N, B> a, T b)
-> ManualDual<T, N, B> {
return {a.value * b, b * a.partials};
}
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator*(const T &a,
const ManualDual<T, N, B> &b)
[[gnu::always_inline]] constexpr auto operator*(T a, ManualDual<T, N, B> b)
-> ManualDual<T, N, B> {
return {b.value * a, a * b.partials};
}
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator+(const ManualDual<T, N, B> &a,
const ManualDual<T, N, B> &b)
[[gnu::always_inline]] constexpr auto operator+(ManualDual<T, N, B> a,
ManualDual<T, N, B> b)
-> ManualDual<T, N, B> {
return {a.value + b.value, a.partials + b.partials};
}
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator+(const ManualDual<T, N, B> &a,
const T &b)
[[gnu::always_inline]] constexpr auto operator+(ManualDual<T, N, B> a, T b)
-> ManualDual<T, N, B> {
return {a.value + b, a.partials};
}
template <typename T, ptrdiff_t N, bool B>
[[gnu::always_inline]] constexpr auto operator+(const T &a,
const ManualDual<T, N, B> &b)
[[gnu::always_inline]] constexpr auto operator+(T a, ManualDual<T, N, B> b)
-> ManualDual<T, N, B> {
return {b.value + a, b.partials};
}
Expand Down

0 comments on commit 359d087

Please sign in to comment.