├── .github
└── workflows
│ └── ci.yaml
├── .gitignore
├── .travis.yml
├── .travis
└── amd_sdk.sh
├── AUTHORS
├── CMakeLists.txt
├── ChangeLog
├── INSTALL
├── LICENSE
├── NEWS
├── README.md
├── beagle-dox.png
├── beagle.dox
├── benchmarks
└── v3-app-note
│ ├── Dengue997.nex
│ ├── Dengue997_s3_AMVN_BTL.xml
│ ├── Dengue997_s3_AMVN_MPDLD.xml
│ ├── Dengue997_s3_codon.xml
│ ├── mcmc-dengue-multi-chain.nex
│ ├── mcmc-dengue-single-chain.nex
│ ├── run_benchmarks_pll_cipres.py
│ └── run_benchmarks_pll_empirical.py
├── build.xml
├── examples
├── CMakeLists.txt
├── complextest
│ ├── check_lnL_using_BEAST.xml
│ ├── compareValues.r
│ └── complextest.cpp
├── fourtaxon
│ ├── fourtaxon.Makefile
│ ├── fourtaxon.cpp
│ ├── fourtaxon.dat
│ └── fourtaxon.h
├── hmctest
│ ├── hmcGapTest.cpp
│ ├── hmcGaptest.R
│ ├── hmcWeibullTest.R
│ ├── hmcWeibullTest.cpp
│ ├── hmctest.R
│ ├── hmctest.cpp
│ ├── hmctest5.cpp
│ ├── hmctestMedium.R
│ └── hmctestMedium.cpp
├── matrixtest
│ └── matrixtest.cpp
├── oddstatetest
│ └── oddstatetest.cpp
├── standalone
│ ├── epochtest
│ │ ├── .config
│ │ │ ├── depcomp
│ │ │ ├── install-sh
│ │ │ └── missing
│ │ ├── .cproject
│ │ ├── .project
│ │ ├── AUTHORS
│ │ ├── ChangeLog
│ │ ├── INSTALL
│ │ ├── LICENSE
│ │ ├── NEWS
│ │ ├── README
│ │ ├── autogen.sh
│ │ ├── check_lnL_using_BEAST.xml
│ │ ├── configure.ac
│ │ └── src
│ │ │ ├── .deps
│ │ │ ├── .dirstamp
│ │ │ └── epochtest-epochtest.Po
│ │ │ ├── .dirstamp
│ │ │ └── epochtest.cpp
│ └── hellobeagle
│ │ ├── AUTHORS
│ │ ├── COPYING
│ │ ├── ChangeLog
│ │ ├── INSTALL
│ │ ├── NEWS
│ │ ├── README
│ │ ├── autogen.sh
│ │ ├── configure.ac
│ │ └── src
│ │ └── hello.cpp
├── swig_python
│ ├── README
│ ├── beagle.i
│ ├── beagle.py
│ ├── beagle_wrap.c
│ ├── build.sh
│ ├── setup.py
│ └── test.py
├── synthetictest
│ ├── linalg.cpp
│ ├── linalg.h
│ └── synthetictest.cpp
└── tinytest
│ ├── check_lnL_using_BEAST.xml
│ ├── check_lnL_using_paup.nex
│ ├── tinytest.Makefile
│ └── tinytest.cpp
├── java
└── beagle
│ ├── Beagle.java
│ ├── BeagleBenchmarkFlag.java
│ ├── BeagleErrorCode.java
│ ├── BeagleException.java
│ ├── BeagleFactory.java
│ ├── BeagleFlag.java
│ ├── BeagleInfo.java
│ ├── BeagleJNIImpl.java
│ ├── BeagleJNIWrapper.java
│ ├── BenchmarkedResourceDetails.java
│ ├── FourStateBeagleImpl.java
│ ├── GeneralBeagleImpl.java
│ ├── InstanceDetails.java
│ └── ResourceDetails.java
├── libhmsbeagle
├── BeagleImpl.h
├── CMakeLists.txt
├── CPU
│ ├── AVXDefinitions.h
│ ├── BeagleCPU4StateAVXImpl.h
│ ├── BeagleCPU4StateAVXImpl.hpp
│ ├── BeagleCPU4StateImpl.h
│ ├── BeagleCPU4StateImpl.hpp
│ ├── BeagleCPU4StateSSEImpl.h
│ ├── BeagleCPU4StateSSEImpl.hpp
│ ├── BeagleCPUAVXImpl.h
│ ├── BeagleCPUAVXImpl.hpp
│ ├── BeagleCPUAVXPlugin.cpp
│ ├── BeagleCPUAVXPlugin.h
│ ├── BeagleCPUImpl.h
│ ├── BeagleCPUImpl.hpp
│ ├── BeagleCPUOpenMPPlugin.cpp
│ ├── BeagleCPUOpenMPPlugin.h
│ ├── BeagleCPUPlugin.cpp
│ ├── BeagleCPUPlugin.h
│ ├── BeagleCPUSSEImpl.h
│ ├── BeagleCPUSSEImpl.hpp
│ ├── BeagleCPUSSEPlugin.cpp
│ ├── BeagleCPUSSEPlugin.h
│ ├── CMakeLists.txt
│ ├── EigenDecomposition.h
│ ├── EigenDecompositionCube.h
│ ├── EigenDecompositionCube.hpp
│ ├── EigenDecompositionSquare.h
│ ├── EigenDecompositionSquare.hpp
│ ├── Precision.h
│ ├── SSEDefinitions.h
│ └── sse2neon.h
├── GPU
│ ├── BeagleGPUImpl.h
│ ├── BeagleGPUImpl.hpp
│ ├── CMakeLists.txt
│ ├── CMake_CUDA
│ │ └── CMakeLists.txt
│ ├── CMake_OpenCL
│ │ └── CMakeLists.txt
│ ├── CUDAPlugin.cpp
│ ├── CUDAPlugin.h
│ ├── GPUImplDefs.h
│ ├── GPUImplHelper.cpp
│ ├── GPUImplHelper.h
│ ├── GPUInterface.h
│ ├── GPUInterfaceCUDA.cpp
│ ├── GPUInterfaceOpenCL.cpp
│ ├── KernelLauncher.cpp
│ ├── KernelLauncher.h
│ ├── KernelResource.cpp
│ ├── KernelResource.h
│ ├── OpenCLAlteraPlugin.cpp
│ ├── OpenCLAlteraPlugin.h
│ ├── OpenCLPlugin.cpp
│ ├── OpenCLPlugin.h
│ ├── Precision.h
│ └── kernels
│ │ ├── createCUDAKernels.bat
│ │ ├── createOpenCLHeader.bat
│ │ ├── kernels4.cu
│ │ ├── kernels4Derivatives.cu
│ │ ├── kernelsAll.cu
│ │ ├── kernelsX.cu
│ │ ├── kernelsXDerivatives.cu
│ │ ├── make_cuda_kernels.sh
│ │ └── make_opencl_kernels.sh
├── JNI
│ ├── CMakeLists.txt
│ ├── beagle_BeagleJNIWrapper.cpp
│ └── beagle_BeagleJNIWrapper.h
├── beagle.cpp
├── beagle.h
├── benchmark
│ ├── BeagleBenchmark.cpp
│ ├── BeagleBenchmark.h
│ ├── linalg.cpp
│ └── linalg.h
├── hmsbeagle-1.pc.in
├── platform.h
└── plugin
│ ├── BeaglePlugin.h
│ ├── LibtoolSharedLibrary.h
│ ├── Plugin.cpp
│ ├── Plugin.h
│ ├── SharedLibrary.h
│ ├── UnixSharedLibrary.cpp
│ ├── UnixSharedLibrary.h
│ ├── WinSharedLibrary.cpp
│ └── WinSharedLibrary.h
├── project
├── beagle-macos
│ └── README.txt
├── beagle-vs-2012-installer
│ ├── banner.jpg
│ ├── beagle-installer.sln
│ ├── beagle-installer
│ │ ├── beagle-installer.isl
│ │ └── beagle-installer.isproj
│ └── welcome.jpg
├── beagle-vs-2017
│ ├── complextest
│ │ ├── complextest.vcxproj
│ │ └── complextest.vcxproj.filters
│ ├── cuda-kernels
│ │ ├── bin2c.exe
│ │ ├── createCUDAHeader.bat
│ │ ├── createCUDAKernels.bat
│ │ ├── cuda-kernels.vcxproj
│ │ └── cuda-kernels.vcxproj.filters
│ ├── findJava.bat
│ ├── fourtaxon
│ │ ├── fourtaxon.vcxproj
│ │ └── fourtaxon.vcxproj.filters
│ ├── installer
│ │ ├── banner.jpg
│ │ ├── installer.vdproj
│ │ └── welcome.jpg
│ ├── libhmsbeagle-cpu-sse
│ │ ├── libhmsbeagle-cpu-sse.vcxproj
│ │ └── libhmsbeagle-cpu-sse.vcxproj.filters
│ ├── libhmsbeagle-cpu
│ │ ├── libhmsbeagle-cpu.vcxproj
│ │ └── libhmsbeagle-cpu.vcxproj.filters
│ ├── libhmsbeagle-cuda
│ │ ├── libhmsbeagle-cuda.vcxproj
│ │ └── libhmsbeagle-cuda.vcxproj.filters
│ ├── libhmsbeagle-opencl-altera
│ │ ├── createCombinedOpenCLKernels.bat
│ │ ├── createOpenCLHeader.bat
│ │ ├── libhmsbeagle-opencl-altera.vcxproj
│ │ └── libhmsbeagle-opencl-altera.vcxproj.filters
│ ├── libhmsbeagle-opencl
│ │ ├── createOpenCLHeader.bat
│ │ ├── libhmsbeagle-opencl.vcxproj
│ │ └── libhmsbeagle-opencl.vcxproj.filters
│ ├── libhmsbeagle.sln
│ ├── libhmsbeagle
│ │ ├── PropertySheet.props
│ │ ├── libhmsbeagle.vcxproj
│ │ └── libhmsbeagle.vcxproj.filters
│ ├── matrixtest
│ │ ├── matrixtest.vcxproj
│ │ └── matrixtest.vcxproj.filters
│ ├── oddstatetest
│ │ ├── oddstatetest.vcxproj
│ │ └── oddstatetest.vcxproj.filters
│ ├── synthetictest
│ │ ├── synthetictest.vcxproj
│ │ └── synthetictest.vcxproj.filters
│ └── tinytest
│ │ ├── tinytest.vcxproj
│ │ └── tinytest.vcxproj.filters
├── beagle-vs-2019-wix
│ ├── LICENSE.rtf
│ ├── banner.jpg
│ ├── bin2c.exe
│ ├── patch.xml
│ └── welcome.jpg
└── beagle-xcode
│ ├── beagle-icon.png
│ ├── beagle-package.pmdoc
│ ├── 01libhmsbeagle-contents.xml
│ ├── 01libhmsbeagle.xml
│ ├── 02libhmsbeagle-contents.xml
│ ├── 02libhmsbeagle.xml
│ ├── 03libhmsbeagle-contents.xml
│ ├── 03libhmsbeagle.xml
│ ├── 04libhmsbeagle-contents.xml
│ ├── 04libhmsbeagle.xml
│ ├── 05libhmsbeagle-contents.xml
│ ├── 05libhmsbeagle.xml
│ ├── 06libhmsbeagle-contents.xml
│ ├── 06libhmsbeagle.xml
│ ├── 07libhmsbeagle-contents.xml
│ ├── 07libhmsbeagle.xml
│ ├── 08libhmsbeagle-contents.xml
│ └── 08libhmsbeagle.xml
│ └── beagle-xcode.xcodeproj
│ └── project.pbxproj
├── suppress_cuda.valgrind
└── tests
├── parse_test.sh
├── run_benchmarks.sh
├── run_tests.sh
└── test_resource.sh
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build:
13 | name: Build on Linux x86_64
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - name: Checkout
18 | uses: actions/checkout@v4
19 |
20 | - name: Install dependencies
21 | run: |
22 | sudo apt-get update
23 | sudo apt-get install -y cmake file
24 |
25 | - name: Build
26 | run: |
27 | mkdir build
28 | cd build
29 | cmake ..
30 | make -j
31 | file libhmsbeagle/libhmsbeagle.so.* | grep x86-64
32 |
33 | build-aarch64:
34 | name: Build on Linux aarch64
35 | runs-on: ubuntu-latest
36 |
37 | steps:
38 | - name: Checkout
39 | uses: actions/checkout@v4
40 |
41 | - name: Build
42 | uses: uraimo/run-on-arch-action@v2
43 | with:
44 | arch: aarch64
45 | distro: ubuntu20.04
46 | githubToken: ${{ github.token }}
47 | dockerRunArgs: |
48 | --volume "${PWD}:/beagle-lib"
49 | install: |
50 | apt-get update -q -y
51 | apt-get install -q -y cmake gcc g++ openjdk-11-jdk file
52 | run: |
53 | export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64
54 | cd /beagle-lib
55 | mkdir build
56 | cd build
57 | cmake ..
58 | make -j
59 | file libhmsbeagle/libhmsbeagle.so.* | grep aarch64
60 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Enable C++ support
2 | language: cpp
3 |
4 | # Compiler selection
5 | matrix:
6 | include:
7 | - compiler: gcc
8 | addons:
9 | apt:
10 | sources:
11 | - ubuntu-toolchain-r-test
12 | packages:
13 | - gdb
14 | - apport
15 | - nvidia-opencl-dev
16 |
17 | #cache:
18 | # directories:
19 | # - ${OPENCL_ROOT}
20 |
21 | before_install:
22 | - |
23 | if [[ "linux" == "linux" ]]; then
24 | mkdir -p ${OPENCL_ROOT}
25 | bash .travis/amd_sdk.sh ${AMDAPPSDK_VERSION}
26 | tar -xjf AMD-SDK.tar.bz2
27 | export OPENCL_VENDOR_PATH=${AMDAPPSDKROOT}/etc/OpenCL/vendors
28 | mkdir -p ${OPENCL_VENDOR_PATH}
29 | sh AMD-APP-SDK*.sh --tar -xf -C ${AMDAPPSDKROOT}
30 | echo libamdocl64.so > ${OPENCL_VENDOR_PATH}/amdocl64.icd
31 | export LD_LIBRARY_PATH=${AMDAPPSDKROOT}/lib/x86_64:${LD_LIBRARY_PATH}
32 | export CMAKE_LIBRARY_PATH=${AMDAPPSDKROOT}/lib/x86_64;
33 | chmod +x ${AMDAPPSDKROOT}/bin/x86_64/clinfo
34 | ${AMDAPPSDKROOT}/bin/x86_64/clinfo
35 | rm AMD-APP-SDK*.sh
36 | rm AMD-SDK.tar.bz2
37 | fi
38 |
39 | install:
40 | - export CPLUS_INCLUDE_PATH=${AMDAPPSDKROOT}/include
41 | - export LD_LIBRARY_PATH=${AMDAPPSDKROOT}/lib/x86_64:${LD_LIBRARY_PATH}
42 | - export LIBRARY_PATH=${AMDAPPSDKROOT}/lib/x86_64:${LIBRARY_PATH}
43 |
44 | before_script:
45 | - ulimit -c unlimited -S # Enable core dumps
46 |
47 | after_failure:
48 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/synthetictest/test-suite.log
49 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/tinytest/test-suite.log
50 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/oddstatetest/test-suite.log
51 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/complextest/test-suite.log
52 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/fourtaxon/test-suite.log
53 | - cat /home/travis/build/beagle-dev/beagle-lib/examples/matrixtest/test-suite.log
54 |
55 | # Build steps
56 | script:
57 | - mkdir build; cd build
58 | - cmake ..
59 | - make
60 | - make test
61 |
62 | # after_failure:
63 | # - ls
64 | # - COREFILE=$(find . -maxdepth 1 -name "core*" | head -n 1) # find core file
65 | # - if [[ -f "$COREFILE" ]]; then gdb -c "$COREFILE" ./benchmark -ex "thread apply all bt" -ex "set pagination 0" -batch; fi
66 |
67 | notifications:
68 | recipients:
69 | - msuchard@gmail.com
70 | - daniel@kotim.me
71 | email:
72 | on_success: change
73 | on_failure: always
74 |
75 | env:
76 | global:
77 | - OPENCL_ROOT=$HOME/opencl
78 | - OPENCL_LIB=amdappsdk
79 | - OPENCL_VERSION="12"
80 | - AMDAPPSDK_VERSION=291 # OpenCL 1.2
81 | - AMDAPPSDKROOT=${OPENCL_ROOT}/AMDAPPSDK
82 |
--------------------------------------------------------------------------------
/.travis/amd_sdk.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Original script from https://github.com/gregvw/amd_sdk/
4 |
5 | # Location from which get nonce and file name from
6 | URL="https://developer.amd.com/amd-accelerated-parallel-processing-app-sdk/"
7 | URLDOWN="https://developer.amd.com/amd-license-agreement-appsdk/"
8 |
9 | NONCE1_STRING='name="amd_developer_central_downloads_page_nonce"'
10 | FILE_STRING='name="f"'
11 | POSTID_STRING='name="post_id"'
12 | NONCE2_STRING='name="amd_developer_central_nonce"'
13 |
14 | #AMD APP SDK v3.0:
15 | if [[ $1 == "300" ]]; then
16 | echo "AMD APP SDK v3.0"
17 | FORM=`wget -qO - $URL | sed -n '/download-2/,/64-bit/p'`
18 | else
19 | #AMD APP SDK v2.9.1:
20 | echo "AMD APP SDK v2.9.1"
21 | FORM=`wget -qO - $URL | sed -n '/download-5/,/64-bit/p'`
22 | fi
23 |
24 | # Get nonce from form
25 | NONCE1=`echo $FORM | awk -F ${NONCE1_STRING} '{print $2}'`
26 | echo $NONCE1
27 |
28 | NONCE1=`echo $NONCE1 | awk -F'"' '{print $2}'`
29 | echo $NONCE1
30 |
31 | echo "TEST ME"
32 |
33 | # get the postid
34 | POSTID=`echo $FORM | awk -F ${POSTID_STRING} '{print $2}'`
35 | POSTID=`echo $POSTID | awk -F'"' '{print $2}'`
36 | echo $POSTID
37 |
38 | # get file name
39 | FILE=`echo $FORM | awk -F ${FILE_STRING} '{print $2}'`
40 | FILE=`echo $FILE | awk -F'"' '{print $2}'`
41 | echo $FILE
42 |
43 | FORM=`wget -qO - $URLDOWN --post-data "amd_developer_central_downloads_page_nonce=${NONCE1}&f=${FILE}&post_id=${POSTID}"`
44 |
45 | NONCE2=`echo $FORM | awk -F ${NONCE2_STRING} '{print $2}'`
46 | NONCE2=`echo $NONCE2 | awk -F'"' '{print $2}'`
47 | echo $NONCE2
48 |
49 | wget --content-disposition --trust-server-names $URLDOWN --post-data "amd_developer_central_nonce=${NONCE2}&f=${FILE}" -O AMD-SDK.tar.bz2;
50 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | The BEAGLE Developer group (https://github.com/beagle-dev)
2 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/ChangeLog
--------------------------------------------------------------------------------
/INSTALL:
--------------------------------------------------------------------------------
1 | # @author Marc A. Suchard
2 | # @author Andrew Rambaut
3 | # @author Daniel L. Ayres
4 |
5 | 1. General overview of BEAGLE
6 |
7 | BEAGLE is a high-performance library that can perform the core calculations at the heart of most Bayesian
8 | and Maximum Likelihood phylogenetics packages. It can make use of highly-parallel processors such as those
9 | in graphics cards (GPUs) found in many PCs.
10 |
11 | The project involves an open API and fast implementations of a library for evaluating phylogenetic
12 | likelihoods (continuous time Markov processes) of biomolecular sequence evolution.
13 |
14 | The aim is to provide high performance evaluation ‘services’ to a wide range of phylogenetic software,
15 | both Bayesian samplers and Maximum Likelihood optimizers. This allows these packages to make use of
16 | implementations that make use of optimized hardware such as graphics processing units.
17 |
18 | 2. Compilation instructions
19 |
20 | Quick and dirty instructions on how to compile and install the BEAGLE library from the git repository `master`:
21 |
22 | $ git clone --depth=1 https://github.com/beagle-dev/beagle-lib.git
23 | $ cd beagle-lib
24 | $ mkdir build; cd build
25 | $ cmake ..
26 | $ make
27 | $ sudo make install
28 |
29 | To build the installer package, then execute:
30 |
31 | $ cpack .
32 |
33 | Remarks:
34 |
35 | * Command-lines `cmake -DBUILD_CUDA=OFF ..`, `cmake -DBUILD_OPENCL=OFF ..` and `cmake -DBUILD_JNI=OFF`
36 | turn off automatic building of the CUDA, OpenCL and Java JNI sub-libraries, respectively.
37 |
38 | * When compiling in the MacOS Unix environment ("Terminal"), you need to install the CMake build toolset. We
39 | suggest using the 'brew' package installer:
40 |
41 | $ brew install cmake
42 |
43 | * Compiling and building the installer in a Windows environment requires VisualStudio 2019. From the
44 | x64 Native Tools Command Prompt for VS 2019:
45 |
46 | $ mkdir build; cd build
47 | $ cmake ..
48 | $ devenv BEAGLE.sln /build "Release"
49 | $ cpack .
50 |
51 | 3. Contact information
52 |
53 | BEAGLE developer group: beagle-dev@googlegroups.com
54 |
55 |
56 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Phylogenetic Likelihood Working Group
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NEWS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/NEWS
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Overview
2 |
3 | BEAGLE is a high-performance library that can perform the core calculations at the heart of most Bayesian and Maximum Likelihood phylogenetics packages. It can make use of highly-parallel processors such as those in graphics cards (GPUs) found in many PCs.
4 |
5 | The project involves an open API and fast implementations of a library for evaluating phylogenetic likelihoods (continuous time Markov processes) of biomolecular sequence evolution.
6 |
7 | The aim is to provide high performance evaluation 'services' to a wide range of phylogenetic software, both Bayesian samplers and Maximum Likelihood optimizers. This allows these packages to make use of implementations that make use of optimized hardware such as graphics processing units.
8 |
9 | Currently the following software packages can make use of the BEAGLE library:
10 |
11 | * [BEAST](http://beast.community/)
12 | * [BEAST2](http://beast2.org/)
13 | * [MrBayes](https://github.com/NBISweden/MrBayes)
14 |
15 | Support for BEAGLE is experimental or in development for the following packages:
16 |
17 | * [Garli](https://molevol.mbl.edu/index.php/Garli_wiki)
18 | * [PhyML](http://www.atgc-montpellier.fr/phyml/)
19 | * [RevBayes](https://revbayes.github.io)
20 | * [PAUP*](https://paup.phylosolutions.com)
21 |
22 | ### References
23 |
24 | A manuscript describes the BEAGLE API and library: [http://sysbio.oxfordjournals.org/content/61/1/170](http://sysbio.oxfordjournals.org/content/61/1/170)
25 |
26 | The paper describing the algorithms used for calculating likelihoods of sequences on trees using many core devices like graphics processing units (GPUs) is available from: [http://tree.bio.ed.ac.uk/publications/390/](http://tree.bio.ed.ac.uk/publications/390/)
27 |
28 | ### Current binary installers
29 |
30 | * [BEAGLE v4.0.0 for macOS universal](https://github.com/beagle-dev/beagle-lib/releases/download/v4.0.0/BEAGLE-4.0.0-Darwin-x86-ARM.pkg)
31 | * [BEAGLE v4.0.0 for Windows 64-bit](https://github.com/beagle-dev/beagle-lib/releases/download/v4.0.0/BEAGLE-4.0.0-win64.msi)
32 |
33 | ### Previous binary installers
34 |
35 | * [BEAGLE v3.1.0 for macOS with CUDA](https://github.com/beagle-dev/beagle-lib/releases/download/v3.1.0/BEAGLE.v3.1.0.pkg)
36 | * [BEAGLE v3.1.0 for Windows 64-bit](https://github.com/beagle-dev/beagle-lib/releases/download/v3.1.0/BEAGLE.v3.1.0.msi)
37 | * [BEAGLE v2.1.2 for Mac OS X 10.6 and later](https://www.dropbox.com/s/11kgt2jlq3lzln3/BEAGLE-2.1.2.pkg)
38 | * [BEAGLE v2.1.0 for Windows XP and later](https://www.dropbox.com/s/61z48jvruzkwkku/BEAGLE-2.1.msi)
39 |
40 | ### Installation instructions
41 |
42 | * [Instructions for installing BEAGLE on macOS](https://github.com/beagle-dev/beagle-lib/wiki/MacInstallInstructions)
43 | * [Instructions for installing BEAGLE on Windows](https://github.com/beagle-dev/beagle-lib/wiki/WindowsInstallInstructions)
44 | * [Instructions for installing BEAGLE on Linux](https://github.com/beagle-dev/beagle-lib/wiki/LinuxInstallInstructions)
45 |
46 | ### Documentation
47 |
48 | * [Release notes](https://github.com/beagle-dev/beagle-lib/wiki/ReleaseNotes)
49 | * [API documentation](https://beagle-dev.github.io/html/beagle_8h.html)
50 | * [Phylogenetic Software Development Tutorial](https://stromtutorial.github.io/)
51 |
52 | ### Acknowledgements
53 |
54 | * This project is supported in part through the National Science Foundation grants IIS-1251151, DMS-1264153, DBI-1356562, DBI-1661443 & DEB-1354146; National Institutes of Health grants R01-HG006139, R01-AI107034, U19-AI135995 & R01-AI153044; Wellcome Trust grant 206298/Z/17/Z; and European Research Council grant 725422-ReservoirDOCS.
55 |
--------------------------------------------------------------------------------
/beagle-dox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/beagle-dox.png
--------------------------------------------------------------------------------
/benchmarks/v3-app-note/mcmc-dengue-multi-chain.nex:
--------------------------------------------------------------------------------
1 | #NEXUS
2 |
3 | begin mrbayes;
4 |
5 | set autoclose=yes nowarn=yes seed=1 swapseed=1;
6 |
7 | exe Dengue997.nex;
8 |
9 |
10 |
11 | charset capsid = 1-342;
12 | charset glycoprotein = 343-834;
13 | charset envelope = 835-2325;
14 | charset NS1 = 2325-3381;
15 | charset NS2A = 3382-4038;
16 | charset NS2B = 4039-4428;
17 | charset NS3 = 4429-6285;
18 | charset NS4A = 6286-6735;
19 | charset NS4B = 6736-7482;
20 | charset NS5 = 7483-.;
21 |
22 | [partition by_codon = 3:1st_pos,2nd_pos,3rd_pos;]
23 | partition by_gene = 10:capsid,glycoprotein,envelope,NS1,NS2A,NS2B,NS3,NS4A,NS4B,NS5;
24 |
25 | set partition=by_gene;
26 |
27 | lset nst=6 rates=invgamma;
28 |
29 | [lset rates=propinv;]
30 |
31 | [prset brlenspr=clock:uni;]
32 | [prset applyto=(all) brlenspr=clock:uni;]
33 |
34 | prset applyto=(all) ratepr=variable;
35 |
36 | unlink shape=(all);
37 | unlink pinvar=(all);
38 | unlink statefreq=(all);
39 | unlink revmat=(all);
40 | unlink ratemultiplier=(all);
41 | [unlink brlens=(all);]
42 | [unlink clockrate=(all);]
43 |
44 | set seed=1 swapseed=1;
45 |
46 | [mcmc ngen=50000 nruns=1 nchains=1;]
47 | [mcmc ngen=1 nruns=1 nchains=1;]
48 | mcmc ngen=100000 nruns=2 nchains=4 printfreq=1000;
49 |
50 | end;
51 |
--------------------------------------------------------------------------------
/benchmarks/v3-app-note/mcmc-dengue-single-chain.nex:
--------------------------------------------------------------------------------
1 | #NEXUS
2 |
3 | begin mrbayes;
4 |
5 | set autoclose=yes nowarn=yes seed=1 swapseed=1;
6 |
7 | exe Dengue997.nex;
8 |
9 |
10 |
11 | charset capsid = 1-342;
12 | charset glycoprotein = 343-834;
13 | charset envelope = 835-2325;
14 | charset NS1 = 2325-3381;
15 | charset NS2A = 3382-4038;
16 | charset NS2B = 4039-4428;
17 | charset NS3 = 4429-6285;
18 | charset NS4A = 6286-6735;
19 | charset NS4B = 6736-7482;
20 | charset NS5 = 7483-.;
21 |
22 | [partition by_codon = 3:1st_pos,2nd_pos,3rd_pos;]
23 | partition by_gene = 10:capsid,glycoprotein,envelope,NS1,NS2A,NS2B,NS3,NS4A,NS4B,NS5;
24 |
25 | set partition=by_gene;
26 |
27 | lset nst=6 rates=invgamma;
28 |
29 | [lset rates=propinv;]
30 |
31 | [prset brlenspr=clock:uni;]
32 | [prset applyto=(all) brlenspr=clock:uni;]
33 |
34 | prset applyto=(all) ratepr=variable;
35 |
36 | unlink shape=(all);
37 | unlink pinvar=(all);
38 | unlink statefreq=(all);
39 | unlink revmat=(all);
40 | unlink ratemultiplier=(all);
41 | [unlink brlens=(all);]
42 | [unlink clockrate=(all);]
43 |
44 | set seed=1 swapseed=1;
45 |
46 | [mcmc ngen=50000 nruns=1 nchains=1;]
47 | [mcmc ngen=1 nruns=1 nchains=1;]
48 | mcmc ngen=100000 nruns=1 nchains=1 printfreq=1000;
49 |
50 | end;
51 |
--------------------------------------------------------------------------------
/benchmarks/v3-app-note/run_benchmarks_pll_empirical.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 |
3 | # Daniel Ayres
4 |
5 | import sys
6 | import argparse
7 | import subprocess
8 | import re
9 | from math import log, exp
10 |
11 | # def gen_log_site_list(min, max, samples):
12 | # log_range=(log(max) - log(min))
13 | # samples_list = []
14 | # for i in range(0, samples):
15 | # samples_list.append(int(round(exp(log(min) + log_range/(samples-1)*i))))
16 | # return samples_list
17 |
18 | def main():
19 | parser = argparse.ArgumentParser(description='generate synthetictest benchmarks')
20 | parser.add_argument('synthetictest_path', help='path to synthetictest')
21 | args = parser.parse_args()
22 |
23 | file_list = ['59', '128', '354', '404']
24 | rates = 4
25 | precision_list = ['double']
26 |
27 | states_list = [4]
28 | # site_samples = 40
29 | # sites_min = 100
30 | # sites_max = 1000000
31 | # sites_list = gen_log_site_list(sites_min, sites_max, site_samples)
32 | rsrc_list = ['cpu', 'cpu-threaded', 'pll', 'pll-repeats', 'gpu', 'dual-gpu']
33 | reps = 10
34 |
35 | seed_list = range(1,11)
36 |
37 | extra_args = ['--randomtree', '--stdrand', '--fulltiming', '--newparameters', '--reroot', '--newtree']
38 |
39 | throughput_re = re.compile('tree throughput total: (.*) M partials/second')
40 |
41 | debug_file = open('debug.txt', 'w')
42 |
43 | header = 'iteration, precision, states, file, seed, resource, throughput'
44 | print header
45 |
46 | iteration = 0
47 |
48 | for file in file_list:
49 | for rsrc in rsrc_list:
50 | for precision in precision_list:
51 | for states in states_list:
52 | for seed in seed_list:
53 | out_string = str(iteration)
54 | out_string += ', ' + str(precision)
55 | out_string += ', ' + str(states)
56 | out_string += ', ' + str(file)
57 | out_string += ', ' + str(seed)
58 | synthetictest_cmd = [args.synthetictest_path]
59 | synthetictest_cmd.extend(['--alignmentdna', file + '.phy'])
60 | synthetictest_cmd.extend(['--tree', file + '.tree'])
61 | synthetictest_cmd.extend(['--states', str(states)])
62 | synthetictest_cmd.extend(['--reps', str(reps), '--rates', str(rates)])
63 | synthetictest_cmd.extend(['--seed', str(seed)])
64 | throughput_re_index = 0
65 | if rsrc == 'cpu':
66 | synthetictest_cmd.extend(['--rsrc', '0', '--postorder'])
67 | elif rsrc == 'cpu-threaded':
68 | synthetictest_cmd.extend(['--rsrc', '0', '--enablethreads', '--postorder'])
69 | elif rsrc == 'pll':
70 | synthetictest_cmd.extend(['--rsrc', '0', '--pllonly', '--postorder'])
71 | elif rsrc == 'pll-repeats':
72 | synthetictest_cmd.extend(['--rsrc', '0', '--pllonly', '--pllrepeats', '--postorder'])
73 | elif rsrc == 'gpu':
74 | synthetictest_cmd.extend(['--rsrc', '1'])
75 | elif rsrc == 'dual-gpu':
76 | synthetictest_cmd.extend(['--rsrc', '1,2','--multirsrc'])
77 | elif rsrc == 'quadruple-gpu':
78 | synthetictest_cmd.extend(['--rsrc', '1,2,3,4','--multirsrc'])
79 | synthetictest_cmd.extend(extra_args)
80 | if precision == 'double':
81 | synthetictest_cmd.extend(['--doubleprecision'])
82 | try:
83 | synthetictest_out = subprocess.check_output(synthetictest_cmd)
84 | out_string += ', ' + rsrc
85 | throughput = throughput_re.findall(synthetictest_out)
86 | if throughput:
87 | out_string += ', ' + throughput[throughput_re_index]
88 | print out_string
89 | except subprocess.CalledProcessError:
90 | debug_file.write('ERROR')
91 | debug_file.write('===============================================================\n')
92 | debug_file.write(out_string + '\n')
93 | debug_file.write(' '.join(synthetictest_cmd) + '\n')
94 | debug_file.write(synthetictest_out)
95 | iteration += 1
96 | return 0
97 |
98 | if __name__ == '__main__':
99 | sys.exit(main())
100 |
101 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Build file for BEAGLE Java library
6 | $Id:$
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(hmctest
2 | hmctest/hmctest.cpp)
3 |
4 | #add_executable(hmctest5
5 | # hmctest/hmctest5.cpp)
6 |
7 | #add_executable(hmcGaptest
8 | # hmctest/hmcGapTest.cpp)
9 |
10 | #add_executable(tinytest
11 | # tinytest/tinytest.cpp)
12 |
13 | #add_executable(hmctestMedium
14 | # hmctest/hmctestMedium.cpp)
15 |
16 | #add_executable(genomictest
17 | # genomictest/genomictest.cpp
18 | # genomictest/linalg.cpp
19 | # genomictest/linalg.h
20 | # )
21 |
22 | add_executable(synthetictest
23 | synthetictest/synthetictest.cpp
24 | synthetictest/linalg.cpp
25 | synthetictest/linalg.h
26 | )
27 |
28 | #add_executable(complextest
29 | # complextest/complextest.cpp)
30 |
31 | target_link_libraries(hmctest
32 | hmsbeagle
33 | # hmsbeagle-cpu-sse
34 | hmsbeagle-cpu
35 | ${CMAKE_DL_LIBS})
36 |
37 | target_link_libraries(synthetictest
38 | hmsbeagle
39 | # hmsbeagle-cpu-sse
40 | hmsbeagle-cpu
41 | ${CMAKE_DL_LIBS})
42 |
43 | if(BUILD_SSE)
44 | target_link_libraries(hmctest
45 | hmsbeagle-cpu-sse)
46 |
47 | target_link_libraries(synthetictest
48 | hmsbeagle-cpu-sse)
49 | endif(BUILD_SSE)
50 |
51 | add_test(hmctest hmctest)
52 |
53 | #target_link_libraries(hmctest5 hmsbeagle ${CMAKE_DL_LIBS})
54 | #target_link_libraries(hmcGaptest hmsbeagle ${CMAKE_DL_LIBS})
55 | #target_link_libraries(genomictest beagle_lib)
56 | #target_link_libraries(tinytest hmsbeagle)
57 |
--------------------------------------------------------------------------------
/examples/complextest/compareValues.r:
--------------------------------------------------------------------------------
1 | evec = matrix(
2 | c( -0.5, 0.6906786606674509, 0.15153543380548623, 0.5,
3 | 0.5, -0.15153543380548576, 0.6906786606674498, 0.5,
4 | -0.5, -0.6906786606674498, -0.15153543380548617, 0.5,
5 | 0.5, 0.15153543380548554, -0.6906786606674503, 0.5),
6 | nrow=4,ncol=4,byrow=T)
7 |
8 | ievc = matrix(
9 | c( -0.5, 0.5, -0.5, 0.5,
10 | 0.6906786606674505, -0.15153543380548617, -0.6906786606674507, 0.15153543380548645,
11 | 0.15153543380548568, 0.6906786606674509, -0.15153543380548584, -0.6906786606674509,
12 | 0.5, 0.5, 0.5, 0.5),
13 | nrow=4,ncol=4,byrow=T)
14 |
15 | make.expDt = function(t) {
16 | matrix(
17 | c(exp(-2*t), 0, 0, 0,
18 | 0, exp(-1*t)*cos(1*t), exp(-1*t)*sin(1*t), 0,
19 | 0, -exp(-1*t)*sin(1*t), exp(-1*t)*cos(1*t), 0,
20 | 0, 0, 0, 1),
21 | nrow=4,ncol=4,byrow=T)
22 | }
23 |
24 | q.circulant = matrix(
25 | c(-1, 1, 0, 0,
26 | 0, -1, 1, 0,
27 | 0, 0, -1, 1,
28 | 1, 0, 0, -1),
29 | nrow=4,ncol=4,byrow=T)
30 |
31 | test.1 = evec %*% make.expDt(0.1) %*% ievc # Schur decomposition (method used in BEAGLE)
32 |
33 | Evec = eigen(q.circulant)$vectors # Complex eigendecomposition
34 | Ievc = solve(Evec)
35 | make2.expDt = function(t) {
36 | diag(exp(eigen(q.circulant)$values * t))
37 | }
38 |
39 | test.2 = Evec %*% make2.expDt(0.1) %*% Ievc # Should (and does) equal test.1
40 |
41 | out.1 = t(make.expDt(0.1)) %*% t(evec) # Should be intermediate result
42 |
43 | out.2 = t(ievc) %*% out.1 # Should (and does) equal t(test.1)
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/examples/fourtaxon/fourtaxon.Makefile:
--------------------------------------------------------------------------------
1 | CPP = g++
2 | CPP_FLAGS = -g -O0 -I. -I../../include
3 | LD_FLAGS = -L../../lib/
4 |
5 | .cpp.o:
6 | $(CPP) $(CPP_FLAGS) -c $*.cpp
7 |
8 | fourtaxon: fourtaxon.o ../../src/beagle.o
9 | $(CPP) -o fourtaxon beagle.o fourtaxon.o ../../lib/BeagleCPUImpl.o
10 |
11 | clean:
12 | rm -f *.o
13 | rm -f fourtaxon
14 |
--------------------------------------------------------------------------------
/examples/fourtaxon/fourtaxon.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "libhmsbeagle/beagle.h"
4 |
5 | typedef std::vector CodedSequence;
6 | typedef std::vector PartialVector;
7 |
8 | /*-----------------------------------------------------------------------------
9 | | FourTaxonExample reads in DNA sequence data for four taxa and simply
10 | | recomputes the likelihood of the following unrooted tree numerous times:
11 | |
12 | | (1:0.01, 2:0.02, (3:0.03, 4:0.04):0.05)
13 | |
14 | | Future improvements:
15 | | - estimate something
16 | */
17 | class FourTaxonExample
18 | {
19 | public:
20 | FourTaxonExample();
21 | void interpretCommandLineParameters(int argc, char* argv[]);
22 | void run();
23 |
24 | private:
25 | void helpMessage();
26 | void abort(std::string msg);
27 | void initBeagleLib();
28 | void readData();
29 | void writeData();
30 | void updateBrlen(unsigned brlen_index);
31 | void defineOperations();
32 | double calcLnL(int return_value);
33 |
34 | private:
35 | bool quiet;
36 | unsigned niters;
37 | unsigned like_root_node;
38 | unsigned like_parent_index;
39 | unsigned like_child_index;
40 | unsigned transmat_index;
41 | std::string data_file_name;
42 | bool scaling;
43 | bool single;
44 | bool require_double;
45 | const unsigned ntaxa;
46 | unsigned nsites;
47 | unsigned nrates;
48 | double delta;
49 | double mu;
50 | unsigned seed;
51 | std::vector taxon_name;
52 | std::vector data;
53 | std::vector partial;
54 | std::vector transition_matrix_index;
55 | std::vector brlens;
56 | std::vector operations;
57 | std::vector scaleIndices;
58 | int instance_handle;
59 | int rsrc_number;
60 | bool use_tip_partials;
61 | bool accumulate_on_the_fly;
62 | bool dynamic_scaling;
63 | bool do_rescaling;
64 | bool auto_scaling;
65 | int calculate_derivatives;
66 | bool empirical_derivatives;
67 | bool sse_vectorization;
68 | };
69 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | epochtest
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 | ?name?
14 |
15 |
16 |
17 | org.eclipse.cdt.make.core.append_environment
18 | true
19 |
20 |
21 | org.eclipse.cdt.make.core.autoBuildTarget
22 | all
23 |
24 |
25 | org.eclipse.cdt.make.core.buildArguments
26 |
27 |
28 |
29 | org.eclipse.cdt.make.core.buildCommand
30 | make
31 |
32 |
33 | org.eclipse.cdt.make.core.buildLocation
34 | ${workspace_loc:/epochtest}
35 |
36 |
37 | org.eclipse.cdt.make.core.cleanBuildTarget
38 | clean
39 |
40 |
41 | org.eclipse.cdt.make.core.contents
42 | org.eclipse.cdt.make.core.activeConfigSettings
43 |
44 |
45 | org.eclipse.cdt.make.core.enableAutoBuild
46 | false
47 |
48 |
49 | org.eclipse.cdt.make.core.enableCleanBuild
50 | true
51 |
52 |
53 | org.eclipse.cdt.make.core.enableFullBuild
54 | true
55 |
56 |
57 | org.eclipse.cdt.make.core.fullBuildTarget
58 |
59 |
60 |
61 | org.eclipse.cdt.make.core.stopOnError
62 | true
63 |
64 |
65 | org.eclipse.cdt.make.core.useDefaultBuildCmd
66 | true
67 |
68 |
69 |
70 |
71 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
72 |
73 |
74 |
75 |
76 |
77 | org.eclipse.cdt.core.cnature
78 | org.eclipse.cdt.core.ccnature
79 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
80 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
81 |
82 |
83 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/AUTHORS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/epochtest/AUTHORS
--------------------------------------------------------------------------------
/examples/standalone/epochtest/ChangeLog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/epochtest/ChangeLog
--------------------------------------------------------------------------------
/examples/standalone/epochtest/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Phylogenetic Likelihood Working Group
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/NEWS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/epochtest/NEWS
--------------------------------------------------------------------------------
/examples/standalone/epochtest/README:
--------------------------------------------------------------------------------
1 | To start editing as Eclipse project:
2 |
3 | (1)./autoconf.sh
4 | (2)./configure
5 | (3) Import to Your workspace as an existing Eclipse project
6 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p .config
3 | autoreconf --force --install -I .config
4 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/configure.ac:
--------------------------------------------------------------------------------
1 | # this is a very basic configuration example
2 | AC_INIT([EpochTest C++], [0.1], [bug-report@hello.beagle-gpu.com],
3 | [hellobeagle], [http://hello.beagle-gpu.com/])
4 | AC_PREREQ([2.59])
5 | AC_CONFIG_AUX_DIR(.config)
6 | AM_INIT_AUTOMAKE([1.10 -Wall no-define])
7 | AC_CONFIG_HEADERS([config.h])
8 | AC_PROG_CXX
9 |
10 | PKG_CHECK_MODULES(DEPS, hmsbeagle-1 >= 1.0.0)
11 | AC_SUBST(DEPS_CFLAGS)
12 | AC_SUBST(DEPS_LIBS)
13 |
14 | AC_CONFIG_FILES([Makefile])
15 | AC_OUTPUT
16 |
--------------------------------------------------------------------------------
/examples/standalone/epochtest/src/.deps/.dirstamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/epochtest/src/.deps/.dirstamp
--------------------------------------------------------------------------------
/examples/standalone/epochtest/src/.dirstamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/epochtest/src/.dirstamp
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/AUTHORS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/hellobeagle/AUTHORS
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/COPYING:
--------------------------------------------------------------------------------
1 | The hellobeagle example is hereby released unto the public domain.
2 | Unrestricted modification, sale, and redistribution are permitted.
3 | If you don't want this license for your derivative product, then
4 | change it!
5 |
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/ChangeLog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/hellobeagle/ChangeLog
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/NEWS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/hellobeagle/NEWS
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beagle-dev/beagle-lib/3d3dfe11963175cda3e9cc0dfd8eca05c39ae02c/examples/standalone/hellobeagle/README
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mkdir -p .config
3 | autoreconf --force --install -I .config
4 |
--------------------------------------------------------------------------------
/examples/standalone/hellobeagle/configure.ac:
--------------------------------------------------------------------------------
1 | # this is a very basic configuration example
2 | AC_INIT([HelloBeagle C++], [0.1], [bug-report@hello.beagle-gpu.com],
3 | [hellobeagle], [http://hello.beagle-gpu.com/])
4 | AC_PREREQ([2.59])
5 | AC_CONFIG_AUX_DIR(.config)
6 | AM_INIT_AUTOMAKE([1.10 -Wall no-define])
7 | AC_CONFIG_HEADERS([config.h])
8 | AC_PROG_CXX
9 |
10 | PKG_CHECK_MODULES(DEPS, hmsbeagle-1 >= 1.0.0)
11 | AC_SUBST(DEPS_CFLAGS)
12 | AC_SUBST(DEPS_LIBS)
13 |
14 | AC_CONFIG_FILES([Makefile])
15 | AC_OUTPUT
16 |
--------------------------------------------------------------------------------
/examples/swig_python/README:
--------------------------------------------------------------------------------
1 | This is a proof-of-concept of wrapping libhmsbeagle using SWIG to generate Python wrappers. This has been tested only on Linux; building the module can be done either by the shell script
2 |
3 | bash ./build.sh
4 |
5 | or by using python setuptools
6 |
7 | python setup.py build_ext --inplace
8 |
9 | You can then run a test, which is basically a 1:1 translation of hellobeagle:
10 |
11 | python test.py
12 |
13 | This prints out
14 | -84.8523582328
15 | Woof!
16 |
17 | If you get a strange message like this:
18 | Traceback (most recent call last):
19 | File "setup.py", line 10, in
20 | beagle_module = Extension("_beagle",sources=['beagle_wrap.c'],**pkgconfig('hmsbeagle-1'))
21 | TypeError: __init__() keywords must be strings
22 |
23 | it's probably because pkgconfig can't find hmsbeagle.
24 |
25 | Simon Frost
26 | Cambridge 2/2/12
27 | sdf22 at cam dot ac dot uk
28 |
29 |
--------------------------------------------------------------------------------
/examples/swig_python/build.sh:
--------------------------------------------------------------------------------
1 | export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
2 | export PKG_CONFIG_PATH=$HOME/lib/pkgconfig:$PKG_CONFIG_PATH
3 |
4 | swig -python beagle.i
5 | gcc -fPIC -c beagle_wrap.c -I. -I/usr/include/python2.7 `pkg-config --cflags --libs hmsbeagle-1`
6 | gcc -shared beagle_wrap.o -o _beagle.so `pkg-config --cflags --libs hmsbeagle-1`
7 |
8 |
--------------------------------------------------------------------------------
/examples/swig_python/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup, Extension
2 | import commands
3 |
4 | def pkgconfig(*packages, **kw):
5 | flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
6 | for token in commands.getoutput("pkg-config --libs --cflags %s" % ' '.join(packages)).split():
7 | kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
8 | return kw
9 |
10 | beagle_module = Extension("_beagle",sources=['beagle_wrap.c'],**pkgconfig('hmsbeagle-1'))
11 |
12 | setup(name='beagle',
13 | version='0.1',
14 | author="Simon Frost",
15 | description="""BEAGLE module""",
16 | ext_modules = [beagle_module],
17 | py_modules = ["beagle"],
18 | )
19 |
20 |
--------------------------------------------------------------------------------
/examples/swig_python/test.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from beagle import *
3 |
4 | def getTable():
5 | table={}
6 | table['A']=0
7 | table['C']=1
8 | table['G']=2
9 | table['T']=3
10 | table['a']=0
11 | table['c']=1
12 | table['g']=2
13 | table['t']=3
14 | table['-']=4
15 | return table
16 |
17 |
18 | mars = "CCGAG-AGCAGCAATGGAT-GAGGCATGGCG"
19 | saturn = "GCGCGCAGCTGCTGTAGATGGAGGCATGACG"
20 | jupiter = "GCGCGCAGCAGCTGTGGATGGAAGGATGACG"
21 |
22 | nPatterns = len(mars)
23 |
24 | returnInfo = BeagleInstanceDetails()
25 |
26 | instance = beagleCreateInstance(3,
27 | 2,
28 | 3,
29 | 4,
30 | nPatterns,
31 | 1,
32 | 4,
33 | 1,
34 | 0,
35 | None,
36 | 0,
37 | 0,
38 | 0,
39 | returnInfo)
40 |
41 | if instance<0:
42 | print "Failed to obtain BEAGLE instance"
43 | sys.exit()
44 |
45 | table = getTable()
46 |
47 | marsStates = createStates(mars,table)
48 | saturnStates = createStates(saturn,table)
49 | jupiterStates = createStates(jupiter,table)
50 |
51 | beagleSetTipStates(instance,0,marsStates)
52 | beagleSetTipStates(instance,1,saturnStates)
53 | beagleSetTipStates(instance,2,jupiterStates)
54 |
55 | patternWeights = createPatternWeights([1]*len(mars))
56 | beagleSetPatternWeights(instance, patternWeights);
57 |
58 | freqs = createPatternWeights([0.25]*4)
59 | beagleSetStateFrequencies(instance,0,freqs)
60 |
61 | weights = createPatternWeights([1.0])
62 | rates = createPatternWeights([1.0])
63 | beagleSetCategoryWeights(instance, 0, weights)
64 | beagleSetCategoryRates(instance, rates)
65 |
66 | evec = createPatternWeights([1.0, 2.0, 0.0, 0.5,
67 | 1.0, -2.0, 0.5, 0.0,
68 | 1.0, 2.0, 0.0, -0.5,
69 | 1.0, -2.0, -0.5, 0.0])
70 | ivec = createPatternWeights([0.25, 0.25, 0.25, 0.25,
71 | 0.125, -0.125, 0.125, -0.125,
72 | 0.0, 1.0, 0.0, -1.0,
73 | 1.0, 0.0, -1.0, 0.0])
74 | eval = createPatternWeights([0.0, -1.3333333333333333, -1.3333333333333333, -1.3333333333333333])
75 |
76 | beagleSetEigenDecomposition(instance, 0, evec, ivec, eval)
77 |
78 | nodeIndices = make_intarray([0,1,2,3])
79 | edgeLengths = make_doublearray([0.1,0.1,0.2,0.1])
80 |
81 | beagleUpdateTransitionMatrices(instance, # instance
82 | 0, # eigenIndex
83 | nodeIndices, # probabilityIndices
84 | None, # firstDerivativeIndices
85 | None, # secondDerivativeIndices
86 | edgeLengths, # edgeLengths
87 | 4); # count
88 |
89 | operations = new_BeagleOperationArray(2)
90 | op0 = make_operation([3,BEAGLE_OP_NONE,BEAGLE_OP_NONE,0,0,1,1])
91 | op1 = make_operation([4,BEAGLE_OP_NONE,BEAGLE_OP_NONE,2,2,3,3])
92 | BeagleOperationArray_setitem(operations,0,op0)
93 | BeagleOperationArray_setitem(operations,1,op1)
94 |
95 | beagleUpdatePartials(instance,
96 | operations,
97 | 2,
98 | BEAGLE_OP_NONE)
99 |
100 | logLp = new_doublep()
101 | rootIndex = make_intarray([4])
102 | categoryWeightIndex = make_intarray([0])
103 | stateFrequencyIndex = make_intarray([0])
104 | cumulativeScaleIndex = make_intarray([BEAGLE_OP_NONE])
105 |
106 | beagleCalculateRootLogLikelihoods(instance,
107 | rootIndex,
108 | categoryWeightIndex,
109 | stateFrequencyIndex,
110 | cumulativeScaleIndex,
111 | 1,
112 | logLp)
113 |
114 | logL=doublep_value(logLp)
115 | print(logL)
116 | print("Woof!")
117 |
--------------------------------------------------------------------------------
/examples/synthetictest/linalg.h:
--------------------------------------------------------------------------------
1 | /* linalg.h
2 | |
3 | | Prototypes for matrix-inversion and eigensystem functions
4 | |
5 | | Copyright (c) 1998 by David L. Swofford, Smithsonian Institution.
6 | | All rights reserved.
7 | |
8 | | NOTE: if ANSI function prototypes are not supported, define NO_PROTOTYPES
9 | | before including this file.
10 | */
11 |
12 | #define RC_COMPLEX_EVAL 2 /* code that complex eigenvalue obtained */
13 |
14 | extern int InvertMatrix (double **a, int n, double *col, int *indx, double **a_inv);
15 | extern int LUDecompose (double **a, int n, double *vv, int *indx, double *pd);
16 | int EigenRealGeneral (int n, double **a, double *v, double *vi, double **u, int *iwork, double *work);
17 |
18 |
19 | template T **New2DArray(unsigned f , unsigned s)
20 | {
21 | T **temp;
22 | temp = new T *[f];
23 | *temp = new T [f * s];
24 | for (unsigned fIt = 1 ; fIt < f ; fIt ++)
25 | temp[fIt] = temp[fIt -1] + s ;
26 | return temp;
27 | }
28 |
29 | /*--------------------------------------------------------------------------------------------------------------------------
30 | | Delete a 2 Dimensional Array New2DArray
31 | */
32 | template inline void Delete2DArray (T **temp)
33 | {
34 | if (temp)
35 | {
36 | if (*temp)
37 | delete [] * temp;
38 | delete [] temp;
39 | }
40 | }
--------------------------------------------------------------------------------
/examples/tinytest/check_lnL_using_paup.nex:
--------------------------------------------------------------------------------
1 | #NEXUS
2 | BEGIN TAXA;
3 | Dimensions ntax=3;
4 | Taxlabels
5 | human
6 | chimp
7 | gorilla
8 | ;
9 | END;
10 |
11 | BEGIN CHARACTERS;
12 | dimensions nchar=768;
13 | format datatype=dna missing=? gap=-;
14 | matrix
15 |
16 | human AGAAATATGTCTGATAAAAGAGTTACTTTGATAGAGTAAATAATAGGAGCTTAAACCCCCTTATTTCTACTAGGACTATGAGAATCGAACCCATCCCTGAGAATCCAAAATTCTCCGTGCCACCTATCACACCCCATCCTAAGTAAGGTCAGCTAAATAAGCTATCGGGCCCATACCCCGAAAATGTTGGTTATACCCTTCCCGTACTAAGAAATTTAGGTTAAATACAGAC
17 | CAAGAGCCTTCAAAGCCCTCAGTAAGTTG-CAATACTTAATTTCTGTAAGGACTGCAAAACCCCACTCTGCATCAACTGAACGCAAATCAGCCACTTTAATTAAGCTAAGCCCTTCTAGACCAATGGGACTTAAACCCACAAACACTTAGTTAACAGCTAAGCACCCTAATCAAC-TGGCTTCAATCTAAAGCCCCGGCAGG-TTTGAAGCTGCTTCTTCGAATTTGCAATTCAATATGAAAA-TCACCTCGGAGCTTGGTAAAAAGAGGCCTAACCCCTGTCTTTAGATTTACAGTCCAATGCTTCA-CTCAGCCATTTTACCACAAAAAAGGAAGGAATCGAACCCCCCAAAGCTGGTTTCAAGCCAACCCCATGGCCTCCATGACTTTTTCAAAAGGTATTAGAAAAACCATTTCATAACTTTGTCAAAGTTAAATTATAGGCT-AAATCCTATATATCTTA-CACTGTAAAGCTAACTTAGCATTAACCTTTTAAGTTAAAGATTAAGAGAACCAACACCTCTTTACAGTGA
18 |
19 | chimp AGAAATATGTCTGATAAAAGAATTACTTTGATAGAGTAAATAATAGGAGTTCAAATCCCCTTATTTCTACTAGGACTATAAGAATCGAACTCATCCCTGAGAATCCAAAATTCTCCGTGCCACCTATCACACCCCATCCTAAGTAAGGTCAGCTAAATAAGCTATCGGGCCCATACCCCGAAAATGTTGGTTACACCCTTCCCGTACTAAGAAATTTAGGTTAAGCACAGAC
20 | CAAGAGCCTTCAAAGCCCTCAGCAAGTTA-CAATACTTAATTTCTGTAAGGACTGCAAAACCCCACTCTGCATCAACTGAACGCAAATCAGCCACTTTAATTAAGCTAAGCCCTTCTAGATTAATGGGACTTAAACCCACAAACATTTAGTTAACAGCTAAACACCCTAATCAAC-TGGCTTCAATCTAAAGCCCCGGCAGG-TTTGAAGCTGCTTCTTCGAATTTGCAATTCAATATGAAAA-TCACCTCAGAGCTTGGTAAAAAGAGGCTTAACCCCTGTCTTTAGATTTACAGTCCAATGCTTCA-CTCAGCCATTTTACCACAAAAAAGGAAGGAATCGAACCCCCTAAAGCTGGTTTCAAGCCAACCCCATGACCTCCATGACTTTTTCAAAAGATATTAGAAAAACTATTTCATAACTTTGTCAAAGTTAAATTACAGGTT-AACCCCCGTATATCTTA-CACTGTAAAGCTAACCTAGCATTAACCTTTTAAGTTAAAGATTAAGAGGACCGACACCTCTTTACAGTGA
21 |
22 | gorilla AGAAATATGTCTGATAAAAGAGTTACTTTGATAGAGTAAATAATAGAGGTTTAAACCCCCTTATTTCTACTAGGACTATGAGAATTGAACCCATCCCTGAGAATCCAAAATTCTCCGTGCCACCTGTCACACCCCATCCTAAGTAAGGTCAGCTAAATAAGCTATCGGGCCCATACCCCGAAAATGTTGGTCACATCCTTCCCGTACTAAGAAATTTAGGTTAAACATAGAC
23 | CAAGAGCCTTCAAAGCCCTTAGTAAGTTA-CAACACTTAATTTCTGTAAGGACTGCAAAACCCTACTCTGCATCAACTGAACGCAAATCAGCCACTTTAATTAAGCTAAGCCCTTCTAGATCAATGGGACTCAAACCCACAAACATTTAGTTAACAGCTAAACACCCTAGTCAAC-TGGCTTCAATCTAAAGCCCCGGCAGG-TTTGAAGCTGCTTCTTCGAATTTGCAATTCAATATGAAAT-TCACCTCGGAGCTTGGTAAAAAGAGGCCCAGCCTCTGTCTTTAGATTTACAGTCCAATGCCTTA-CTCAGCCATTTTACCACAAAAAAGGAAGGAATCGAACCCCCCAAAGCTGGTTTCAAGCCAACCCCATGACCTTCATGACTTTTTCAAAAGATATTAGAAAAACTATTTCATAACTTTGTCAAGGTTAAATTACGGGTT-AAACCCCGTATATCTTA-CACTGTAAAGCTAACCTAGCGTTAACCTTTTAAGTTAAAGATTAAGAGTATCGGCACCTCTTTGCAGTGA
24 |
25 | ;
26 | END;
27 |
28 | set
29 | criterion=likelihood
30 | storebrlens=yes;
31 |
32 | BEGIN TREES;
33 | tree PAUP_1 = [&U] ((human:0.1,chimp:0.1):0.1,gorilla:0.2);
34 | END;
35 |
36 | BEGIN PAUP;
37 |
38 | [JC-G]
39 | lscores 1/
40 | nst=1
41 | basefreq=equal
42 | rates=gamma
43 | shape=0.5
44 | reprate=mean
45 | pinv=0
46 | userbrlens=yes;
47 |
48 | END;
49 |
--------------------------------------------------------------------------------
/examples/tinytest/tinytest.Makefile:
--------------------------------------------------------------------------------
1 | CPP = g++
2 | CPP_FLAGS = -g -O0 -I. -I../../include
3 | LD_FLAGS = -L../../lib/
4 |
5 | .cpp.o:
6 | $(CPP) $(CPP_FLAGS) -c $*.cpp
7 |
8 | tinytest: tinytest.o ../../src/beagle.o
9 | $(CPP) -o tinytest beagle.o tinytest.o ../../lib/BeagleCPUImpl.o
10 |
11 | clean:
12 | rm -f *.o
13 | rm -f tinytest
14 |
--------------------------------------------------------------------------------
/java/beagle/BeagleBenchmarkFlag.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * @author Daniel Ayres
5 | * (based on BeagleFlag.java by Andrew Rambaut and Marc Suchard)
6 | * @version $Id$
7 | */
8 | public enum BeagleBenchmarkFlag {
9 | SCALING_NONE(1 << 0, "No scaling"),
10 | SCALING_ALWAYS(1 << 1, "Scale at every iteration"),
11 | SCALING_DYNAMIC(1 << 2, "Scale every fixed number of iterations or when a numerical error occurs, and re-use scale factors for subsequent iterations");
12 |
13 | BeagleBenchmarkFlag(long mask, String meaning) {
14 | this.mask = mask;
15 | this.meaning = meaning;
16 | }
17 |
18 | public long getMask() {
19 | return mask;
20 | }
21 |
22 | public String getMeaning() {
23 | return meaning;
24 | }
25 |
26 | public boolean isSet(long flags) {
27 | return (flags & mask) != 0;
28 | }
29 |
30 | public static String toString(long flags) {
31 | StringBuilder sb = new StringBuilder();
32 | for (BeagleBenchmarkFlag flag : BeagleBenchmarkFlag.values()) {
33 | if (flag.isSet(flags)) {
34 | sb.append(" ").append(flag.name());
35 | }
36 | }
37 | return sb.toString();
38 | }
39 |
40 | private final long mask;
41 | private final String meaning;
42 | }
--------------------------------------------------------------------------------
/java/beagle/BeagleErrorCode.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * @author Andrew Rambaut
5 | * @author Marc Suchard
6 | * @version $Id$
7 | */
8 | public enum BeagleErrorCode {
9 | NO_ERROR(0, "no error"),
10 | GENERAL_ERROR(-1, "general error"),
11 | OUT_OF_MEMORY_ERROR(-2, "out of memory error"),
12 | UNIDENTIFIED_EXCEPTION_ERROR(-3, "unidentified exception error"),
13 | UNINITIALIZED_INSTANCE_ERROR(-4, "uninitialized instance error"),
14 | OUT_OF_RANGE_ERROR(-5, "One of the indices specified exceeded the range of the array"),
15 | NO_RESOURCE_ERROR(-6, "No resource matches requirements"),
16 | NO_IMPLEMENTATION_ERROR(-7, "No implementation matches requirements"),
17 | FLOATING_POINT_ERROR(-8, "Floating-point range exceeded");
18 |
19 | BeagleErrorCode(int errCode, String meaning) {
20 | this.errCode = errCode;
21 | this.meaning = meaning;
22 | }
23 |
24 | public int getErrCode() {
25 | return errCode;
26 | }
27 |
28 | public String getMeaning() {
29 | return meaning;
30 | }
31 |
32 | private final int errCode;
33 | private final String meaning;
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/java/beagle/BeagleException.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * @author Andrew Rambaut
5 | * @author Marc Suchard
6 | */
7 | public class BeagleException extends RuntimeException {
8 | public BeagleException(String functionName, int errCode) {
9 | this.functionName = functionName;
10 | this.errCode = errCode;
11 | }
12 |
13 | @Override
14 | public String getMessage() {
15 | BeagleErrorCode code = null;
16 | for (BeagleErrorCode c : BeagleErrorCode.values()) {
17 | if (c.getErrCode() == errCode) {
18 | code = c;
19 | }
20 | }
21 | if (code == null) {
22 | return "BEAGLE function, " + functionName + ", returned error code " + errCode + " (unrecognized error code)";
23 | }
24 | return "BEAGLE function, " + functionName + ", returned error code " + errCode + " (" + code.getMeaning() + ")";
25 | }
26 |
27 | public String getFunctionName() {
28 | return functionName;
29 | }
30 |
31 | public int getErrCode() {
32 | return errCode;
33 | }
34 |
35 | private final String functionName;
36 | private final int errCode;
37 | }
38 |
--------------------------------------------------------------------------------
/java/beagle/BeagleFlag.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * @author Andrew Rambaut
5 | * @author Marc Suchard
6 | * @version $Id$
7 | */
8 | public enum BeagleFlag {
9 | PRECISION_SINGLE(1 << 0, "double precision computation"),
10 | PRECISION_DOUBLE(1 << 1, "single precision computation"),
11 |
12 | COMPUTATION_SYNCH(1 << 2, "synchronous computation (blocking"),
13 | COMPUTATION_ASYNCH(1 << 3, "asynchronous computation (non-blocking)"),
14 |
15 | EIGEN_REAL(1 <<4, "real eigenvalue computation"),
16 | EIGEN_COMPLEX(1 <<5, "complex eigenvalue computation"),
17 |
18 | SCALING_MANUAL(1 << 6, "manual scaling"),
19 | SCALING_AUTO(1 << 7, "auto-scaling on"),
20 | SCALING_ALWAYS(1 << 8, "scale at every update"),
21 | SCALING_DYNAMIC(1 << 19, "manual scaling with dynamic checking"),
22 |
23 | SCALERS_RAW(1 << 9, "save raw scalers"),
24 | SCALERS_LOG(1 << 10, "save log scalers"),
25 |
26 | VECTOR_SSE(1 << 11, "SSE vector computation"),
27 | VECTOR_NONE(1 << 12, "no vector computation"),
28 |
29 | THREADING_CPP(1 << 30, "C++11 threading"),
30 | THREADING_OPENMP(1 << 13, "OpenMP threading"),
31 | THREADING_NONE(1 << 14, "no threading"),
32 |
33 | PROCESSOR_CPU(1 << 15, "use CPU as main processor"),
34 | PROCESSOR_GPU(1 << 16, "use GPU as main processor"),
35 | PROCESSOR_FPGA(1 << 17, "use FPGA as main processor"),
36 | PROCESSOR_CELL(1 << 18, "use CELL as main processor"),
37 |
38 | FRAMEWORK_CUDA(1 << 22, "use CUDA implementation with GPU resources"),
39 | FRAMEWORK_OPENCL(1 << 23, "use OpenCL implementation with CPU or GPU resources"),
40 | FRAMEWORK_CPU(1 << 27, "use CPU implementation"),
41 |
42 | PARALLELOPS_STREAMS(1 << 28, "Operations in updatePartials may be assigned to separate device streams"),
43 | PARALLELOPS_GRID(1 << 29, "Operations in updatePartials may be folded into single kernel launch (necessary for partitions; typically performs better for problems with fewer pattern sites)"),
44 |
45 | PREORDER_TRANSPOSE_MANUAL(1 << 30, "Pre-order transition matrices passed to BEAGLE have been transposed"),
46 | PREORDER_TRANSPOSE_AUTO(1 << 31, "Automatically transpose pre-order transition matrices");
47 |
48 | BeagleFlag(long mask, String meaning) {
49 | this.mask = mask;
50 | this.meaning = meaning;
51 | }
52 |
53 | public long getMask() {
54 | return mask;
55 | }
56 |
57 | public String getMeaning() {
58 | return meaning;
59 | }
60 |
61 | public boolean isSet(long flags) {
62 | return (flags & mask) != 0;
63 | }
64 |
65 | public static String toString(long flags) {
66 | StringBuilder sb = new StringBuilder();
67 | for (BeagleFlag flag : BeagleFlag.values()) {
68 | if (flag.isSet(flags)) {
69 | sb.append(" ").append(flag.name());
70 | }
71 | }
72 | return sb.toString();
73 | }
74 |
75 | private final long mask;
76 | private final String meaning;
77 | }
78 |
--------------------------------------------------------------------------------
/java/beagle/BeagleInfo.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.regex.Matcher;
6 | import java.util.regex.Pattern;
7 |
8 | /**
9 | * @author Marc A. Suchard
10 | * @author Andrew Rambaut
11 | */
12 | public class BeagleInfo {
13 |
14 | public static String getVersion() {
15 | return BeagleFactory.getVersion();
16 | }
17 |
18 | public static String getVersionInformation() {
19 | return BeagleFactory.getVersionInformation();
20 | }
21 |
22 | public static int[] getVersionNumbers() {
23 | String version = BeagleFactory.getVersion();
24 | Pattern p = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+).*");
25 | Matcher m = p.matcher(version);
26 | if (m.matches()) {
27 | return new int[] {Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3))};
28 | }
29 | return new int[] {};
30 | }
31 |
32 | public static void printVersionInformation() {
33 |
34 | System.out.println(getVersionInformation());
35 | System.out.println();
36 | }
37 |
38 | public static void printResourceList() {
39 |
40 | List resourceDetails = BeagleFactory.getResourceDetails();
41 |
42 | System.out.println("BEAGLE resources available:");
43 | for (ResourceDetails resource : resourceDetails) {
44 | System.out.println(resource.toString());
45 | System.out.println();
46 |
47 | }
48 | }
49 |
50 | public static void main(String[] argv) {
51 | printVersionInformation();
52 | printResourceList();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/java/beagle/BenchmarkedResourceDetails.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * An interface for reporting information about the available benchmarked resources
5 | * as reported by the BEAGLE API.
6 | * @author Daniel Ayres
7 | * (based on ResourceDetails.java by Andrew Rambaut)
8 | * @version $Id$
9 | */
10 | public class BenchmarkedResourceDetails {
11 |
12 | public BenchmarkedResourceDetails(int number) {
13 | this.number = number;
14 | }
15 |
16 | public int getNumber() {
17 | return number;
18 | }
19 |
20 | public int getResourceNumber() {
21 | return resourceNumber;
22 | }
23 |
24 | public void setResourceNumber(int resourceNumber) {
25 | this.resourceNumber = resourceNumber;
26 | }
27 |
28 | public String getName() {
29 | return name;
30 | }
31 |
32 | public void setName(String name) {
33 | this.name = name;
34 | }
35 |
36 | public String getDescription() {
37 | return description;
38 | }
39 |
40 | public void setDescription(String description) {
41 | this.description = description;
42 | }
43 |
44 | public long getSupportFlags() {
45 | return supportFlags;
46 | }
47 |
48 | public void setSupportFlags(long supportFlags) {
49 | this.supportFlags = supportFlags;
50 | }
51 |
52 | public long getRequiredFlags() {
53 | return requiredFlags;
54 | }
55 |
56 | public void setRequiredFlags(long requiredFlags) {
57 | this.requiredFlags = requiredFlags;
58 | }
59 |
60 | public int getReturnCode() {
61 | return returnCode;
62 | }
63 |
64 | public void setReturnCode(int returnCode) {
65 | this.returnCode = returnCode;
66 | }
67 |
68 | public String getImplName() {
69 | return implName;
70 | }
71 |
72 | public void setImplName(String implName) {
73 | this.implName = implName;
74 | }
75 |
76 | public long getBenchedFlags() {
77 | return benchedFlags;
78 | }
79 |
80 | public void setBenchedFlags(long benchedFlags) {
81 | this.benchedFlags = benchedFlags;
82 | }
83 |
84 | public double getBenchmarkResult() {
85 | return benchmarkResult;
86 | }
87 |
88 | public void setBenchmarkResult(double benchmarkResult) {
89 | this.benchmarkResult = benchmarkResult;
90 | }
91 |
92 | public double getPerformanceRatio() {
93 | return performanceRatio;
94 | }
95 |
96 | public void setPerformanceRatio(double performanceRatio) {
97 | this.performanceRatio = performanceRatio;
98 | }
99 |
100 | @Override
101 | public String toString() {
102 | StringBuilder sb = new StringBuilder();
103 | sb.append(" Resource ").append(getResourceNumber()).append(": ").append(getName()).append("\n");
104 | if (getDescription() != null) {
105 | String[] description = getDescription().split("\\|");
106 | for (String desc : description) {
107 | if (desc.trim().length() > 0) {
108 | sb.append(" ").append(desc.trim()).append("\n");
109 | }
110 | }
111 | }
112 | sb.append(" Benchmark Flags:");
113 | sb.append(BeagleFlag.toString(getBenchedFlags()));
114 | sb.append("\n");
115 | sb.append(" Benchmark Result: ");
116 | sb.append(String.format ("%.3f", getBenchmarkResult()));
117 | sb.append(" ms (");
118 | sb.append(String.format ("%.2f", getPerformanceRatio()));
119 | sb.append("x CPU)");
120 | sb.append("\n");
121 | return sb.toString();
122 | }
123 |
124 | private final int number;
125 | private int resourceNumber;
126 | private String name;
127 | private String description;
128 | private long supportFlags;
129 | private long requiredFlags;
130 | private int returnCode;
131 | private String implName;
132 | private long benchedFlags;
133 | private double benchmarkResult;
134 | private double performanceRatio;
135 | }
136 |
--------------------------------------------------------------------------------
/java/beagle/InstanceDetails.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * An interface for reporting information about a particular instance
7 | * as reported by the BEAGLE API.
8 | * @author Andrew Rambaut
9 | * @author Marc Suchard
10 | * @version $Id$
11 | */
12 | public class InstanceDetails implements Serializable {
13 |
14 | public InstanceDetails() {
15 | }
16 |
17 | public int getResourceNumber() {
18 | return resourceNumber;
19 | }
20 |
21 | public void setResourceNumber(int resourceNumber) {
22 | this.resourceNumber = resourceNumber;
23 | }
24 |
25 | public String getResourceName() {
26 | return resourceName;
27 | }
28 |
29 | public void setResourceName(String resourceName) {
30 | this.resourceName = resourceName;
31 | }
32 |
33 | public String getImplementationName() {
34 | return implementationName;
35 | }
36 |
37 | public void setImplementationName(String implementationName) {
38 | this.implementationName = implementationName;
39 | }
40 |
41 | public long getFlags() {
42 | return flags;
43 | }
44 |
45 | public void setFlags(long flags) {
46 | this.flags = flags;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return BeagleFlag.toString(getFlags());
52 | }
53 |
54 | private int resourceNumber;
55 | private long flags;
56 | private String resourceName;
57 | private String implementationName;
58 | }
59 |
--------------------------------------------------------------------------------
/java/beagle/ResourceDetails.java:
--------------------------------------------------------------------------------
1 | package beagle;
2 |
3 | /**
4 | * An interface for reporting information about the available resources
5 | * as reported by the BEAGLE API.
6 | * @author Andrew Rambaut
7 | * @version $Id$
8 | */
9 | public class ResourceDetails {
10 |
11 | public ResourceDetails(int number) {
12 | this.number = number;
13 | }
14 |
15 | public int getNumber() {
16 | return number;
17 | }
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 | public String getDescription() {
28 | return description;
29 | }
30 |
31 | public void setDescription(String description) {
32 | this.description = description;
33 | }
34 |
35 | public long getFlags() {
36 | return flags;
37 | }
38 |
39 | public void setFlags(long flags) {
40 | this.flags = flags;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | StringBuilder sb = new StringBuilder();
46 | sb.append("").append(getNumber()).append(" : ").append(getName()).append("\n");
47 | if (getDescription() != null) {
48 | String[] description = getDescription().split("\\|");
49 | for (String desc : description) {
50 | if (desc.trim().length() > 0) {
51 | sb.append(" ").append(desc.trim()).append("\n");
52 | }
53 | }
54 | }
55 | sb.append(" Flags:");
56 | sb.append(BeagleFlag.toString(getFlags()));
57 | sb.append("\n");
58 | return sb.toString();
59 | }
60 |
61 | private final int number;
62 | private String name;
63 | private String description;
64 | private long flags;
65 | }
66 |
--------------------------------------------------------------------------------
/libhmsbeagle/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | if(WIN32)
2 | add_definitions(-D_EXPORTING)
3 | add_definitions(-DWIN32)
4 | add_definitions(-D_CONSOLE)
5 | # add_definitions(-DPACKAGE_VERSION="${BEAGLE_VERSION}")
6 | # add_definitions(-DPLUGIN_VERSION="${BEAGLE_PLUGIN_VERSION}")
7 |
8 | set(BEAGLE_PLUGIN_SUFFIX "64-${BEAGLE_PLUGIN_VERSION}.dll")
9 | set(BEAGLE_INSTALL_DIR ".")
10 | set(BEAGLE_HEADER_DIR ".")
11 |
12 | set(BEAGLE_PLUGIN_SOURCE
13 | plugin/WinSharedLibrary.cpp
14 | plugin/WinSharedLibrary.h
15 | )
16 |
17 | set(BEAGLE_INTEGRATED_JNI_SOURCE
18 | JNI/beagle_BeagleJNIWrapper.cpp
19 | JNI/beagle_BeagleJNIWrapper.h
20 | )
21 | else(WIN32)
22 | set(BEAGLE_PLUGIN_SUFFIX ".so")
23 | set(BEAGLE_INSTALL_DIR lib)
24 | set(BEAGLE_HEADER_DIR include/libhmsbeagle-1/libhmsbeagle)
25 |
26 | set(BEAGLE_PLUGIN_SOURCE
27 | plugin/UnixSharedLibrary.cpp
28 | plugin/UnixSharedLibrary.h
29 | plugin/LibtoolSharedLibrary.h
30 | )
31 |
32 | set(BEAGLE_INTEGRATED_JNI_SOURCE
33 | )
34 |
35 | if(BEAGLE_EXPERIMENTAL_LTDL)
36 | find_library(BEAGLE_LTDL_LIB
37 | NAMES ltdl
38 | PATH_SUFFIXES lib lib64)
39 | endif(BEAGLE_EXPERIMENTAL_LTDL)
40 |
41 | if(BEAGLE_LTDL_LIB)
42 | add_definitions(-DHAVE_LIBLTDL)
43 | message(STATUS "Using libtools for plugins: ${BEAGLE_LTDL_LIB}")
44 | else(BEAGLE_LTDL_LIB)
45 | message(STATUS "Not using libtools for plugins")
46 | endif(BEAGLE_LTDL_LIB)
47 |
48 | if(NOT APPLE)
49 | set(BEAGLE_PLUGIN_VERSION_EXTENDED "${BEAGLE_PLUGIN_VERSION}.0.0")
50 | else(NOT APPLE)
51 | set(BEAGLE_PLUGIN_VERSION_EXTENDED "${BEAGLE_PLUGIN_VERSION}")
52 | endif(NOT APPLE)
53 |
54 | endif(WIN32)
55 |
56 | # build minimum functional beagle-lib
57 | add_library(hmsbeagle SHARED
58 | beagle.cpp
59 | beagle.h
60 | BeagleImpl.h
61 | platform.h
62 |
63 | benchmark/BeagleBenchmark.h
64 | benchmark/BeagleBenchmark.cpp
65 | benchmark/linalg.h
66 | benchmark/linalg.cpp
67 |
68 | ${BEAGLE_INTEGRATED_JNI_SOURCE}
69 |
70 | plugin/BeaglePlugin.h
71 | plugin/Plugin.cpp
72 | plugin/Plugin.h
73 | plugin/SharedLibrary.h
74 | ${BEAGLE_PLUGIN_SOURCE}
75 | )
76 |
77 | set_target_properties(hmsbeagle PROPERTIES
78 | PUBLIC_HEADER "beagle.h;platform.h"
79 | VERSION ${GENERIC_API_VERSION})
80 |
81 | if(NOT WIN32 AND NOT APPLE)
82 | target_link_libraries(hmsbeagle ${CMAKE_DL_LIBS})
83 | endif(NOT WIN32 AND NOT APPLE)
84 |
85 | add_subdirectory(CPU)
86 | add_subdirectory(GPU)
87 | if(BUILD_JNI)
88 | add_subdirectory(JNI)
89 | endif(BUILD_JNI)
90 |
91 | set(PKG "hmsbeagle-${GENERIC_API_VERSION}")
92 |
93 | install(TARGETS hmsbeagle
94 | EXPORT ${PKG}
95 | LIBRARY DESTINATION ${BEAGLE_INSTALL_DIR}
96 | PUBLIC_HEADER DESTINATION ${BEAGLE_HEADER_DIR}
97 | COMPONENT main
98 | )
99 |
100 | include(CMakePackageConfigHelpers)
101 |
102 | write_basic_package_version_file(
103 | ${PKG}ConfigVersion.cmake
104 | VERSION ${BEAGLE_VERSION}
105 | COMPATIBILITY AnyNewerVersion
106 | )
107 |
108 | install(EXPORT ${PKG}
109 | FILE ${PKG}Config.cmake
110 | NAMESPACE ${PKG}-${BEAGLE_VERSION}::
111 | DESTINATION lib/cmake/${PKG}
112 | )
113 |
114 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hmsbeagle-1ConfigVersion.cmake"
115 | DESTINATION lib/cmake/${PKG}
116 | )
117 |
118 | configure_file(
119 | ${PKG}.pc.in
120 | ${PKG}.pc
121 | @ONLY
122 | )
123 |
124 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PKG}.pc"
125 | DESTINATION lib/pkg-config
126 | )
127 |
128 | if(WIN32)
129 | SET_TARGET_PROPERTIES(hmsbeagle
130 | PROPERTIES
131 | SUFFIX "64.dll"
132 | )
133 | endif(WIN32)
134 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/AVXDefinitions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AVXDefinitions.h
3 | * BEAGLE
4 | *
5 | * Copyright 2013 Phylogenetic Likelihood Working Group
6 | *
7 | * This file is part of BEAGLE.
8 | *
9 | * Use of this source code is governed by an MIT-style
10 | * license that can be found in the LICENSE file or at
11 | * https://opensource.org/licenses/MIT.
12 | *
13 | * @author Marc Suchard
14 | */
15 |
16 | #ifndef __AVXDefinitions__
17 | #define __AVXDefinitions__
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "libhmsbeagle/config.h"
21 | #endif
22 |
23 | #define USE_AVX
24 |
25 | #if defined(USE_AVX)
26 | # include
27 | #endif
28 | typedef double VecEl_t;
29 |
30 | #ifdef __GNUC__
31 | #define ALIGN16 __attribute__((aligned(16)))
32 | #else
33 | #define ALIGN16 __declspec(align(16))
34 | #endif
35 |
36 | #define USE_DOUBLE_PREC
37 | #if defined(USE_DOUBLE_PREC)
38 | typedef double RealType;
39 | typedef __m256d V_Real;
40 | # define REALS_PER_VEC 4 /* number of elements per vector */
41 | # define VEC_LOAD(a) _mm256_load_pd(a)
42 | //# define VEC_LOAD_SCALAR(a) _mm_load1_pd(a)
43 | # define VEC_STORE(a, b) _mm256_store_pd((a), (b))
44 | //# define VEC_STORE _SCALAR(a, b) _mm_store_sd((a), (b))
45 | # define VEC_MULT(a, b) _mm256_mul_pd((a), (b))
46 | # define VEC_DIV(a, b) _mm256_div_pd((a), (b))
47 | # define VEC_MADD(a, b, c) _mm256_add_pd(_mm256_mul_pd((a), (b)), (c))
48 | # define VEC_SPLAT(a) _mm256_set1_pd(a)
49 | # define VEC_ADD(a, b) _mm256_add_pd(a, b)
50 | # define VEC_SWAP(a) _mm256_shuffle_pd(a, a, _MM_SHUFFLE2(0,1))
51 | # define VEC_SETZERO() _mm256_setzero_pd()
52 | # define VEC_SET1(a) _mm256_set_sd((a))
53 | # define VEC_SET(a, b) _mm256_set_pd((a), (b))
54 | # define VEC_MOVE(a, b) _mm256_move_sd((a), (b))
55 | #else
56 | typedef float RealType;
57 | typedef __m256 V_Real;
58 | # define REALS_PER_VEC 8 /* number of elements per vector */
59 | # define VEC_MULT(a, b) _mm256_mul_ps((a), (b))
60 | # define VEC_MADD(a, b, c) _mm256_add_ps(_mm256_mul_ps((a), (b)), (c))
61 | # define VEC_SPLAT(a) _mm256_set1_ps(a)
62 | # define VEC_ADD(a, b) _mm256_add_ps(a, b)
63 | #endif
64 | typedef union /* for copying individual elements to and from vector floats */
65 | {
66 | RealType x[REALS_PER_VEC];
67 | V_Real vx;
68 | }
69 | VecUnion;
70 |
71 | #ifdef __GNUC__
72 | #define cpuid(func,ax,bx,cx,dx)\
73 | __asm__ __volatile__ ("cpuid":\
74 | "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
75 | #endif
76 |
77 | #ifdef _WIN32
78 |
79 | #endif
80 |
81 | int CPUSupportsAVX() {
82 | //int a,b,c,d;
83 | //cpuid(0,a,b,c,d);
84 | //fprintf(stderr,"a = %d\nb = %d\nc = %d\nd = %d\n",a,b,c,d);
85 | return 1;
86 | }
87 |
88 | #endif // __AVXDefinitions__
89 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUAVXPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_CPU_AVE_PLUGIN_H__
9 | #define __BEAGLE_CPU_AVE_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace cpu {
20 |
21 | class BEAGLE_DLLEXPORT BeagleCPUAVXPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | BeagleCPUAVXPlugin();
25 | private:
26 | BeagleCPUAVXPlugin( const BeagleCPUAVXPlugin& cp ); // disallow copy by defining this private
27 | };
28 |
29 | } // namespace cpu
30 | } // namespace beagle
31 |
32 | extern "C" {
33 | BEAGLE_DLLEXPORT void* plugin_init(void);
34 | }
35 |
36 | #endif // __BEAGLE_CPU_AVE_PLUGIN_H__
37 |
38 |
39 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUOpenMPPlugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "libhmsbeagle/CPU/BeagleCPUOpenMPPlugin.h"
9 | #include "libhmsbeagle/CPU/BeagleCPU4StateImpl.h"
10 | #include "libhmsbeagle/CPU/BeagleCPUImpl.h"
11 | #include "libhmsbeagle/CPU/BeagleCPUSSEPlugin.h"
12 | #include "libhmsbeagle/CPU/BeagleCPU4StateSSEImpl.h"
13 | #include "libhmsbeagle/CPU/BeagleCPUSSEImpl.h"
14 | #include
15 |
16 | namespace beagle {
17 | namespace cpu {
18 |
19 | BeagleCPUOpenMPPlugin::BeagleCPUOpenMPPlugin() :
20 | Plugin("CPU-SSE-OpenMP", "CPU-SSE-OpenMP")
21 | {
22 | BeagleResource resource;
23 | resource.name = (char*) "CPU";
24 | resource.description = (char*) "";
25 | resource.supportFlags = BEAGLE_FLAG_COMPUTATION_SYNCH |
26 | BEAGLE_FLAG_SCALING_MANUAL | BEAGLE_FLAG_SCALING_ALWAYS | BEAGLE_FLAG_SCALING_AUTO |
27 | BEAGLE_FLAG_THREADING_NONE |
28 | BEAGLE_FLAG_PROCESSOR_CPU |
29 | BEAGLE_FLAG_PRECISION_SINGLE | BEAGLE_FLAG_PRECISION_DOUBLE |
30 | BEAGLE_FLAG_VECTOR_NONE |
31 | BEAGLE_FLAG_SCALERS_LOG | BEAGLE_FLAG_SCALERS_RAW |
32 | BEAGLE_FLAG_EIGEN_COMPLEX | BEAGLE_FLAG_EIGEN_REAL |
33 | BEAGLE_FLAG_INVEVEC_STANDARD | BEAGLE_FLAG_INVEVEC_TRANSPOSED |
34 | BEAGLE_FLAG_PREORDER_TRANSPOSE_MANUAL | BEAGLE_FLAG_PREORDER_TRANSPOSE_AUTO |
35 | BEAGLE_FLAG_FRAMEWORK_CPU;
36 | resource.supportFlags |= BEAGLE_FLAG_VECTOR_SSE;
37 | resource.supportFlags |= BEAGLE_FLAG_THREADING_OPENMP;
38 | resource.requiredFlags = BEAGLE_FLAG_FRAMEWORK_CPU;
39 | beagleResources.push_back(resource);
40 |
41 | // Optional for plugins: check if the hardware is compatible and only populate
42 | // list with compatible factories
43 | beagleFactories.push_back(new beagle::cpu::BeagleCPU4StateImplFactory());
44 | beagleFactories.push_back(new beagle::cpu::BeagleCPU4StateImplFactory());
45 | beagleFactories.push_back(new beagle::cpu::BeagleCPUImplFactory());
46 | beagleFactories.push_back(new beagle::cpu::BeagleCPUImplFactory());
47 |
48 | // FIXME: the SSE plugin currently assumes all hardware is compatible
49 | beagleFactories.push_back(new beagle::cpu::BeagleCPU4StateSSEImplFactory());
50 | // implFactory->push_back(new beagle::cpu::BeagleCPU4StateSSEImplFactory()); // TODO Not yet written
51 | beagleFactories.push_back(new beagle::cpu::BeagleCPUSSEImplFactory()); // TODO In process of writing
52 |
53 | }
54 |
55 | } // namespace cpu
56 | } // namespace beagle
57 |
58 |
59 | extern "C" {
60 | void* plugin_init(void){
61 | return new beagle::cpu::BeagleCPUOpenMPPlugin();
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUOpenMPPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_CPU_OPENMP_PLUGIN_H__
9 | #define __BEAGLE_CPU_OPENMP_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace cpu {
20 |
21 | /*
22 | * An OpenMP plugin based on the standard CPU plugin
23 | * This plugin uses all the same code as the CPU plugin, but should be built with
24 | * OpenMP enabled
25 | */
26 | class BEAGLE_DLLEXPORT BeagleCPUOpenMPPlugin : public beagle::plugin::Plugin
27 | {
28 | public:
29 | BeagleCPUOpenMPPlugin();
30 | private:
31 | BeagleCPUOpenMPPlugin( const BeagleCPUOpenMPPlugin& cp ); // disallow copy by defining this private
32 | };
33 |
34 | } // namespace cpu
35 | } // namespace beagle
36 |
37 | extern "C" {
38 | BEAGLE_DLLEXPORT void* plugin_init(void);
39 | }
40 |
41 | #endif // __BEAGLE_CPU_OPENMP_PLUGIN_H__
42 |
43 |
44 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUPlugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "libhmsbeagle/CPU/BeagleCPUPlugin.h"
9 | #include "libhmsbeagle/CPU/BeagleCPU4StateImpl.h"
10 | #include "libhmsbeagle/CPU/BeagleCPUImpl.h"
11 | #include
12 |
13 | namespace beagle {
14 | namespace cpu {
15 |
16 | BeagleCPUPlugin::BeagleCPUPlugin() :
17 | Plugin("CPU", "CPU")
18 | {
19 | BeagleResource resource;
20 | #ifdef __aarch64__
21 | resource.name = (char*) "CPU (arm64)";
22 | #else
23 | resource.name = (char*) "CPU (x86_64)";
24 | #endif
25 | resource.description = (char*) "";
26 | resource.supportFlags = BEAGLE_FLAG_COMPUTATION_SYNCH |
27 | BEAGLE_FLAG_SCALING_MANUAL | BEAGLE_FLAG_SCALING_ALWAYS | BEAGLE_FLAG_SCALING_AUTO | BEAGLE_FLAG_SCALING_DYNAMIC |
28 | BEAGLE_FLAG_THREADING_NONE | BEAGLE_FLAG_THREADING_CPP |
29 | BEAGLE_FLAG_PROCESSOR_CPU |
30 | BEAGLE_FLAG_PRECISION_SINGLE | BEAGLE_FLAG_PRECISION_DOUBLE |
31 | BEAGLE_FLAG_VECTOR_NONE |
32 | BEAGLE_FLAG_SCALERS_LOG | BEAGLE_FLAG_SCALERS_RAW |
33 | BEAGLE_FLAG_EIGEN_COMPLEX | BEAGLE_FLAG_EIGEN_REAL |
34 | BEAGLE_FLAG_INVEVEC_STANDARD | BEAGLE_FLAG_INVEVEC_TRANSPOSED |
35 | BEAGLE_FLAG_PREORDER_TRANSPOSE_MANUAL | BEAGLE_FLAG_PREORDER_TRANSPOSE_AUTO |
36 | BEAGLE_FLAG_FRAMEWORK_CPU;
37 | resource.requiredFlags = BEAGLE_FLAG_FRAMEWORK_CPU;
38 | beagleResources.push_back(resource);
39 |
40 | // Optional for plugins: check if the hardware is compatible and only populate
41 | // list with compatible factories
42 | beagleFactories.push_back(new beagle::cpu::BeagleCPU4StateImplFactory());
43 | beagleFactories.push_back(new beagle::cpu::BeagleCPU4StateImplFactory());
44 | beagleFactories.push_back(new beagle::cpu::BeagleCPUImplFactory());
45 | beagleFactories.push_back(new beagle::cpu::BeagleCPUImplFactory());
46 | }
47 |
48 | } // namespace cpu
49 | } // namespace beagle
50 |
51 |
52 | extern "C" {
53 | void* plugin_init(void){
54 | return new beagle::cpu::BeagleCPUPlugin();
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_CPU_PLUGIN_H__
9 | #define __BEAGLE_CPU_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace cpu {
20 |
21 | class BEAGLE_DLLEXPORT BeagleCPUPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | BeagleCPUPlugin();
25 | private:
26 | BeagleCPUPlugin( const BeagleCPUPlugin& cp ); // disallow copy by defining this private
27 | };
28 |
29 | } // namespace cpu
30 | } // namespace beagle
31 |
32 | extern "C" {
33 | BEAGLE_DLLEXPORT void* plugin_init(void);
34 | }
35 |
36 | #endif // __BEAGLE_CPU_PLUGIN_H__
37 |
38 |
39 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/BeagleCPUSSEPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_CPU_SSE_PLUGIN_H__
9 | #define __BEAGLE_CPU_SSE_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace cpu {
20 |
21 | class BEAGLE_DLLEXPORT BeagleCPUSSEPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | BeagleCPUSSEPlugin();
25 | private:
26 | BeagleCPUSSEPlugin( const BeagleCPUSSEPlugin& cp ); // disallow copy by defining this private
27 | };
28 |
29 | } // namespace cpu
30 | } // namespace beagle
31 |
32 | extern "C" {
33 | BEAGLE_DLLEXPORT void* plugin_init(void);
34 | }
35 |
36 | #endif // __BEAGLE_CPU_SSE_PLUGIN_H__
37 |
38 |
39 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(hmsbeagle-cpu SHARED
2 | BeagleCPU4StateImpl.h
3 | BeagleCPU4StateImpl.hpp
4 | BeagleCPUImpl.h
5 | BeagleCPUImpl.hpp
6 | BeagleCPUPlugin.cpp
7 | BeagleCPUPlugin.h
8 | EigenDecomposition.h
9 | EigenDecompositionCube.h
10 | EigenDecompositionCube.hpp
11 | EigenDecompositionSquare.h
12 | EigenDecompositionSquare.hpp
13 | Precision.h
14 | SSEDefinitions.h
15 | )
16 |
17 | install(TARGETS hmsbeagle-cpu
18 | DESTINATION ${BEAGLE_INSTALL_DIR}
19 | COMPONENT cpu
20 | )
21 |
22 | SET_TARGET_PROPERTIES(hmsbeagle-cpu
23 | PROPERTIES
24 | SOVERSION "${BEAGLE_PLUGIN_VERSION_EXTENDED}"
25 | SUFFIX "${BEAGLE_PLUGIN_SUFFIX}"
26 | )
27 |
28 | if(BUILD_SSE)
29 | add_library(hmsbeagle-cpu-sse SHARED
30 | BeagleCPU4StateSSEImpl.h
31 | BeagleCPU4StateSSEImpl.hpp
32 | BeagleCPU4StateImpl.h
33 | BeagleCPU4StateImpl.hpp
34 | BeagleCPUSSEImpl.h
35 | BeagleCPUSSEImpl.hpp
36 | BeagleCPUImpl.h
37 | BeagleCPUImpl.hpp
38 | BeagleCPUSSEPlugin.cpp
39 | BeagleCPUSSEPlugin.h
40 | EigenDecomposition.h
41 | EigenDecompositionCube.h
42 | EigenDecompositionCube.hpp
43 | EigenDecompositionSquare.h
44 | EigenDecompositionSquare.hpp
45 | Precision.h
46 | SSEDefinitions.h
47 | )
48 |
49 | install(TARGETS hmsbeagle-cpu-sse
50 | DESTINATION ${BEAGLE_INSTALL_DIR}
51 | COMPONENT cpu_sse
52 | )
53 |
54 | SET_TARGET_PROPERTIES(hmsbeagle-cpu-sse
55 | PROPERTIES
56 | SOVERSION "${BEAGLE_PLUGIN_VERSION_EXTENDED}"
57 | SUFFIX "${BEAGLE_PLUGIN_SUFFIX}"
58 | )
59 | endif(BUILD_SSE)
60 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/EigenDecomposition.h:
--------------------------------------------------------------------------------
1 | /*
2 | * EigenDecomposition.h
3 | *
4 | * Created on: Sep 24, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #ifndef EIGENDECOMPOSITION_H_
9 | #define EIGENDECOMPOSITION_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #define BEAGLE_CPU_EIGEN_GENERIC REALTYPE, T_PAD
20 | #define BEAGLE_CPU_EIGEN_TEMPLATE template
21 |
22 | namespace beagle {
23 | namespace cpu {
24 |
25 | BEAGLE_CPU_EIGEN_TEMPLATE
26 | class EigenDecomposition {
27 |
28 | protected:
29 | REALTYPE** gEigenValues;
30 | int kStateCount;
31 | int kEigenDecompCount;
32 | int kCategoryCount;
33 | long kFlags;
34 | REALTYPE* matrixTmp;
35 | REALTYPE* firstDerivTmp;
36 | REALTYPE* secondDerivTmp;
37 |
38 | public:
39 | EigenDecomposition(int decompositionCount,
40 | int stateCount,
41 | int categoryCount,
42 | long flags)
43 | {
44 |
45 | kEigenDecompCount = decompositionCount;
46 | kStateCount = stateCount;
47 | kCategoryCount = categoryCount;
48 | kFlags = flags;
49 | };
50 |
51 | virtual ~EigenDecomposition() {};
52 |
53 | // sets the Eigen decomposition for a given matrix
54 | //
55 | // matrixIndex the matrix index to update
56 | // eigenVectors an array containing the Eigen Vectors
57 | // inverseEigenVectors an array containing the inverse Eigen Vectors
58 | // eigenValues an array containing the Eigen Values
59 | virtual void setEigenDecomposition(int eigenIndex,
60 | const double* inEigenVectors,
61 | const double* inInverseEigenVectors,
62 | const double* inEigenValues) = 0;
63 |
64 | // calculate a transition probability matrices for a given list of node. This will
65 | // calculate for all categories (and all matrices if more than one is being used).
66 | //
67 | // nodeIndices an array of node indices that require transition probability matrices
68 | // edgeLengths an array of expected lengths in substitutions per site
69 | // count the number of elements in the above arrays
70 | virtual void updateTransitionMatrices(int eigenIndex,
71 | const int* probabilityIndices,
72 | const int* firstDerivativeIndices,
73 | const int* secondDerivativeIndices,
74 | const double* edgeLengths,
75 | const double* categoryRates,
76 | REALTYPE** transitionMatrices,
77 | int count) = 0;
78 |
79 | virtual void updateTransitionMatricesWithModelCategories(int* eigenIndices,
80 | const int* probabilityIndices,
81 | const int* firstDerivativeIndices,
82 | const int* secondDerivativeIndices,
83 | const double* edgeLengths,
84 | REALTYPE** transitionMatrices,
85 | int count) = 0;
86 |
87 |
88 | };
89 |
90 | }
91 | }
92 |
93 | #endif /* EIGENDECOMPOSITION_H_ */
94 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/EigenDecompositionCube.h:
--------------------------------------------------------------------------------
1 | /*
2 | * EigenDecompositionCube.h
3 | *
4 | * Created on: Sep 24, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #ifndef EIGENDECOMPOSITIONCUBE_H_
9 | #define EIGENDECOMPOSITIONCUBE_H_
10 |
11 | #include "libhmsbeagle/CPU/EigenDecomposition.h"
12 |
13 | namespace beagle {
14 | namespace cpu {
15 |
16 | BEAGLE_CPU_EIGEN_TEMPLATE
17 | class EigenDecompositionCube : public EigenDecomposition {
18 |
19 | using EigenDecomposition::gEigenValues;
20 | using EigenDecomposition::kStateCount;
21 | using EigenDecomposition::kEigenDecompCount;
22 | using EigenDecomposition::kCategoryCount;
23 | using EigenDecomposition::matrixTmp;
24 | using EigenDecomposition::firstDerivTmp;
25 | using EigenDecomposition::secondDerivTmp;
26 | using EigenDecomposition::kFlags;
27 |
28 | protected:
29 | REALTYPE** gCMatrices;
30 |
31 | public:
32 | EigenDecompositionCube(int decompositionCount,
33 | int stateCount,
34 | int categoryCount,
35 | long flags);
36 |
37 | virtual ~EigenDecompositionCube();
38 |
39 | virtual void setEigenDecomposition(int eigenIndex,
40 | const double* inEigenVectors,
41 | const double* inInverseEigenVectors,
42 | const double* inEigenValues);
43 |
44 | virtual void updateTransitionMatrices(int eigenIndex,
45 | const int* probabilityIndices,
46 | const int* firstDerivativeIndices,
47 | const int* secondDerivativeIndices,
48 | const double* edgeLengths,
49 | const double* categoryRates,
50 | REALTYPE** transitionMatrices,
51 | int count);
52 |
53 | virtual void updateTransitionMatricesWithModelCategories(int* eigenIndices,
54 | const int* probabilityIndices,
55 | const int* firstDerivativeIndices,
56 | const int* secondDerivativeIndices,
57 | const double* edgeLengths,
58 | REALTYPE** transitionMatrices,
59 | int count);
60 | };
61 |
62 | }
63 | }
64 |
65 | // Include the template implementation
66 | #include "libhmsbeagle/CPU/EigenDecompositionCube.hpp"
67 |
68 | #endif /* EIGENDECOMPOSITIONCUBE_H_ */
69 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/EigenDecompositionSquare.h:
--------------------------------------------------------------------------------
1 | /*
2 | * EigenDecompositionSquare.h
3 | *
4 | * Created on: Sep 24, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #ifndef EIGENDECOMPOSITIONSQUARE_H_
9 | #define EIGENDECOMPOSITIONSQUARE_H_
10 |
11 | #include "EigenDecomposition.h"
12 |
13 | namespace beagle {
14 | namespace cpu {
15 |
16 | BEAGLE_CPU_EIGEN_TEMPLATE
17 | class EigenDecompositionSquare: public EigenDecomposition {
18 |
19 | using EigenDecomposition::gEigenValues;
20 | using EigenDecomposition::kStateCount;
21 | using EigenDecomposition::kEigenDecompCount;
22 | using EigenDecomposition::kCategoryCount;
23 | using EigenDecomposition::matrixTmp;
24 | using EigenDecomposition::kFlags;
25 |
26 | protected:
27 | REALTYPE** gEMatrices; // kStateCount^2 flattened array
28 | REALTYPE** gIMatrices; // kStateCount^2 flattened array
29 | bool isComplex;
30 | int kEigenValuesSize;
31 |
32 | public:
33 | EigenDecompositionSquare(int decompositionCount,
34 | int stateCount,
35 | int categoryCount,
36 | long flags);
37 |
38 | virtual ~EigenDecompositionSquare();
39 |
40 | virtual void setEigenDecomposition(int eigenIndex,
41 | const double* inEigenVectors,
42 | const double* inInverseEigenVectors,
43 | const double* inEigenValues);
44 |
45 | virtual void updateTransitionMatrices(int eigenIndex,
46 | const int* probabilityIndices,
47 | const int* firstDerivativeIndices,
48 | const int* secondDerivativeIndices,
49 | const double* edgeLengths,
50 | const double* categoryRates,
51 | REALTYPE** transitionMatrices,
52 | int count);
53 |
54 | virtual void updateTransitionMatricesWithModelCategories(int* eigenIndices,
55 | const int* probabilityIndices,
56 | const int* firstDerivativeIndices,
57 | const int* secondDerivativeIndices,
58 | const double* edgeLengths,
59 | REALTYPE** transitionMatrices,
60 | int count);
61 | };
62 |
63 | }
64 | }
65 |
66 | // Include the template implementation header
67 | #include "libhmsbeagle/CPU/EigenDecompositionSquare.hpp"
68 |
69 | #endif /* EIGENDECOMPOSITIONSQUARE_H_ */
70 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/Precision.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Precision.h
3 | *
4 | * Created on: Oct 13, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #ifndef PRECISION_H_
9 | #define PRECISION_H_
10 |
11 | #include
12 |
13 | #define DOUBLE_PRECISION (sizeof(REALTYPE) == 8)
14 |
15 | template
16 | inline void beagleMemCpy( T* to, F* from, unsigned int length )
17 | {
18 | for(unsigned int m=0; m
23 | inline void beagleMemCpy( F* to, const F* from, unsigned int length )
24 | {
25 | memcpy( to, from, length*sizeof(F) );
26 | }
27 |
28 | /*#define MEMCNV(to, from, length, toType) { \
29 | int m; \
30 | for(m = 0; m < length; m++) { \
31 | to[m] = (toType) from[m]; \
32 | } \
33 | }
34 | */
35 |
36 | #endif /* PRECISION_H_ */
37 |
--------------------------------------------------------------------------------
/libhmsbeagle/CPU/SSEDefinitions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * BeagleCPU4StateSSEImpl.h
3 | * BEAGLE
4 | *
5 | * Copyright 2009 Phylogenetic Likelihood Working Group
6 | *
7 | * This file is part of BEAGLE.
8 | *
9 | * Use of this source code is governed by an MIT-style
10 | * license that can be found in the LICENSE file or at
11 | * https://opensource.org/licenses/MIT.
12 | *
13 | * @author Marc Suchard
14 | */
15 |
16 | #ifndef __SSEDefinitions__
17 | #define __SSEDefinitions__
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "libhmsbeagle/config.h"
21 | #endif
22 |
23 | #define DLS_USE_SSE2
24 |
25 | #if defined(DLS_USE_SSE2)
26 | # if defined(__aarch64__)
27 | # include "libhmsbeagle/CPU/sse2neon.h"
28 | # define _MM_SHUFFLE2(fp1,fp0) (((fp1) << 1) | (fp0))
29 | # define VEC_SHUFFLE0(a,b) _mm_shuffle_pd(a, b, _MM_SHUFFLE2(0,0)) // vreinterpretq_f64_m128d(a)
30 | # define VEC_SHUFFLE1(a,b) _mm_shuffle_pd(a, b, _MM_SHUFFLE2(1,1)) // vreinterpretq_f64_m128d(a)
31 |
32 | # else
33 | # if !defined(DLS_MACOS)
34 | # include
35 | # endif
36 | # include
37 | # include
38 | # include
39 | # endif
40 | #endif
41 | typedef double VecEl_t;
42 |
43 | #ifdef __GNUC__
44 | #define ALIGN16 __attribute__((aligned(16)))
45 | #else
46 | #define ALIGN16 __declspec(align(16))
47 | #endif
48 |
49 | #define USE_DOUBLE_PREC
50 | #if defined(USE_DOUBLE_PREC)
51 | typedef double RealType;
52 | typedef __m128d V_Real;
53 | # define REALS_PER_VEC 2 /* number of elements per vector */
54 | # define VEC_LOAD(a) _mm_load_pd(a)
55 | # define VEC_LOAD_SCALAR(a) _mm_load1_pd(a)
56 | # define VEC_STORE(a, b) _mm_store_pd((a), (b))
57 | # define VEC_STORE_SCALAR(a, b) _mm_store_sd((a), (b))
58 | # define VEC_STOREU(a, b) _mm_storeu_pd((a), (b))
59 | # define VEC_MULT(a, b) _mm_mul_pd((a), (b))
60 | # define VEC_DIV(a, b) _mm_div_pd((a), (b))
61 | # define VEC_MADD(a, b, c) _mm_add_pd(_mm_mul_pd((a), (b)), (c))
62 | # define VEC_SPLAT(a) _mm_set1_pd(a)
63 | # define VEC_ADD(a, b) _mm_add_pd(a, b)
64 | # define VEC_SWAP(a) _mm_shuffle_pd(a, a, _MM_SHUFFLE2(0,1))
65 | # define VEC_SETZERO() _mm_setzero_pd()
66 | # define VEC_SET1(a) _mm_set_sd((a))
67 | # define VEC_SET(a, b) _mm_set_pd((a), (b))
68 | # define VEC_MOVE(a, b) _mm_move_sd((a), (b))
69 | # define VEC_SHUFFLE0(a, b) _mm_shuffle_pd(a, b, _MM_SHUFFLE2(0,0))
70 | # define VEC_SHUFFLE1(a, b) _mm_shuffle_pd(a, b, _MM_SHUFFLE2(1,1))
71 | #else
72 | typedef float RealType;
73 | typedef __m128 V_Real;
74 | # define REALS_PER_VEC 4 /* number of elements per vector */
75 | # define VEC_MULT(a, b) _mm_mul_ps((a), (b))
76 | # define VEC_MADD(a, b, c) _mm_add_ps(_mm_mul_ps((a), (b)), (c))
77 | # define VEC_SPLAT(a) _mm_set1_ps(a)
78 | # define VEC_ADD(a, b) _mm_add_ps(a, b)
79 | #endif
80 | typedef union /* for copying individual elements to and from vector floats */
81 | {
82 | RealType x[REALS_PER_VEC];
83 | V_Real vx;
84 | }
85 | VecUnion;
86 |
87 | #ifdef __GNUC__
88 | #define cpuid(func,ax,bx,cx,dx)\
89 | __asm__ __volatile__ ("cpuid":\
90 | "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
91 | #endif
92 |
93 | #ifdef _WIN32
94 |
95 | #endif
96 |
97 | int CPUSupportsSSE() {
98 | //int a,b,c,d;
99 | //cpuid(0,a,b,c,d);
100 | //fprintf(stderr,"a = %d\nb = %d\nc = %d\nd = %d\n",a,b,c,d);
101 | return 1;
102 | }
103 |
104 | //inline XMVECTOR XMVector4Dot( FXMVECTOR V1, FXMVECTOR V2 )
105 | //{
106 | //#if defined(_XM_NO_INTRINSICS_)
107 | //
108 | // XMVECTOR Result;
109 | // Result.vector4_f32[0] =
110 | // Result.vector4_f32[1] =
111 | // Result.vector4_f32[2] =
112 | // Result.vector4_f32[3] = V1.vector4_f32[0] * V2.vector4_f32[0] + V1.vector4_f32[1] * V2.vector4_f32[1] + V1.vector4_f32[2] * V2.vector4_f32[2] + V1.vector4_f32[3] * V2.vector4_f32[3];
113 | // return Result;
114 | //
115 | //#elif defined(_M_ARM) || defined(_M_ARM64)
116 | //
117 | // float32x4_t vTemp = vmulq_f32( V1, V2 );
118 | // float32x2_t v1 = vget_low_f32( vTemp );
119 | // float32x2_t v2 = vget_high_f32( vTemp );
120 | // v1 = vpadd_f32( v1, v1 );
121 | // v2 = vpadd_f32( v2, v2 );
122 | // v1 = vadd_f32( v1, v2 );
123 | // return vcombine_f32( v1, v1 );
124 | //
125 | //#elif defined(__AVX__) || defined(__AVX2__)
126 | //
127 | // return _mm_dp_ps( V1, V2, 0xff );
128 | //
129 | //#elif defined(_M_IX86) || defined(_M_X64)
130 | //
131 | // XMVECTOR vTemp2 = V2;
132 | // XMVECTOR vTemp = _mm_mul_ps(V1,vTemp2);
133 | // vTemp2 = _mm_shuffle_ps(vTemp2,vTemp,_MM_SHUFFLE(1,0,0,0));
134 | // vTemp2 = _mm_add_ps(vTemp2,vTemp);
135 | // vTemp = _mm_shuffle_ps(vTemp,vTemp2,_MM_SHUFFLE(0,3,0,0));
136 | // vTemp = _mm_add_ps(vTemp,vTemp2);
137 | // return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2));
138 | //
139 | //#else
140 | //#error Unsupported platform
141 | //#endif
142 | //}
143 |
144 | #endif // __SSEDefinitions__
145 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | if(BUILD_OPENCL)
3 | find_package(OpenCL)
4 | if(OpenCL_FOUND)
5 | message(STATUS "OpenCL Includes: ${OpenCL_INCLUDE_DIRS}")
6 | message(STATUS "OpenCL Libraries: ${OpenCL_LIBRARIES}")
7 | add_subdirectory("CMake_OpenCL")
8 | endif(OpenCL_FOUND)
9 | endif(BUILD_OPENCL)
10 |
11 | if(BUILD_CUDA)
12 | find_package(CUDA)
13 | if(CUDA_FOUND)
14 | message(STATUS "CUDA Includes: ${CUDA_INCLUDE_DIRS}")
15 | add_subdirectory("CMake_CUDA")
16 | endif(CUDA_FOUND)
17 | endif(BUILD_CUDA)
18 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/CMake_CUDA/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | include_directories(
3 | ${CUDA_INCLUDE_DIRS}
4 | )
5 |
6 | add_definitions(-DCUDA)
7 |
8 | link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib
9 | ${CUDA_TOOLKIT_ROOT_DIR}/lib/x64
10 | ${CUDA_TOOLKIT_ROOT_DIR}/lib64
11 | )
12 |
13 | if(WIN32)
14 | set(NVCC "nvcc.exe")
15 | set(NVCCFLAGS "-O3 -Wno-deprecated-gpu-targets")
16 | set(NVCC_INC "-I../../..")
17 | set(CMD_NAME createCUDAKernels.bat)
18 | else(WIN32)
19 | set(NVCC "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc")
20 | set(NVCCFLAGS "-O3 -Wno-deprecated-gpu-targets -ccbin ${CMAKE_CXX_COMPILER} -m64 -D_POSIX_C_SOURCE -std=c++11")
21 | set(NVCC_INC "-I${CMAKE_SOURCE_DIR}")
22 | set(CMD_NAME make_cuda_kernels.sh)
23 | endif(WIN32)
24 |
25 | add_custom_command(
26 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/BeagleCUDA_kernels.h
27 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/${CMD_NAME} ${NVCC} "${NVCCFLAGS}" "${NVCC_INC}"
28 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../kernels
29 | DEPENDS "../kernels/kernels4.cu" "../kernels/kernels4Derivatives.cu" "../kernels/kernelsXDerivatives.cu" "../kernels/kernelsAll.cu"
30 | COMMENT "Building CUDA kernels"
31 | VERBATIM)
32 |
33 | add_custom_target(CudaKernels DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/BeagleCUDA_kernels.h)
34 |
35 | add_library(hmsbeagle-cuda SHARED
36 | ../BeagleGPUImpl.h
37 | ../BeagleGPUImpl.hpp
38 | ../GPUImplDefs.h
39 | ../GPUImplHelper.cpp
40 | ../GPUImplHelper.h
41 | ../GPUInterfaceCUDA.cpp
42 | ../KernelLauncher.cpp
43 | ../KernelLauncher.h
44 | ../KernelResource.cpp
45 | ../KernelResource.h
46 | ../CUDAPlugin.cpp
47 | ../CUDAPlugin.h
48 | ../Precision.h
49 | )
50 |
51 | add_dependencies(hmsbeagle-cuda CudaKernels)
52 |
53 | target_link_libraries(hmsbeagle-cuda cuda ${CUDA_LIBRARIES})
54 |
55 | install(TARGETS hmsbeagle-cuda
56 | DESTINATION ${BEAGLE_INSTALL_DIR}
57 | COMPONENT cuda
58 | )
59 |
60 | SET_TARGET_PROPERTIES(hmsbeagle-cuda
61 | PROPERTIES
62 | SOVERSION "${BEAGLE_PLUGIN_VERSION_EXTENDED}"
63 | SUFFIX "${BEAGLE_PLUGIN_SUFFIX}"
64 | )
65 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/CMake_OpenCL/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | include_directories(
3 | ${OpenCL_INCLUDE_DIRS}
4 | )
5 |
6 | add_definitions(-DFW_OPENCL)
7 | #include_directories(${OpenCL_INCLUDE_DIRS})
8 |
9 | # For OpenCL, we need to generate the file `BeagleOpenCL_kernels.h` using the commands (and dependencies) below
10 | if(WIN32)
11 | set(CMD_NAME createOpenCLHeader.bat)
12 | else(WIN32)
13 | set(CMD_NAME make_opencl_kernels.sh)
14 | endif(WIN32)
15 |
16 | add_custom_command(
17 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/BeagleOpenCL_kernels.h
18 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/${CMD_NAME}
19 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../kernels
20 | DEPENDS "../kernels/kernels4.cu" "../kernels/kernels4Derivatives.cu" "../kernels/kernelsXDerivatives.cu" "../kernels/kernelsAll.cu"
21 | COMMENT "Building OpenCL kernels"
22 | VERBATIM)
23 |
24 | add_custom_target(OpenKernels DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../kernels/BeagleOpenCL_kernels.h)
25 |
26 | add_library(hmsbeagle-opencl SHARED
27 | ../BeagleGPUImpl.h
28 | ../BeagleGPUImpl.hpp
29 | ../GPUImplDefs.h
30 | ../GPUImplHelper.cpp
31 | ../GPUImplHelper.h
32 | ../GPUInterfaceOpenCL.cpp
33 | ../KernelLauncher.cpp
34 | ../KernelLauncher.h
35 | ../KernelResource.cpp
36 | ../KernelResource.h
37 | ../OpenCLPlugin.cpp
38 | ../OpenCLPlugin.h
39 | ../Precision.h
40 | )
41 |
42 | add_dependencies(hmsbeagle-opencl OpenKernels)
43 |
44 | target_link_libraries(hmsbeagle-opencl ${OpenCL_LIBRARIES})
45 |
46 | install(TARGETS hmsbeagle-opencl
47 | DESTINATION ${BEAGLE_INSTALL_DIR}
48 | COMPONENT opencl
49 | )
50 |
51 | SET_TARGET_PROPERTIES(hmsbeagle-opencl
52 | PROPERTIES
53 | SOVERSION "${BEAGLE_PLUGIN_VERSION_EXTENDED}"
54 | SUFFIX "${BEAGLE_PLUGIN_SUFFIX}"
55 | )
56 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/CUDAPlugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "libhmsbeagle/GPU/BeagleGPUImpl.h"
9 | #include "libhmsbeagle/GPU/CUDAPlugin.h"
10 |
11 | namespace beagle {
12 | namespace gpu {
13 |
14 | CUDAPlugin::CUDAPlugin() :
15 | Plugin("GPU-CUDA", "GPU-CUDA")
16 | {
17 | GPUInterface gpu;
18 | bool anyGPUSupportsCUDA = false;
19 | bool anyGPUSupportsDP = false;
20 | if (gpu.Initialize()) {
21 | int gpuDeviceCount = gpu.GetDeviceCount();
22 | anyGPUSupportsCUDA = (gpuDeviceCount > 0);
23 | for (int i = 0; i < gpuDeviceCount; i++) {
24 | int nameDescSize = 256;
25 | char* dName = (char*) malloc(sizeof(char) * nameDescSize);
26 | char* dDesc = (char*) malloc(sizeof(char) * nameDescSize);
27 | gpu.GetDeviceName(i, dName, nameDescSize);
28 | gpu.GetDeviceDescription(i, dDesc);
29 |
30 | BeagleResource resource;
31 | resource.name = dName;
32 | resource.description = dDesc;
33 | resource.supportFlags = BEAGLE_FLAG_COMPUTATION_SYNCH | BEAGLE_FLAG_COMPUTATION_ASYNCH |
34 | BEAGLE_FLAG_PRECISION_SINGLE |
35 | BEAGLE_FLAG_SCALING_MANUAL | BEAGLE_FLAG_SCALING_ALWAYS |
36 | BEAGLE_FLAG_SCALING_AUTO | BEAGLE_FLAG_SCALING_DYNAMIC |
37 | BEAGLE_FLAG_THREADING_NONE |
38 | BEAGLE_FLAG_VECTOR_NONE |
39 | BEAGLE_FLAG_PROCESSOR_GPU |
40 | BEAGLE_FLAG_SCALERS_LOG | BEAGLE_FLAG_SCALERS_RAW |
41 | BEAGLE_FLAG_EIGEN_COMPLEX | BEAGLE_FLAG_EIGEN_REAL |
42 | BEAGLE_FLAG_INVEVEC_STANDARD | BEAGLE_FLAG_INVEVEC_TRANSPOSED |
43 | BEAGLE_FLAG_PREORDER_TRANSPOSE_MANUAL | BEAGLE_FLAG_PREORDER_TRANSPOSE_AUTO |
44 | BEAGLE_FLAG_PARALLELOPS_GRID | BEAGLE_FLAG_PARALLELOPS_STREAMS |
45 | BEAGLE_FLAG_FRAMEWORK_CUDA;
46 | // Determine DP capability
47 | if (gpu.GetSupportsDoublePrecision(i)) {
48 | resource.supportFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
49 | anyGPUSupportsDP = true;
50 | }
51 |
52 | resource.requiredFlags = BEAGLE_FLAG_FRAMEWORK_CUDA;
53 |
54 | beagleResources.push_back(resource);
55 | }
56 | }
57 |
58 | // Optional for plugins: check if the hardware is compatible and only populate
59 | // list with compatible factories
60 | // if(beagleResources.size() > 0) {
61 | if (anyGPUSupportsCUDA) {
62 | using namespace cuda;
63 | if (anyGPUSupportsDP) {
64 | // TODO Uncomment when working
65 | beagleFactories.push_back(new BeagleGPUImplFactory());
66 | }
67 | beagleFactories.push_back(new BeagleGPUImplFactory());
68 | }
69 | }
70 |
71 | CUDAPlugin::~CUDAPlugin()
72 | {
73 | }
74 |
75 | } // namespace gpu
76 | } // namespace beagle
77 |
78 |
79 | extern "C" {
80 | void* plugin_init(void){
81 | return new beagle::gpu::CUDAPlugin();
82 | }
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/CUDAPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_CUDA_PLUGIN_H__
9 | #define __BEAGLE_CUDA_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace gpu {
20 |
21 | class BEAGLE_DLLEXPORT CUDAPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | CUDAPlugin();
25 | ~CUDAPlugin();
26 | private:
27 | CUDAPlugin( const CUDAPlugin& cp ); // disallow copy by defining this private
28 | };
29 |
30 | } // namespace gpu
31 | } // namespace beagle
32 |
33 | extern "C" {
34 | BEAGLE_DLLEXPORT void* plugin_init(void);
35 | }
36 |
37 | #endif // __BEAGLE_CUDA_PLUGIN_H__
38 |
39 |
40 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/GPUImplHelper.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2009 Phylogenetic Likelihood Working Group
4 | *
5 | * This file is part of BEAGLE.
6 | *
7 | * Use of this source code is governed by an MIT-style
8 | * license that can be found in the LICENSE file or at
9 | * https://opensource.org/licenses/MIT.
10 | *
11 | * @author Marc Suchard
12 | * @author Daniel Ayres
13 | */
14 |
15 | #ifdef HAVE_CONFIG_H
16 | #include "libhmsbeagle/config.h"
17 | #endif
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include "libhmsbeagle/GPU/GPUImplDefs.h"
24 |
25 | void checkHostMemory(void* ptr) {
26 | if (ptr == NULL) {
27 | fprintf(stderr, "Unable to allocate some memory!\n");
28 | exit(-1);
29 | }
30 | }
31 |
32 | void printfInt(int* ptr,
33 | int length) {
34 | fprintf(stderr, "[ %d", ptr[0]);
35 | int i;
36 | for (i = 1; i < length; i++)
37 | fprintf(stderr, " %d", ptr[i]);
38 | fprintf(stderr, " ]\n");
39 | }
40 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/GPUImplHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * @brief GPU implementation helper functions
3 | *
4 | * Copyright 2009 Phylogenetic Likelihood Working Group
5 | *
6 | * This file is part of BEAGLE.
7 | *
8 | * Use of this source code is governed by an MIT-style
9 | * license that can be found in the LICENSE file or at
10 | * https://opensource.org/licenses/MIT.
11 | *
12 | * @author Marc Suchard
13 | * @author Daniel Ayres
14 | */
15 |
16 | #ifndef __GPUImplHelper__
17 | #define __GPUImplHelper__
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "libhmsbeagle/config.h"
21 | #endif
22 |
23 | #include "libhmsbeagle/GPU/GPUImplDefs.h"
24 |
25 | void checkHostMemory(void* ptr);
26 |
27 | /**
28 | * @brief Transposes a square matrix in place
29 | */
30 | template
31 | void transposeSquareMatrix(Real* mat,
32 | int size) {
33 | for (int i = 0; i < size - 1; i++) {
34 | for (int j = i + 1; j < size; j++) {
35 | Real tmp = mat[i * size + j];
36 | mat[i * size + j] = mat[j * size + i];
37 | mat[j * size + i] = tmp;
38 | }
39 | }
40 | }
41 |
42 | template
43 | void printfVector(Real* ptr,
44 | int length) {
45 | fprintf(stderr, "[ %1.5e", ptr[0]);
46 | int i;
47 | for (i = 1; i < length; i++)
48 | fprintf(stderr, " %1.5e", ptr[i]);
49 | fprintf(stderr, " ]\n");
50 | }
51 |
52 | void printfInt(int* ptr,
53 | int length);
54 |
55 | #endif // __GPUImplHelper__
56 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/KernelResource.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * KernelResource.cpp
3 | *
4 | * Created on: Sep 7, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #include "KernelResource.h"
9 |
10 |
11 | //#ifdef CUDA
12 | // using namespace cuda_device;
13 | //#else
14 | //#ifdef FW_OPENCL
15 | // using namespace opencl_device;
16 | //#endif
17 | //#endif
18 |
19 | KernelResource::KernelResource() {
20 | }
21 |
22 | KernelResource::KernelResource(
23 | int inPaddedStateCount,
24 | char* inKernelString,
25 | int inPatternBlockSize,
26 | int inMatrixBlockSize,
27 | int inBlockPeelingSize,
28 | int inSlowReweighing,
29 | int inMultiplyBlockSize,
30 | int inCategoryCount,
31 | int inPatternCount,
32 | int inUnpaddedPatternCount,
33 | long inFlags
34 | ) {
35 | paddedStateCount = inPaddedStateCount;
36 | kernelCode = inKernelString;
37 | patternBlockSize = inPatternBlockSize;
38 | matrixBlockSize = inMatrixBlockSize;
39 | blockPeelingSize = inBlockPeelingSize,
40 | slowReweighing = inSlowReweighing;
41 | multiplyBlockSize = inMultiplyBlockSize;
42 | categoryCount = inCategoryCount;
43 | patternCount = inPatternCount;
44 | unpaddedPatternCount = inUnpaddedPatternCount;
45 | flags = inFlags;
46 | }
47 |
48 | KernelResource::KernelResource(const KernelResource& krIn,
49 | char* inKernelCode) {
50 | paddedStateCount = krIn.paddedStateCount;
51 | kernelCode = inKernelCode;
52 | patternBlockSize = krIn.patternBlockSize;
53 | matrixBlockSize = krIn.matrixBlockSize;
54 | blockPeelingSize = krIn.blockPeelingSize,
55 | slowReweighing = krIn.slowReweighing;
56 | multiplyBlockSize = krIn.multiplyBlockSize;
57 | categoryCount = krIn.categoryCount;
58 | patternCount = krIn.patternCount;
59 | unpaddedPatternCount = krIn.unpaddedPatternCount;
60 | flags = krIn.flags;
61 | }
62 |
63 | KernelResource::~KernelResource() {
64 | }
65 |
66 | KernelResource* KernelResource::copy(void) {
67 | return new KernelResource(
68 | paddedStateCount,
69 | kernelCode,
70 | patternBlockSize,
71 | matrixBlockSize,
72 | blockPeelingSize,
73 | slowReweighing,
74 | multiplyBlockSize,
75 | categoryCount,
76 | patternCount,
77 | unpaddedPatternCount,
78 | flags);
79 | }
80 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/KernelResource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * KernelResource.h
3 | * BEAGLE
4 | *
5 | * Copyright 2009 Phylogenetic Likelihood Working Group
6 | *
7 | * This file is part of BEAGLE.
8 | *
9 | * Use of this source code is governed by an MIT-style
10 | * license that can be found in the LICENSE file or at
11 | * https://opensource.org/licenses/MIT.
12 | *
13 | * @author Marc Suchard
14 | */
15 |
16 | #ifndef KERNELRESOURCE_H_
17 | #define KERNELRESOURCE_H_
18 |
19 | class KernelResource {
20 | public:
21 | KernelResource();
22 |
23 | KernelResource(
24 | int inPaddedStateCount,
25 | char* inKernelString,
26 | int inPatternBlockSize,
27 | int inMatrixBlockSize,
28 | int inBlockPeelingSize,
29 | int inSlowReweighing,
30 | int inMultiplyBlockSize,
31 | int inCategoryCount,
32 | int inPatternCount,
33 | int inUnpaddedPatternCount,
34 | long inFlags
35 | );
36 |
37 | KernelResource(const KernelResource& krIn,
38 | char* inKernelCode);
39 |
40 | virtual ~KernelResource();
41 |
42 | int paddedStateCount;
43 | int categoryCount;
44 | int patternCount;
45 | int unpaddedPatternCount;
46 | char* kernelCode;
47 | int patternBlockSize;
48 | int matrixBlockSize;
49 | int blockPeelingSize;
50 | int isPowerOfTwo;
51 | int smallestPowerOfTwo;
52 | int slowReweighing;
53 | int multiplyBlockSize;
54 | long flags;
55 |
56 | KernelResource* copy();
57 | };
58 |
59 | #endif /* KERNELRESOURCE_H_ */
60 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/OpenCLAlteraPlugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "libhmsbeagle/GPU/BeagleGPUImpl.h"
9 | #include "libhmsbeagle/GPU/OpenCLAlteraPlugin.h"
10 |
11 | namespace beagle {
12 | namespace gpu {
13 |
14 | OpenCLAlteraPlugin::OpenCLAlteraPlugin() :
15 | Plugin("GPU-OpenCL-Altera", "GPU-OpenCL-Altera")
16 | {
17 | GPUInterface gpu;
18 | bool anyGPUSupportsOpenCL = false;
19 | bool anyGPUSupportsDP = false;
20 | if (gpu.Initialize()) {
21 | int gpuDeviceCount = gpu.GetDeviceCount();
22 | anyGPUSupportsOpenCL = (gpuDeviceCount > 0);
23 | for (int i = 0; i < gpuDeviceCount; i++) {
24 | int nameDescSize = 256;
25 | char* dName = (char*) malloc(sizeof(char) * nameDescSize);
26 | char* dDesc = (char*) malloc(sizeof(char) * nameDescSize);
27 | gpu.GetDeviceName(i, dName, nameDescSize);
28 | gpu.GetDeviceDescription(i, dDesc);
29 | BeagleResource resource;
30 | resource.name = dName;
31 | resource.description = dDesc;
32 | resource.supportFlags = BEAGLE_FLAG_COMPUTATION_SYNCH |
33 | BEAGLE_FLAG_PRECISION_SINGLE |
34 | BEAGLE_FLAG_SCALING_MANUAL | BEAGLE_FLAG_SCALING_ALWAYS |
35 | BEAGLE_FLAG_SCALING_AUTO | BEAGLE_FLAG_SCALING_DYNAMIC |
36 | BEAGLE_FLAG_THREADING_NONE |
37 | BEAGLE_FLAG_VECTOR_NONE |
38 | BEAGLE_FLAG_SCALERS_LOG | BEAGLE_FLAG_SCALERS_RAW |
39 | BEAGLE_FLAG_EIGEN_COMPLEX | BEAGLE_FLAG_EIGEN_REAL |
40 | BEAGLE_FLAG_INVEVEC_STANDARD | BEAGLE_FLAG_INVEVEC_TRANSPOSED |
41 | BEAGLE_FLAG_FRAMEWORK_OPENCL;
42 |
43 | long deviceTypeFlag = gpu.GetDeviceTypeFlag(i);
44 |
45 | resource.supportFlags |= deviceTypeFlag;
46 |
47 | // Determine DP capability
48 | if (gpu.GetSupportsDoublePrecision(i)) {
49 | resource.supportFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
50 | anyGPUSupportsDP = true;
51 | }
52 |
53 | resource.requiredFlags = BEAGLE_FLAG_FRAMEWORK_OPENCL;
54 |
55 | beagleResources.push_back(resource);
56 | }
57 | }
58 |
59 | // Optional for plugins: check if the hardware is compatible and only populate
60 | // list with compatible factories
61 | // if(beagleResources.size() > 0) {
62 | if (anyGPUSupportsOpenCL) {
63 | beagleFactories.push_back(new BeagleGPUImplFactory());
64 | if (anyGPUSupportsDP) {
65 | // TODO Uncomment when working
66 | beagleFactories.push_back(new BeagleGPUImplFactory());
67 | }
68 | }
69 | }
70 | OpenCLAlteraPlugin::~OpenCLAlteraPlugin()
71 | {
72 | }
73 |
74 |
75 | } // namespace gpu
76 | } // namespace beagle
77 |
78 |
79 | extern "C" {
80 | void* plugin_init(void){
81 | return new beagle::gpu::OpenCLAlteraPlugin();
82 | }
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/OpenCLAlteraPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_OPENCL_ALTERA_PLUGIN_H__
9 | #define __BEAGLE_OPENCL_ALTERA_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace gpu {
20 |
21 | class BEAGLE_DLLEXPORT OpenCLAlteraPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | OpenCLAlteraPlugin();
25 | ~OpenCLAlteraPlugin();
26 | private:
27 | OpenCLAlteraPlugin( const OpenCLAlteraPlugin& cp ); // disallow copy by defining this private
28 | };
29 |
30 | } // namespace gpu
31 | } // namespace beagle
32 |
33 | extern "C" {
34 | BEAGLE_DLLEXPORT void* plugin_init(void);
35 | }
36 |
37 | #endif // __BEAGLE_OPENCL_ALTERA_PLUGIN_H__
38 |
39 |
40 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/OpenCLPlugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "libhmsbeagle/GPU/BeagleGPUImpl.h"
9 | #include "libhmsbeagle/GPU/OpenCLPlugin.h"
10 |
11 | namespace beagle {
12 | namespace gpu {
13 |
14 | OpenCLPlugin::OpenCLPlugin() :
15 | Plugin("GPU-OpenCL", "GPU-OpenCL")
16 | {
17 | GPUInterface gpu;
18 | bool anyGPUSupportsOpenCL = false;
19 | bool anyGPUSupportsDP = false;
20 | if (gpu.Initialize()) {
21 | int gpuDeviceCount = gpu.GetDeviceCount();
22 | anyGPUSupportsOpenCL = (gpuDeviceCount > 0);
23 | for (int i = 0; i < gpuDeviceCount; i++) {
24 | #ifdef BEAGLE_DEBUG_OPENCL_CORES
25 | gpu.CreateDevice(i);
26 | #endif
27 |
28 | int nameDescSize = 256;
29 | char* dName = (char*) malloc(sizeof(char) * nameDescSize);
30 | char* dDesc = (char*) malloc(sizeof(char) * nameDescSize);
31 | gpu.GetDeviceName(i, dName, nameDescSize);
32 | gpu.GetDeviceDescription(i, dDesc);
33 | BeagleResource resource;
34 | resource.name = dName;
35 | resource.description = dDesc;
36 | resource.supportFlags = BEAGLE_FLAG_COMPUTATION_SYNCH | BEAGLE_FLAG_COMPUTATION_ASYNCH |
37 | BEAGLE_FLAG_PRECISION_SINGLE |
38 | BEAGLE_FLAG_SCALING_MANUAL | BEAGLE_FLAG_SCALING_ALWAYS |
39 | BEAGLE_FLAG_SCALING_AUTO | BEAGLE_FLAG_SCALING_DYNAMIC |
40 | BEAGLE_FLAG_THREADING_NONE |
41 | BEAGLE_FLAG_VECTOR_NONE |
42 | BEAGLE_FLAG_SCALERS_LOG | BEAGLE_FLAG_SCALERS_RAW |
43 | BEAGLE_FLAG_EIGEN_COMPLEX | BEAGLE_FLAG_EIGEN_REAL |
44 | BEAGLE_FLAG_PREORDER_TRANSPOSE_MANUAL | BEAGLE_FLAG_PREORDER_TRANSPOSE_AUTO |
45 | BEAGLE_FLAG_INVEVEC_STANDARD | BEAGLE_FLAG_INVEVEC_TRANSPOSED |
46 | BEAGLE_FLAG_PARALLELOPS_GRID | BEAGLE_FLAG_PARALLELOPS_STREAMS |
47 | BEAGLE_FLAG_FRAMEWORK_OPENCL;
48 |
49 | long deviceTypeFlag = gpu.GetDeviceTypeFlag(i);
50 |
51 | resource.supportFlags |= deviceTypeFlag;
52 |
53 | // Determine DP capability
54 | if (gpu.GetSupportsDoublePrecision(i)) {
55 | resource.supportFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
56 | anyGPUSupportsDP = true;
57 | }
58 |
59 | resource.requiredFlags = BEAGLE_FLAG_FRAMEWORK_OPENCL;
60 |
61 | beagleResources.push_back(resource);
62 |
63 | #ifdef BEAGLE_DEBUG_OPENCL_CORES
64 | gpu.ReleaseDevice(i);
65 | #endif
66 | }
67 | }
68 |
69 | // Optional for plugins: check if the hardware is compatible and only populate
70 | // list with compatible factories
71 | // if(beagleResources.size() > 0) {
72 | if (anyGPUSupportsOpenCL) {
73 | using namespace opencl;
74 | if (anyGPUSupportsDP) {
75 | // TODO Uncomment when working
76 | beagleFactories.push_back(new BeagleGPUImplFactory());
77 | }
78 | beagleFactories.push_back(new BeagleGPUImplFactory());
79 | }
80 | }
81 | OpenCLPlugin::~OpenCLPlugin()
82 | {
83 | }
84 |
85 |
86 | } // namespace gpu
87 | } // namespace beagle
88 |
89 |
90 | extern "C" {
91 | void* plugin_init(void){
92 | return new beagle::gpu::OpenCLPlugin();
93 | }
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/OpenCLPlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __BEAGLE_OPENCL_PLUGIN_H__
9 | #define __BEAGLE_OPENCL_PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/plugin/Plugin.h"
17 |
18 | namespace beagle {
19 | namespace gpu {
20 |
21 | class BEAGLE_DLLEXPORT OpenCLPlugin : public beagle::plugin::Plugin
22 | {
23 | public:
24 | OpenCLPlugin();
25 | ~OpenCLPlugin();
26 | private:
27 | OpenCLPlugin( const OpenCLPlugin& cp ); // disallow copy by defining this private
28 | };
29 |
30 | } // namespace gpu
31 | } // namespace beagle
32 |
33 | extern "C" {
34 | BEAGLE_DLLEXPORT void* plugin_init(void);
35 | }
36 |
37 | #endif // __BEAGLE_OPENCL_PLUGIN_H__
38 |
39 |
40 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/Precision.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Precision.h
3 | *
4 | * Created on: Oct 13, 2009
5 | * Author: msuchard
6 | */
7 |
8 | #ifndef GPU_PRECISION_H_
9 | #define GPU_PRECISION_H_
10 |
11 | template
12 | inline void beagleMemCpy( T* to, F* from, unsigned int length )
13 | {
14 | for(unsigned int m=0; m
19 | inline void beagleMemCpy( F* to, const F* from, unsigned int length )
20 | {
21 | memcpy( to, from, length*sizeof(F) );
22 | }
23 |
24 | template
25 | inline const F* beagleCastIfNecessary(const F* from, F* cache,
26 | unsigned int length) {
27 | return from;
28 | }
29 |
30 | template
31 | inline const T* beagleCastIfNecessary(const F* from, T* cache,
32 | unsigned int length) {
33 | beagleMemCpy(cache, from, length);
34 | return cache;
35 | }
36 | //
37 | //template
38 | //inline void beagleCopyFromDeviceAndCastIfNecessary(GPUInterface* gpu, F* to, const F* from, F* cache,
39 | // unsigned int length) {
40 | // gpu->MemcpyDeviceToHost(to, from, sizeof(F) * kPatternCount);
41 | //}
42 | //
43 | //template
44 | //inline void beagleCopyFromDeviceAndCastIfNecessary(GPUInterface* gpu, T* to, const F* from, F* cache,
45 | // unsigned int length) {
46 | // gpu->MemcpyDeviceToHost(cache, from, sizeof(F) * kPatternCount);
47 | // beagleMemCpy(to, cache, kPatternCount);
48 | //}
49 |
50 |
51 | //#ifdef DOUBLE_PRECISION
52 | // gpu->MemcpyDeviceToHost(outLogLikelihoods, dIntegrationTmp, sizeof(Real) * kPatternCount);
53 | //#else
54 | // gpu->MemcpyDeviceToHost(hLogLikelihoodsCache, dIntegrationTmp, sizeof(Real) * kPatternCount);
55 | // MEMCNV(outLogLikelihoods, hLogLikelihoodsCache, kPatternCount, double);
56 | //#endif
57 |
58 |
59 |
60 | #endif /* GPU_PRECISION_H_ */
61 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/kernels/createCUDAKernels.bat:
--------------------------------------------------------------------------------
1 | ::
2 | :: windows script to create cuda files for each state count
3 | :: from the generic state count file
4 | :: @author Aaron Darling
5 | :: @author Daniel Ayres
6 | :: @author Marc Suchard
7 |
8 | ::"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
9 |
10 | echo // DO NOT EDIT -- autogenerated file -- edit kernels4.cu instead > tmp_kernels_sp_4.cu
11 | echo #define STATE_COUNT 4 >> tmp_kernels_sp_4.cu
12 | type kernels4.cu >> tmp_kernels_sp_4.cu
13 | nvcc.exe -o tmp_kernels_sp_4.ptx -ptx -arch compute_60 -I../../.. -DCUDA -O3 -m64 tmp_kernels_sp_4.cu
14 |
15 | FOR %%G IN (16 32 48 64 80 128 192 256) DO (
16 |
17 | echo // DO NOT EDIT -- autogenerated file -- edit kernelsX.cu instead > tmp_kernels_sp_%%G.cu
18 | echo #define STATE_COUNT %%G >> tmp_kernels_sp_%%G.cu
19 | type kernelsX.cu >> tmp_kernels_sp_%%G.cu
20 | nvcc.exe -o tmp_kernels_sp_%%G.ptx -ptx -arch compute_60 -I../../.. -DCUDA -O3 -m64 tmp_kernels_sp_%%G.cu
21 |
22 | )
23 |
24 | echo // DO NOT EDIT -- autogenerated file -- edit kernels4.cu instead > tmp_kernels_dp_4.cu
25 | echo #define STATE_COUNT 4 >> tmp_kernels_dp_4.cu
26 | echo #define DOUBLE_PRECISION >> tmp_kernels_dp_4.cu
27 | type kernels4.cu >> tmp_kernels_dp_4.cu
28 | nvcc.exe -o tmp_kernels_dp_4.ptx -ptx -arch compute_60 -I../../.. -DCUDA -O3 -m64 tmp_kernels_dp_4.cu
29 |
30 | FOR %%G IN (16 32 48 64 80 128 192 256) DO (
31 |
32 | echo // DO NOT EDIT -- autogenerated file -- edit kernelsX.cu instead > tmp_kernels_dp_%%G.cu
33 | echo #define STATE_COUNT %%G >> tmp_kernels_dp_%%G.cu
34 | echo #define DOUBLE_PRECISION >> tmp_kernels_dp_%%G.cu
35 | type kernelsX.cu >> tmp_kernels_dp_%%G.cu
36 | nvcc.exe -o tmp_kernels_dp_%%G.ptx -ptx -arch compute_60 -I../../.. -DCUDA -O3 -m64 tmp_kernels_dp_%%G.cu
37 |
38 | )
39 |
40 | set OUTFILE="BeagleCUDA_kernels.h"
41 |
42 | echo // auto-generated header file with CUDA kernels code > %OUTFILE%
43 |
44 | echo #ifndef __BeagleCUDA_kernels__ >> %OUTFILE%
45 | echo #define __BeagleCUDA_kernels__ >> %OUTFILE%
46 |
47 | FOR %%G IN (4 16 32 48 64 80 128 192 256) DO (
48 |
49 | ..\..\..\project\beagle-vs-2019-wix\bin2c.exe -p 0 -st -n KERNELS_STRING_SP_%%G tmp_kernels_sp_%%G.ptx >> %OUTFILE%
50 | ..\..\..\project\beagle-vs-2019-wix\bin2c.exe -p 0 -st -n KERNELS_STRING_DP_%%G tmp_kernels_dp_%%G.ptx >> %OUTFILE%
51 |
52 | )
53 |
54 | echo #endif // __BeagleCUDA_kernels__ >> %OUTFILE%
55 |
56 | del tmp_kernels*
57 |
58 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/kernels/createOpenCLHeader.bat:
--------------------------------------------------------------------------------
1 | ::
2 | :: windows script to create a single header with OpenCL
3 | :: kernels defined as variables
4 | :: @author Daniel Ayres
5 | :: @author Aaron Darling
6 | ::
7 | cd ..\..\..\libhmsbeagle\GPU\kernels
8 | echo #define STATE_COUNT 4 > kernels4.cl
9 | type ..\GPUImplDefs.h >> kernels4.cl
10 | type kernelsAll.cu >> kernels4.cl
11 | type kernels4.cu >> kernels4.cl
12 |
13 | FOR %%G IN (16 32 48 64 80 128 192 256) DO (
14 |
15 | echo #define STATE_COUNT %%G> kernels%%G.cl
16 | type ..\GPUImplDefs.h >> kernels%%G.cl
17 | type kernelsAll.cu >> kernels%%G.cl
18 | type kernelsX.cu >> kernels%%G.cl
19 |
20 | )
21 |
22 | echo #define STATE_COUNT 4 > kernels_dp_4.cl
23 | echo #define DOUBLE_PRECISION>> kernels_dp_4.cl
24 | type ..\GPUImplDefs.h >> kernels_dp_4.cl
25 | type kernelsAll.cu >> kernels_dp_4.cl
26 | type kernels4.cu >> kernels_dp_4.cl
27 |
28 | FOR %%G IN (16 32 48 64 80 128 192 256) DO (
29 |
30 | echo #define STATE_COUNT %%G> kernels_dp_%%G.cl
31 | echo #define DOUBLE_PRECISION>> kernels_dp_%%G.cl
32 | type ..\GPUImplDefs.h >> kernels_dp_%%G.cl
33 | type kernelsAll.cu >> kernels_dp_%%G.cl
34 | type kernelsX.cu >> kernels_dp_%%G.cl
35 |
36 | )
37 |
38 | set OUTFILE="BeagleOpenCL_kernels.h"
39 |
40 | echo // auto-generated header file with OpenCL kernels code > %OUTFILE%
41 |
42 | echo #ifndef __BeagleOpenCL_kernels__ >> %OUTFILE%
43 | echo #define __BeagleOpenCL_kernels__ >> %OUTFILE%
44 |
45 | FOR %%G IN (4 16 32 48 64 80 128 192 256) DO (
46 |
47 | ..\..\..\project\beagle-vs-2019-wix\bin2c.exe -p 0 -st -n KERNELS_STRING_SP_%%G kernels%%G.cl >> %OUTFILE%
48 | ..\..\..\project\beagle-vs-2019-wix\bin2c.exe -p 0 -st -n KERNELS_STRING_DP_%%G kernels_dp_%%G.cl >> %OUTFILE%
49 |
50 | del kernels%%G.cl
51 | del kernels_dp_%%G.cl
52 |
53 | )
54 |
55 | echo #endif // __BeagleOpenCL_kernels__ >> %OUTFILE%
56 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/kernels/make_cuda_kernels.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | NVCC="$1"
4 | NVCCFLAGS="$2"
5 | INCLUDE_DIRS="$3"
6 |
7 | echo "NVCC=${NVCC}"
8 | echo "NVCCFLAGS=${NVCCFLAGS}"
9 | echo "INCLUDE_DIRS=${INCLUDE_DIRS}"
10 |
11 | # For OpenCL, we need to generate the file `BeagleOpenCL_kernels.h` using the commands (and dependencies) below
12 |
13 | STATE_COUNT_LIST='16 32 48 64 80 128 192 256'
14 |
15 | srcdir="."
16 |
17 | # rules for building cuda files
18 | #BeagleCUDA_kernels.h: Makefile kernels4.cu kernels4Derivatives.cu kernelsX.cu kernelsXDerivatives.cu kernelsAll.cu ../GPUImplDefs.h
19 | echo "// auto-generated header file with CUDA kernels PTX code" > BeagleCUDA_kernels.h
20 | #
21 | # Compile single-precision kernels
22 | #
23 | # Compile 4-state model
24 | ${NVCC} -o BeagleCUDA_kernels.ptx --default-stream per-thread -ptx -DCUDA -DSTATE_COUNT=4 \
25 | $srcdir/kernels4.cu ${NVCCFLAGS} -DHAVE_CONFIG_H ${INCLUDE_DIRS} || { \rm BeagleCUDA_kernels.h; exit; }; \
26 | echo "#define KERNELS_STRING_SP_4 \"" | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
27 | cat BeagleCUDA_kernels.ptx | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
28 | echo "\"" >> BeagleCUDA_kernels.h
29 | #
30 | # HERE IS THE LOOP FOR GENERIC KERNELS
31 | #
32 | for s in $STATE_COUNT_LIST; do \
33 | echo "Making CUDA SP state count = $s" ; \
34 | ${NVCC} -o BeagleCUDA_kernels.ptx --default-stream per-thread -ptx -DCUDA -DSTATE_COUNT=$s \
35 | $srcdir/kernelsX.cu ${NVCCFLAGS} -DHAVE_CONFIG_H ${INCLUDE_DIRS} || { \rm BeagleCUDA_kernels.h; exit; }; \
36 | echo "#define KERNELS_STRING_SP_$s \"" | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
37 | cat BeagleCUDA_kernels.ptx | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
38 | echo "\"" >> BeagleCUDA_kernels.h; \
39 | done
40 |
41 | #
42 | # Compile double-precision kernels
43 | #
44 | # Compile 4-state model
45 | ${NVCC} -o BeagleCUDA_kernels.ptx --default-stream per-thread -ptx -DCUDA -DSTATE_COUNT=4 -DDOUBLE_PRECISION \
46 | $srcdir/kernels4.cu ${NVCCFLAGS} -DHAVE_CONFIG_H ${INCLUDE_DIRS} || { \rm BeagleCUDA_kernels.h; exit; }; \
47 | echo "#define KERNELS_STRING_DP_4 \"" | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
48 | cat BeagleCUDA_kernels.ptx | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
49 | echo "\"" >> BeagleCUDA_kernels.h
50 | #
51 | # HERE IS THE LOOP FOR GENERIC KERNELS
52 | #
53 | for s in $STATE_COUNT_LIST; do \
54 | echo "Making CUDA DP state count = $s" ; \
55 | ${NVCC} -o BeagleCUDA_kernels.ptx --default-stream per-thread -ptx -DCUDA -DSTATE_COUNT=$s -DDOUBLE_PRECISION \
56 | $srcdir/kernelsX.cu ${NVCCFLAGS} -DHAVE_CONFIG_H ${INCLUDE_DIRS} || { \rm BeagleCUDA_kernels.h; exit; }; \
57 | echo "#define KERNELS_STRING_DP_$s \"" | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
58 | cat BeagleCUDA_kernels.ptx | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleCUDA_kernels.h; \
59 | echo "\"" >> BeagleCUDA_kernels.h; \
60 | done
61 |
--------------------------------------------------------------------------------
/libhmsbeagle/GPU/kernels/make_opencl_kernels.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # For OpenCL, we need to generate the file `BeagleOpenCL_kernels.h` using the commands (and dependencies) below
4 |
5 | STATE_COUNT_LIST='16 32 48 64 80 128 192 256'
6 |
7 | srcdir="."
8 |
9 | # rules for building opencl files
10 | #BeagleOpenCL_kernels.h: Makefile kernels4.cu kernelsX.cu kernelsAll.cu ../GPUImplDefs.h
11 | echo "// auto-generated header file with OpenCL kernels code" > BeagleOpenCL_kernels.h
12 |
13 | #
14 | # Compile single-precision kernels
15 | #
16 | # Compile 4-state model
17 | echo "#define KERNELS_STRING_SP_4 \"" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
18 | echo "#define STATE_COUNT 4" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
19 | cat $srcdir/../GPUImplDefs.h | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
20 | cat $srcdir/kernelsAll.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
21 | cat $srcdir/kernels4.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
22 | cat $srcdir/kernels4Derivatives.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
23 | echo "\"" >> BeagleOpenCL_kernels.h
24 |
25 | #
26 | # HERE IS THE LOOP FOR GENERIC KERNELS
27 | #
28 | for s in $STATE_COUNT_LIST
29 | do
30 | echo "Making OpenCL SP state count = $s" ; \
31 | echo "#define KERNELS_STRING_SP_$s \"" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
32 | echo "#define STATE_COUNT $s" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
33 | cat $srcdir/../GPUImplDefs.h | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
34 | cat $srcdir/kernelsAll.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
35 | cat $srcdir/kernelsX.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
36 | cat $srcdir/kernelsXDerivatives.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
37 | echo "\"" >> BeagleOpenCL_kernels.h; \
38 | done
39 |
40 | #
41 | # Compile double-precision kernels
42 | #
43 | # Compile 4-state model
44 | echo "#define KERNELS_STRING_DP_4 \"" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
45 | echo "#define STATE_COUNT 4" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
46 | echo "#define DOUBLE_PRECISION" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
47 | cat $srcdir/../GPUImplDefs.h | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
48 | cat $srcdir/kernelsAll.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
49 | cat $srcdir/kernels4.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
50 | cat $srcdir/kernels4Derivatives.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h
51 | echo "\"" >> BeagleOpenCL_kernels.h
52 |
53 | #
54 | # HERE IS THE LOOP FOR GENERIC KERNELS
55 | #
56 | for s in $STATE_COUNT_LIST
57 | do
58 | echo "Making OpenCL DP state count = $s DP"; \
59 | echo "#define KERNELS_STRING_DP_$s \"" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
60 | echo "#define STATE_COUNT $s" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
61 | echo "#define DOUBLE_PRECISION" | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
62 | cat $srcdir/../GPUImplDefs.h | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
63 | cat $srcdir/kernelsAll.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
64 | cat $srcdir/kernelsX.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
65 | cat $srcdir/kernelsXDerivatives.cu | sed 's/\\/\\\\/g' | sed 's/\"/\\"/g' | sed 's/$/\\n\\/' >> BeagleOpenCL_kernels.h; \
66 | echo "\"" >> BeagleOpenCL_kernels.h; \
67 | done
68 |
--------------------------------------------------------------------------------
/libhmsbeagle/JNI/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # clang++ -dynamiclib -undefined dynamic_lookup -o libhmsbeagle-jni.jnilib beagle_BeagleJNIWrapper.o
2 | # cc -bundle -l hmsbeagle -o libhmsbeagle-jni.jnilib beagle_BeagleJNIWrapper.o
3 |
4 | add_library(hmsbeagle-jni SHARED
5 | beagle_BeagleJNIWrapper.cpp
6 | beagle_BeagleJNIWrapper.h
7 | )
8 |
9 | target_link_libraries(hmsbeagle-jni hmsbeagle)
10 |
11 | if(APPLE)
12 | set_target_properties(hmsbeagle-jni PROPERTIES PREFIX "lib" SUFFIX ".jnilib")
13 | elseif(WIN32)
14 | set_target_properties(hmsbeagle-jni PROPERTIES PREFIX "" SUFFIX "64.dll")
15 | elseif(UNIX)
16 | set_target_properties(hmsbeagle-jni PROPERTIES PREFIX "lib" SUFFIX ".so")
17 | endif(APPLE)
18 |
19 | install(TARGETS hmsbeagle-jni
20 | DESTINATION ${BEAGLE_INSTALL_DIR}
21 | )
22 |
--------------------------------------------------------------------------------
/libhmsbeagle/benchmark/BeagleBenchmark.h:
--------------------------------------------------------------------------------
1 | /*
2 | * beagleBenchmark.h
3 | * Resource/implementation benchmarking
4 | *
5 | * Copyright 2009 Phylogenetic Likelihood Working Group
6 | *
7 | * This file is part of BEAGLE.
8 | *
9 | * Use of this source code is governed by an MIT-style
10 | * license that can be found in the LICENSE file or at
11 | * https://opensource.org/licenses/MIT.
12 | *
13 | * @author Daniel Ayres
14 | */
15 |
16 | #ifndef __beagle_benchmark__
17 | #define __beagle_benchmark__
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include "libhmsbeagle/beagle.h"
32 | #include "libhmsbeagle/benchmark/linalg.h"
33 |
34 | #define BENCHMARK_REPLICATES 15
35 | #define GT_RAND_MAX 0x7fffffff
36 |
37 | #ifdef _WIN32
38 | //From January 1, 1601 (UTC). to January 1,1970
39 | #define FACTOR 0x19db1ded53e8000
40 | #include
41 | #include
42 | #else
43 | #include
44 | #endif
45 |
46 | namespace beagle {
47 | namespace benchmark {
48 |
49 | int benchmarkResource(int resource,
50 | int stateCount,
51 | int ntaxa,
52 | int nsites,
53 | bool manualScaling,
54 | int rateCategoryCount,
55 | int nreps,
56 | int compactTipCount,
57 | int rescaleFrequency,
58 | bool unrooted,
59 | bool calcderivs,
60 | int eigenCount,
61 | int partitionCount,
62 | long preferenceFlags,
63 | long requirementFlags,
64 | int* resourceNumber,
65 | char** implName,
66 | long* benchedFlags,
67 | double* benchmarkResult,
68 | bool instOnly);
69 |
70 | #endif // __beagle_benchmark__
71 |
72 |
73 | } // namespace benchmark
74 | } // namespace beagle
75 |
--------------------------------------------------------------------------------
/libhmsbeagle/benchmark/linalg.h:
--------------------------------------------------------------------------------
1 | /* linalg.h
2 | |
3 | | Prototypes for matrix-inversion and eigensystem functions
4 | |
5 | | Copyright (c) 1998 by David L. Swofford, Smithsonian Institution.
6 | | All rights reserved.
7 | |
8 | | NOTE: if ANSI function prototypes are not supported, define NO_PROTOTYPES
9 | | before including this file.
10 | */
11 |
12 | #define RC_COMPLEX_EVAL 2 /* code that complex eigenvalue obtained */
13 |
14 | extern int InvertMatrix (double **a, int n, double *col, int *indx, double **a_inv);
15 | extern int LUDecompose (double **a, int n, double *vv, int *indx, double *pd);
16 | int EigenRealGeneral (int n, double **a, double *v, double *vi, double **u, int *iwork, double *work);
17 |
18 |
19 | template T **New2DArray(unsigned f , unsigned s)
20 | {
21 | T **temp;
22 | temp = new T *[f];
23 | *temp = new T [f * s];
24 | for (unsigned fIt = 1 ; fIt < f ; fIt ++)
25 | temp[fIt] = temp[fIt -1] + s ;
26 | return temp;
27 | }
28 |
29 | /*--------------------------------------------------------------------------------------------------------------------------
30 | | Delete a 2 Dimensional Array New2DArray
31 | */
32 | template inline void Delete2DArray (T **temp)
33 | {
34 | if (temp)
35 | {
36 | if (*temp)
37 | delete [] * temp;
38 | delete [] temp;
39 | }
40 | }
--------------------------------------------------------------------------------
/libhmsbeagle/hmsbeagle-1.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@CMAKE_INSTALL_PREFIX@
2 | exec_prefix=${prefix}
3 | libdir=${exec_prefix}/lib
4 | includedir=${prefix}/include
5 |
6 | Name: hmsbeagle
7 | Description: A library to calculate phylogenetic likelihoods.
8 | Requires:
9 | Version: @BEAGLE_VERSION@
10 | Libs: -L"${libdir}" -lhmsbeagle
11 | Cflags: -I"${includedir}/libhmsbeagle-1"
12 |
--------------------------------------------------------------------------------
/libhmsbeagle/platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * platform.h
3 | * Definitions and compiler support for platform-specific features
4 | *
5 | * Copyright 2009 Phylogenetic Likelihood Working Group
6 | *
7 | * This file is part of BEAGLE.
8 | *
9 | * Use of this source code is governed by an MIT-style
10 | * license that can be found in the LICENSE file or at
11 | * https://opensource.org/licenses/MIT.
12 | *
13 | * @author Aaron Darling
14 | */
15 |
16 | #ifndef __beagle_platform__
17 | #define __beagle_platform__
18 |
19 | #ifdef _WIN32
20 | // needed to export library symbols
21 | #ifdef _EXPORTING
22 | #define BEAGLE_DLLEXPORT __declspec(dllexport)
23 | #else
24 | #define BEAGLE_DLLEXPORT __declspec(dllimport)
25 | #endif
26 | /*
27 | // automatically include the appropriate beagle library
28 | #ifdef _WIN64
29 | #ifdef _DEBUG
30 | #pragma comment( lib, "libhmsbeagle64d" )
31 | #else
32 | #pragma comment( lib, "libhmsbeagle64" )
33 | #endif
34 | #else
35 | #ifdef _DEBUG
36 | #pragma comment( lib, "libhmsbeagle32d" )
37 | #else
38 | #pragma comment( lib, "libhmsbeagle32" )
39 | #endif
40 | #endif
41 | */
42 |
43 |
44 | #else // not windows
45 | #define BEAGLE_DLLEXPORT
46 | #endif
47 |
48 | #ifndef M_LN2 /* Work around for OS X 10.8 and gcc 4.7.1 */
49 | #define M_LN2 0.693147180559945309417232121458176568 /* log_e 2 */
50 | #endif
51 |
52 | #endif
53 |
54 |
--------------------------------------------------------------------------------
/libhmsbeagle/plugin/BeaglePlugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #include "Plugin.h"
9 |
10 | namespace beagle {
11 |
12 | class BeaglePlugin : public Plugin
13 | {
14 | public:
15 | BeaglePlugin(const char* plugin_name)
16 | : Plugin(plugin_name,"Text") { }
17 | virtual const char* getSayHelloString() const = 0;
18 | };
19 |
20 | } // namespace beagle
21 |
22 |
23 |
--------------------------------------------------------------------------------
/libhmsbeagle/plugin/LibtoolSharedLibrary.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | *
7 | * This header implements unix libraries using libtool loading instead of
8 | * the standard dlopen() interface
9 | */
10 |
11 | #ifndef __LIBTOOLSHAREDLIBRARY_H__
12 | #define __LIBTOOLSHAREDLIBRARY_H__
13 |
14 | #ifdef HAVE_CONFIG_H
15 | #include "libhmsbeagle/config.h"
16 | #endif
17 |
18 | #include "libhmsbeagle/plugin/SharedLibrary.h"
19 |
20 | #ifdef HAVE_LIBLTDL
21 |
22 | // use libtool-devel library loading
23 | #include
24 | #include
25 |
26 |
27 | namespace beagle {
28 | namespace plugin {
29 |
30 | class UnixSharedLibrary : public SharedLibrary
31 | {
32 | public:
33 | UnixSharedLibrary(const char* name);
34 | ~UnixSharedLibrary();
35 |
36 | void* findSymbol(const char* name);
37 |
38 | private:
39 | lt_dlhandle m_handle;
40 | };
41 |
42 | UnixSharedLibrary::UnixSharedLibrary(const char* name)
43 | : m_handle(0)
44 | {
45 | lt_dlinit();
46 | std::string libname = "lib";
47 | libname += name;
48 | #ifdef DLS_MACOS
49 | libname += ".";
50 | libname += PLUGIN_VERSION;
51 | libname += ".so";
52 | #elif defined(__OpenBSD__) || defined(__NetBSD__)
53 | libname += ".so.";
54 | libname += PLUGIN_VERSION;
55 | libname += ".0";
56 | #else
57 | libname += ".so.";
58 | libname += PLUGIN_VERSION;
59 | libname += ".0.0";
60 | #endif
61 |
62 | m_handle = lt_dlopen(libname.c_str());
63 | if (m_handle == 0)
64 | {
65 | const char* s = lt_dlerror();
66 | throw SharedLibraryException(s?s:"Exact Error Not Reported");
67 | }
68 | }
69 | UnixSharedLibrary::~UnixSharedLibrary() {
70 | lt_dlclose(m_handle);
71 | lt_dlexit();
72 | }
73 |
74 | void* UnixSharedLibrary::findSymbol(const char* name)
75 | {
76 | void* sym = lt_dlsym(m_handle,name);
77 | if (sym == 0)
78 | throw SharedLibraryException("Symbol Not Found");
79 | else
80 | return sym;
81 | }
82 |
83 | } // namespace plugin
84 | } // namespace beagle
85 |
86 | #endif // HAVE_LIBLTDL
87 |
88 | #endif // __LIBTOOLSHAREDLIBRARY_H__
89 |
90 |
--------------------------------------------------------------------------------
/libhmsbeagle/plugin/Plugin.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 | // Plugin.cxx
8 |
9 | #include "libhmsbeagle/plugin/Plugin.h"
10 | #include
11 | using namespace std;
12 |
13 | namespace beagle {
14 | namespace plugin {
15 |
16 | PluginManager* PluginManager::ms_instance = 0;
17 |
18 | PluginManager& PluginManager::instance()
19 | {
20 | if (! ms_instance)
21 | ms_instance = new PluginManager();
22 | return *ms_instance;
23 | }
24 | Plugin* PluginManager::findPlugin(const char* name) noexcept(false)
25 | {
26 | if (m_plugin_map.count(name) > 0)
27 | return m_plugin_map[name]->m_plugin;
28 |
29 | PluginInfo* pi = new PluginInfo;
30 | pi->m_library = SharedLibrary::openSharedLibrary(name);
31 | plugin_init_func pif =
32 | findSymbol(*pi->m_library,"plugin_init");
33 |
34 | pi->m_plugin = (*pif)();
35 | if (!pi->m_plugin)
36 | {
37 | delete pi;
38 | throw SharedLibraryException("plugin_init error");
39 | }
40 | m_plugin_map[name]=pi;
41 | return pi->m_plugin;
42 | }
43 |
44 | } // namespace plugin
45 | } // namespace beagle
46 |
--------------------------------------------------------------------------------
/libhmsbeagle/plugin/Plugin.h:
--------------------------------------------------------------------------------
1 | /**
2 | * libhmsbeagle plugin system
3 | * @author Aaron E. Darling
4 | * Based on code found in "Dynamic Plugins for C++" by Arthur J. Musgrove
5 | * and published in Dr. Dobbs Journal, July 1, 2004.
6 | */
7 |
8 | #ifndef __PLUGIN_H__
9 | #define __PLUGIN_H__
10 |
11 | #ifdef HAVE_CONFIG_H
12 | #include "libhmsbeagle/config.h"
13 | #endif
14 |
15 | #include "libhmsbeagle/platform.h"
16 | #include "libhmsbeagle/BeagleImpl.h"
17 | #include "libhmsbeagle/plugin/SharedLibrary.h"
18 | #include
19 | #include
20 | #include