Skip to content

Commit

Permalink
Merge pull request #214 from ji-group/github-actions
Browse files Browse the repository at this point in the history
Add GitHub actions to test build on various architectures.
  • Loading branch information
xji3 authored Feb 14, 2024
2 parents cfac5c9 + a605944 commit 2345cf0
Show file tree
Hide file tree
Showing 36 changed files with 592 additions and 356 deletions.
176 changes: 176 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
name: Build and test

on:
push:
branches:
- "*"
pull_request:
branches:
- "*"

jobs:
build:
strategy:
matrix:
name: [ubuntu-gcc-10,
ubuntu-gcc-11,
ubuntu-gcc-12,
ubuntu-clang-15,
macos-xcode-14-intel,
macos-xcode-14-arm,
windows
]

include:
- name: ubuntu-gcc-10
os: ubuntu-20.04
compiler: gcc
version: "10"
buildtype: "release"
arch: "linux64"

- name: ubuntu-gcc-11
os: ubuntu-22.04
compiler: gcc
version: "11"
buildtype: "release"
arch: "linux64"

- name: ubuntu-gcc-12
os: ubuntu-22.04
compiler: gcc
version: "12"
buildtype: "release"
arch: "linux64"

- name: ubuntu-clang-15
os: ubuntu-22.04
compiler: clang
version: "15"
buildtype: "release"
arch: "linux64"

- name: macos-xcode-14-intel
os: macos-12
compiler: xcode
version: "14"
buildtype: "release"
arch: "mac-intel64"

- name: macos-xcode-14-arm
os: macos-14
compiler: xcode
version: "14"
buildtype: "release"
arch: "mac-arm64"

- name: windows
os: ubuntu-22.04
compiler: mingw
version: "N/A"
buildtype: "release"
arch: "win64"

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12.0

- name: Install (Linux)
if: runner.os == 'Linux' && matrix.name != 'windows'
run: |
sudo apt-get install -y cmake ninja-build ccache pkg-config
sudo apt-get install -y openjdk-17-jdk libeigen3-dev ocl-icd-opencl-dev
if [ "${{ matrix.compiler }}" = "gcc" ]; then
# For newer GCCs, maybe.
# sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
# sudo apt-get update
sudo apt-get install -y g++-${{ matrix.version }}
echo "CC=ccache gcc-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=ccache g++-${{ matrix.version }}" >> $GITHUB_ENV
else
sudo apt-get install -y clang-${{ matrix.version }}
echo "CC=ccache clang-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=ccache clang++-${{ matrix.version }}" >> $GITHUB_ENV
echo "CMAKE_ARGS=-DBUILD_OPENMP=OFF" >> $GITHUB_ENV
fi
- name: Install (Linux -> Windows [cross])
if: matrix.name == 'windows'
run: |
# For mingw/gcc-12.
cat /etc/apt/sources.list
sudo sed -i 's/jammy/lunar/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y cmake ninja-build ccache pkg-config
sudo apt-get install -y dos2unix g++-mingw-w64 mingw-w64-tools wine64 zstd
echo "CMAKE_ARGS=-DBUILD_ACTION=OFF -DBUILD_JNI=OFF -DBUILD_OPENMP=OFF -DCMAKE_TOOLCHAIN_FILE=scripts/mingw-w64-x86_64.cmake" >> $GITHUB_ENV
- name: Select XCode version (macOS)
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.version }}

- name: Install (macOS)
if: runner.os == 'macOS'
run: |
brew install cmake ninja pkg-config ccache coreutils eigen openjdk
echo "CC=ccache clang" >> $GITHUB_ENV
echo "CXX=ccache clang++" >> $GITHUB_ENV
echo "CMAKE_ARGS=-DBUILD_OPENMP=OFF" >> $GITHUB_ENV
# Caches for different branches are isolated, so we don't need to put the branch name into the key.
# The total size for all caches in a repository is 5Gb.

- name: Prepare ccache timestamp
id: ccache_cache_timestamp
run: |
ccache --set-config=cache_dir=$HOME/.ccache
if [ "${{ runner.os }}" = "Linux" ]; then
stamp=$(date '+%s')
else
stamp=$(gdate '+%s')
fi
echo "${stamp}"
echo "timestamp=${stamp}" >> $GITHUB_OUTPUT
- name: ccache cache files
# uses: actions/cache@v2
uses: pat-s/always-upload-cache@v3.0.11
with:
path: ~/.ccache
key: ${{ matrix.name }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
restore-keys: |
${{ matrix.name }}-ccache-
- name: Configure
run: |
if [ "${{ matrix.cxxflags }}" != "" ] ; then
CPPARGS="$CPPARGS ${{ matrix.cxxflags }}"
fi
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=$HOME/local ${CMAKE_ARGS}
- name: Build
run: |
ccache -p
ccache -s
ninja -C build install -j4
ccache -s
- name: Test
if: matrix.name != 'windows'
run: |
cd build
./examples/synthetictest
./examples/hmctest
./examples/actiontest
34 changes: 25 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,31 @@ add_definitions(
)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#SET(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

## flags for standard library
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")

if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ot /MT")
else(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -pthread")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -pthread")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
endif(WIN32)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()

if (NOT ${CMAKE_BUILD_TYPE} MATCHES Debug)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ot")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
endif()
endif()

#if(NOT WIN32)
# add_definitions(-DHAVE_CONFIG_H)
Expand Down Expand Up @@ -149,6 +159,12 @@ if(APPLE)

# Seems necessary from macOS 10.15
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
elseif(UNIX)
# This tells libhmsbeagle.so to search the same directory to find plugins.
SET(CMAKE_INSTALL_RPATH "\$ORIGIN")
# $ORIGIN/{CPU,GPU,JNI} is so that libhmsbeagle.so can find the plugins in their build location.
# $ORIGIN/../libhmsbeagle is so that examples/* can find libhmsbeagle.so
SET(CMAKE_BUILD_RPATH "\$ORIGIN:\$ORIGIN/CPU:\$ORIGIN/GPU:\$ORIGIN/JNI:\$ORIGIN/../libhmsbeagle")
endif(APPLE)

if (BEAGLE_OPTIMIZE_FOR_NATIVE_ARCH)
Expand Down
22 changes: 13 additions & 9 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ add_executable(hmctest
add_executable(hmctest5
hmctest/hmctest5.cpp)

add_executable(actiontest
actiontest/actiontest.cpp)
if(BUILD_ACTION)

add_executable(actiontest actiontest/actiontest.cpp)

target_link_libraries(
actiontest
hmsbeagle
hmsbeagle-cpu-sse
hmsbeagle-cpu
hmsbeagle-cpu-action
${CMAKE_DL_LIBS})

endif()

#add_executable(hmcGaptest
# hmctest/hmcGapTest.cpp)
Expand All @@ -31,13 +42,6 @@ add_executable(synthetictest
#add_executable(complextest
# complextest/complextest.cpp)

target_link_libraries(actiontest
hmsbeagle
hmsbeagle-cpu-sse
hmsbeagle-cpu
hmsbeagle-cpu-action
${CMAKE_DL_LIBS})

target_link_libraries(hmctest
hmsbeagle
hmsbeagle-cpu-sse
Expand Down
4 changes: 2 additions & 2 deletions examples/actiontest/actiontest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int main( int argc, const char* argv[] )

BeagleInstanceDetails instDetails;

long preferenceFlags = (long) BEAGLE_FLAG_COMPUTATION_ACTION;
long long preferenceFlags = BEAGLE_FLAG_COMPUTATION_ACTION;

if (useGpu) {
preferenceFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
Expand All @@ -200,7 +200,7 @@ int main( int argc, const char* argv[] )
}

// long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
long requirementFlags = BEAGLE_FLAG_FRAMEWORK_CPU;
long long requirementFlags = BEAGLE_FLAG_FRAMEWORK_CPU;
if (useSSE) {
requirementFlags |= BEAGLE_FLAG_VECTOR_SSE;
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/hmctest/hmcGapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int main( int argc, const char* argv[] )

BeagleInstanceDetails instDetails;

long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;
long long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;

if (useGpu) {
preferenceFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
Expand All @@ -195,7 +195,7 @@ int main( int argc, const char* argv[] )
preferenceFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
}

long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
long long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
if (useSSE) {
requirementFlags |= BEAGLE_FLAG_VECTOR_SSE;
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/hmctest/hmcWeibullTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int main( int argc, const char* argv[] )

BeagleInstanceDetails instDetails;

long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;
long long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;

if (useGpu) {
preferenceFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
Expand All @@ -195,7 +195,7 @@ int main( int argc, const char* argv[] )
preferenceFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
}

long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
long long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
if (useSSE) {
requirementFlags |= BEAGLE_FLAG_VECTOR_SSE;
} else {
Expand Down
7 changes: 4 additions & 3 deletions examples/hmctest/hmctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ double* getPartials(char *sequence, int repeats) {
return partials;
}

void printFlags(long inFlags) {
void printFlags(long long inFlags) {
if (inFlags & BEAGLE_FLAG_PROCESSOR_CPU) fprintf(stdout, " PROCESSOR_CPU");
if (inFlags & BEAGLE_FLAG_PROCESSOR_GPU) fprintf(stdout, " PROCESSOR_GPU");
if (inFlags & BEAGLE_FLAG_PROCESSOR_FPGA) fprintf(stdout, " PROCESSOR_FPGA");
Expand All @@ -131,6 +131,7 @@ void printFlags(long inFlags) {
if (inFlags & BEAGLE_FLAG_FRAMEWORK_CPU) fprintf(stdout, " FRAMEWORK_CPU");
if (inFlags & BEAGLE_FLAG_FRAMEWORK_CUDA) fprintf(stdout, " FRAMEWORK_CUDA");
if (inFlags & BEAGLE_FLAG_FRAMEWORK_OPENCL) fprintf(stdout, " FRAMEWORK_OPENCL");
if (inFlags & BEAGLE_FLAG_COMPUTATION_ACTION) fprintf(stdout, " COMPUTATION_ACTION");
}

int main( int argc, const char* argv[] )
Expand Down Expand Up @@ -186,7 +187,7 @@ int main( int argc, const char* argv[] )

BeagleInstanceDetails instDetails;

long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;
long long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;

if (useGpu) {
preferenceFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
Expand All @@ -200,7 +201,7 @@ int main( int argc, const char* argv[] )
preferenceFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
}

long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
long long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
if (useSSE) {
requirementFlags |= BEAGLE_FLAG_VECTOR_SSE;
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/hmctest/hmctest5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int main( int argc, const char* argv[] )

BeagleInstanceDetails instDetails;

long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;
long long preferenceFlags = BEAGLE_FLAG_SCALERS_RAW;

if (useGpu) {
preferenceFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
Expand All @@ -198,7 +198,7 @@ int main( int argc, const char* argv[] )
preferenceFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
}

long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
long long requirementFlags = BEAGLE_FLAG_EIGEN_REAL;
if (autoTranspose) {
requirementFlags |= BEAGLE_FLAG_PREORDER_TRANSPOSE_AUTO;
} else {
Expand Down
Loading

0 comments on commit 2345cf0

Please sign in to comment.