Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppleClang15 patch #116

56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,62 @@ jobs:
-DCMAKE_PREFIX_PATH="${{ github.workspace }}/install"
cmake --build .

build_and_test_macos_clang15:
name: Mac/Clang15
strategy:
fail-fast: false
matrix:
config: [Release, Debug]
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup dependencies
run: |
brew update
brew install ccache ninja
- name: Setup Clang 15
run: |
brew install llvm@15
raneamri marked this conversation as resolved.
Show resolved Hide resolved
echo 'export PATH="/usr/local/opt/llvm@15/bin:$PATH"' >> $GITHUB_ENV
- name: Configure
run: |
mkdir build
cd build
cmake .. -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
- name: Build
run: |
cd build
cmake --build .
- name: Test
run: |
cd build
ctest --no-compress-output --output-on-failure --parallel $(sysctl -n hw.ncpu) --output-junit test_results.xml
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: Test Results (Mac Clang-15-${{ matrix.config }})
path: build/test_results.xml
- name: Install
run: |
cd build
cmake --install .
- name: Install test
run: |
mkdir installtest
cd installtest
cmake ../samples -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
-DCMAKE_PREFIX_PATH="${{ github.workspace }}/install" \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang
cmake --build .

coverage_finish:
name: Coverage Collect
needs: [ build_and_test_gcc, build_and_test_macos]
Expand Down
9 changes: 6 additions & 3 deletions cmake/SetupCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL
set(xad_cxx_flags -Wall -Wshadow -Wconversion)
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# otherwise we get clashes with complex headers and other things on MacOS
list(APPEND xad_cxx_flags -stdlib=libc++ -mmacosx-version-min=10.9)
list(APPEND xad_cxx_flags -stdlib=libc++ -mmacosx-version-min=10.9 -fbuiltin)
raneamri marked this conversation as resolved.
Show resolved Hide resolved
endif()
set(xad_cxx_flags_warnings -Werror -W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls)
if(XAD_SIMD_OPTION STREQUAL SSE2)
Expand All @@ -62,6 +62,8 @@ 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 NEON)
set(xad_cxx_extra -march=native)
endif()
set(xad_cxx_asan_flags -fsanitize=address -fno-omit-frame-pointer)
set(xad_link_asan_flags -fsanitize=address)
Expand All @@ -76,6 +78,8 @@ 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 NEON)
set(xad_cxx_extra -march=native)
raneamri marked this conversation as resolved.
Show resolved Hide resolved
endif()
set(xad_cxx_asan_flags -fsanitize=address -fno-omit-frame-pointer)
set(xad_link_asan_flags -fsanitize=address)
Expand Down Expand Up @@ -180,5 +184,4 @@ function(xad_add_executable name)
RELWITHDEBINFO_POSTFIX ""
MINSIZEREL_POSTFIX ""
)
endfunction()

endfunction()
raneamri marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 8 additions & 3 deletions cmake/SetupOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ 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" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(XAD_SIMD_OPTION "NEON" CACHE STRING "SIMD instruction set to use")
raneamri marked this conversation as resolved.
Show resolved Hide resolved
else()
set(XAD_SIMD_OPTION "AVX" CACHE STRING "SIMD instruction set to use")
endif()

set_property(CACHE XAD_SIMD_OPTION PROPERTY STRINGS SSE2 AVX AVX2 AVX512 NEON) # for drop-down in GUI
raneamri marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Using SIMD instruction set: ${XAD_SIMD_OPTION}")

option(XAD_ENABLE_ADDRESS_SANITIZER "Enable address sanitizer (Gcc/Clang only)" OFF)
Expand Down
23 changes: 17 additions & 6 deletions src/XAD/Complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,17 @@ 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__)
#if defined(__apple_build_version__) && (__apple_build_version__ >= 15000000)
template <class T>
XAD_INLINE T norm(complex<T>& x)
{
return ::xad::detail::norm_impl(x);
}
raneamri marked this conversation as resolved.
Show resolved Hide resolved
#endif
#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,20 +1492,20 @@ 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 = 0)
raneamri marked this conversation as resolved.
Show resolved Hide resolved
{
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 = 0)
{
return xad::detail::polar_impl(r, theta);
}

template <class Scalar, class Expr>
XAD_INLINE complex<typename xad::ExprTraits<Expr>::value_type> polar(
const xad::Expression<Scalar, Expr>& r, const xad::Expression<Scalar, Expr>& theta)
const xad::Expression<Scalar, Expr>& r, const xad::Expression<Scalar, Expr>& theta = 0)
raneamri marked this conversation as resolved.
Show resolved Hide resolved
{
typedef typename xad::ExprTraits<Expr>::value_type type;
return xad::detail::polar_impl(type(r), type(theta));
Expand Down Expand Up @@ -1660,7 +1671,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 +1680,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 = 0)
raneamri marked this conversation as resolved.
Show resolved Hide resolved
{
return xad::detail::polar_impl(r.derived(), typename xad::ExprTraits<Expr>::value_type(theta));
}
Expand Down
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
2 changes: 1 addition & 1 deletion src/XAD/UnaryOperators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,4 @@ XAD_INLINE float copysign(float x, const Expression<Scalar, Derived>& y)
#undef XAD_MAKE_UNARY_FUNC
#undef XAD_MAKE_FPCLASSIFY_FUNC
#undef XAD_MAKE_FPCLASSIFY_FUNC_RET
} // namespace xad
} // namespace xad
raneamri marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions src/XAD/XAD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#include <XAD/Interface.hpp>
#include <XAD/Literals.hpp>
#include <XAD/MathFunctions.hpp>
#if defined(__APPLE__) && defined(__clang__)
#if defined(__apple_build_version__) && (__apple_build_version__ >= 15000000)
#include <XAD/StdCompatibility.hpp>
raneamri marked this conversation as resolved.
Show resolved Hide resolved
#endif
#endif
#include <XAD/Tape.hpp>
#include <XAD/TapeContainer.hpp>
#include <XAD/Traits.hpp>
Expand Down
Loading