Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/hendrikmuhs/ccache…
Browse files Browse the repository at this point in the history
…-action-1.2.13
  • Loading branch information
auto-differentiation-dev committed Jun 6, 2024
2 parents 83b0cff + 1b8be41 commit 484f811
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 26 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ IncludeCategories:
- Regex: '^<.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
InsertNewlineAtEOF: true
...

51 changes: 40 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
compiler: msvc
os: windows-2019
vsvarsall: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
- toolset: "14.1"
compiler: msvc
os: windows-2019
vsvarsall: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
exclude:
- compiler: clang
toolset: "14.1"
Expand Down Expand Up @@ -322,27 +326,51 @@ jobs:
build_and_test_macos:
name: Mac
runs-on: macos-13
strategy:
fail-fast: false
matrix:
config: [Release, Debug]
os: [macos-13, macos-latest]
compiler: [default, clang15]
include:
- config: Release
os: macos-13
compiler: default
coverage: false
- config: Debug
os: macos-13
compiler: default
coverage: true
coverage_cxx_flags: "-fprofile-arcs -ftest-coverage"
coverage_cxx_flags: "-fprofile-arcs -ftest-coverage"
coverage_ld_flags: "-ftest-coverage"
- config: Release
os: macos-latest
compiler: clang15
coverage: false
- config: Debug
os: macos-latest
compiler: clang15
coverage: true
coverage_cxx_flags: "-fprofile-arcs -ftest-coverage"
coverage_ld_flags: "-ftest-coverage"
exclude:
- os: macos-13
compiler: clang15
- os: macos-latest
compiler: default
runs-on: ${{ matrix.os }}
steps:
- name: setup
run: |
brew install ninja
brew install ccache
brew update
brew install ninja ccache
- name: setup coverage
if: ${{ matrix.coverage }}
# needs to be lcov1.14 specifically and brew no longer supports version selection
run: |
brew install lcov
git clone --branch v1.14 https://github.com/linux-test-project/lcov.git
cd lcov
sudo make install
- uses: actions/checkout@v3
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.13
Expand All @@ -357,7 +385,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
-DCMAKE_CXX_FLAGS="${{ matrix.coverage_cxx_flags }}" \
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.coverage_ld_flags }}" \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install \
${{ matrix.compiler == 'clang15' && ' -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++ -DCMAKE_C_COMPILER=clang' || '' }}
- name: build
run: |
cd build
Expand All @@ -367,11 +396,11 @@ jobs:
run: |
cd build
mkdir coverage tmp
lcov --no-external --keep-going --capture --initial --directory ${{ github.workspace }} --output-file ./tmp/lcov_base.info
lcov --no-external --capture --initial --directory ${{ github.workspace }} --output-file ./tmp/lcov_base.info
- name: test
run: |
cd build
ctest --no-compress-output --output-on-failure -j3 --output-junit test_results.xml
ctest --no-compress-output --output-on-failure -j$(sysctl -n hw.ncpu) --output-junit test_results.xml
- name: upload test results
if: always()
uses: actions/upload-artifact@v3
Expand All @@ -382,7 +411,7 @@ jobs:
if: ${{ matrix.coverage }}
run: |
cd build
lcov --no-external --keep-going --capture --directory ${{ github.workspace }} --output-file ./tmp/lcov_run.info
lcov --no-external --capture --directory ${{ github.workspace }} --output-file ./tmp/lcov_run.info
lcov --add-tracefile ./tmp/lcov_base.info --add-tracefile ./tmp/lcov_run.info --ignore-errors inconsistent --output-file ./tmp/lcov_total.info
lcov --remove ./tmp/lcov_total.info "$PWD/*" "${{ github.workspace }}/test/*" "${{ github.workspace }}/samples/*" --ignore-errors inconsistent --output-file ./coverage/lcov.info
- name: upload coverage results
Expand All @@ -405,8 +434,8 @@ jobs:
cmake ../samples -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.coverage_ld_flags }}" \
-DCMAKE_PREFIX_PATH="${{ github.workspace }}/install"
-DCMAKE_PREFIX_PATH="${{ github.workspace }}/install" \
${{ matrix.compiler == 'clang15' && ' -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++ -DCMAKE_C_COMPILER=clang' || '' }}
cmake --build .
coverage_finish:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
We love pull requests from everyone. By participating in this project, you agree to abide
by our [code of conduct](CODE_OF_CONDUCT.md).

1. Fork, then clone the repository:
1. [Fork](https://github.com/auto-differentiation/xad/fork), then clone the repository:

```bash
git clone https://github.com/yourusername/xad.git
Expand Down
9 changes: 8 additions & 1 deletion cmake/SetupCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL
set(xad_cxx_extra -mavx2)
elseif(XAD_SIMD_OPTION STREQUAL AVX512)
set(xad_cxx_extra -march=cascadelake)
elseif(XAD_SIMD_OPTION STREQUAL NATIVE)
set(xad_cxx_extra -march=native)
elseif(XAD_SIMD_OPTION STREQUAL APPLE_M1)
set(xad_cxx_extra -march=armv8.5-a)
endif()
set(xad_cxx_asan_flags -fsanitize=address -fno-omit-frame-pointer)
set(xad_link_asan_flags -fsanitize=address)
Expand All @@ -76,6 +80,10 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
set(xad_cxx_extra -mavx2)
elseif(XAD_SIMD_OPTION STREQUAL AVX512)
set(xad_cxx_extra -march=cascadelake)
elseif(XAD_SIMD_OPTION STREQUAL NATIVE)
set(xad_cxx_extra -march=native)
elseif(XAD_SIMD_OPTION STREQUAL APPLE_M1)
set(xad_cxx_extra -march=armv8.5-a)
endif()
set(xad_cxx_asan_flags -fsanitize=address -fno-omit-frame-pointer)
set(xad_link_asan_flags -fsanitize=address)
Expand Down Expand Up @@ -181,4 +189,3 @@ function(xad_add_executable name)
MINSIZEREL_POSTFIX ""
)
endfunction()

17 changes: 14 additions & 3 deletions cmake/SetupOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ include(CMakeDependentOption)
# Build options
# Enable the tests only if this is the main project
if(CMAKE_PROJECT_NAME STREQUAL "xad")
option(XAD_ENABLE_TESTS "Enable the XAD Tests" ON)
option(XAD_ENABLE_TESTS "Enable the XAD tests" ON)
else()
option(XAD_ENABLE_TESTS "Enable the XAD tests" OFF)
endif()
option(XAD_WARNINGS_PARANOID "Use extra-paranoid warning level" ON)
option(XAD_POSITION_INDEPENDENT_CODE "Generate PIC code, so it can be linked into a shared library" ON)

set(XAD_SIMD_OPTION "AVX" CACHE STRING "SIMD instruction set to use")
set_property(CACHE XAD_SIMD_OPTION PROPERTY STRINGS SSE2 AVX AVX2 AVX512) # for drop-down in GUI
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(XAD_SIMD_OPTION "APPLE_M1" CACHE STRING "SIMD instruction set to use")
set_property(CACHE XAD_SIMD_OPTION PROPERTY STRINGS APPLE_M1 NATIVE)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(XAD_SIMD_OPTION "NATIVE" CACHE STRING "SIMD instruction set to use")
set_property(CACHE XAD_SIMD_OPTION PROPERTY STRINGS NATIVE)
endif()
else()
set(XAD_SIMD_OPTION "AVX" CACHE STRING "SIMD instruction set to use")
set_property(CACHE XAD_SIMD_OPTION PROPERTY STRINGS SSE2 AVX AVX2 AVX512 NATIVE) # for drop-down in GUI
endif()

message(STATUS "Using SIMD instruction set: ${XAD_SIMD_OPTION}")

option(XAD_ENABLE_ADDRESS_SANITIZER "Enable address sanitizer (Gcc/Clang only)" OFF)
Expand Down
24 changes: 18 additions & 6 deletions src/XAD/Complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,16 @@ XAD_INLINE xad::FReal<T> norm(const complex<xad::FReal<T>>& x)
return ::xad::detail::norm_impl(x);
}

// appleclang15 needs this overload for type paramed norm
#if defined(__APPLE__) && defined(__clang__) && defined(__apple_build_version__) && \
(__apple_build_version__ >= 15000000)
template <class T>
XAD_INLINE typename std::enable_if<xad::ExprTraits<T>::isExpr, T>::type norm(complex<T>& x)
{
return ::xad::detail::norm_impl(x);
}
#endif

// return the expression type from multiplying x*x without actually evaluating it
template <class Scalar, class Derived>
XAD_INLINE auto norm(const xad::Expression<Scalar, Derived>& x) -> decltype(x * x)
Expand Down Expand Up @@ -1481,13 +1491,15 @@ XAD_INLINE auto proj(const xad::FReal<T>& x) -> decltype(::xad::detail::proj_imp
// different expr (derived1, derived2 - returns scalar)

template <class T>
XAD_INLINE complex<xad::AReal<T>> polar(const xad::AReal<T>& r, const xad::AReal<T>& theta)
XAD_INLINE complex<xad::AReal<T>> polar(const xad::AReal<T>& r,
const xad::AReal<T>& theta = xad::AReal<T>())
{
return xad::detail::polar_impl(r, theta);
}

template <class T>
XAD_INLINE complex<xad::FReal<T>> polar(const xad::FReal<T>& r, const xad::FReal<T>& theta)
XAD_INLINE complex<xad::FReal<T>> polar(const xad::FReal<T>& r,
const xad::FReal<T>& theta = xad::FReal<T>())
{
return xad::detail::polar_impl(r, theta);
}
Expand Down Expand Up @@ -1660,7 +1672,7 @@ template <class Scalar, class Expr1, class Expr2>
XAD_INLINE typename std::enable_if<std::is_same<typename xad::ExprTraits<Expr1>::value_type,
typename xad::ExprTraits<Expr2>::value_type>::value,
complex<typename xad::ExprTraits<Expr1>::value_type>>::type
polar(const xad::Expression<Scalar, Expr1>& r, const xad::Expression<Scalar, Expr2>& theta)
polar(const xad::Expression<Scalar, Expr1>& r, const xad::Expression<Scalar, Expr2>& theta = 0)
{
typedef typename xad::ExprTraits<Expr1>::value_type type;
return xad::detail::polar_impl(type(r), type(theta));
Expand All @@ -1669,15 +1681,15 @@ polar(const xad::Expression<Scalar, Expr1>& r, const xad::Expression<Scalar, Exp
// T, expr - only enabled if T is scalar
template <class Scalar, class Expr>
XAD_INLINE std::complex<typename xad::ExprTraits<Expr>::value_type> polar(
Scalar r, const xad::Expression<Scalar, Expr>& theta)
Scalar r, const xad::Expression<Scalar, Expr>& theta = 0)
{
return xad::detail::polar_impl(typename xad::ExprTraits<Expr>::value_type(r), theta.derived());
}

// expr, T - only enabled if T is scalar
template <class Scalar, class Expr>
XAD_INLINE std::complex<typename xad::ExprTraits<Expr>::value_type> polar(
const xad::Expression<Scalar, Expr>& r, Scalar theta)
const xad::Expression<Scalar, Expr>& r, Scalar theta = Scalar())
{
return xad::detail::polar_impl(r.derived(), typename xad::ExprTraits<Expr>::value_type(theta));
}
Expand Down Expand Up @@ -2613,4 +2625,4 @@ XAD_INLINE std::complex<typename xad::ExprTraits<Derived>::value_type> proj_impl
#endif

} // namespace detail
} // namespace xad
} // namespace xad
2 changes: 1 addition & 1 deletion src/XAD/StdCompatibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct is_arithmetic<xad::FReal<T>> : std::is_arithmetic<T>
{
};
template <class T>
struct is_signed<xad::AReal<T>> : std::is_signed<T>
struct is_signed<xad::AReal<T>> : std::is_signed<T>
{
};
template <class T>
Expand Down
6 changes: 3 additions & 3 deletions test/Expressions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ TEST(Expressions, canEvaluateLongExpressionsLikeHestonAdjoint)
double yd_eps = testerd.c4(value(x) + eps);
double dxd = (yd_eps - yd) / eps;

EXPECT_DOUBLE_EQ(value(y), yd);
EXPECT_THAT(value(y), DoubleNear(yd, 1e-9));
EXPECT_THAT(dx, DoubleNear(dxd, 1e-5));
}

Expand All @@ -1723,7 +1723,7 @@ TEST(Expressions, canEvaluateLongExpressionsLikeHestonForward)
double yd_eps = testerd.c4(value(x) + eps);
double dxd = (yd_eps - yd) / eps;

EXPECT_DOUBLE_EQ(value(y), yd);
EXPECT_THAT(value(y), DoubleNear(yd, 1e-9));
EXPECT_THAT(dx, DoubleNear(dxd, 1e-5));
}

Expand Down Expand Up @@ -1819,4 +1819,4 @@ TEST(Expressions, notWarningAboutSizetToDouble)
x -= d;

EXPECT_THAT(value(x), DoubleEq(2.0));
}
}

0 comments on commit 484f811

Please sign in to comment.