Skip to content
New issue

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

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

Already on GitHub? # to your account

Add support for aarch64 #34

Merged
merged 11 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,33 @@ jobs:
uses: ./.github/workflows/fedora35
- name: Get the output status
run: exit ${{ steps.compileindocker.outputs.out }}


compilejobRocky9_ARM:
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: Rocky9aarch64_ARM
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: QEMU
run: |
set -x
sudo apt update
sudo apt install --yes binfmt-support qemu-user-static wget
- name: Compile_with_arm
continue-on-error: true
uses: addnab/docker-run-action@v3
with:
image: arm64v8/rockylinux:9
options: -v ${{ github.workspace }}:/work --platform=linux/arm64/v8
run: |
set -e
set -x
dnf -y install gcc gcc-c++ gcc-gfortran make which cmake cmake-data cmake-filesystem
cd work
pwd
ls
cmake -S . -B BUILD -DCMAKE_INSTALL_PREFIX=$(pwd)/INSTALL
cmake --build BUILD
cmake --install BUILD
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ configure_file(
"${PROJECT_SOURCE_DIR}/src/qcdloop.pc.in"
"${PROJECT_SOURCE_DIR}/src/qcdloop.pc"
)

IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
Copy link
Contributor

@matthewfeickert matthewfeickert Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andriish Doesn't this assume only the existence of x86 and aarch64? Won't this break ppc64le builds now?

set(QUADMATH_NAMES ${QUADMATH_NAMES} libquadmath.so quadmath)
find_library(QUADMATH_LIBRARY
NAMES ${QUADMATH_NAMES}
Expand Down Expand Up @@ -95,7 +95,7 @@ else(QUADMATH_FOUND)
message(FATAL_ERROR "Could not find QuadMath")
endif(QUADMATH_FIND_REQUIRED)
endif(QUADMATH_FOUND)

endif()
# libqcdloop configuration
include_directories(src/qcdloop src)
FILE(GLOB_RECURSE Headers "src/qcdloop/*.h")
Expand Down
2 changes: 2 additions & 0 deletions src/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace std {
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

#if defined(__x86_64__) || defined(__i386__)
template <>
struct hash<ql::qdouble> : public __hash_base<size_t, ql::qdouble>
{
Expand All @@ -25,6 +26,7 @@ namespace std {
return x != 0.0q ? std::_Hash_impl::hash(x) : 0;
}
};
#endif

template <> struct hash<ql::complex> : public __hash_base<size_t, ql::complex>
{
Expand Down
54 changes: 49 additions & 5 deletions src/qcdloop/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#pragma once

#include "types.h"

#include <stdlib.h>
#include <complex.h>
#include <tgmath.h>
#include <float.h>
#include <cmath>
/*!
* Some basic math functions with inline (performance)
* for double and quadruple precision.
Expand All @@ -17,41 +21,81 @@ namespace ql
{
// Logarithms
inline double Log(double const& x) { return std::log(x); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Log(qdouble const& x) { return logq(x); }
inline complex Log(complex const& x) { return std::log(x); }
inline qcomplex Log(qcomplex const& x) { return clogq(x); }
#endif
#if defined(__aarch64__)
inline qdouble Log(qdouble const& x) { return std::log(x); }
inline qcomplex Log(qcomplex const& x) { return clogl(x); }
#endif
inline complex Log(complex const& x) { return std::log(x); }

// Power
inline double Pow(double const& x, int const& a) { return std::pow(x, a); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Pow(qdouble const& x, int const& a) { return powq(x,a); }
inline complex Pow(complex const& x, int const& a) { return std::pow(x,a); }
inline qcomplex Pow(qcomplex const& x, int const& a){ return cpowq(x,a); }
#endif
#if defined(__aarch64__)
inline qdouble Pow(qdouble const& x, int const& a) { return std::pow(x,a); }
inline qcomplex Pow(qcomplex const& x, int const& a){ return cpowl(x,a); }
#endif
inline complex Pow(complex const& x, int const& a) { return std::pow(x,a); }

// Root
inline double Sqrt(double const& x) { return std::sqrt(x); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Sqrt(qdouble const& x) { return sqrtq(x); }
inline complex Sqrt(complex const& x) { return std::sqrt(x); }
inline qcomplex Sqrt(qcomplex const& x){ return csqrtq(x); }
#endif
#if defined(__aarch64__)
inline qdouble Sqrt(qdouble const& x) { return std::sqrt(x); }
inline qcomplex Sqrt(qcomplex const& x){ return csqrtl(x); }
#endif
inline complex Sqrt(complex const& x) { return std::sqrt(x); }

// Absolute value
inline double Abs(double const& x) { return std::abs(x); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Abs(qdouble const& x) { return fabsq(x);}
inline double Abs(complex const& x) { return std::abs(x);}
inline qdouble Abs(qcomplex const& x) { return cabsq(x); }
#endif
#if defined(__aarch64__)
inline qdouble Abs(qdouble const& x) { return std::abs(x);}
inline qdouble Abs(qcomplex const& x) { return cabsl(x); }
#endif
inline double Abs(complex const& x) { return std::abs(x);}

// Complex tools, imag, real and conj.
inline double Imag(double const& x) { UNUSED(x); return 0; }
inline qdouble Imag(qdouble const& x) { UNUSED(x); return qdouble(0); }
inline double Imag(complex const& x) { return x.imag(); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Imag(qcomplex const& x){ return cimagq(x);}
#endif
#if defined(__aarch64__)
inline qdouble Imag(qcomplex const& x){ return cimagl(x);}
#endif

inline double Real(double const& x) { return x; }
inline qdouble Real(qdouble const& x) { return x; }
inline double Real(complex const& x) { return x.real(); }
#if defined(__x86_64__) || defined(__i386__)
inline qdouble Real(qcomplex const& x) { return crealq(x); }
#endif
#if defined(__aarch64__)
inline qdouble Real(qcomplex const& x) { return creall(x); }
#endif

inline complex Conjg(complex const& x) { return std::conj(x); }
#if defined(__x86_64__) || defined(__i386__)
inline qcomplex Conjg(qcomplex const& x){ return conjq(x); }
#endif
#if defined(__aarch64__)
inline qcomplex Conjg(qcomplex const& x){ return conjl(x); }
#endif


// Comparison and sign operations
inline int Sign(double const& x) { return (double(0) < x) - (x < double(0)); }
Expand Down
22 changes: 22 additions & 0 deletions src/qcdloop/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,28 @@

#pragma once

#if defined(__x86_64__) || defined(__i386__)
extern "C" { // for gcc4.7 compatibility
#include <quadmath.h>
}
#endif
#if defined(__aarch64__)
#include <stdlib.h>
#include <complex.h>
#include <tgmath.h>
#include <float.h>
using __float128 = long double;
using __complex128 = long double _Complex;
extern "C" {
__complex128 conjl(__complex128);
__float128 cimagl(__complex128);
__float128 creall(__complex128);
__complex128 csqrtl(__complex128);
__complex128 clogl(__complex128);
__float128 cabsl(__complex128);
__complex128 cpowl(__complex128,__complex128);
}
#endif
#include <complex>

#define UNUSED(expr) (void)(expr)
Expand All @@ -29,8 +48,11 @@ namespace ql

namespace std
{

#if defined(__x86_64__) || defined(__i386__)
//! implementation of operator<< for qdouble
ostream& operator<<(std::ostream& out, ql::qdouble f);
#endif

//! implementation of operator<< for qcomplex
ostream& operator<<(std::ostream& out, ql::qcomplex f);
Expand Down
5 changes: 5 additions & 0 deletions src/tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ namespace ql {
template<typename TOutput, typename TMass, typename TScale>
Tools<TOutput,TMass,TScale>::Tools():
_qlonshellcutoff(is_same<TScale,double>::value ? 1e-10 : 1e-20q),
#if defined(__x86_64__) || defined(__i386__)
_pi(is_same<TScale,double>::value ? M_PI : M_PIq),
#endif
#if defined(__aarch64__)
_pi(is_same<TScale,double>::value ? M_PI : M_PIl),
#endif
_pi2 (_pi*_pi),
_pio3 (_pi/TScale(3)),
_pio6 (_pi/TScale(6)),
Expand Down
9 changes: 9 additions & 0 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace std
{
#if defined(__x86_64__) || defined(__i386__)
ostream& operator<<(std::ostream& out, ql::qdouble f)
{
char buf[200];
Expand All @@ -24,6 +25,14 @@ namespace std
out << "(" << crealq(f) << "," << cimagq(f) << ")";
return out;
}
#endif
#if defined(__aarch64__)
ostream& operator<<(std::ostream& out, ql::qcomplex f)
{
out << "(" << creall(f) << "," << cimagl(f) << ")";
return out;
}
#endif

ostream& operator<<(std::ostream& os, ql::Code code)
{
Expand Down
Loading